~ubuntu-branches/ubuntu/wily/tdiary/wily

« back to all changes in this revision

Viewing changes to vendor/rdtool-0.6.33/lib/rd/block-element.rb

  • Committer: Package Import Robot
  • Author(s): Hideki Yamane
  • Date: 2013-05-19 16:14:01 UTC
  • mfrom: (12.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130519161401-hf5oyr8g8a94fsew
Tags: 3.2.2-2
Upload to unstable 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require 'rd/element'
2
 
require 'rd/labeled-element'
3
 
 
4
 
module RD
5
 
  # Block-level Element of document tree. abstruct class.
6
 
  class BlockElement < Element
7
 
  end
8
 
 
9
 
  class Headline < BlockElement
10
 
    include NonterminalElement
11
 
    include LabeledElement
12
 
 
13
 
    MARK2LEVEL = {
14
 
      "=" => 1,
15
 
      "==" => 2,
16
 
      "===" => 3,
17
 
      "====" => 4,
18
 
      "+" => 5,
19
 
      "++" => 6
20
 
    }
21
 
    
22
 
    attr_accessor :level
23
 
    attr_reader :title
24
 
    
25
 
    def initialize(level_num)
26
 
      super()
27
 
      @level = level_num
28
 
      @title = []
29
 
    end
30
 
    
31
 
    def accept(visitor)
32
 
      visitor.visit_Headline(self)
33
 
    end
34
 
 
35
 
    def calculate_label
36
 
      ret = ""
37
 
      @title.each do |i|
38
 
        ret << i.to_label
39
 
      end
40
 
      ret
41
 
    end
42
 
    private :calculate_label
43
 
    
44
 
    def Headline.mark_to_level(mark_str)
45
 
      MARK2LEVEL[mark_str] or
46
 
        raise ArgumentError, "#{mark_str} is irregular for Headline mark."
47
 
    end
48
 
 
49
 
    def children
50
 
      @title
51
 
    end
52
 
  end
53
 
  
54
 
  class Include < BlockElement
55
 
    include TerminalElement
56
 
    
57
 
    attr_accessor :filename
58
 
    
59
 
    def initialize(filename)
60
 
      super()
61
 
      @filename = filename
62
 
    end
63
 
    
64
 
    def accept(visitor)
65
 
      visitor.visit_Include(self)
66
 
    end
67
 
  end # Include
68
 
  
69
 
  class TextBlock < BlockElement
70
 
    include NonterminalElement
71
 
    
72
 
    attr_accessor :content
73
 
    
74
 
    def initialize()
75
 
      super()
76
 
      @content = []
77
 
    end
78
 
    
79
 
    def accept(visitor)
80
 
      visitor.visit_TextBlock(self)
81
 
    end
82
 
    
83
 
    def children
84
 
      @content
85
 
    end
86
 
  end
87
 
  
88
 
  class Verbatim < BlockElement
89
 
    include TerminalElement
90
 
    
91
 
    attr_reader :content
92
 
    
93
 
    def initialize(content_strings = [])
94
 
      super()
95
 
      @content = content_strings  # Array of String
96
 
    end
97
 
    
98
 
    def accept(visitor)
99
 
      visitor.visit_Verbatim(self)
100
 
    end
101
 
    
102
 
    def each_line
103
 
      if @content.respond_to?(:each_line)
104
 
        @content.each_line {|i|
105
 
          yield i
106
 
        }
107
 
      else
108
 
        @content.each {|i|
109
 
          yield i
110
 
        }
111
 
      end
112
 
    end
113
 
  end
114
 
end