Module: Lookbook::ComponentHelper

Included in:
BaseComponent, TagComponent
Defined in:
app/helpers/lookbook/component_helper.rb

Constant Summary collapse

COMPONENT_CLASSES =

cache for constantized references

{}

Instance Method Summary collapse

Instance Method Details

#class_names(*args) ⇒ Object



25
26
27
28
# File 'app/helpers/lookbook/component_helper.rb', line 25

def class_names(*args)
  tokens = build_tag_values(*args).flat_map { |value| value.to_s.split(/\s+/) }.uniq
  safe_join(tokens, " ")
end

#code(language = :html, **attrs, &block) ⇒ Object



9
10
11
12
# File 'app/helpers/lookbook/component_helper.rb', line 9

def code(language = :html, **attrs, &block)
  attrs[:language] ||= language
  render Lookbook::Code::Component.new(**attrs), &block
end

#icon(name, **attrs) ⇒ Object



5
6
7
# File 'app/helpers/lookbook/component_helper.rb', line 5

def icon(name, **attrs)
  render Lookbook::Icon::Component.new(name: name, **attrs)
end

#render_component(ref, **attrs, &block) ⇒ Object



14
15
16
17
18
# File 'app/helpers/lookbook/component_helper.rb', line 14

def render_component(ref, **attrs, &block)
  klass = component_class(ref)
  comp = attrs.key?(:content) ? klass.new(**attrs.except(:content)).with_content(attrs[:content]) : klass.new(**attrs)
  render comp, &block
end

#render_tag(tag = :div, **attrs, &block) ⇒ Object



20
21
22
# File 'app/helpers/lookbook/component_helper.rb', line 20

def render_tag(tag = :div, **attrs, &block)
  render Lookbook::TagComponent.new(tag: tag, **attrs), &block
end