Sha256: 0678b475a08a7c3caec7889bd78d028c6c8fb781a3ce8b54056e4fd6a7bc3247
Contents?: true
Size: 1.49 KB
Versions: 1
Compression:
Stored size: 1.49 KB
Contents
module Futurism module Helpers def futurize(records_or_string = nil, extends:, **options, &block) placeholder = capture(&block) if records_or_string.is_a?(ActiveRecord::Base) || records_or_string.is_a?(ActiveRecord::Relation) futurize_active_record(records_or_string, extends: extends, placeholder: placeholder) elsif records_or_string.is_a?(String) futurize_with_options(extends: extends, partial: records_or_string, locals: options, placeholder: placeholder) else futurize_with_options(extends: extends, placeholder: placeholder, **options) end end def futurize_with_options(extends:, placeholder:, **options) case extends when :tr content_tag :tr, placeholder, data: {signed_params: futurism_signed_params(options)}, is: "futurism-table-row" else content_tag :"futurism-element", placeholder, data: {signed_params: futurism_signed_params(options)} end end def futurize_active_record(records, extends:, placeholder:) Array(records).map { |record| case extends when :tr content_tag :tr, placeholder, data: {signed_params: futurism_signed_params(record)}, is: "futurism-table-row" else content_tag :"futurism-element", placeholder, data: {signed_params: futurism_signed_params(record)} end }.join.html_safe end def futurism_signed_params(params) Rails.application.message_verifier("futurism").generate(params) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
futurism-0.2.0 | lib/futurism/helpers.rb |