Class: Coradoc::Element::Block::SourceCode

Inherits:
Core
  • Object
show all
Defined in:
lib/coradoc/element/block/sourcecode.rb

Instance Attribute Summary

Attributes inherited from Core

#attributes, #id, #lang, #lines, #title

Instance Method Summary collapse

Methods inherited from Core

#gen_anchor, #gen_attributes, #gen_delimiter, #gen_lines, #gen_title, #type

Constructor Details

#initialize(title, options = {}) ⇒ SourceCode

Returns a new instance of SourceCode.



5
6
7
8
9
10
11
12
# File 'lib/coradoc/element/block/sourcecode.rb', line 5

def initialize(title, options = {})
  @id = options.fetch(:id, nil)
  @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
  @lang = options.fetch(:lang, '')
  @lines = options.fetch(:lines, [])
  @delimiter_char = "-"
  @delimiter_len = options.fetch(:delimiter_len, 4)
end

Instance Method Details

#to_adocObject



14
15
16
# File 'lib/coradoc/element/block/sourcecode.rb', line 14

def to_adoc
  "\n\n#{gen_anchor}[source,#{@lang}]\n#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
end