module Lookbook::UiElementsHelper
def code(language = :html, **opts, &block)
-
block
(Proc
) -- Code block -
opts
(Hash
) -- Options hash -
language
(Symbol
) -- Which language the code is written in
def code(language = :html, **opts, &block) opts[:language] ||= language lookbook_render :code, **opts, &block end
def component_class(ref)
- Api: - private
def component_class(ref) klass = COMPONENT_CLASSES[ref] if klass.nil? ref = ref.to_s.tr("-", "_") class_namespace = ref.camelize begin klass = "Lookbook::#{class_namespace}::Component".constantize rescue klass = "Lookbook::#{class_namespace}Component".constantize end COMPONENT_CLASSES[ref] = klass end klass end
def icon(name, **opts)
-
opts
(Hash
) -- Options hash -
name
(Symbol, String
) -- Name of the icon
def icon(name, **opts) lookbook_render(:icon, name: name, **opts) end
def lookbook_render(ref, **attrs, &block)
- Api: - private
def lookbook_render(ref, **attrs, &block) comp = if ref.is_a? ViewComponent::Base ref else klass = component_class(ref) attrs.key?(:content) ? klass.new(**attrs.except(:content)).with_content(attrs[:content]) : klass.new(**attrs) end if block && !attrs.key?(:content) public_send render_method_name, comp, &block else public_send render_method_name, comp end end
def lookbook_tag(tag = :div, **attrs, &block)
- Api: - private
def lookbook_tag(tag = :div, **attrs, &block) lookbook_render(:tag, tag: tag, **attrs, &block) end
def prose(**opts, &block)
- Api: - private
def prose(**opts, &block) lookbook_render(:prose, **opts, &block) end
def render_method_name
- Api: - private
def render_method_name if Rails.application.config.view_component.render_monkey_patch_enabled || Rails.version.to_f >= 6.1 :render else :render_component end end