tumblargh 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +2 -2
- data/README.md +3 -0
- data/lib/tumblargh/renderer.rb +8 -5
- data/lib/tumblargh/renderer/base.rb +0 -1
- data/lib/tumblargh/renderer/blocks/base.rb +3 -3
- data/lib/tumblargh/renderer/blocks/posts.rb +17 -1
- data/lib/tumblargh/renderer/document.rb +2 -1
- data/lib/tumblargh/version.rb +1 -1
- data/spec/renderer/blocks/posts_spec.rb +9 -0
- data/spec/renderer/blocks_spec.rb +50 -21
- data/spec/resource/post_spec.rb +1 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2797b0ef63ebf34cc39bd5287f6a6a62f4fd2123
|
4
|
+
data.tar.gz: a1b6a5bb0ebeea850dd41b038d8c2f87230d8a9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25e5eaac7e0c20219cd221b2549ce9e7ad34e2234f69d27df36e8b67d5ae473aa2c6839afe690b56ed4d8b9d2e7187837e4a86d2ae33f52eb3fbf2b39a3f45f8
|
7
|
+
data.tar.gz: 87e6edc18b48d1d240ba5b8431a6d445a31e2a31cbc082c6126ffe0e93aff7d1e7ac7b404a6e9e68796ea17f11f4aac2e3f91445629a36f6dbfdf3bfc9d14eb5
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tumblargh (0.2.
|
4
|
+
tumblargh (0.2.1)
|
5
5
|
activesupport (>= 3.1)
|
6
6
|
api_cache
|
7
7
|
nokogiri
|
@@ -35,7 +35,7 @@ GEM
|
|
35
35
|
multi_json (~> 1.0)
|
36
36
|
simplecov-html (~> 0.5.3)
|
37
37
|
simplecov-html (0.5.3)
|
38
|
-
treetop (1.4.
|
38
|
+
treetop (1.4.15)
|
39
39
|
polyglot
|
40
40
|
polyglot (>= 0.3.1)
|
41
41
|
|
data/README.md
CHANGED
data/lib/tumblargh/renderer.rb
CHANGED
@@ -29,13 +29,16 @@ module Tumblargh
|
|
29
29
|
args << n_post[1].to_i
|
30
30
|
end
|
31
31
|
|
32
|
-
base = "Blocks::#{block_name}"
|
32
|
+
base = "Blocks::#{ block_name }"
|
33
33
|
end
|
34
34
|
|
35
|
-
klass_name = "Tumblargh::Renderer::#{base}"
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
klass_name = "Tumblargh::Renderer::#{ base }"
|
36
|
+
begin
|
37
|
+
klass = klass_name.constantize
|
38
|
+
klass.new(node, context, options, *args)
|
39
|
+
rescue NameError => e
|
40
|
+
puts "WARNING: Unsupported block `#{ klass_name }`"
|
41
|
+
end
|
39
42
|
end
|
40
43
|
|
41
44
|
end
|
@@ -55,7 +55,6 @@ module Tumblargh
|
|
55
55
|
alias_method :to_s, :render
|
56
56
|
|
57
57
|
def method_missing(method, *arguments)
|
58
|
-
# puts "mm #{method} - #{self.class.name} -- context is: #{context.class.name}"
|
59
58
|
raise "Can't find anything to do with '#{method}'" if context.nil?
|
60
59
|
context.send(method, *arguments)
|
61
60
|
end
|
@@ -9,7 +9,6 @@ module Tumblargh
|
|
9
9
|
alias_method :should_render_unless_empty, :should_render_if=
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
12
|
def should_render?
|
14
13
|
if defined?(@should_render_if)
|
15
14
|
val = send(@should_render_if)
|
@@ -25,10 +24,11 @@ module Tumblargh
|
|
25
24
|
_, type, options, *nodes = node
|
26
25
|
|
27
26
|
res = nodes.map do |n|
|
28
|
-
Renderer.factory(n, self, options)
|
27
|
+
renderer = Renderer.factory(n, self, options)
|
28
|
+
renderer.render unless renderer.nil?
|
29
29
|
end
|
30
30
|
|
31
|
-
" #{res.join('')} "
|
31
|
+
" #{ res.join('') } "
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -3,7 +3,7 @@ module Tumblargh
|
|
3
3
|
module Blocks
|
4
4
|
# Posts Loop
|
5
5
|
#
|
6
|
-
# {block:Posts} is executed once for each post. Some post related tags can
|
6
|
+
# {block:Posts} is executed once for each post. Some post related tags can
|
7
7
|
# exist outside of a `type` block, such as {Title} or {Permalink}, so
|
8
8
|
# they should be defined here
|
9
9
|
class Posts < Base
|
@@ -31,6 +31,22 @@ module Tumblargh
|
|
31
31
|
"/reblog/#{context.reblog_key}"
|
32
32
|
end
|
33
33
|
|
34
|
+
# An HTML class-attribute friendly list of the post's tags.
|
35
|
+
# Example: "humor office new_york_city"
|
36
|
+
#
|
37
|
+
# By default, an HTML friendly version of the source domain of imported
|
38
|
+
# posts will be included. This may not behave as expected with feeds
|
39
|
+
# like Del.icio.us that send their content URLs as their permalinks.
|
40
|
+
# Example: "twitter_com", "digg_com", etc.
|
41
|
+
#
|
42
|
+
# The class-attribute "reblog" will be included automatically if the
|
43
|
+
# post was reblogged from another post.
|
44
|
+
def tags_as_classes
|
45
|
+
context.tags.map do |tag|
|
46
|
+
tag.name.titlecase.gsub(/\s+/, '').underscore.downcase
|
47
|
+
end.join " "
|
48
|
+
end
|
49
|
+
|
34
50
|
def render
|
35
51
|
if context.is_a? Resource::Post
|
36
52
|
super
|
data/lib/tumblargh/version.rb
CHANGED
@@ -14,4 +14,13 @@ describe Tumblargh::Renderer::Blocks::Posts do
|
|
14
14
|
result.count("!").should eql @json[:posts].size
|
15
15
|
end
|
16
16
|
|
17
|
+
describe "{TagsAsClasses}" do
|
18
|
+
let(:post) { Tumblargh::Resource::Post.new({ tags: ["TROLOLOL", "Herp derp"] }, nil) }
|
19
|
+
|
20
|
+
subject { Tumblargh::Renderer::Blocks::Posts.new(nil, post) }
|
21
|
+
|
22
|
+
it "should give the tags as class names" do
|
23
|
+
subject.tags_as_classes.should eql "trololol herp_derp"
|
24
|
+
end
|
25
|
+
end
|
17
26
|
end
|
@@ -3,13 +3,22 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe Tumblargh::Renderer::Blocks do
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
def capture_stdout(&block)
|
7
|
+
original_stdout = $stdout
|
8
|
+
$stdout = fake = StringIO.new
|
9
|
+
begin
|
10
|
+
yield
|
11
|
+
ensure
|
12
|
+
$stdout = original_stdout
|
13
|
+
end
|
14
|
+
fake.string
|
8
15
|
end
|
9
16
|
|
17
|
+
let(:parser) { Tumblargh::Parser.new }
|
18
|
+
|
10
19
|
describe "{block:PermalinkPage}" do
|
11
20
|
before do
|
12
|
-
|
21
|
+
parser.html = <<-eos
|
13
22
|
{block:PermalinkPage}
|
14
23
|
ERMAGERD PERMERLINK
|
15
24
|
{/block:PermalinkPage}
|
@@ -17,23 +26,21 @@ describe Tumblargh::Renderer::Blocks do
|
|
17
26
|
end
|
18
27
|
|
19
28
|
it "should render its content when it is a permalink page" do
|
20
|
-
|
21
|
-
|
22
|
-
|
29
|
+
document = Tumblargh::Renderer::Document.new(parser.tree, nil, :permalink => true)
|
30
|
+
output = document.render
|
31
|
+
output.should match(/ERMAGERD PERMERLINK/)
|
23
32
|
end
|
24
33
|
|
25
34
|
it "should NOT render its content when it is a permalink page" do
|
26
|
-
|
27
|
-
|
28
|
-
|
35
|
+
document = Tumblargh::Renderer::Document.new(parser.tree, nil, :permalink => false)
|
36
|
+
output = document.render
|
37
|
+
output.should_not match(/ERMAGERD PERMERLINK/)
|
29
38
|
end
|
30
|
-
|
31
39
|
end
|
32
40
|
|
33
41
|
describe "boolean blocks" do
|
34
|
-
|
35
42
|
before do
|
36
|
-
|
43
|
+
parser.html = <<-eos
|
37
44
|
{block:IfSomethingOnByDefault}
|
38
45
|
PASS_ON
|
39
46
|
{/block:IfSomethingOnByDefault}
|
@@ -50,29 +57,51 @@ describe Tumblargh::Renderer::Blocks do
|
|
50
57
|
PASS_INVERSE_OFF
|
51
58
|
{/block:IfNotSomethingOffByDefault}
|
52
59
|
eos
|
60
|
+
end
|
53
61
|
|
54
|
-
|
62
|
+
let(:options) do
|
63
|
+
{
|
55
64
|
"if" => {
|
56
65
|
"somethingonbydefault" => true,
|
57
66
|
"somethingoffbydefault" => false
|
58
67
|
}
|
59
68
|
}
|
60
|
-
|
61
|
-
@document = Tumblargh::Renderer::Document.new(@parser.tree, nil, options)
|
62
|
-
@output = @document.render
|
63
69
|
end
|
64
70
|
|
71
|
+
let(:output) { Tumblargh::Renderer::Document.new(parser.tree, nil, options).render }
|
72
|
+
|
65
73
|
it "should respect the default settings" do
|
66
|
-
|
67
|
-
|
74
|
+
output.should match(/PASS_ON/)
|
75
|
+
output.should_not match(/FAIL_OFF/)
|
68
76
|
end
|
69
77
|
|
70
78
|
|
71
79
|
it "inverse (IfNot) blocks should work" do
|
72
|
-
|
73
|
-
|
80
|
+
output.should_not match(/FAIL_INVERSE_ON/)
|
81
|
+
output.should match(/PASS_INVERSE_OFF/)
|
74
82
|
end
|
75
|
-
|
76
83
|
end
|
77
84
|
|
85
|
+
describe "using unsupported blocks" do
|
86
|
+
before do
|
87
|
+
parser.html = <<-eos
|
88
|
+
{block:ThisIsDefinitelyNotABlock}{/block:ThisIsDefinitelyNotABlock}
|
89
|
+
eos
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should not raise an error" do
|
93
|
+
expect {
|
94
|
+
Tumblargh::Renderer::Document.new(parser.tree, nil, {}).render
|
95
|
+
}.not_to raise_error
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should output a warning" do
|
99
|
+
out = capture_stdout {
|
100
|
+
Tumblargh::Renderer::Document.new(parser.tree, nil, {}).render
|
101
|
+
}
|
102
|
+
|
103
|
+
out.should =~ /WARNING: Unsupported block `Tumblargh::Renderer::Blocks::ThisIsDefinitelyNotABlock`/
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
78
107
|
end
|
data/spec/resource/post_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Tumblargh::Resource::Post do
|
4
|
-
|
4
|
+
|
5
5
|
before do
|
6
6
|
json_path = File.join(FIXTURE_PATH, "data", "staff.tumblr.com-2012-05-06", "posts.json")
|
7
7
|
@json = ActiveSupport::JSON.decode(open(json_path).read)["response"]
|
@@ -33,6 +33,4 @@ describe Tumblargh::Resource::Post do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tumblargh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Webster
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -132,6 +132,7 @@ extra_rdoc_files: []
|
|
132
132
|
files:
|
133
133
|
- .gitignore
|
134
134
|
- .rspec
|
135
|
+
- .travis.yml
|
135
136
|
- CHANGELOG.md
|
136
137
|
- Gemfile
|
137
138
|
- Gemfile.lock
|