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

« back to all changes in this revision

Viewing changes to vendor/rdtool-0.6.38/lib/rd/inline-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
 
 
3
module RD
 
4
  
 
5
  # Inline-level Element of document tree
 
6
  class InlineElement < Element
 
7
  end
 
8
 
 
9
  # abstruct class.
 
10
  class TerminalInline < InlineElement
 
11
    include TerminalElement
 
12
 
 
13
    attr_accessor :content
 
14
 
 
15
    def initialize(content)
 
16
      super()
 
17
      @content = content
 
18
    end
 
19
  end
 
20
  
 
21
  # abstract class.
 
22
  class NonterminalInline < InlineElement
 
23
    include NonterminalElement
 
24
 
 
25
    attr_reader :content
 
26
    
 
27
    def initialize
 
28
      super()
 
29
      @content = []
 
30
    end
 
31
 
 
32
    def children
 
33
      @content
 
34
    end
 
35
 
 
36
    def to_label
 
37
      ret = ""
 
38
      children.each do |i|
 
39
        ret << i.to_label
 
40
      end
 
41
      ret.strip
 
42
    end
 
43
  end # NonterminalInline
 
44
  
 
45
  class StringElement < TerminalInline
 
46
    def accept(visitor)
 
47
      visitor.visit_StringElement(self)
 
48
    end
 
49
 
 
50
    def to_label
 
51
      @content
 
52
    end
 
53
  end
 
54
  
 
55
  class Verb < TerminalInline
 
56
    def accept(visitor)
 
57
      visitor.visit_Verb(self)
 
58
    end
 
59
 
 
60
    def to_label
 
61
      @content.strip
 
62
    end
 
63
  end
 
64
  
 
65
  class Emphasis < NonterminalInline
 
66
    def accept(visitor)
 
67
      visitor.visit_Emphasis(self)
 
68
    end
 
69
  end
 
70
  
 
71
  class Code < NonterminalInline
 
72
    def accept(visitor)
 
73
      visitor.visit_Code(self)
 
74
    end
 
75
  end
 
76
  
 
77
  class Var < NonterminalInline
 
78
    def accept(visitor)
 
79
      visitor.visit_Var(self)
 
80
    end
 
81
  end
 
82
  
 
83
  class Keyboard < NonterminalInline
 
84
    def accept(visitor)
 
85
      visitor.visit_Keyboard(self)
 
86
    end
 
87
  end
 
88
  
 
89
  class Index < NonterminalInline
 
90
    def accept(visitor)
 
91
      visitor.visit_Index(self)
 
92
    end
 
93
  end
 
94
 
 
95
  class Footnote < NonterminalInline
 
96
    def accept(visitor)
 
97
      visitor.visit_Footnote(self)
 
98
    end
 
99
  end
 
100
 
 
101
  class Reference < NonterminalInline
 
102
    attr_accessor :label   # Reference::Label
 
103
    alias set_label label=
 
104
 
 
105
    def initialize(label)
 
106
      super()
 
107
      @content = []
 
108
      @label = label.renew_label
 
109
    end
 
110
 
 
111
    def Reference.new_from_label(label)
 
112
      ref = Reference.new(label)
 
113
      ref.add_children(label.to_reference_content)
 
114
      return ref
 
115
    end
 
116
 
 
117
    def Reference.new_from_label_under_document_struct(label, struct)
 
118
      ref = Reference.new(label)
 
119
      ref.add_children_under_document_struct(label.to_reference_content,
 
120
                                             struct)
 
121
      return ref
 
122
    end
 
123
 
 
124
    def Reference.new_from_label_without_document_struct(label)
 
125
      ref = Reference.new(label)
 
126
      ref.add_children_without_document_struct(label.to_reference_content)
 
127
      return ref
 
128
    end
 
129
    
 
130
    def accept(visitor)
 
131
      visitor.visit_Reference(self)
 
132
    end
 
133
 
 
134
    def result_of_apply_method_of(visitor, children)
 
135
      label.result_of_apply_method_of(visitor, self, children)
 
136
    end
 
137
    
 
138
    def to_label
 
139
      @label.to_label
 
140
    end
 
141
 
 
142
    # abstruct class. Label for Reference 
 
143
    class Label
 
144
      def extract_label
 
145
        raise NotImplementedError, "[BUG] must be overridden."
 
146
      end
 
147
 
 
148
      def to_reference_content
 
149
        raise NotImplementedError, "[BUG] must be overridden."
 
150
      end
 
151
 
 
152
      def result_of_apply_method_of(visitor)
 
153
        raise NotImplementedError, "[BUG] must be overridden."
 
154
      end
 
155
    end
 
156
  
 
157
    class URL < Label
 
158
      attr_accessor :url
 
159
      
 
160
      def initialize(url_str)
 
161
        @url = url_str
 
162
      end
 
163
      
 
164
      def to_label
 
165
        ""
 
166
      end
 
167
 
 
168
      def result_of_apply_method_of(visitor, reference, children)
 
169
        visitor.apply_to_Reference_with_URL(reference, children)
 
170
      end
 
171
 
 
172
      def to_reference_content
 
173
        [StringElement.new("<URL:#{self.url}>")]
 
174
      end
 
175
 
 
176
      def renew_label
 
177
        self
 
178
      end
 
179
    end # URL
 
180
 
 
181
    class RDLabel < Label
 
182
      attr_accessor :element_label
 
183
      attr_accessor :filename
 
184
 
 
185
      def initialize(element_label, filename = nil)
 
186
        @element_label = element_label
 
187
        @filename = filename
 
188
      end
 
189
 
 
190
      def result_of_apply_method_of(visitor, reference, children)
 
191
        visitor.apply_to_Reference_with_RDLabel(reference, children)
 
192
      end
 
193
 
 
194
      def to_reference_content
 
195
        []
 
196
      end
 
197
 
 
198
      def renew_label
 
199
        self
 
200
      end
 
201
      
 
202
      alias to_label element_label
 
203
    end # RDLabel
 
204
 
 
205
    # for initialization. Parameter Object(?)
 
206
    class TemporaryLabel < Label
 
207
      attr_accessor :element_label
 
208
      attr_accessor :filename
 
209
 
 
210
      def initialize(element_label = [], filename = nil)
 
211
        @element_label = element_label
 
212
        @filename = filename
 
213
      end
 
214
 
 
215
      def to_reference_content
 
216
        self.element_label
 
217
      end
 
218
 
 
219
      def renew_label
 
220
        RDLabel.new(extract_label(self.element_label), self.filename)
 
221
      end
 
222
 
 
223
      def extract_label(elements)
 
224
        ret = ""
 
225
        elements.each do |i|
 
226
          ret << i.to_label
 
227
        end
 
228
        ret.strip
 
229
      end
 
230
      private :extract_label
 
231
    end
 
232
  end # Reference
 
233
end