tributary 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec CHANGED
@@ -1,6 +1,5 @@
1
1
  --colour
2
2
  --require rack/test
3
3
  --require ./lib/tributary
4
- --require ./lib/tributary/plugins/dummy
5
4
  --require ./lib/tributary/plugins/mnml
6
5
  --require ./lib/tributary/plugins/unbreak_my_art
data/README.md CHANGED
@@ -90,7 +90,7 @@ The settings altered by the user are kept in the given user’s session and so p
90
90
  Plugins
91
91
  -------
92
92
 
93
- Plugins (put in the `App.plugins` `Array`) are objects which can be sent a `handle` method with an `Item` as a parameter and are expected to return the `Item` (so the calls to subsequent plugins are chainable). See the `Mnml` plugin for an example implementation utilising a `SimpleDelegator` to filter the given `Item`’s `body` and `title` methods.
93
+ Plugins (put in the `App.plugins` `Array`) are modules which get to extend `Item`s. See the `Mnml` plugin for an example implementation filtering the output of the `body` and `title` methods.
94
94
 
95
95
 
96
96
 
@@ -1,14 +1,11 @@
1
- module Tributary module Plugins class Mnml
1
+ module Tributary module Plugins module Mnml
2
2
 
3
- def handle item
4
- mnml = SimpleDelegator.new item
5
- def mnml.body
6
- super.tr 'aeiouy', ''
7
- end
8
- def mnml.title
9
- super.tr 'aeiouy', ''
10
- end
11
- mnml
3
+ def body
4
+ super.tr 'aeiouy', ''
5
+ end
6
+
7
+ def title
8
+ super.tr 'aeiouy', ''
12
9
  end
13
10
 
14
11
  end end end
@@ -1,21 +1,18 @@
1
1
  # encoding: UTF-8
2
2
 
3
- module Tributary module Plugins class UnbreakMyArt
3
+ module Tributary module Plugins module UnbreakMyArt
4
4
 
5
- def handle item
6
- unbroken = SimpleDelegator.new item
7
- def unbroken.body
8
- Plugins::UnbreakMyArt.unbreak super
9
- end
10
- def unbroken.title
11
- Plugins::UnbreakMyArt.unbreak super
12
- end
13
- unbroken
5
+ def body
6
+ unbreak super
7
+ end
8
+
9
+ def title
10
+ unbreak super
14
11
  end
15
12
 
16
13
  private
17
14
 
18
- def self.unbreak string
15
+ def unbreak string
19
16
  string.gsub /((^|[^\p{L}<])\p{L}\p{P}?) /, '\1 '
20
17
  end
21
18
 
@@ -3,7 +3,7 @@ module Tributary class Stream
3
3
  def initialize root = App.root, plugins = App.plugins
4
4
  @items = Dir["#{root}/*/*.md"].map { |file| Item.new file }
5
5
  plugins.each do |plugin|
6
- @items.map! { |item| plugin.handle item }
6
+ @items.each { |item| item.extend plugin }
7
7
  end
8
8
  end
9
9
 
@@ -2,13 +2,13 @@
2
2
 
3
3
  module Tributary describe Plugins::Mnml do
4
4
 
5
- describe '#handle' do
5
+ describe '#body, #title' do
6
6
 
7
- it 'minimalises the given Item’s title and body' do
8
- item = mock Item, body: 'a wonderful body', title: 'an interesting title'
9
- mnml = Plugins::Mnml.new.handle item
10
- mnml.body.should == ' wndrfl bd'
11
- mnml.title.should == 'n ntrstng ttl'
7
+ it 'returns the relevant minimalised part' do
8
+ file = Tempfile.open('Plugins::Mnml') { |f| f << "title: an interesting title\n\na wonderful body" }
9
+ item = Item.new(file.path).extend Plugins::Mnml
10
+ item.title.should == 'n ntrstng ttl'
11
+ item.body.should == "<p> wndrfl bd</p>\n"
12
12
  end
13
13
 
14
14
  end
@@ -3,10 +3,22 @@
3
3
  module Tributary describe Plugins::UnbreakMyArt do
4
4
 
5
5
  def unbreak string
6
- Plugins::UnbreakMyArt.new.handle(mock Item, body: string).body
6
+ file = Tempfile.open('Plugins::UnbreakMyArt') { |f| f << "\n\n#{string}" }
7
+ Item.new(file.path).extend(Plugins::UnbreakMyArt).body[3..-6]
7
8
  end
8
9
 
9
- describe '#handle' do
10
+ describe '#body, #title' do
11
+
12
+ it 'returns the relevant unbroken part' do
13
+ file = Tempfile.open('Plugins::UnbreakMyArt') { |f| f << "title: about a ninja\n\nand a pirate" }
14
+ item = Item.new(file.path).extend Plugins::UnbreakMyArt
15
+ item.title.should == 'about a ninja'
16
+ item.body.should == "<p>and a pirate</p>\n"
17
+ end
18
+
19
+ end
20
+
21
+ describe '#unbreak' do
10
22
 
11
23
  it 'prevents line wrapping after single-letter words' do
12
24
  unbreak('give me a break').should == 'give me a break'
@@ -18,19 +30,13 @@ module Tributary describe Plugins::UnbreakMyArt do
18
30
  end
19
31
 
20
32
  it 'does not alter one-letter HTML tags' do
21
- unbreak("<a href='http://en.wikipedia.org/wiki/Invisible_Pink_Unicorn'>I want to believe</a>").should == "<a href='http://en.wikipedia.org/wiki/Invisible_Pink_Unicorn'>I want to believe</a>"
33
+ unbreak("<a href='http://en.wikipedia.org/wiki/Invisible_Pink_Unicorn'>I want to believe</a>").should == '<a href="http://en.wikipedia.org/wiki/Invisible_Pink_Unicorn">I want to believe</a>'
22
34
  end
23
35
 
24
36
  it 'allows for optional trailing punctuation' do
25
37
  unbreak('I, Clau-Clau-Claudius').should == 'I, Clau-Clau-Claudius'
26
38
  end
27
39
 
28
- it 'unbreaks bodies and titles' do
29
- unbroken = Plugins::UnbreakMyArt.new.handle mock Item, title: 'about a ninja', body: 'and a pirate'
30
- unbroken.title.should == 'about a ninja'
31
- unbroken.body.should == 'and a pirate'
32
- end
33
-
34
40
  end
35
41
 
36
42
  end end
@@ -23,7 +23,7 @@ module Tributary describe Stream do
23
23
  describe '#initialize' do
24
24
 
25
25
  it 'filters the Items through the provided Plugins' do
26
- App.plugins = [Plugins::Mnml.new]
26
+ App.plugins = [Plugins::Mnml]
27
27
  plugged = Stream.new
28
28
  @stream.recent.map(&:title).should == ['ten…', 'this…', '600th anniversary (intl.)', 'bilinguality', 'a…', 'welcome to tributary']
29
29
  plugged.recent.map(&:title).should == ['tn…', 'ths…', '600th nnvrsr (ntl.)', 'blnglt', '…', 'wlcm t trbtr']
data/tributary.gemspec CHANGED
@@ -4,7 +4,7 @@ YAML::ENGINE.yamler = 'syck'
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = 'tributary'
7
- gem.version = '0.0.3'
7
+ gem.version = '0.0.4'
8
8
  gem.summary = 'tributary: a tiny, toto-inspired blogging engine'
9
9
  gem.homepage = 'http://github.com/chastell/tributary'
10
10
  gem.author = 'Piotr Szotkowski'
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: tributary
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Piotr Szotkowski
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-08 00:00:00 +01:00
13
+ date: 2011-03-10 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -97,7 +97,6 @@ files:
97
97
  - lib/tributary.rb
98
98
  - lib/tributary/app.rb
99
99
  - lib/tributary/item.rb
100
- - lib/tributary/plugins/dummy.rb
101
100
  - lib/tributary/plugins/mnml.rb
102
101
  - lib/tributary/plugins/unbreak_my_art.rb
103
102
  - lib/tributary/stream.rb
@@ -141,7 +140,6 @@ files:
141
140
  - spec/site/views/pages.sass
142
141
  - spec/tributary/app_spec.rb
143
142
  - spec/tributary/item_spec.rb
144
- - spec/tributary/plugins/dummy_spec.rb
145
143
  - spec/tributary/plugins/mnml_spec.rb
146
144
  - spec/tributary/plugins/unbreak_my_art_spec.rb
147
145
  - spec/tributary/stream_spec.rb
@@ -178,6 +176,5 @@ test_files:
178
176
  - spec/tributary/app_spec.rb
179
177
  - spec/tributary/stream_spec.rb
180
178
  - spec/tributary/item_spec.rb
181
- - spec/tributary/plugins/dummy_spec.rb
182
179
  - spec/tributary/plugins/unbreak_my_art_spec.rb
183
180
  - spec/tributary/plugins/mnml_spec.rb
@@ -1,7 +0,0 @@
1
- module Tributary module Plugins class Dummy
2
-
3
- def handle item
4
- item
5
- end
6
-
7
- end end end
@@ -1,12 +0,0 @@
1
- module Tributary describe Plugins::Dummy do
2
-
3
- describe '#handle' do
4
-
5
- it 'returns an unmodified Item' do
6
- item = mock Item
7
- Plugins::Dummy.new.handle(item).should equal item
8
- end
9
-
10
- end
11
-
12
- end end