tumblargh 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +8 -12
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/examples/middleman_config.rb +3 -4
- data/lib/middleman/extensions/tumblargh.rb +39 -0
- data/lib/rack/tumblargh.rb +10 -3
- data/lib/tumblargh.rb +5 -0
- data/lib/tumblargh/renderer.rb +1 -275
- data/lib/tumblargh/renderer/base.rb +0 -1
- data/lib/tumblargh/renderer/blocks.rb +276 -0
- data/lib/tumblargh/renderer/blocks/audio.rb +7 -1
- data/lib/tumblargh/renderer/blocks/base.rb +2 -1
- data/lib/tumblargh/renderer/blocks/chat.rb +44 -0
- data/lib/tumblargh/renderer/blocks/photoset.rb +27 -0
- data/lib/tumblargh/resource.rb +2 -0
- data/lib/tumblargh/resource/blog.rb +1 -1
- data/lib/tumblargh/resource/dialogue.rb +8 -0
- data/lib/tumblargh/resource/photo.rb +19 -0
- data/lib/tumblargh/resource/post.rb +17 -9
- data/spec/renderer/blocks_spec.rb +78 -0
- data/spec/renderer/document_spec.rb +6 -42
- data/tumblargh.gemspec +10 -4
- metadata +34 -54
- data/lib/middleman/features/tumblargh.rb +0 -41
@@ -0,0 +1,276 @@
|
|
1
|
+
module Tumblargh
|
2
|
+
module Renderer
|
3
|
+
module Blocks
|
4
|
+
|
5
|
+
require 'tumblargh/renderer/blocks/base'
|
6
|
+
|
7
|
+
class Description < Base
|
8
|
+
def should_render?
|
9
|
+
!description.blank?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class NumberedPost < Base
|
14
|
+
attr_reader :num
|
15
|
+
|
16
|
+
def initialize(node, context, *args)
|
17
|
+
@num = args[0]
|
18
|
+
super(node, context)
|
19
|
+
end
|
20
|
+
|
21
|
+
def should_render?
|
22
|
+
num == context.posts.index(context_post) + 1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Common post blocks
|
27
|
+
class Title < Base
|
28
|
+
def should_render?
|
29
|
+
!(title.nil? || title.blank?)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Caption < Base
|
34
|
+
def should_render?
|
35
|
+
!(caption.nil? || caption.blank?)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Base post type
|
40
|
+
class Post < Base
|
41
|
+
def should_render?
|
42
|
+
self.class.name.demodulize.downcase == context.type
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Source block for Quote posts
|
47
|
+
class Source < Base
|
48
|
+
def should_render?
|
49
|
+
!source.blank?
|
50
|
+
end
|
51
|
+
|
52
|
+
def source
|
53
|
+
context.source
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class Text < Post
|
58
|
+
end
|
59
|
+
|
60
|
+
class Photo < Post
|
61
|
+
def should_render?
|
62
|
+
context_post.type == 'photo' && context_post.photos.size == 1
|
63
|
+
end
|
64
|
+
|
65
|
+
def photo_alt
|
66
|
+
strip_html(context.caption)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
class Video < Photo
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
class Quote < Post
|
78
|
+
def quote
|
79
|
+
context.text
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class Chat < Post
|
84
|
+
end
|
85
|
+
|
86
|
+
class Link < Post
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
# Meta-block for Appearance booleans, like {block:IfSomething}
|
91
|
+
class Boolean < Base
|
92
|
+
attr_reader :variable
|
93
|
+
|
94
|
+
def initialize(node, context, *args)
|
95
|
+
@variable = args[0]
|
96
|
+
super(node, context)
|
97
|
+
end
|
98
|
+
|
99
|
+
def should_render?
|
100
|
+
context.boolean(variable.downcase)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
class InverseBoolean < Boolean
|
105
|
+
def should_render?
|
106
|
+
! super
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
# Rendered on permalink pages. (Useful for displaying the current post's
|
112
|
+
# title in the page title)
|
113
|
+
class PostTitle < Base
|
114
|
+
def should_render?
|
115
|
+
false
|
116
|
+
end
|
117
|
+
|
118
|
+
def post_title
|
119
|
+
# TODO: Implementation
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Identical to {PostTitle}, but will automatically generate a summary
|
124
|
+
# if a title doesn't exist.
|
125
|
+
class PostSummary < PostTitle
|
126
|
+
def post_summary
|
127
|
+
# TODO: Implementation
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
class ContentSource < Base
|
134
|
+
def should_render?
|
135
|
+
!source_title.nil?
|
136
|
+
end
|
137
|
+
|
138
|
+
contextual_tag :source_url
|
139
|
+
contextual_tag :source_title
|
140
|
+
|
141
|
+
# TODO: Impl.
|
142
|
+
def black_logo_url
|
143
|
+
end
|
144
|
+
|
145
|
+
def logo_width
|
146
|
+
end
|
147
|
+
|
148
|
+
def logo_height
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
class SourceLogo < Base
|
154
|
+
# TODO: Impl.
|
155
|
+
end
|
156
|
+
|
157
|
+
class NoSourceLogo < SourceLogo
|
158
|
+
def should_render?
|
159
|
+
! super
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
class HasTags < Base
|
164
|
+
def should_render?
|
165
|
+
!(tags.nil? || tags.blank?)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
# Rendered on index (post) pages.
|
171
|
+
class IndexPage < Base
|
172
|
+
def should_render?
|
173
|
+
! context.permalink?
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
# Rendered on post permalink pages.
|
178
|
+
class PermalinkPage < Base
|
179
|
+
def should_render?
|
180
|
+
context.permalink?
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
class SearchPage < Base
|
185
|
+
def should_render?
|
186
|
+
false
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
class NoSearchResults < Base
|
191
|
+
def should_render?
|
192
|
+
false
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
class TagPage < Base
|
197
|
+
def should_render?
|
198
|
+
false
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
# Rendered if you have defined any custom pages.
|
203
|
+
class HasPages < Base
|
204
|
+
# TODO: Implementation
|
205
|
+
|
206
|
+
def should_render?
|
207
|
+
false
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
# Rendered for each custom page.
|
212
|
+
class Pages < Base
|
213
|
+
# TODO: Implementation
|
214
|
+
|
215
|
+
def should_render?
|
216
|
+
false
|
217
|
+
end
|
218
|
+
|
219
|
+
# custom page url
|
220
|
+
def url
|
221
|
+
end
|
222
|
+
|
223
|
+
# custom page name/label
|
224
|
+
def label
|
225
|
+
end
|
226
|
+
|
227
|
+
end
|
228
|
+
|
229
|
+
# Rendered if you have Twitter integration enabled.
|
230
|
+
class Twitter < Base
|
231
|
+
# TODO: Implementation
|
232
|
+
|
233
|
+
def should_render?
|
234
|
+
false
|
235
|
+
end
|
236
|
+
|
237
|
+
def twitter_username
|
238
|
+
end
|
239
|
+
|
240
|
+
end
|
241
|
+
|
242
|
+
|
243
|
+
# {block:Likes} {/block:Likes} Rendered if you are sharing your likes.
|
244
|
+
# {Likes} Standard HTML output of your likes.
|
245
|
+
# {Likes limit="5"} Standard HTML output of your last 5 likes.
|
246
|
+
# Maximum: 10
|
247
|
+
# {Likes width="200"} Standard HTML output of your likes with Audio and Video players scaled to 200-pixels wide.
|
248
|
+
# Scale images with CSS max-width or similar.
|
249
|
+
# {Likes summarize="100"} Standard HTML output of your likes with text summarize to 100-characters.
|
250
|
+
# Maximum: 250
|
251
|
+
class Likes < Base
|
252
|
+
# TODO: Implementation
|
253
|
+
|
254
|
+
def should_render?
|
255
|
+
false
|
256
|
+
end
|
257
|
+
|
258
|
+
def likes
|
259
|
+
end
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
require 'tumblargh/renderer/blocks/answer'
|
264
|
+
require 'tumblargh/renderer/blocks/audio'
|
265
|
+
require 'tumblargh/renderer/blocks/chat'
|
266
|
+
require 'tumblargh/renderer/blocks/dates'
|
267
|
+
require 'tumblargh/renderer/blocks/navigation'
|
268
|
+
require 'tumblargh/renderer/blocks/notes'
|
269
|
+
require 'tumblargh/renderer/blocks/photoset'
|
270
|
+
require 'tumblargh/renderer/blocks/posts'
|
271
|
+
require 'tumblargh/renderer/blocks/reblogs'
|
272
|
+
require 'tumblargh/renderer/blocks/tags'
|
273
|
+
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
@@ -23,7 +23,7 @@ module Tumblargh
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def audio_player_black
|
26
|
-
|
26
|
+
audio_player(:black)
|
27
27
|
end
|
28
28
|
|
29
29
|
# def raw_audio_url
|
@@ -65,6 +65,12 @@ module Tumblargh
|
|
65
65
|
contextual_tag :track_name
|
66
66
|
end
|
67
67
|
|
68
|
+
class AudioEmbed < Base
|
69
|
+
end
|
70
|
+
|
71
|
+
class AudioPlayer < Base
|
72
|
+
end
|
73
|
+
|
68
74
|
end
|
69
75
|
end
|
70
76
|
end
|
@@ -6,13 +6,14 @@ module Tumblargh
|
|
6
6
|
class << self
|
7
7
|
attr_accessor :should_render_if
|
8
8
|
alias_method :should_render_unless_blank, :should_render_if=
|
9
|
+
alias_method :should_render_unless_empty, :should_render_if=
|
9
10
|
end
|
10
11
|
|
11
12
|
|
12
13
|
def should_render?
|
13
14
|
if defined?(@should_render_if)
|
14
15
|
val = send(@should_render_if)
|
15
|
-
return !(val || val.nil? || val.blank?)
|
16
|
+
return !(val || val.nil? || (val.respond_to?(:blank?) ? val.blank? : val.empty?))
|
16
17
|
end
|
17
18
|
|
18
19
|
true
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Tumblargh
|
2
|
+
module Renderer
|
3
|
+
module Blocks
|
4
|
+
|
5
|
+
class Lines < Base
|
6
|
+
|
7
|
+
contextual_tag :label
|
8
|
+
contextual_tag :name
|
9
|
+
contextual_tag :line, :phrase
|
10
|
+
|
11
|
+
# "odd" or "even" for each line of this post.
|
12
|
+
# TODO Implementation
|
13
|
+
def alt
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
# A unique identifying integer representing the user of the current line of this post.
|
18
|
+
# TODO Implementation
|
19
|
+
def user_number
|
20
|
+
end
|
21
|
+
|
22
|
+
def render
|
23
|
+
if context.is_a? Resource::Dialogue
|
24
|
+
super
|
25
|
+
else
|
26
|
+
context.dialogue.map do |l|
|
27
|
+
l.context = self
|
28
|
+
self.class.new(node, l).render
|
29
|
+
end.flatten.join('')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
class Label < Base
|
36
|
+
|
37
|
+
should_render_unless_blank :label
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Tumblargh
|
2
|
+
module Renderer
|
3
|
+
module Blocks
|
4
|
+
|
5
|
+
class Photoset < Photo
|
6
|
+
def should_render?
|
7
|
+
context_post.type == 'photoset' && context_post.photos.size > 1
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Rendered for each of the Photoset photos
|
12
|
+
class Photos < Base
|
13
|
+
def render
|
14
|
+
if context.is_a? Resource::Photo
|
15
|
+
super
|
16
|
+
else
|
17
|
+
context.photos.map do |photo|
|
18
|
+
photo.context = self
|
19
|
+
self.class.new(node, photo).render
|
20
|
+
end.flatten.join('')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/tumblargh/resource.rb
CHANGED
@@ -3,7 +3,9 @@ module Tumblargh
|
|
3
3
|
|
4
4
|
autoload :Base, 'tumblargh/resource/base'
|
5
5
|
autoload :Blog, 'tumblargh/resource/blog'
|
6
|
+
autoload :Dialogue, 'tumblargh/resource/dialogue'
|
6
7
|
autoload :Note, 'tumblargh/resource/note'
|
8
|
+
autoload :Photo, 'tumblargh/resource/photo'
|
7
9
|
autoload :Post, 'tumblargh/resource/post'
|
8
10
|
autoload :Tag, 'tumblargh/resource/tag'
|
9
11
|
autoload :User, 'tumblargh/resource/user'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Tumblargh
|
2
|
+
module Resource
|
3
|
+
|
4
|
+
class Photo < Base
|
5
|
+
|
6
|
+
def photo_url(size=500)
|
7
|
+
size = size.to_i
|
8
|
+
|
9
|
+
res = alt_sizes.select do |p|
|
10
|
+
p[:width] == size
|
11
|
+
end
|
12
|
+
|
13
|
+
res.empty? ? original_size[:url] : res.first[:url]
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|