Class: Phlex::Stimulus::Components::Base Abstract

Inherits:
HTML
  • Object
show all
Defined in:
lib/phlex/stimulus/components/base.rb

Overview

This class is abstract.

Abstract class for Phlex components that render HTML with better sorbet and stimulus support.

Direct Known Subclasses

Controller

Instance Method Summary collapse

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

#hObject

: -> ApplicationController::HelperProxy



11
# File 'lib/phlex/stimulus/components/base.rb', line 11

def h = view_context

#image_exists?(path) ⇒ Boolean

: (String) -> bool

Returns:

  • (Boolean)


75
76
77
# File 'lib/phlex/stimulus/components/base.rb', line 75

def image_exists?(path)
  Boolean(h.resolve_asset_path(path))
end

#inspectObject

: -> 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