Class: Riven::Markup::CodeBlock
- Inherits:
-
Object
- Object
- Riven::Markup::CodeBlock
- Defined in:
- lib/riven/markup/code_block.rb
Overview
Class that contains data for a code block
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
Instance Method Summary collapse
-
#highlighted ⇒ String
Returns the code with syntax highlightning.
-
#initialize(id, language, code) ⇒ CodeBlock
constructor
A new instance of CodeBlock.
Constructor Details
#initialize(id, language, code) ⇒ CodeBlock
Returns a new instance of CodeBlock.
11 12 13 |
# File 'lib/riven/markup/code_block.rb', line 11 public def initialize(id, language, code) @id, @language, @code = id, language, code end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
9 10 11 |
# File 'lib/riven/markup/code_block.rb', line 9 def code @code end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/riven/markup/code_block.rb', line 9 def id @id end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
9 10 11 |
# File 'lib/riven/markup/code_block.rb', line 9 def language @language end |
Instance Method Details
#highlighted ⇒ String
Returns the code with syntax highlightning
18 19 20 21 22 23 24 |
# File 'lib/riven/markup/code_block.rb', line 18 public def highlighted if @language CodeRay.scan(@code, @language).div(tab_width: 4, css: :class) else CodeRay.scan(@code, :text).div(tab_width: 4, css: :class) end end |