Class: PhlexUI::Codeblock
- Defined in:
- lib/phlex_ui/codeblock.rb
Constant Summary collapse
- FORMATTER =
::Rouge::Formatters::HTML.new
- ROUGE_CSS =
See themes here: rouge-ruby.github.io/docs/Rouge/CSSTheme.html
Rouge::Themes::Github.mode(:dark).render(scope: ".highlight")
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(code, syntax:, clipboard: true, clipboard_success: "Copied!", clipboard_error: "Copy failed!", **attrs) ⇒ Codeblock
constructor
A new instance of Codeblock.
- #view_template ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(code, syntax:, clipboard: true, clipboard_success: "Copied!", clipboard_error: "Copy failed!", **attrs) ⇒ Codeblock
Returns a new instance of Codeblock.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/phlex_ui/codeblock.rb', line 10 def initialize(code, syntax:, clipboard: true, clipboard_success: "Copied!", clipboard_error: "Copy failed!", **attrs) @code = code @syntax = syntax.to_sym @clipboard = clipboard @clipboard_success = clipboard_success @clipboard_error = clipboard_error if @syntax == :ruby || @syntax == :html @code = @code.gsub(/(?:^|\G) {2}/m, " ") end super(**attrs) end |
Instance Method Details
#view_template ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/phlex_ui/codeblock.rb', line 24 def view_template style { ROUGE_CSS.html_safe } # For faster load times, move this to the head of your document. (Also move ROUGE_CSS value to head of document) if @clipboard with_clipboard else codeblock end end |