Class: PhlexKit::Codeblock

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/codeblock/codeblock.rb

Overview

Preformatted code block. Ported from ruby_ui's RubyUI::Codeblock, minus the server-side syntax highlighting (ruby_ui uses the rouge gem). Ships a plain styled

; add rouge yourself and pass pre-highlighted HTML if wanted.

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(code = nil, syntax: nil, **attrs) ⇒ Codeblock

Returns a new instance of Codeblock.



6
7
8
9
10
# File 'app/components/phlex_kit/codeblock/codeblock.rb', line 6

def initialize(code = nil, syntax: nil, **attrs)
  @code = code
  @syntax = syntax
  @attrs = attrs
end

Instance Method Details

#view_template(&block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'app/components/phlex_kit/codeblock/codeblock.rb', line 11

def view_template(&block)
  div(**mix({ class: "pk-codeblock", data: { syntax: @syntax } }, @attrs)) do
    pre do
      if block
        code(&block)
      else
        code { @code }
      end
    end
  end
end