raf 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rafelement.rb DELETED
@@ -1,229 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- # Copyright (C) garin <garin54@gmail.com> 2011
3
- # See the included file COPYING for details.
4
- # = RafObject
5
- module Raf
6
- class HeadIndex
7
- def initialize
8
- @head_index = []
9
- @point_pre = 0
10
- end
11
-
12
- def update(level)
13
- point = level - 2
14
- if @point_pre > point
15
- (@point_pre - point).times do
16
- @head_index.pop
17
- @point_pre -= 1
18
- end
19
- end
20
- @head_index[point] ||= 0
21
- @head_index[point] += 1
22
- @point_pre = point
23
- end
24
-
25
- def to_s
26
- @head_index.map{|n|
27
- n = 0 if n.nil?
28
- n
29
- }.join(".") + "."
30
- end
31
-
32
- def clear
33
- @heade_index = [0,0,0,0,0,0,0]
34
- end
35
- end
36
- end
37
- module Raf
38
- class Element
39
- def initialize(contents = "")
40
- @contents = Array(contents)
41
- end
42
- attr_reader :contents
43
-
44
- def apply
45
- @contents
46
- end
47
- def add=(content)
48
- @contents.concat(content.lines)
49
- end
50
- end
51
-
52
- # ----- Blocks
53
- class WhiteLine < Element
54
- def apply # noop
55
- ""
56
- end
57
- end
58
-
59
- class PlainTextBlock < Element
60
- def apply
61
- @contents.map {|c| c.apply }
62
- end
63
- end
64
-
65
- class HeadLine < Element
66
- # @contents = [level, title]
67
- def apply
68
- "=" * @contents[0] + " #{@contents[1]}\n"
69
- end
70
- end
71
-
72
- class Paragraph < Element
73
- def apply
74
- "#{@contents.map{|c| c.apply}}"
75
- end
76
- end
77
-
78
- class Quote < Element
79
- def apply
80
- "#{@contents}"
81
- end
82
- end
83
-
84
- class ItemList < Element
85
- def apply
86
- str = "<ItemList>"
87
- @contents.map do |c|
88
- if c == :INDENT
89
- str += "<INDENT/>"
90
- elsif c == :DEDENT
91
- str +="<DEDENT/>"
92
- else
93
- str += "<ItemListItem>#{c.apply}</ItemListItem>"
94
- end
95
- end
96
- str += "</ItemList>"
97
- str
98
- end
99
- end
100
-
101
- class NumList < Element
102
- def apply
103
- str = "<NumList>"
104
- num = 1
105
- @contents.map do |c|
106
- if c == :INDENT
107
- str += "<INDENT/>"
108
- elsif c == :DEDENT
109
- str +="<DEDENT/>"
110
- else
111
- str += "<NumListItem>#{num}. #{c.apply}</NumListItem>"
112
- num += 1
113
- end
114
- end
115
- str += "</NumList>"
116
- str
117
- end
118
- end
119
-
120
- class Desc < Element
121
- def apply
122
- ":#{@contents[0]}\n#{@contents[1].map {|c| c.apply} }"
123
- end
124
- end
125
-
126
- class Table < Element
127
- def apply
128
- str = ""
129
- @contents.each do |line|
130
- line.each do |item|
131
- if item.split(//)[0] == "*"
132
- str += "|*#{item.sub(/^\*/, "").sub(/\*$/,"")}"
133
- else
134
- str += "|#{item}"
135
- end
136
- end
137
- str += "\n"
138
- end
139
- str
140
- end
141
- end
142
-
143
- # -- Blocks end
144
-
145
- # -- Inlines
146
- class Plain < Element
147
- def apply
148
- "#{contents}"
149
- end
150
- end
151
-
152
- class Label < Element
153
- # @contents = [label, title, id]
154
- def apply
155
- # "#{@contents[1]}(#{@contents[0]}) raf-label-#{@contents[2]}"
156
- "#{@contents[1]}(#{@contents[0]}):#{@contents[2]}"
157
- end
158
- end
159
-
160
- class Reference < Element
161
- # @contents = [title, uri]
162
- def apply
163
- "#{@contents}"
164
- end
165
- end
166
-
167
- class Emphasis < Element
168
- def apply
169
- "<Emphasis>#{@contents.map{|c| c.apply}}</Emphasis>"
170
- end
171
- end
172
-
173
- class Italic < Element
174
- def apply
175
- "<Italic>#{@contents.map{|c| c.apply}}</Italic>"
176
- end
177
- end
178
-
179
- class Strike < Element
180
- def apply
181
- "<Strike>#{@contents.map{|c| c.apply}}</Strike>"
182
- end
183
- end
184
-
185
- class Ruby < Element
186
- def apply
187
- "<Ruby>Base:#{@contents[0]},Text:#{@contents[1]}</Ruby>"
188
- end
189
- end
190
-
191
- class Footnote < Element
192
- #@contents = [contents, id]
193
- def apply
194
- "<Footnote>#{@contents[0].map{|c| c.apply}}</Footnote>"
195
- end
196
- end
197
-
198
- class Image < Element
199
- def apply
200
- "<Image>#{@contents}</Image>"
201
- end
202
- end
203
-
204
- class Verb < Element
205
- def apply
206
- "<Verb>#{@contents}</Verb>"
207
- end
208
- end
209
-
210
- class Manuedo < Element
211
- def apply
212
- "<Manuedo>#{@contents}</Manuedo>"
213
- end
214
- end
215
- end
216
-
217
-
218
- class String
219
- def to_code
220
- self.lines.to_a.pack('m').tr("012345679+/=\n", 'abcdefghiPSIQ').strip
221
- end
222
- end
223
-
224
- # support for ruby-2.0.0
225
- class Array
226
- def to_s
227
- self.join
228
- end
229
- end