Class: Coradoc::AsciiDoc::Model::Include

Inherits:
Base
  • Object
show all
Includes:
Resolvable
Defined in:
lib/coradoc/asciidoc/model/include.rb

Overview

Include directive element for AsciiDoc documents.

Include directives allow incorporating content from external files into the current document at processing time.

Examples:

Create an include directive

inc = Coradoc::AsciiDoc::Model::Include.new
inc.path = "chapter1.adoc"
inc.to_adoc # => "include::chapter1.adoc[]\n"

Instance Attribute Summary collapse

Attributes inherited from Base

#id

Instance Method Summary collapse

Methods included from Resolvable

#local_reference?, #remote_reference?

Methods inherited from Base

#block_level?, #inline?, #serialize_content, #simplify_block_content, #to_adoc, #to_h, visit, #visit

Instance Attribute Details

#attributesCoradoc::AsciiDoc::Model::AttributeList (readonly)

Returns Include attributes.

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/coradoc/asciidoc/model/include.rb', line 27

class Include < Base
  include Resolvable

  attribute :path, :string
  attribute :attributes, Coradoc::AsciiDoc::Model::AttributeList, default: lambda {
    Coradoc::AsciiDoc::Model::AttributeList.new
  }
  attribute :line_break, :string, default: -> { "\n" }

  # @return [String] the path to the included file
  def reference_path
    path
  end

  # @return [Symbol] the reference type
  def reference_type
    :include
  end

  # @return [Hash] include options (leveloffset, lines, tags, etc.)
  def reference_options
    options = {}
    if attributes.is_a?(Coradoc::AsciiDoc::Model::AttributeList)
      attributes.named.each do |attr|
        case attr.name.to_s
        when 'leveloffset'
          options[:leveloffset] = attr.value
        when 'lines'
          options[:lines] = attr.value
        when 'tags'
          options[:tags] = attr.value.to_s.split(';')
        end
      end
    end
    options
  end
end

#line_breakString (readonly)

Returns Line break character (default: “n”).

Returns:

  • (String)

    Line break character (default: “n”)



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/coradoc/asciidoc/model/include.rb', line 27

class Include < Base
  include Resolvable

  attribute :path, :string
  attribute :attributes, Coradoc::AsciiDoc::Model::AttributeList, default: lambda {
    Coradoc::AsciiDoc::Model::AttributeList.new
  }
  attribute :line_break, :string, default: -> { "\n" }

  # @return [String] the path to the included file
  def reference_path
    path
  end

  # @return [Symbol] the reference type
  def reference_type
    :include
  end

  # @return [Hash] include options (leveloffset, lines, tags, etc.)
  def reference_options
    options = {}
    if attributes.is_a?(Coradoc::AsciiDoc::Model::AttributeList)
      attributes.named.each do |attr|
        case attr.name.to_s
        when 'leveloffset'
          options[:leveloffset] = attr.value
        when 'lines'
          options[:lines] = attr.value
        when 'tags'
          options[:tags] = attr.value.to_s.split(';')
        end
      end
    end
    options
  end
end

#pathString (readonly)

Returns The path to the file to include.

Returns:

  • (String)

    The path to the file to include



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/coradoc/asciidoc/model/include.rb', line 27

class Include < Base
  include Resolvable

  attribute :path, :string
  attribute :attributes, Coradoc::AsciiDoc::Model::AttributeList, default: lambda {
    Coradoc::AsciiDoc::Model::AttributeList.new
  }
  attribute :line_break, :string, default: -> { "\n" }

  # @return [String] the path to the included file
  def reference_path
    path
  end

  # @return [Symbol] the reference type
  def reference_type
    :include
  end

  # @return [Hash] include options (leveloffset, lines, tags, etc.)
  def reference_options
    options = {}
    if attributes.is_a?(Coradoc::AsciiDoc::Model::AttributeList)
      attributes.named.each do |attr|
        case attr.name.to_s
        when 'leveloffset'
          options[:leveloffset] = attr.value
        when 'lines'
          options[:lines] = attr.value
        when 'tags'
          options[:tags] = attr.value.to_s.split(';')
        end
      end
    end
    options
  end
end

Instance Method Details

#reference_optionsHash

Returns include options (leveloffset, lines, tags, etc.).

Returns:

  • (Hash)

    include options (leveloffset, lines, tags, etc.)



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/coradoc/asciidoc/model/include.rb', line 47

def reference_options
  options = {}
  if attributes.is_a?(Coradoc::AsciiDoc::Model::AttributeList)
    attributes.named.each do |attr|
      case attr.name.to_s
      when 'leveloffset'
        options[:leveloffset] = attr.value
      when 'lines'
        options[:lines] = attr.value
      when 'tags'
        options[:tags] = attr.value.to_s.split(';')
      end
    end
  end
  options
end

#reference_pathString

Returns the path to the included file.

Returns:

  • (String)

    the path to the included file



37
38
39
# File 'lib/coradoc/asciidoc/model/include.rb', line 37

def reference_path
  path
end

#reference_typeSymbol

Returns the reference type.

Returns:

  • (Symbol)

    the reference type



42
43
44
# File 'lib/coradoc/asciidoc/model/include.rb', line 42

def reference_type
  :include
end