tumblargh 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +52 -0
- data/LICENSE +20 -0
- data/README.md +84 -0
- data/Rakefile +43 -0
- data/VERSION +1 -0
- data/examples/confg.ru +18 -0
- data/examples/middleman_config.rb +7 -0
- data/lib/middleman/features/tumblargh.rb +41 -0
- data/lib/rack/tumblargh.rb +51 -0
- data/lib/tumblargh.rb +60 -0
- data/lib/tumblargh/api.rb +60 -0
- data/lib/tumblargh/grammar.rb +560 -0
- data/lib/tumblargh/grammar.treetop +42 -0
- data/lib/tumblargh/node.rb +14 -0
- data/lib/tumblargh/node/base.rb +21 -0
- data/lib/tumblargh/node/block.rb +31 -0
- data/lib/tumblargh/node/block_end.rb +9 -0
- data/lib/tumblargh/node/block_start.rb +22 -0
- data/lib/tumblargh/node/literal.rb +9 -0
- data/lib/tumblargh/node/root.rb +17 -0
- data/lib/tumblargh/node/tag.rb +33 -0
- data/lib/tumblargh/parser.rb +96 -0
- data/lib/tumblargh/renderer.rb +316 -0
- data/lib/tumblargh/renderer/base.rb +64 -0
- data/lib/tumblargh/renderer/blocks/answer.rb +22 -0
- data/lib/tumblargh/renderer/blocks/audio.rb +70 -0
- data/lib/tumblargh/renderer/blocks/base.rb +35 -0
- data/lib/tumblargh/renderer/blocks/dates.rb +62 -0
- data/lib/tumblargh/renderer/blocks/navigation.rb +65 -0
- data/lib/tumblargh/renderer/blocks/notes.rb +68 -0
- data/lib/tumblargh/renderer/blocks/posts.rb +50 -0
- data/lib/tumblargh/renderer/blocks/reblogs.rb +50 -0
- data/lib/tumblargh/renderer/blocks/tags.rb +37 -0
- data/lib/tumblargh/renderer/document.rb +70 -0
- data/lib/tumblargh/renderer/literal.rb +9 -0
- data/lib/tumblargh/renderer/tag.rb +37 -0
- data/lib/tumblargh/resource.rb +12 -0
- data/lib/tumblargh/resource/base.rb +39 -0
- data/lib/tumblargh/resource/blog.rb +49 -0
- data/lib/tumblargh/resource/note.rb +8 -0
- data/lib/tumblargh/resource/post.rb +63 -0
- data/lib/tumblargh/resource/tag.rb +8 -0
- data/lib/tumblargh/resource/user.rb +8 -0
- data/spec/api_spec.rb +1 -0
- data/spec/fixtures/data/staff.tumblr.com-2012-05-06/posts.json +1203 -0
- data/spec/fixtures/themes/fluid.html +1138 -0
- data/spec/fixtures/themes/solstice.html +392 -0
- data/spec/parser_spec.rb +159 -0
- data/spec/renderer/blocks/posts_spec.rb +17 -0
- data/spec/renderer/document_spec.rb +57 -0
- data/spec/resource/post_spec.rb +38 -0
- data/spec/resource_spec.rb +23 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/tumblargh_spec.rb +50 -0
- data/tumblargh.gemspec +120 -0
- metadata +237 -0
@@ -0,0 +1,560 @@
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
+
|
3
|
+
|
4
|
+
module Tumblr
|
5
|
+
include Treetop::Runtime
|
6
|
+
|
7
|
+
def root
|
8
|
+
@root ||= :root
|
9
|
+
end
|
10
|
+
|
11
|
+
def _nt_root
|
12
|
+
start_index = index
|
13
|
+
if node_cache[:root].has_key?(index)
|
14
|
+
cached = node_cache[:root][index]
|
15
|
+
if cached
|
16
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
17
|
+
@index = cached.interval.end
|
18
|
+
end
|
19
|
+
return cached
|
20
|
+
end
|
21
|
+
|
22
|
+
s0, i0 = [], index
|
23
|
+
loop do
|
24
|
+
i1 = index
|
25
|
+
r2 = _nt_block
|
26
|
+
if r2
|
27
|
+
r1 = r2
|
28
|
+
else
|
29
|
+
r3 = _nt_tag
|
30
|
+
if r3
|
31
|
+
r1 = r3
|
32
|
+
else
|
33
|
+
r4 = _nt_orphan
|
34
|
+
if r4
|
35
|
+
r1 = r4
|
36
|
+
else
|
37
|
+
r5 = _nt_literal
|
38
|
+
if r5
|
39
|
+
r1 = r5
|
40
|
+
else
|
41
|
+
@index = i1
|
42
|
+
r1 = nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
if r1
|
48
|
+
s0 << r1
|
49
|
+
else
|
50
|
+
break
|
51
|
+
end
|
52
|
+
end
|
53
|
+
r0 = instantiate_node(Tumblargh::Node::Root,input, i0...index, s0)
|
54
|
+
|
55
|
+
node_cache[:root][start_index] = r0
|
56
|
+
|
57
|
+
r0
|
58
|
+
end
|
59
|
+
|
60
|
+
module Block0
|
61
|
+
def block_start
|
62
|
+
elements[0]
|
63
|
+
end
|
64
|
+
|
65
|
+
def block_end
|
66
|
+
elements[2]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def _nt_block
|
71
|
+
start_index = index
|
72
|
+
if node_cache[:block].has_key?(index)
|
73
|
+
cached = node_cache[:block][index]
|
74
|
+
if cached
|
75
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
76
|
+
@index = cached.interval.end
|
77
|
+
end
|
78
|
+
return cached
|
79
|
+
end
|
80
|
+
|
81
|
+
i0, s0 = index, []
|
82
|
+
r1 = _nt_block_start
|
83
|
+
s0 << r1
|
84
|
+
if r1
|
85
|
+
s2, i2 = [], index
|
86
|
+
loop do
|
87
|
+
i3 = index
|
88
|
+
r4 = _nt_block
|
89
|
+
if r4
|
90
|
+
r3 = r4
|
91
|
+
else
|
92
|
+
r5 = _nt_tag
|
93
|
+
if r5
|
94
|
+
r3 = r5
|
95
|
+
else
|
96
|
+
r6 = _nt_orphan
|
97
|
+
if r6
|
98
|
+
r3 = r6
|
99
|
+
else
|
100
|
+
r7 = _nt_literal
|
101
|
+
if r7
|
102
|
+
r3 = r7
|
103
|
+
else
|
104
|
+
@index = i3
|
105
|
+
r3 = nil
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
if r3
|
111
|
+
s2 << r3
|
112
|
+
else
|
113
|
+
break
|
114
|
+
end
|
115
|
+
end
|
116
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
117
|
+
s0 << r2
|
118
|
+
if r2
|
119
|
+
r8 = _nt_block_end
|
120
|
+
s0 << r8
|
121
|
+
end
|
122
|
+
end
|
123
|
+
if s0.last
|
124
|
+
r0 = instantiate_node(Tumblargh::Node::Block,input, i0...index, s0)
|
125
|
+
r0.extend(Block0)
|
126
|
+
else
|
127
|
+
@index = i0
|
128
|
+
r0 = nil
|
129
|
+
end
|
130
|
+
|
131
|
+
node_cache[:block][start_index] = r0
|
132
|
+
|
133
|
+
r0
|
134
|
+
end
|
135
|
+
|
136
|
+
module BlockStart0
|
137
|
+
end
|
138
|
+
|
139
|
+
def _nt_block_start
|
140
|
+
start_index = index
|
141
|
+
if node_cache[:block_start].has_key?(index)
|
142
|
+
cached = node_cache[:block_start][index]
|
143
|
+
if cached
|
144
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
145
|
+
@index = cached.interval.end
|
146
|
+
end
|
147
|
+
return cached
|
148
|
+
end
|
149
|
+
|
150
|
+
i0, s0 = index, []
|
151
|
+
if has_terminal?('{block:', false, index)
|
152
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 7))
|
153
|
+
@index += 7
|
154
|
+
else
|
155
|
+
terminal_parse_failure('{block:')
|
156
|
+
r1 = nil
|
157
|
+
end
|
158
|
+
s0 << r1
|
159
|
+
if r1
|
160
|
+
s2, i2 = [], index
|
161
|
+
loop do
|
162
|
+
if has_terminal?('\G[^\\s}:;]', true, index)
|
163
|
+
r3 = true
|
164
|
+
@index += 1
|
165
|
+
else
|
166
|
+
r3 = nil
|
167
|
+
end
|
168
|
+
if r3
|
169
|
+
s2 << r3
|
170
|
+
else
|
171
|
+
break
|
172
|
+
end
|
173
|
+
end
|
174
|
+
if s2.empty?
|
175
|
+
@index = i2
|
176
|
+
r2 = nil
|
177
|
+
else
|
178
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
179
|
+
end
|
180
|
+
s0 << r2
|
181
|
+
if r2
|
182
|
+
if has_terminal?('}', false, index)
|
183
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
184
|
+
@index += 1
|
185
|
+
else
|
186
|
+
terminal_parse_failure('}')
|
187
|
+
r4 = nil
|
188
|
+
end
|
189
|
+
s0 << r4
|
190
|
+
if r4
|
191
|
+
r6 = _nt_space
|
192
|
+
if r6
|
193
|
+
r5 = r6
|
194
|
+
else
|
195
|
+
r5 = instantiate_node(SyntaxNode,input, index...index)
|
196
|
+
end
|
197
|
+
s0 << r5
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
if s0.last
|
202
|
+
r0 = instantiate_node(Tumblargh::Node::BlockStart,input, i0...index, s0)
|
203
|
+
r0.extend(BlockStart0)
|
204
|
+
else
|
205
|
+
@index = i0
|
206
|
+
r0 = nil
|
207
|
+
end
|
208
|
+
|
209
|
+
node_cache[:block_start][start_index] = r0
|
210
|
+
|
211
|
+
r0
|
212
|
+
end
|
213
|
+
|
214
|
+
module BlockEnd0
|
215
|
+
end
|
216
|
+
|
217
|
+
def _nt_block_end
|
218
|
+
start_index = index
|
219
|
+
if node_cache[:block_end].has_key?(index)
|
220
|
+
cached = node_cache[:block_end][index]
|
221
|
+
if cached
|
222
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
223
|
+
@index = cached.interval.end
|
224
|
+
end
|
225
|
+
return cached
|
226
|
+
end
|
227
|
+
|
228
|
+
i0, s0 = index, []
|
229
|
+
if has_terminal?('{/block:', false, index)
|
230
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 8))
|
231
|
+
@index += 8
|
232
|
+
else
|
233
|
+
terminal_parse_failure('{/block:')
|
234
|
+
r1 = nil
|
235
|
+
end
|
236
|
+
s0 << r1
|
237
|
+
if r1
|
238
|
+
s2, i2 = [], index
|
239
|
+
loop do
|
240
|
+
if has_terminal?('\G[^\\s}]', true, index)
|
241
|
+
r3 = true
|
242
|
+
@index += 1
|
243
|
+
else
|
244
|
+
r3 = nil
|
245
|
+
end
|
246
|
+
if r3
|
247
|
+
s2 << r3
|
248
|
+
else
|
249
|
+
break
|
250
|
+
end
|
251
|
+
end
|
252
|
+
if s2.empty?
|
253
|
+
@index = i2
|
254
|
+
r2 = nil
|
255
|
+
else
|
256
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
257
|
+
end
|
258
|
+
s0 << r2
|
259
|
+
if r2
|
260
|
+
if has_terminal?('}', false, index)
|
261
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
262
|
+
@index += 1
|
263
|
+
else
|
264
|
+
terminal_parse_failure('}')
|
265
|
+
r4 = nil
|
266
|
+
end
|
267
|
+
s0 << r4
|
268
|
+
if r4
|
269
|
+
r6 = _nt_space
|
270
|
+
if r6
|
271
|
+
r5 = r6
|
272
|
+
else
|
273
|
+
r5 = instantiate_node(SyntaxNode,input, index...index)
|
274
|
+
end
|
275
|
+
s0 << r5
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
if s0.last
|
280
|
+
r0 = instantiate_node(Tumblargh::Node::BlockEnd,input, i0...index, s0)
|
281
|
+
r0.extend(BlockEnd0)
|
282
|
+
else
|
283
|
+
@index = i0
|
284
|
+
r0 = nil
|
285
|
+
end
|
286
|
+
|
287
|
+
node_cache[:block_end][start_index] = r0
|
288
|
+
|
289
|
+
r0
|
290
|
+
end
|
291
|
+
|
292
|
+
module Tag0
|
293
|
+
def tag_name
|
294
|
+
elements[1]
|
295
|
+
end
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
def _nt_tag
|
300
|
+
start_index = index
|
301
|
+
if node_cache[:tag].has_key?(index)
|
302
|
+
cached = node_cache[:tag][index]
|
303
|
+
if cached
|
304
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
305
|
+
@index = cached.interval.end
|
306
|
+
end
|
307
|
+
return cached
|
308
|
+
end
|
309
|
+
|
310
|
+
i0, s0 = index, []
|
311
|
+
if has_terminal?('{', false, index)
|
312
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
313
|
+
@index += 1
|
314
|
+
else
|
315
|
+
terminal_parse_failure('{')
|
316
|
+
r1 = nil
|
317
|
+
end
|
318
|
+
s0 << r1
|
319
|
+
if r1
|
320
|
+
r2 = _nt_tag_name
|
321
|
+
s0 << r2
|
322
|
+
if r2
|
323
|
+
if has_terminal?('}', false, index)
|
324
|
+
r3 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
325
|
+
@index += 1
|
326
|
+
else
|
327
|
+
terminal_parse_failure('}')
|
328
|
+
r3 = nil
|
329
|
+
end
|
330
|
+
s0 << r3
|
331
|
+
end
|
332
|
+
end
|
333
|
+
if s0.last
|
334
|
+
r0 = instantiate_node(Tumblargh::Node::Tag,input, i0...index, s0)
|
335
|
+
r0.extend(Tag0)
|
336
|
+
else
|
337
|
+
@index = i0
|
338
|
+
r0 = nil
|
339
|
+
end
|
340
|
+
|
341
|
+
node_cache[:tag][start_index] = r0
|
342
|
+
|
343
|
+
r0
|
344
|
+
end
|
345
|
+
|
346
|
+
module TagName0
|
347
|
+
end
|
348
|
+
|
349
|
+
def _nt_tag_name
|
350
|
+
start_index = index
|
351
|
+
if node_cache[:tag_name].has_key?(index)
|
352
|
+
cached = node_cache[:tag_name][index]
|
353
|
+
if cached
|
354
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
355
|
+
@index = cached.interval.end
|
356
|
+
end
|
357
|
+
return cached
|
358
|
+
end
|
359
|
+
|
360
|
+
i0, s0 = index, []
|
361
|
+
s1, i1 = [], index
|
362
|
+
loop do
|
363
|
+
if has_terminal?('\G[a-zA-Z0-9]', true, index)
|
364
|
+
r2 = true
|
365
|
+
@index += 1
|
366
|
+
else
|
367
|
+
r2 = nil
|
368
|
+
end
|
369
|
+
if r2
|
370
|
+
s1 << r2
|
371
|
+
else
|
372
|
+
break
|
373
|
+
end
|
374
|
+
end
|
375
|
+
if s1.empty?
|
376
|
+
@index = i1
|
377
|
+
r1 = nil
|
378
|
+
else
|
379
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
380
|
+
end
|
381
|
+
s0 << r1
|
382
|
+
if r1
|
383
|
+
if has_terminal?(':', false, index)
|
384
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
385
|
+
@index += 1
|
386
|
+
else
|
387
|
+
terminal_parse_failure(':')
|
388
|
+
r4 = nil
|
389
|
+
end
|
390
|
+
if r4
|
391
|
+
r3 = r4
|
392
|
+
else
|
393
|
+
r3 = instantiate_node(SyntaxNode,input, index...index)
|
394
|
+
end
|
395
|
+
s0 << r3
|
396
|
+
if r3
|
397
|
+
s5, i5 = [], index
|
398
|
+
loop do
|
399
|
+
if has_terminal?('\G[^\\n:/{};\\[\\]\\(\\)]', true, index)
|
400
|
+
r6 = true
|
401
|
+
@index += 1
|
402
|
+
else
|
403
|
+
r6 = nil
|
404
|
+
end
|
405
|
+
if r6
|
406
|
+
s5 << r6
|
407
|
+
else
|
408
|
+
break
|
409
|
+
end
|
410
|
+
end
|
411
|
+
r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
|
412
|
+
s0 << r5
|
413
|
+
end
|
414
|
+
end
|
415
|
+
if s0.last
|
416
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
417
|
+
r0.extend(TagName0)
|
418
|
+
else
|
419
|
+
@index = i0
|
420
|
+
r0 = nil
|
421
|
+
end
|
422
|
+
|
423
|
+
node_cache[:tag_name][start_index] = r0
|
424
|
+
|
425
|
+
r0
|
426
|
+
end
|
427
|
+
|
428
|
+
module Orphan0
|
429
|
+
end
|
430
|
+
|
431
|
+
def _nt_orphan
|
432
|
+
start_index = index
|
433
|
+
if node_cache[:orphan].has_key?(index)
|
434
|
+
cached = node_cache[:orphan][index]
|
435
|
+
if cached
|
436
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
437
|
+
@index = cached.interval.end
|
438
|
+
end
|
439
|
+
return cached
|
440
|
+
end
|
441
|
+
|
442
|
+
i0, s0 = index, []
|
443
|
+
if has_terminal?('{', false, index)
|
444
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
445
|
+
@index += 1
|
446
|
+
else
|
447
|
+
terminal_parse_failure('{')
|
448
|
+
r1 = nil
|
449
|
+
end
|
450
|
+
s0 << r1
|
451
|
+
if r1
|
452
|
+
i2 = index
|
453
|
+
if has_terminal?('/', false, index)
|
454
|
+
r3 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
455
|
+
@index += 1
|
456
|
+
else
|
457
|
+
terminal_parse_failure('/')
|
458
|
+
r3 = nil
|
459
|
+
end
|
460
|
+
if r3
|
461
|
+
r2 = nil
|
462
|
+
else
|
463
|
+
@index = i2
|
464
|
+
r2 = instantiate_node(SyntaxNode,input, index...index)
|
465
|
+
end
|
466
|
+
s0 << r2
|
467
|
+
end
|
468
|
+
if s0.last
|
469
|
+
r0 = instantiate_node(Tumblargh::Node::Literal,input, i0...index, s0)
|
470
|
+
r0.extend(Orphan0)
|
471
|
+
else
|
472
|
+
@index = i0
|
473
|
+
r0 = nil
|
474
|
+
end
|
475
|
+
|
476
|
+
node_cache[:orphan][start_index] = r0
|
477
|
+
|
478
|
+
r0
|
479
|
+
end
|
480
|
+
|
481
|
+
def _nt_literal
|
482
|
+
start_index = index
|
483
|
+
if node_cache[:literal].has_key?(index)
|
484
|
+
cached = node_cache[:literal][index]
|
485
|
+
if cached
|
486
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
487
|
+
@index = cached.interval.end
|
488
|
+
end
|
489
|
+
return cached
|
490
|
+
end
|
491
|
+
|
492
|
+
s0, i0 = [], index
|
493
|
+
loop do
|
494
|
+
if has_terminal?('\G[^{]', true, index)
|
495
|
+
r1 = true
|
496
|
+
@index += 1
|
497
|
+
else
|
498
|
+
r1 = nil
|
499
|
+
end
|
500
|
+
if r1
|
501
|
+
s0 << r1
|
502
|
+
else
|
503
|
+
break
|
504
|
+
end
|
505
|
+
end
|
506
|
+
if s0.empty?
|
507
|
+
@index = i0
|
508
|
+
r0 = nil
|
509
|
+
else
|
510
|
+
r0 = instantiate_node(Tumblargh::Node::Literal,input, i0...index, s0)
|
511
|
+
end
|
512
|
+
|
513
|
+
node_cache[:literal][start_index] = r0
|
514
|
+
|
515
|
+
r0
|
516
|
+
end
|
517
|
+
|
518
|
+
def _nt_space
|
519
|
+
start_index = index
|
520
|
+
if node_cache[:space].has_key?(index)
|
521
|
+
cached = node_cache[:space][index]
|
522
|
+
if cached
|
523
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
524
|
+
@index = cached.interval.end
|
525
|
+
end
|
526
|
+
return cached
|
527
|
+
end
|
528
|
+
|
529
|
+
s0, i0 = [], index
|
530
|
+
loop do
|
531
|
+
if has_terminal?('\G[\\s]', true, index)
|
532
|
+
r1 = true
|
533
|
+
@index += 1
|
534
|
+
else
|
535
|
+
r1 = nil
|
536
|
+
end
|
537
|
+
if r1
|
538
|
+
s0 << r1
|
539
|
+
else
|
540
|
+
break
|
541
|
+
end
|
542
|
+
end
|
543
|
+
if s0.empty?
|
544
|
+
@index = i0
|
545
|
+
r0 = nil
|
546
|
+
else
|
547
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
548
|
+
end
|
549
|
+
|
550
|
+
node_cache[:space][start_index] = r0
|
551
|
+
|
552
|
+
r0
|
553
|
+
end
|
554
|
+
|
555
|
+
end
|
556
|
+
|
557
|
+
class TumblrParser < Treetop::Runtime::CompiledParser
|
558
|
+
include Tumblr
|
559
|
+
end
|
560
|
+
|