Class: Futurism::Helpers::WrappingFuturismElement

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers, MessageVerifier
Defined in:
lib/futurism/helpers.rb

Overview

wraps functionality for rendering a futurism element

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MessageVerifier

message_verifier, #message_verifier

Constructor Details

#initialize(extends:, placeholder:, options:) ⇒ WrappingFuturismElement

Returns a new instance of WrappingFuturismElement.



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/futurism/helpers.rb', line 61

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

Instance Attribute Details

#broadcast_eachObject (readonly)

Returns the value of attribute broadcast_each.



59
60
61
# File 'lib/futurism/helpers.rb', line 59

def broadcast_each
  @broadcast_each
end

#controllerObject (readonly)

Returns the value of attribute controller.



59
60
61
# File 'lib/futurism/helpers.rb', line 59

def controller
  @controller
end

#data_attributesObject (readonly)

Returns the value of attribute data_attributes.



59
60
61
# File 'lib/futurism/helpers.rb', line 59

def data_attributes
  @data_attributes
end

#eagerObject (readonly)

Returns the value of attribute eager.



59
60
61
# File 'lib/futurism/helpers.rb', line 59

def eager
  @eager
end

#extendsObject (readonly)

Returns the value of attribute extends.



59
60
61
# File 'lib/futurism/helpers.rb', line 59

def extends
  @extends
end

#html_optionsObject (readonly)

Returns the value of attribute html_options.



59
60
61
# File 'lib/futurism/helpers.rb', line 59

def html_options
  @html_options
end

#modelObject (readonly)

Returns the value of attribute model.



59
60
61
# File 'lib/futurism/helpers.rb', line 59

def model
  @model
end

#optionsObject (readonly)

Returns the value of attribute options.



59
60
61
# File 'lib/futurism/helpers.rb', line 59

def options
  @options
end

#placeholderObject (readonly)

Returns the value of attribute placeholder.



59
60
61
# File 'lib/futurism/helpers.rb', line 59

def placeholder
  @placeholder
end

Instance Method Details

#datasetObject



73
74
75
76
77
78
79
80
81
# File 'lib/futurism/helpers.rb', line 73

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

#renderObject



83
84
85
86
87
88
89
90
91
92
# File 'lib/futurism/helpers.rb', line 83

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

#transformed_optionsObject



94
95
96
97
98
99
100
101
102
103
# File 'lib/futurism/helpers.rb', line 94

def transformed_options
  require_relative "shims/deep_transform_values" unless options.respond_to? :deep_transform_values

  options.deep_transform_values do |value|
    next(value) unless value.respond_to?(:to_global_id)
    next(value) if value.is_a?(ActiveRecord::Base) && value.new_record?

    value.to_global_id.to_s
  end
end