Class: OkonomiUiKit::Components::Code

Inherits:
OkonomiUiKit::Component show all
Defined in:
app/helpers/okonomi_ui_kit/components/code.rb

Instance Attribute Summary

Attributes inherited from OkonomiUiKit::Component

#view

Instance Method Summary collapse

Methods inherited from OkonomiUiKit::Component

#combined_styles, config_class?, config_class_name, config_classes, config_namespace, #config_styles_registry, config_styles_registry, deep_merge, #initialize, #internal_styles_registry, internal_styles_registry, #name, parent_styles_registry, register_styles, resolve_config_classes, #style, #styles, #template_path, #theme_name, #tw_merge, #variant_style

Constructor Details

This class inherits a constructor from OkonomiUiKit::Component

Instance Method Details

#render(content = nil, options = {}, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/okonomi_ui_kit/components/code.rb', line 4

def render(content = nil, options = {}, &block)
  options, content = content, nil if block_given?
  options ||= {}
  options = options.with_indifferent_access

  # Extract component-specific options
  language = options.delete(:language) || options.delete(:lang)
  variant = (options.delete(:variant) || "default").to_sym
  size = (options.delete(:size) || "default").to_sym
  wrap = options.delete(:wrap) != false # Default to true

  # Build classes
  classes = build_classes(variant: variant, size: size, wrap: wrap, custom_class: options.delete(:class))

  # Escape HTML entities in content
  raw_content = if block_given?
                  view.capture(&block)
  elsif content
                  content
  else
                  ""
  end

  escaped_content = html_escape(raw_content)

  view.render(
    template_path,
    content: escaped_content,
    options: options,
    classes: classes,
    language: language
  )
end