Module: Coradoc::Parser::Asciidoc::Block

Included in:
Base
Defined in:
lib/coradoc/parser/asciidoc/block.rb

Instance Method Summary collapse

Instance Method Details

#block(n_deep = 3) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/coradoc/parser/asciidoc/block.rb', line 6

def block(n_deep = 3)
  (example_block(n_deep) |
  sidebar_block(n_deep) |
  source_block(n_deep) |
  quote_block(n_deep) |
  pass_block(n_deep)).as(:block)
end

#block_content(n_deep = 3) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/coradoc/parser/asciidoc/block.rb', line 51

def block_content(n_deep = 3)
  c = block_image |
    list |
    text_line |
    empty_line.as(:line_break)
  c = c | block(n_deep - 1) if (n_deep > 0)
  c.repeat(1)
end

#block_delimiterObject



60
61
62
63
64
65
66
67
68
69
# File 'lib/coradoc/parser/asciidoc/block.rb', line 60

def block_delimiter
  line_start? >> 
  ((str("*") |
    str("=") |
    str("_") |
    str("+") |
    str("-")).repeat(4) |
    str("-").repeat(2,2)) >>
    newline
end

#block_idObject



45
46
47
48
49
# File 'lib/coradoc/parser/asciidoc/block.rb', line 45

def block_id
  line_start? >>
  (str("[[") >> str('[').absent? >> keyword.as(:id) >> str("]]") |
    str("[#") >> keyword.as(:id) >> str("]")) >> newline
end

#block_style(n_deep = 3, delimiter = "*", repeater = 4, type = nil) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/coradoc/parser/asciidoc/block.rb', line 71

def block_style(n_deep = 3, delimiter = "*", repeater = 4, type = nil)
  block_title.maybe >>
  block_id.maybe >>
    (attribute_list >> newline ).maybe >>
  block_title.maybe >>
    newline.maybe >>
    (line_start? >> str('[').present? >> attribute_list >> newline ).maybe >>
    block_id.maybe >>
    (str('[').present? >> attribute_list >> newline ).maybe >>
    line_start? >>
    str(delimiter).repeat(repeater).capture(:delimit).as(:delimiter) >> newline >>
    if type == :pass
      (text_line | empty_line.as(:line_break)).repeat(1).as(:lines)
    else
      block_delimiter.absent? >> block_content(n_deep-1).as(:lines)
    end >>
    line_start? >>
    dynamic { |s,c| str(c.captures[:delimit].to_s.strip) } >> newline
    # str(delimiter).repeat(repeater) >> str(delimiter).absent? >> newline
end

#block_titleObject



34
35
36
# File 'lib/coradoc/parser/asciidoc/block.rb', line 34

def block_title
  str('.') >> space.absent? >> text.as(:title) >> newline
end

#block_type(type) ⇒ Object



38
39
40
41
42
43
# File 'lib/coradoc/parser/asciidoc/block.rb', line 38

def block_type(type)
  (str("[") >> str("[").absent? >>
    str(type).as(:type) >>
    str("]")) | 
  (match('^\[') >> keyword.as(:type) >> str("]")) >> newline
end

#example_block(n_deep) ⇒ Object



14
15
16
# File 'lib/coradoc/parser/asciidoc/block.rb', line 14

def example_block(n_deep)
  block_style(n_deep, "=")
end

#pass_block(n_deep) ⇒ Object



18
19
20
# File 'lib/coradoc/parser/asciidoc/block.rb', line 18

def pass_block(n_deep)
  block_style(n_deep, "+", 4, :pass)
end

#quote_block(n_deep) ⇒ Object



22
23
24
# File 'lib/coradoc/parser/asciidoc/block.rb', line 22

def quote_block(n_deep)
  block_style(n_deep, "_")
end


26
27
28
# File 'lib/coradoc/parser/asciidoc/block.rb', line 26

def sidebar_block(n_deep)
  block_style(n_deep, "*")
end

#source_block(n_deep) ⇒ Object



30
31
32
# File 'lib/coradoc/parser/asciidoc/block.rb', line 30

def source_block(n_deep)
  block_style(n_deep, "-", 2)
end