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

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.



64
65
66
67
68
# File 'app/components/daisy/mockup/code_component.rb', line 64

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

  @prefix = config_option(:prefix)
end

Instance Method Details

#before_renderObject

Sets up the component’s HTML tags and attributes.



73
74
75
76
77
78
# File 'app/components/daisy/mockup/code_component.rb', line 73

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.



83
84
85
86
87
88
89
# File 'app/components/daisy/mockup/code_component.rb', line 83

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