Class: Futurism::Helpers::WrappingFuturismElement

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers, MessageVerifier, OptionsTransformer
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 OptionsTransformer

#dump_options, #load_options

Methods included from MessageVerifier

message_verifier, #message_verifier

Constructor Details

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

Returns a new instance of WrappingFuturismElement.



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/futurism/helpers.rb', line 65

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.



63
64
65
# File 'lib/futurism/helpers.rb', line 63

def broadcast_each
  @broadcast_each
end

#controllerObject (readonly)

Returns the value of attribute controller.



63
64
65
# File 'lib/futurism/helpers.rb', line 63

def controller
  @controller
end

#data_attributesObject (readonly)

Returns the value of attribute data_attributes.



63
64
65
# File 'lib/futurism/helpers.rb', line 63

def data_attributes
  @data_attributes
end

#eagerObject (readonly)

Returns the value of attribute eager.



63
64
65
# File 'lib/futurism/helpers.rb', line 63

def eager
  @eager
end

#extendsObject (readonly)

Returns the value of attribute extends.



63
64
65
# File 'lib/futurism/helpers.rb', line 63

def extends
  @extends
end

#html_optionsObject (readonly)

Returns the value of attribute html_options.



63
64
65
# File 'lib/futurism/helpers.rb', line 63

def html_options
  @html_options
end

#modelObject (readonly)

Returns the value of attribute model.



63
64
65
# File 'lib/futurism/helpers.rb', line 63

def model
  @model
end

#optionsObject (readonly)

Returns the value of attribute options.



63
64
65
# File 'lib/futurism/helpers.rb', line 63

def options
  @options
end

#placeholderObject (readonly)

Returns the value of attribute placeholder.



63
64
65
# File 'lib/futurism/helpers.rb', line 63

def placeholder
  @placeholder
end

Instance Method Details

#datasetObject



77
78
79
80
81
82
83
84
85
# File 'lib/futurism/helpers.rb', line 77

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

#renderObject



87
88
89
90
91
92
93
94
95
96
# File 'lib/futurism/helpers.rb', line 87

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



98
99
100
# File 'lib/futurism/helpers.rb', line 98

def transformed_options
  dump_options(options)
end