Class: Daisy::Mockup::CodeComponent
- Inherits:
-
LocoMotion::BaseComponent
- Object
- ViewComponent::Base
- LocoMotion::BaseComponent
- Daisy::Mockup::CodeComponent
- Defined in:
- app/components/daisy/mockup/code_component.rb
Defined Under Namespace
Modules: Daisy
Constant Summary
Constants inherited from LocoMotion::BaseComponent
LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS
Instance Attribute Summary
Attributes inherited from LocoMotion::BaseComponent
Instance Method Summary collapse
-
#before_render ⇒ Object
Sets up the component’s CSS classes and HTML attributes.
-
#call ⇒ Object
Renders the code block with its lines or direct content.
-
#initialize(**kws) ⇒ CodeComponent
constructor
Creates a new code block component.
Methods inherited from LocoMotion::BaseComponent
build, #component_ref, #config_option, #cssify, define_modifier, define_modifiers, define_part, define_parts, define_size, define_sizes, #empty_part_content, #inspect, #part, register_component_initializer, register_component_setup, #rendered_css, #rendered_data, #rendered_html, #rendered_stimulus_controllers, #rendered_tag_name, renders_many, renders_one, set_component_name, #set_loco_parent, #strip_spaces
Methods included from LocoMotion::Concerns::InspectableComponent
Constructor Details
#initialize(**kws) ⇒ CodeComponent
Creates a new code block component.
113 114 115 116 117 |
# File 'app/components/daisy/mockup/code_component.rb', line 113 def initialize(**kws) super(**kws) @prefix = config_option(:prefix) end |
Instance Method Details
#before_render ⇒ Object
Sets up the component’s CSS classes and HTML attributes.
122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'app/components/daisy/mockup/code_component.rb', line 122 def before_render add_css(:component, "mockup-code") set_tag_name(:pre, :pre) set_tag_name(:code, :code) add_html(:pre, { "data-prefix": @prefix }) if @prefix # If the prefix is blank, add some left margin and hide the :before # pseudo-element used for the prefix add_css(:pre, "before:!hidden ml-6") if @prefix.blank? end |
#call ⇒ Object
Renders the code block with its lines or direct content.
138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'app/components/daisy/mockup/code_component.rb', line 138 def call part(:component) do if lines.any? lines.each { |line| concat(line) } else part(:pre) do part(:code) do content end end end end end |