Class: Repubmark::Elems::CodeBlock
- Defined in:
- lib/repubmark/elems/code_block.rb
Instance Attribute Summary collapse
-
#indent ⇒ Object
Returns the value of attribute indent.
-
#str ⇒ Object
Returns the value of attribute str.
-
#syntax ⇒ Object
Returns the value of attribute syntax.
Attributes inherited from Base
Instance Method Summary collapse
- #highlighted_str ⇒ Object private
- #indentation ⇒ Object private
-
#initialize(parent, syntax, str, indent: 0) ⇒ CodeBlock
constructor
A new instance of CodeBlock.
- #to_gemtext ⇒ Object
-
#to_html ⇒ Object
Basic methods #.
- #transformed_str ⇒ Object private
Methods inherited from Base
#absolute_url, #config, #count_words, #html_class, #own_url, parent?, parents, #relative_url, #to_summary_plain, #word_count
Constructor Details
#initialize(parent, syntax, str, indent: 0) ⇒ CodeBlock
Returns a new instance of CodeBlock.
10 11 12 13 14 15 16 |
# File 'lib/repubmark/elems/code_block.rb', line 10 def initialize(parent, syntax, str, indent: 0) super parent self.syntax = syntax self.str = str self.indent = indent end |
Instance Attribute Details
#indent ⇒ Object
Returns the value of attribute indent.
8 9 10 |
# File 'lib/repubmark/elems/code_block.rb', line 8 def indent @indent end |
#str ⇒ Object
Returns the value of attribute str.
8 9 10 |
# File 'lib/repubmark/elems/code_block.rb', line 8 def str @str end |
#syntax ⇒ Object
Returns the value of attribute syntax.
8 9 10 |
# File 'lib/repubmark/elems/code_block.rb', line 8 def syntax @syntax end |
Instance Method Details
#highlighted_str ⇒ Object (private)
56 57 58 |
# File 'lib/repubmark/elems/code_block.rb', line 56 def highlighted_str @highlighted_str ||= Highlight.call syntax, transformed_str end |
#indentation ⇒ Object (private)
65 66 67 |
# File 'lib/repubmark/elems/code_block.rb', line 65 def indentation @indentation ||= (' ' * indent).freeze end |
#to_gemtext ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/repubmark/elems/code_block.rb', line 24 def to_gemtext [ "```\n", "#{str.strip}\n", "```\n", ].join.freeze end |
#to_html ⇒ Object
Basic methods #
22 |
# File 'lib/repubmark/elems/code_block.rb', line 22 def to_html = highlighted_str |
#transformed_str ⇒ Object (private)
60 61 62 63 |
# File 'lib/repubmark/elems/code_block.rb', line 60 def transformed_str @transformed_str ||= str.lines.map { |line| "#{indentation}#{line}" }.join.freeze end |