Class: Phlex::Stimulus::Components::Base Abstract
- Inherits:
-
HTML
- Object
- HTML
- Phlex::Stimulus::Components::Base
- Defined in:
- lib/phlex/stimulus/components/base.rb
Overview
Abstract class for Phlex components that render HTML with better sorbet and stimulus support.
Direct Known Subclasses
Instance Method Summary collapse
-
#attrbool(val) ⇒ Object
Converts a Ruby boolean to a boolean value in HTML attributes.
-
#class_list(*args) ⇒ Object
(also: #strlist)
Merges the given list of class names (with optional nils) into a single class string separated by spaces.
-
#class_list!(args) ⇒ Object
(also: #strlist!)
: (Array) -> String.
-
#event(event_name, full_action_name) ⇒ Object
Constructs a Stimulus event hook string eg.
-
#h ⇒ Object
: -> ApplicationController::HelperProxy.
-
#image_exists?(path) ⇒ Boolean
: (String) -> bool.
-
#inspect ⇒ Object
: -> String.
-
#newline(&block) ⇒ Object
Output a single newline character.
Instance Method Details
#attrbool(val) ⇒ Object
Converts a Ruby boolean to a boolean value in HTML attributes.
Returns "true" for a truthy value, otherwise nil.
: (bool) -> String?
34 35 36 |
# File 'lib/phlex/stimulus/components/base.rb', line 34 def attrbool(val) 'true' if val end |
#class_list(*args) ⇒ Object Also known as: strlist
Merges the given list of class names (with optional nils) into a single class string separated by spaces.
: (*String?) -> String
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/phlex/stimulus/components/base.rb', line 54 def class_list(*args) buff = String.new args.each do |arg| next unless arg buff << arg << ' ' end buff.strip end |
#class_list!(args) ⇒ Object Also known as: strlist!
: (Array) -> String
67 68 69 |
# File 'lib/phlex/stimulus/components/base.rb', line 67 def class_list!(args) class_list(*T.unsafe(args)) end |
#event(event_name, full_action_name) ⇒ Object
Constructs a Stimulus event hook string eg.
event('click', 'summary#redirect') #=> "click->summary#redirect"
: (String, String) -> String
24 25 26 |
# File 'lib/phlex/stimulus/components/base.rb', line 24 def event(event_name, full_action_name) "#{event_name}->#{full_action_name}" end |
#h ⇒ Object
: -> ApplicationController::HelperProxy
11 |
# File 'lib/phlex/stimulus/components/base.rb', line 11 def h = view_context |
#image_exists?(path) ⇒ Boolean
: (String) -> bool
75 76 77 |
# File 'lib/phlex/stimulus/components/base.rb', line 75 def image_exists?(path) Boolean(h.resolve_asset_path(path)) end |
#inspect ⇒ Object
: -> String
14 15 16 |
# File 'lib/phlex/stimulus/components/base.rb', line 14 def inspect "#<#{self.class.name}>" end |
#newline(&block) ⇒ Object
Output a single newline character. If a block is given, a space will be output before and after the block.
: ?{ -> void } -> void
42 43 44 45 46 47 48 |
# File 'lib/phlex/stimulus/components/base.rb', line 42 def newline(&block) plain "\n" return unless block block.call plain "\n" end |