Class: Daisy::Mockup::CodeLineComponent

Inherits:
LocoMotion::BaseComponent show all
Defined in:
app/components/daisy/mockup/code_component.rb

Overview

A component for rendering individual lines within a code block.

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

#config, #loco_parent

Instance Method Summary collapse

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

#build_inspect_string

Constructor Details

#initialize(**kws) ⇒ CodeLineComponent

Creates a new code line.

Parameters:

  • kws (Hash)

    a customizable set of options

Options Hash (**kws):

  • prefix (String)

    Optional prefix for the line (e.g., "$", ">", or line numbers).

  • css (String)

    Additional CSS classes for styling the line.



21
22
23
24
25
# File 'app/components/daisy/mockup/code_component.rb', line 21

def initialize(**kws)
  super(**kws)

  @prefix = config_option(:prefix)
end

Instance Method Details

#before_renderObject

Sets up the component's HTML tags and attributes.



30
31
32
33
34
35
# File 'app/components/daisy/mockup/code_component.rb', line 30

def before_render
  set_tag_name(:component, :pre)
  set_tag_name(:code, :code)

  add_html(:component, { "data-prefix": @prefix }) if @prefix
end

#callObject

Renders the line with its code content.



40
41
42
43
44
45
46
# File 'app/components/daisy/mockup/code_component.rb', line 40

def call
  part(:component) do
    part(:code) do
      content
    end
  end
end