Skip to content

Commit

Permalink
merge data attributes from html_options
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbarrow committed Sep 7, 2020
1 parent 17e0a89 commit e7e92e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 8 additions & 7 deletions lib/futurism/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,32 @@ def futurize_active_record(records, extends:, placeholder:, **options)
class Element
include ActionView::Helpers

attr_reader :extends, :placeholder, :html_options, :model, :options
attr_reader :extends, :placeholder, :html_options, :data_attributes, :model, :options

def initialize(extends:, placeholder:, options:)
@extends = extends
@placeholder = placeholder
@html_options = options.delete(:html_options) || {}
@data_attributes = html_options.fetch(:data, {}).except(:sgid, :signed_params)
@model = options.delete(:model)
@options = options
@options = data_attributes.any? ? options.merge(data: data_attributes) : options
end

def dataset
{
data_attributes.merge({
signed_params: signed_params,
sgid: model && model.to_sgid.to_s
}
})
end

def render
case extends
when :li
content_tag :li, placeholder, {data: dataset, is: "futurism-li"}.merge(html_options)
content_tag :li, placeholder, html_options.deep_merge({data: dataset, is: "futurism-li"})
when :tr
content_tag :tr, placeholder, {data: dataset, is: "futurism-table-row"}.merge(html_options)
content_tag :tr, placeholder, html_options.deep_merge({data: dataset, is: "futurism-table-row"})
else
content_tag :"futurism-element", placeholder, {data: dataset}.merge(html_options)
content_tag :"futurism-element", placeholder, html_options.deep_merge({data: dataset})
end
end

Expand Down
2 changes: 0 additions & 2 deletions test/helper/helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class Futurism::HelperTest < ActionView::TestCase
assert_equal signed_params({data: {controller: "test"}}), element.children.first["data-signed-params"]
end



def signed_params(params)
Rails.application.message_verifier("futurism").generate(params)
end
Expand Down

0 comments on commit e7e92e4

Please sign in to comment.