Class: Gimli::Markup::CodeBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/gimli/markup/code_block.rb

Overview

Class that contains data for a code block

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, language, code) ⇒ CodeBlock

Returns a new instance of CodeBlock.



13
14
15
# File 'lib/gimli/markup/code_block.rb', line 13

def initialize(id, language, code)
  @id, @language, @code = id, language, code
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



11
12
13
# File 'lib/gimli/markup/code_block.rb', line 11

def code
  @code
end

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/gimli/markup/code_block.rb', line 11

def id
  @id
end

#languageObject (readonly)

Returns the value of attribute language.



11
12
13
# File 'lib/gimli/markup/code_block.rb', line 11

def language
  @language
end

Instance Method Details

#highlightedString

Returns the code with syntax highlightning

Returns:

  • (String)


19
20
21
22
23
24
25
# File 'lib/gimli/markup/code_block.rb', line 19

def highlighted
  if @language
    CodeRay.scan(@code, @language).html(:line_numbers => :table)
  else
    CodeRay.scan(@code, :text).div
  end
end