Module: Trek::StimulusHelpers
- Included in:
- Component, Form::ContentEditorComponent, Form::ImageFieldComponent, Form::SoundFieldComponent, Form::SwitchBoxComponent
- Defined in:
- app/helpers/trek/stimulus_helpers.rb
Instance Method Summary collapse
- #stimulus_action(action_or_action_method, action_method = nil) ⇒ Object
- #stimulus_class(klass) ⇒ Object
- #stimulus_class_hash(key, klass) ⇒ Object
- #stimulus_class_key(key) ⇒ Object
- #stimulus_target(target) ⇒ Object
-
#stimulus_target_hash(target) ⇒ Object
def stimulus_target(target) “#identifier.#target.to_s.camelcase(:lower)” end.
- #stimulus_target_key ⇒ Object
- #stimulus_value(value) ⇒ Object
- #stimulus_value_hash(key, value) ⇒ Object
- #stimulus_value_key(key) ⇒ Object
Instance Method Details
#stimulus_action(action_or_action_method, action_method = nil) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'app/helpers/trek/stimulus_helpers.rb', line 3 def stimulus_action(action_or_action_method, action_method = nil) if action_or_action_method.is_a?(Hash) action_or_action_method.map { |action, method| stimulus_action(action, method) }.join(" ") elsif action_method "#{action_or_action_method}->#{identifier}##{action_method.to_s.camelcase(:lower)}" else "#{identifier}##{action_or_action_method.to_s.camelcase(:lower)}" end end |
#stimulus_class(klass) ⇒ Object
41 42 43 |
# File 'app/helpers/trek/stimulus_helpers.rb', line 41 def stimulus_class(klass) klass end |
#stimulus_class_hash(key, klass) ⇒ Object
31 32 33 34 35 |
# File 'app/helpers/trek/stimulus_helpers.rb', line 31 def stimulus_class_hash(key, klass) { "#{stimulus_class_key(key)}": stimulus_class(klass) } end |
#stimulus_class_key(key) ⇒ Object
37 38 39 |
# File 'app/helpers/trek/stimulus_helpers.rb', line 37 def stimulus_class_key(key) "#{identifier}-#{key.parameterize}-class" end |
#stimulus_target(target) ⇒ Object
27 28 29 |
# File 'app/helpers/trek/stimulus_helpers.rb', line 27 def stimulus_target(target) target.to_s.camelcase(:lower) end |
#stimulus_target_hash(target) ⇒ Object
def stimulus_target(target)
"#{identifier}.#{target.to_s.camelcase(:lower)}"
end
17 18 19 20 21 |
# File 'app/helpers/trek/stimulus_helpers.rb', line 17 def stimulus_target_hash(target) { "#{stimulus_target_key}": stimulus_target(target) } end |
#stimulus_target_key ⇒ Object
23 24 25 |
# File 'app/helpers/trek/stimulus_helpers.rb', line 23 def stimulus_target_key "#{identifier}-target" end |
#stimulus_value(value) ⇒ Object
55 56 57 |
# File 'app/helpers/trek/stimulus_helpers.rb', line 55 def stimulus_value(value) value end |
#stimulus_value_hash(key, value) ⇒ Object
45 46 47 48 49 |
# File 'app/helpers/trek/stimulus_helpers.rb', line 45 def stimulus_value_hash(key, value) { "#{stimulus_value_key(key)}": stimulus_value(value) } end |
#stimulus_value_key(key) ⇒ Object
51 52 53 |
# File 'app/helpers/trek/stimulus_helpers.rb', line 51 def stimulus_value_key(key) "#{identifier}-#{key.parameterize}-value" end |