Class: Keystone::Ui::CodeComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/keystone/ui/code_component.rb

Constant Summary collapse

WRAPPER_CLASSES =
"overflow-hidden rounded-lg border border-surface-200 dark:border-surface-700"
CAPTION_CLASSES =
"border-b border-surface-200 bg-surface-50 px-4 py-2 font-mono text-xs text-surface-500 dark:border-surface-700 dark:bg-surface-800 dark:text-surface-400"
PRE_CLASSES =
"overflow-x-auto bg-surface-900 p-4 font-mono text-sm leading-relaxed text-surface-100 dark:bg-black"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(language: nil, caption: nil) ⇒ CodeComponent

Returns a new instance of CodeComponent.



12
13
14
15
# File 'app/components/keystone/ui/code_component.rb', line 12

def initialize(language: nil, caption: nil)
  @language = language
  @caption = caption
end

Instance Attribute Details

#captionObject (readonly)

Returns the value of attribute caption.



10
11
12
# File 'app/components/keystone/ui/code_component.rb', line 10

def caption
  @caption
end

#languageObject (readonly)

Returns the value of attribute language.



10
11
12
# File 'app/components/keystone/ui/code_component.rb', line 10

def language
  @language
end

Instance Method Details

#caption?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'app/components/keystone/ui/code_component.rb', line 17

def caption?
  !@caption.nil?
end

#caption_classesObject



25
26
27
# File 'app/components/keystone/ui/code_component.rb', line 25

def caption_classes
  CAPTION_CLASSES
end

#language_classObject



33
34
35
36
37
# File 'app/components/keystone/ui/code_component.rb', line 33

def language_class
  return nil if @language.nil?

  "language-#{@language}"
end

#pre_classesObject



29
30
31
# File 'app/components/keystone/ui/code_component.rb', line 29

def pre_classes
  PRE_CLASSES
end

#wrapper_classesObject



21
22
23
# File 'app/components/keystone/ui/code_component.rb', line 21

def wrapper_classes
  WRAPPER_CLASSES
end