tumblargh 0.2.1 → 0.2.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e50e3d39c5dc3fb912cfcaf48113581fb644456
4
- data.tar.gz: 66980f7b07a44cb19b191f86f3c1ff10fd6a31ac
3
+ metadata.gz: 2797b0ef63ebf34cc39bd5287f6a6a62f4fd2123
4
+ data.tar.gz: a1b6a5bb0ebeea850dd41b038d8c2f87230d8a9c
5
5
  SHA512:
6
- metadata.gz: a37b11aa4bc7d25724f36039cbf566e4f46362be27e13d655fadd4a039d69e9549bbc774150e034142302ccccd35db5b2cb4b6a7be812d04dab621fd0da95497
7
- data.tar.gz: c318b3856836d9f07d7812624c877555963153585324a924f982dc84bf727b91c1a4ddd18c7454f85824efffa8f5258b412b35beaf55c9d14cc69796ff2e6803
6
+ metadata.gz: 25e5eaac7e0c20219cd221b2549ce9e7ad34e2234f69d27df36e8b67d5ae473aa2c6839afe690b56ed4d8b9d2e7187837e4a86d2ae33f52eb3fbf2b39a3f45f8
7
+ data.tar.gz: 87e6edc18b48d1d240ba5b8431a6d445a31e2a31cbc082c6126ffe0e93aff7d1e7ac7b404a6e9e68796ea17f11f4aac2e3f91445629a36f6dbfdf3bfc9d14eb5
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+
6
+ notifications:
7
+ email: false
@@ -1,3 +1,8 @@
1
+ ## 0.2.2
2
+
3
+ - Don't raise an exception on missing blocks, merely log a warning
4
+ - Implement `{TagsAsClasses}` tag
5
+
1
6
  ## 0.2.1
2
7
 
3
8
  - Block arguments, such as `{block:JumpPagination length="5"}` are now supported
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tumblargh (0.2.0)
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.14)
38
+ treetop (1.4.15)
39
39
  polyglot
40
40
  polyglot (>= 0.3.1)
41
41
 
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # Tumblargh
2
+
3
+ [![Build Status](https://travis-ci.org/jasonwebster/tumblargh.png?branch=master)](https://travis-ci.org/jasonwebster/tumblargh)
4
+
2
5
  ## Groan-less Tumblr theme development
3
6
 
4
7
  ### What is this thing, and why should I care?
@@ -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
- klass = klass_name.constantize
37
-
38
- klass.new(node, context, options, *args)
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).render
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
@@ -55,7 +55,8 @@ module Tumblargh
55
55
 
56
56
  def render
57
57
  node.map do |n|
58
- Renderer.factory(n, self).render
58
+ renderer = Renderer.factory(n, self)
59
+ renderer.render unless renderer.nil?
59
60
  end.flatten.join('')
60
61
  end
61
62
  end
@@ -1,3 +1,3 @@
1
1
  module Tumblargh
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.2.2'.freeze
3
3
  end
@@ -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
- before do
7
- @parser = Tumblargh::Parser.new
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
- @parser.html = <<-eos
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
- @document = Tumblargh::Renderer::Document.new(@parser.tree, nil, :permalink => true)
21
- @output = @document.render
22
- @output.should match(/ERMAGERD PERMERLINK/)
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
- @document = Tumblargh::Renderer::Document.new(@parser.tree, nil, :permalink => false)
27
- @output = @document.render
28
- @output.should_not match(/ERMAGERD PERMERLINK/)
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
- @parser.html = <<-eos
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
- options = {
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
- @output.should match(/PASS_ON/)
67
- @output.should_not match(/FAIL_OFF/)
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
- @output.should_not match(/FAIL_INVERSE_ON/)
73
- @output.should match(/PASS_INVERSE_OFF/)
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
@@ -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.1
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-09 00:00:00.000000000 Z
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