wikilink-converter 0.1.0 → 0.2.1

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/Gemfile CHANGED
@@ -16,8 +16,11 @@ group :development do
16
16
  gem 'guard-yard'
17
17
  gem 'redcarpet'
18
18
 
19
- if HOST_OS =~ /linux/i
19
+ case HOST_OS
20
+ when /linux/i
20
21
  gem 'rb-inotify', require: false
21
22
  gem 'libnotify', require: false
23
+ when /darwin/i
24
+ gem 'growl_notify', require: false
22
25
  end
23
26
  end
data/Gemfile.lock CHANGED
@@ -2,8 +2,9 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  diff-lcs (1.1.3)
5
- ffi (1.0.11)
6
5
  git (1.2.5)
6
+ growl_notify (0.0.3)
7
+ rb-appscript
7
8
  guard (0.8.8)
8
9
  thor (~> 0.14.6)
9
10
  guard-bundler (0.1.3)
@@ -18,11 +19,9 @@ GEM
18
19
  bundler (~> 1.0)
19
20
  git (>= 1.2.5)
20
21
  rake
21
- libnotify (0.5.9)
22
22
  multi_json (1.0.4)
23
23
  rake (0.9.2.2)
24
- rb-inotify (0.8.8)
25
- ffi (>= 0.5.0)
24
+ rb-appscript (0.6.1)
26
25
  redcarpet (1.17.2)
27
26
  rspec (2.7.0)
28
27
  rspec-core (~> 2.7.0)
@@ -44,13 +43,12 @@ PLATFORMS
44
43
 
45
44
  DEPENDENCIES
46
45
  bundler
46
+ growl_notify
47
47
  guard
48
48
  guard-bundler
49
49
  guard-rspec
50
50
  guard-yard
51
51
  jeweler
52
- libnotify
53
- rb-inotify
54
52
  redcarpet
55
53
  rspec
56
54
  simplecov
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.1
@@ -5,6 +5,7 @@ module Wikilink
5
5
  # Namespace converter
6
6
  class Namespace
7
7
  include LinkHelper
8
+ include HTMLAttributes
8
9
 
9
10
  DEFAULT_NAME = ''
10
11
 
@@ -19,16 +20,17 @@ module Wikilink
19
20
  self
20
21
  end
21
22
 
22
- def run(colon, path, name, current_page)
23
+ def run(run_options)
23
24
  if @block
24
- instance_exec(colon, path, name, current_page, &@block)
25
+ instance_exec(run_options, &@block)
25
26
  end
26
27
  end
27
28
 
28
29
  class Default < Namespace
29
- def run(colon, path, name, current_page)
30
+ def run(run_options)
30
31
  return super if @block
31
32
 
33
+ path = run_options[:path].to_s
32
34
  path, fragment = path.split('#', 2)
33
35
  path, query = path.split('?', 2)
34
36
 
@@ -37,7 +39,7 @@ module Wikilink
37
39
 
38
40
  url = to_url(path, fragment, query)
39
41
 
40
- link_to(name, url, :class => html_class)
42
+ link_to(run_options[:name], url, :class => html_class(run_options[:class]))
41
43
  end
42
44
 
43
45
  def to_url(path, fragment, query)
@@ -48,11 +50,6 @@ module Wikilink
48
50
  end
49
51
  end
50
52
  end
51
-
52
- protected
53
- def html_class
54
- [options[:class], ('external' if options[:external])]
55
- end
56
53
  end
57
54
  end
58
55
  end
@@ -18,12 +18,12 @@ module Wikilink
18
18
  @options[:prefix] ||= '/' if is_current_site
19
19
  @namespace_converters = {}
20
20
 
21
- on_namespace(DEFAULT_NAMESPACE)
21
+ namespace(DEFAULT_NAMESPACE)
22
22
 
23
23
  yield self if block_given?
24
24
  end
25
25
 
26
- def on_namespace(*args, &block)
26
+ def namespace(*args, &block)
27
27
  namespace, converter, options = extract_arguments(*args)
28
28
  namespace = DEFAULT_NAMESPACE if namespace.to_s.empty?
29
29
 
@@ -50,27 +50,19 @@ module Wikilink
50
50
  set_namespace_converter namespace, converter if converter
51
51
  self
52
52
  end
53
- alias_method :on, :on_namespace
54
- alias_method :namespace, :on_namespace
55
53
 
56
- def on_default_namespace(*args, &block)
57
- on_namespace(DEFAULT_NAMESPACE, *args, &block)
54
+ def default_namespace(*args, &block)
55
+ namespace(DEFAULT_NAMESPACE, *args, &block)
58
56
  end
59
- alias_method :default_namespace, :on_default_namespace
60
57
 
61
- def run(colon, namespace, path, name, current_page)
58
+ def run(namespace, run_options)
62
59
  if converter = namespace_converter(namespace)
63
- converter.run(colon, path, name, current_page)
60
+ converter.run(run_options)
64
61
  elsif converter = instance_method_converter(namespace)
65
- converter.call(colon, path, name, current_page)
62
+ converter.call(run_options)
66
63
  end
67
64
  end
68
65
 
69
- protected
70
- def html_class
71
- [options[:class], ('external' if options[:external])]
72
- end
73
-
74
66
  private
75
67
  def namespace_converter(namespace)
76
68
  namespace = namespace.to_s.downcase
@@ -79,7 +71,11 @@ module Wikilink
79
71
 
80
72
  def instance_method_converter(namespace)
81
73
  namespace = namespace.to_s.downcase
82
- try_message = "on_namespace_#{namespace}".to_sym
74
+ if namespace == DEFAULT_NAMESPACE
75
+ try_message = :run_default_namespace
76
+ else
77
+ try_message = "run_namespace_#{namespace}".to_sym
78
+ end
83
79
  method(try_message) if respond_to?(try_message)
84
80
  end
85
81
 
@@ -6,6 +6,7 @@ module Wikilink
6
6
  module Sites
7
7
  class RubyChina < Wikilink::Converter::Site
8
8
  include Wikilink::Converter::LinkHelper
9
+ include Wikilink::Converter::HTMLAttributes
9
10
 
10
11
  def initialize(options = {})
11
12
  if options[:name] == CURRENT_SITE
@@ -18,14 +19,14 @@ module Wikilink
18
19
  super(options)
19
20
  end
20
21
 
21
- def on_namespace_topic(colon, path, name, current_page)
22
- path = "#{options[:domain]}topics/#{path}"
23
- link_to name, path, :class => html_class
22
+ def run_namespace_topic(run_options)
23
+ path = "#{options[:domain]}topics/#{run_options[:path]}"
24
+ link_to run_options[:name], path, :class => html_class(run_options[:class])
24
25
  end
25
26
 
26
- def on_namespace_node(colon, path, name, current_page)
27
- path = "#{options[:domain]}topics/node#{path}"
28
- link_to name, path, :class => html_class
27
+ def run_namespace_node(run_options)
28
+ path = "#{options[:domain]}topics/node#{run_options[:path]}"
29
+ link_to run_options[:name], path, :class => html_class(run_options[:class])
29
30
  end
30
31
  end
31
32
 
@@ -33,5 +33,19 @@ module Wikilink
33
33
  "<a #{attributes}href=\"#{CGI.escape_html url}\">#{CGI.escape_html name}</a>"
34
34
  end
35
35
  end
36
+
37
+ module HTMLAttributes
38
+ def html_class(extra_classes = nil)
39
+ classes = []
40
+ if respond_to? :options
41
+ classes << options[:class]
42
+ classes << 'external' if options[:external]
43
+ end
44
+
45
+ classes << extra_classes if extra_classes
46
+
47
+ classes.flatten.join(' ').split.uniq.join(' ')
48
+ end
49
+ end
36
50
  end
37
51
  end
@@ -25,6 +25,21 @@ module Wikilink
25
25
  include ArgumentExtractor
26
26
  CURRENT_SITE = ::Wikilink::Converter::Site::CURRENT_SITE_NAME
27
27
 
28
+ class << self
29
+ extend Forwardable
30
+ def instance
31
+ @instance ||= Converter.new
32
+ end
33
+ def config
34
+ yield instance
35
+ end
36
+ def_delegators(:instance,
37
+ :run, :execute,
38
+ :namespace, :default_namespace,
39
+ :site, :current_site,
40
+ :action)
41
+ end
42
+
28
43
  # Setup a converter. Handlers can be registered in block directly. If no
29
44
  # handler is registered on **page**, a default handler
30
45
  # Wikilink::Converter::Page is created with the given `options`.
@@ -35,11 +50,11 @@ module Wikilink
35
50
  @action_handlers = {}
36
51
  @options = options
37
52
 
38
- on_site(CURRENT_SITE, @options)
53
+ site(CURRENT_SITE, @options)
39
54
  yield self if block_given?
40
55
  end
41
56
 
42
- def run(text, current_page = nil)
57
+ def run(text, run_options = {})
43
58
  text.gsub(/(^|.)\[\[(.*?[^:])\]\]/) do |match|
44
59
  prefix, inner = $1, $2.strip
45
60
  if prefix == '\\'
@@ -61,12 +76,13 @@ module Wikilink
61
76
  end
62
77
 
63
78
  if name.to_s.empty?
64
- name = resolve_name(inner, current_page)
79
+ name = resolve_name(inner, run_options)
65
80
  end
66
81
 
67
82
  # ignore malformed wikilink
68
83
  if valid?(site, namespace, path)
69
- result = convert_link(colon, site, namespace, path, name, current_page)
84
+ run_options = run_options.merge(path: path, name: name, colon: colon)
85
+ result = convert_link(site, namespace, run_options)
70
86
  result ? ($1 + result) : match
71
87
  else
72
88
  match
@@ -88,14 +104,10 @@ module Wikilink
88
104
  end
89
105
  end
90
106
 
91
- def_delegator :@current_site_converter, :on_namespace
92
- alias_method :on, :on_namespace
93
- alias_method :namespace, :on_namespace
94
-
95
- def_delegator :@current_site_converter, :on_default_namespace
96
- alias_method :default_namespace, :on_default_namespace
107
+ def_delegator :@current_site_converter, :namespace
108
+ def_delegator :@current_site_converter, :default_namespace
97
109
 
98
- def on_site(*args)
110
+ def site(*args)
99
111
  site, converter, options = extract_arguments(*args)
100
112
  options = @options.merge(options)
101
113
  site = CURRENT_SITE if site.to_s.empty?
@@ -111,19 +123,15 @@ module Wikilink
111
123
  set_site_converter site, converter
112
124
  self
113
125
  end
114
- alias_method :site, :on_site
115
126
 
116
- def on_current_site(*args, &block)
117
- on_site(CURRENT_SITE, *args, &block)
127
+ def current_site(*args, &block)
128
+ site(CURRENT_SITE, *args, &block)
118
129
  end
119
- alias_method :current_site, :on_current_site
120
130
 
121
- def on_action(action, &block)
122
- @action_handlers[action.to_s.downcase] = block
131
+ def action(name, &block)
132
+ @action_handlers[name.to_s.downcase] = block
123
133
  self
124
134
  end
125
- alias_method :action, :on_action
126
-
127
135
 
128
136
  private
129
137
  def site_converter(site)
@@ -145,15 +153,15 @@ module Wikilink
145
153
  handler.call(argument) if handler
146
154
  end
147
155
 
148
- def convert_link(colon, site, namespace, path, name, current_page)
156
+ def convert_link(site, namespace, run_options)
149
157
  converter = site_converter(site)
150
- converter.run(colon, namespace, path, name, current_page) if converter
158
+ converter.run(namespace, run_options) if converter
151
159
  end
152
160
 
153
161
  # TODO: relative
154
162
  # TODO: ruby (computer) -> ruby
155
163
  # TODO: Shanghai, China -> Shanghai
156
- def resolve_name(inner_text, current_path)
164
+ def resolve_name(inner_text, run_options)
157
165
  if inner_text.end_with?('|')
158
166
  inner_text.chop.chomp('/').split(%r{[:/]}, 2).last
159
167
  else
@@ -9,7 +9,7 @@ shared_examples 'converter that can forward to given block' do |klass|
9
9
  describe '#run' do
10
10
  subject { converter.method(:run) }
11
11
  it 'forwards to the block' do
12
- subject.should convert(':', 'Home', 'Home', '/').to('it works')
12
+ subject.should convert(name: 'Home', path: 'Home').to('it works')
13
13
  end
14
14
  end
15
15
  end
@@ -22,7 +22,7 @@ shared_examples 'converter that can forward to given block' do |klass|
22
22
  describe '#run' do
23
23
  subject { converter.method(:run) }
24
24
  it 'forwards to the block and allows options access' do
25
- subject.should convert(':', 'Home', 'Home', '/').to('fake')
25
+ subject.should convert(name: 'Home', path: 'Home').to('fake')
26
26
  end
27
27
  end
28
28
  end
@@ -33,7 +33,7 @@ describe Wikilink::Converter::Namespace do
33
33
  describe '#run' do
34
34
  subject { converter.method(:run) }
35
35
  it 'does nothing' do
36
- subject.should convert(':', 'Home', 'Home', '/').to(nil)
36
+ subject.should convert(name: 'Home', path: 'Home').to(nil)
37
37
  end
38
38
  end
39
39
 
@@ -41,14 +41,16 @@ describe Wikilink::Converter::Namespace do
41
41
  end
42
42
 
43
43
  describe Wikilink::Converter::Namespace::Default do
44
+ let(:run_options) { { name: 'Name', path: 'Home' } }
45
+
44
46
  shared_examples 'converter that keeps query fragment only path untouched' do
45
- it { should convert(':', '#toc-1', 'Header 1', '/').
47
+ it { should convert(path: '#toc-1', name: 'Header 1').
46
48
  to('<a href="#toc-1">Header 1</a>')
47
49
  }
48
- it { should convert(':', '?q=keyword', 'Search keyword', '/').
50
+ it { should convert(path: '?q=keyword', name: 'Search keyword').
49
51
  to('<a href="?q=keyword">Search keyword</a>')
50
52
  }
51
- it { should convert(':', '?q=keyword#page-10', 'Search keyword (page 10)', '/').
53
+ it { should convert(path: '?q=keyword#page-10', name: 'Search keyword (page 10)').
52
54
  to('<a href="?q=keyword#page-10">Search keyword (page 10)</a>')
53
55
  }
54
56
  end
@@ -56,7 +58,7 @@ describe Wikilink::Converter::Namespace::Default do
56
58
  let(:converter) { self.class.describes.new }
57
59
  describe '#run' do
58
60
  subject { converter.method(:run) }
59
- it { should convert(':', 'Home', 'Name', '/').
61
+ it { should convert(run_options).
60
62
  to('<a href="Home">Name</a>')
61
63
  }
62
64
  it_behaves_like 'converter that keeps query fragment only path untouched'
@@ -74,7 +76,7 @@ describe Wikilink::Converter::Namespace::Default do
74
76
  let(:converter) { self.class.describes.new suffix: '/index.html' }
75
77
  describe '#run' do
76
78
  subject { converter.method(:run) }
77
- it { should convert(':', 'Home', 'Name', '/').
79
+ it { should convert(run_options).
78
80
  to('<a href="Home/index.html">Name</a>')
79
81
  }
80
82
  it_behaves_like 'converter that keeps query fragment only path untouched'
@@ -85,7 +87,7 @@ describe Wikilink::Converter::Namespace::Default do
85
87
  let(:converter) { self.class.describes.new external: true }
86
88
  describe '#run' do
87
89
  subject { converter.method(:run) }
88
- it { should convert(':', 'Home', 'Name', '/').
90
+ it { should convert(run_options).
89
91
  to('<a class="external" href="Home">Name</a>')
90
92
  }
91
93
  end
@@ -94,7 +96,7 @@ describe Wikilink::Converter::Namespace::Default do
94
96
  let(:converter) { self.class.describes.new class: 'fancy' }
95
97
  describe '#run' do
96
98
  subject { converter.method(:run) }
97
- it { should convert(':', 'Home', 'Name', '/').
99
+ it { should convert(run_options).
98
100
  to('<a class="fancy" href="Home">Name</a>')
99
101
  }
100
102
  end
@@ -103,7 +105,7 @@ describe Wikilink::Converter::Namespace::Default do
103
105
  let(:converter) { self.class.describes.new external: true, class: 'fancy' }
104
106
  describe '#run' do
105
107
  subject { converter.method(:run) }
106
- it { should convert(':', 'Home', 'Name', '/').
108
+ it { should convert(run_options).
107
109
  to('<a class="fancy external" href="Home">Name</a>')
108
110
  }
109
111
  end
@@ -4,51 +4,15 @@ describe Wikilink::Converter::Site do
4
4
  DEFAULT_NAMESPACE = Wikilink::Converter::Site::DEFAULT_NAMESPACE
5
5
  CURRENT_SITE_NAME = Wikilink::Converter::Site::CURRENT_SITE_NAME
6
6
 
7
- # { subject.foo }.should forward(:bar).to(handler).with(any_args)
8
- RSpec::Matchers.define :forward do |message|
9
- match do |block|
10
- block.call
11
- @handler.received_message?(message, *@arguments)
12
- end
13
-
14
- description do
15
- "forward to message #{message} to #{@handler.inspect}"
16
- end
17
-
18
- failure_message_for_should do |block|
19
- <<MESSAGE
20
- expected forward #{message}
21
- to #{block}
22
- with #{@arguments.inspect}
23
- MESSAGE
24
- end
25
-
26
- failure_message_for_should_not do |block|
27
- <<MESSAGE
28
- expected not forward #{message}
29
- to #{block}
30
- with #{@arguments.inspect}
31
- MESSAGE
32
- end
33
-
34
- chain :with do |*arguments|
35
- @arguments = arguments
36
- end
37
-
38
- chain :to do |handler|
39
- @handler = handler
40
- end
41
- end
42
-
43
7
  shared_examples 'configuring a new instance of class as namespace handler' do |namespace|
44
8
  # require setting converter to an instance of Site
45
9
  context 'with converter class' do
46
10
  class SpecNamespace; end
47
11
  define_method :call do |*args|
48
12
  if namespace.to_s.empty?
49
- converter.on_namespace SpecNamespace, *args
13
+ converter.namespace SpecNamespace, *args
50
14
  else
51
- converter.on_namespace namespace, SpecNamespace, *args
15
+ converter.namespace namespace, SpecNamespace, *args
52
16
  end
53
17
  end
54
18
  let(:namespace_converter) { double(:namespace_converter) }
@@ -62,7 +26,7 @@ MESSAGE
62
26
  SpecNamespace.should_receive(:new).once.and_return(namespace_converter)
63
27
  call
64
28
  namespace_converter.should_receive(:run).and_return('it works')
65
- converter.run(':', namespace, 'Home', 'Name', '/').should eq('it works')
29
+ converter.run(namespace, path: 'Home', name: 'Name').should eq('it works')
66
30
  end
67
31
 
68
32
  context 'and options' do
@@ -82,6 +46,7 @@ MESSAGE
82
46
 
83
47
  let(:default_namespace) { double(:default_namespace).as_null_object }
84
48
  let(:namespace) { double(:namespace).as_null_object }
49
+ let(:run_options) { { path: 'Home', name: 'Name' } }
85
50
  before { Wikilink::Converter::Namespace::Default.stub(:new) { default_namespace } }
86
51
 
87
52
  shared_examples ''
@@ -133,26 +98,26 @@ MESSAGE
133
98
 
134
99
  describe '#run' do
135
100
  it 'delegates default namespace to Namespace::Default instance' do
136
- ->{ converter.run(':', DEFAULT_NAMESPACE, 'Home', 'Name', '/') }.
137
- should forward(:run).to(default_namespace).with(':', 'Home', 'Name', '/')
101
+ default_namespace.should_receive(:run).with(hash_including(run_options))
102
+ converter.run(DEFAULT_NAMESPACE, run_options)
138
103
  end
139
104
  end
140
105
 
141
- describe '#on_default_namespace' do
142
- it 'is a shortcut of #on_namespace' do
143
- converter.should_receive(:on_namespace).with(DEFAULT_NAMESPACE, 'arg')
144
- converter.on_default_namespace 'arg'
106
+ describe '#default_namespace' do
107
+ it 'is a shortcut of #namespace' do
108
+ converter.should_receive(:namespace).with(DEFAULT_NAMESPACE, 'arg')
109
+ converter.default_namespace 'arg'
145
110
  end
146
111
  end
147
112
 
148
- describe '#on_namespace' do
113
+ describe '#namespace' do
149
114
  context 'without any arguments nor block' do
150
115
  let(:default_namespace) { double(:default_namespace) }
151
116
 
152
117
  it 'does not change the default namespace handler' do
153
118
  Wikilink::Converter::Namespace::Default.should_receive(:new).
154
119
  once.and_return(default_namespace)
155
- converter.on_namespace
120
+ converter.namespace
156
121
  end
157
122
  end
158
123
 
@@ -161,7 +126,7 @@ MESSAGE
161
126
  yielded = double('yielded')
162
127
  yielded.should_receive(:poke)
163
128
  default_namespace.should_receive(:config).and_yield
164
- converter.on_namespace do
129
+ converter.namespace do
165
130
  yielded.poke
166
131
  end
167
132
  end
@@ -173,7 +138,7 @@ MESSAGE
173
138
  it 'does not change the default namespace handler' do
174
139
  Wikilink::Converter::Namespace::Default.should_receive(:new).
175
140
  once.and_return(default_namespace)
176
- converter.on_namespace foo: :bar
141
+ converter.namespace foo: :bar
177
142
  end
178
143
  end
179
144
 
@@ -183,37 +148,37 @@ MESSAGE
183
148
  it 'does not change the default namespace handler' do
184
149
  Wikilink::Converter::Namespace::Default.should_receive(:new).
185
150
  once.and_return(default_namespace)
186
- converter.on_namespace(DEFAULT_NAMESPACE)
151
+ converter.namespace(DEFAULT_NAMESPACE)
187
152
  end
188
153
  end
189
154
  context 'with other namespace name' do
190
- let(:name) { 'topics' }
155
+ let(:namespace_name) { 'topics' }
191
156
  let(:klass) { Wikilink::Converter::Namespace }
192
157
 
193
158
  it 'creates a new Wikilink::Converter::Namespace instance' do
194
159
  klass.should_receive(:new)
195
- converter.on_namespace name
160
+ converter.namespace namespace_name
196
161
  end
197
162
  it 'initializes Wikilink::Converter::Namespace instance with option :site_name' do
198
163
  klass.should_receive(:new).with(hash_including(site_name: site_name))
199
- converter.on_namespace name
164
+ converter.namespace namespace_name
200
165
  end
201
166
  it 'initializes Wikilink::Converter::Namespace instance with option :name' do
202
- klass.should_receive(:new).with(hash_including(name: name))
203
- converter.on_namespace name
167
+ klass.should_receive(:new).with(hash_including(name: namespace_name))
168
+ converter.namespace namespace_name
204
169
  end
205
170
  it 'uses the instance of Wikilink::Converter::Namespace as new namespace converter' do
206
171
  klass.should_receive(:new).and_return(namespace)
207
- converter.on_namespace name
172
+ converter.namespace namespace_name
208
173
  namespace.should_receive(:run).and_return('it works')
209
- converter.run(':', name, 'Home', 'Name', '/').should eq('it works')
174
+ converter.run(namespace_name, run_options).should eq('it works')
210
175
  end
211
176
 
212
177
  context 'with object' do
213
178
  it 'uses that object as new namespace converter' do
214
- converter.on_namespace name, namespace
179
+ converter.namespace namespace_name, namespace
215
180
  namespace.should_receive(:run).and_return('it works')
216
- converter.run(':', name, 'Home', 'Name', '/').should eq('it works')
181
+ converter.run(namespace_name, run_options).should eq('it works')
217
182
  end
218
183
  end
219
184
 
@@ -224,9 +189,9 @@ MESSAGE
224
189
 
225
190
  context 'with object' do
226
191
  it 'uses that object as new namespace converter' do
227
- converter.on_namespace namespace
192
+ converter.namespace namespace
228
193
  namespace.should_receive(:run).and_return('it works')
229
- converter.run(':', DEFAULT_NAMESPACE, 'Home', 'Name', '/').should eq('it works')
194
+ converter.run(DEFAULT_NAMESPACE, run_options).should eq('it works')
230
195
  end
231
196
  end
232
197
 
@@ -276,20 +241,20 @@ MESSAGE
276
241
 
277
242
  describe '#run' do
278
243
  it 'delegates default namespace to Namespace::Default instance' do
279
- ->{ converter.run(':', DEFAULT_NAMESPACE, 'Home', 'Name', '/') }.
280
- should forward(:run).to(default_namespace).with(':', 'Home', 'Name', '/')
244
+ default_namespace.should_receive(:run).with(hash_including(run_options))
245
+ converter.run(DEFAULT_NAMESPACE, run_options)
281
246
  end
282
247
 
283
- context 'with method #on_namespace_topics defined' do
248
+ context 'with method #run_namespace_topics defined' do
284
249
  before { Wikilink::Converter::Namespace::Default.unstub(:new) }
285
250
  class SpecSite < Wikilink::Converter::Site
286
- def on_namespace_topics(colon, path, name, current_page)
251
+ def run_namespace_topics(run_options)
287
252
  'it works'
288
253
  end
289
254
  end
290
255
  let(:converter) { SpecSite.new }
291
- it 'invokes #on_namespace_topics to handle namespace topics' do
292
- converter.run(':', 'topics', 'Home', 'Name', '/').should eq('it works')
256
+ it 'invokes #run_namespace_topics to handle namespace topics' do
257
+ converter.run('topics', run_options).should eq('it works')
293
258
  end
294
259
 
295
260
  context 'but user has override it' do
@@ -300,21 +265,21 @@ MESSAGE
300
265
  }
301
266
 
302
267
  it 'uses user version' do
303
- converter.run(':', 'topics', 'Home', 'Name', '/').should eq('use this version')
268
+ converter.run('topics', run_options).should eq('use this version')
304
269
  end
305
270
  end
306
271
  end
307
272
 
308
- context 'with method #on_namespace_ defined' do
273
+ context 'with method #run_default_namespace defined' do
309
274
  before { Wikilink::Converter::Namespace::Default.unstub(:new) }
310
275
  class SpecSite < Wikilink::Converter::Site
311
- def on_namespace_(colon, path, name, current_page)
276
+ def run_default_namespace(run_options)
312
277
  'it works'
313
278
  end
314
279
  end
315
280
  let(:converter) { SpecSite.new }
316
- it 'invokes #on_namespace_ to handle default namespace' do
317
- converter.run(':', DEFAULT_NAMESPACE, 'Home', 'Name', '/').should eq('it works')
281
+ it 'invokes #run_default_namespace to handle default namespace' do
282
+ converter.run(DEFAULT_NAMESPACE, run_options).should eq('it works')
318
283
  end
319
284
 
320
285
  context 'but user has override it' do
@@ -325,7 +290,7 @@ MESSAGE
325
290
  }
326
291
 
327
292
  it 'uses user version' do
328
- converter.run(':', DEFAULT_NAMESPACE, 'Home', 'Name', '/').should eq('use this version')
293
+ converter.run(DEFAULT_NAMESPACE, run_options).should eq('use this version')
329
294
  end
330
295
  end
331
296
  end
@@ -1,8 +1,36 @@
1
1
  require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
+ shared_examples 'singleton' do |klass|
4
+ describe '.instance' do
5
+ subject { klass }
6
+ its(:instance) { should be_a_kind_of(klass) }
7
+ it 'returns the same instances for all calls to #instance' do
8
+ klass.instance.should equal(klass.instance)
9
+ end
10
+ end
11
+ end
12
+
3
13
  describe Wikilink::Converter do
4
14
  CURRENT_SITE = Wikilink::Converter::CURRENT_SITE
5
15
 
16
+ it_behaves_like 'singleton', Wikilink::Converter
17
+ describe '.config' do
18
+ it 'yields the singleton instance' do
19
+ Wikilink::Converter.config do |arg|
20
+ arg.should equal(Wikilink::Converter.instance)
21
+ end
22
+ end
23
+ end
24
+
25
+ %w{run execute}.each do |method|
26
+ describe ".#{method}" do
27
+ it "forwards method #{method} to #instance" do
28
+ Wikilink::Converter.instance.should_receive(method.to_sym).with(:arg)
29
+ Wikilink::Converter.send method.to_sym, :arg
30
+ end
31
+ end
32
+ end
33
+
6
34
  let(:converter) { Wikilink::Converter.new }
7
35
 
8
36
  describe '#run' do
@@ -39,7 +67,7 @@ describe Wikilink::Converter do
39
67
  context 'in namespace topics' do
40
68
  context 'with default handler' do
41
69
  before do
42
- converter.on('topics', Wikilink::Converter::Namespace::Default)
70
+ converter.namespace('topics', Wikilink::Converter::Namespace::Default)
43
71
  end
44
72
  it { should convert('[[topics:World]]').to('<a href="/World">topics:World</a>') }
45
73
  end
@@ -63,23 +91,30 @@ describe Wikilink::Converter do
63
91
  context 'in namespace topics' do
64
92
  context 'with default handler' do
65
93
  before do
66
- converter.on('topics', Wikilink::Converter::Namespace::Default)
94
+ converter.namespace('topics', Wikilink::Converter::Namespace::Default)
67
95
  end
68
96
  it { should convert('[[topics:World|]]').to('<a href="/World">World</a>') }
69
97
  it { should convert('[[:topics:World|]]').to('<a href="/World">World</a>') }
70
98
  end
71
99
  end
72
100
  end
101
+ it 'passes options to namespace converter' do
102
+ Wikilink::Converter::Site.any_instance.should_receive(:run) { |*args|
103
+ args.last[:hello].should eq('world')
104
+ 'result'
105
+ }
106
+ converter.run('[[Hello]]', hello: 'world')
107
+ end
73
108
  end
74
109
 
75
- describe '#on_default_site' do
76
- it 'is a shortcut of #on_site' do
77
- converter.should_receive(:on_site).with(CURRENT_SITE, 'arg')
78
- converter.on_current_site 'arg'
110
+ describe '#default_site' do
111
+ it 'is a shortcut of #site' do
112
+ converter.should_receive(:site).with(CURRENT_SITE, 'arg')
113
+ converter.current_site 'arg'
79
114
  end
80
115
  end
81
116
 
82
- describe '#on_site' do
117
+ describe '#site' do
83
118
  let(:default_site) { double(:default_site).as_null_object }
84
119
  let(:site) { double(:site).as_null_object }
85
120
  before { Wikilink::Converter::Site.stub(:new) { default_site } }
@@ -89,10 +124,10 @@ describe Wikilink::Converter do
89
124
  it 'does not create new instance' do
90
125
  converter # call it to initialize first
91
126
  Wikilink::Converter::Site.should_not_receive :new
92
- converter.on_site
127
+ converter.site
93
128
  end
94
129
  it 'yields the default site converter' do
95
- converter.on_site do |site_converter|
130
+ converter.site do |site_converter|
96
131
  site_converter.should eq(default_site)
97
132
  end
98
133
  end
@@ -102,17 +137,17 @@ describe Wikilink::Converter do
102
137
  it 'creates a new instance of Wikilink::Converter::Site as the site converter' do
103
138
  converter # call it to initialize first
104
139
  Wikilink::Converter::Site.should_receive(:new).once
105
- converter.on_site 'wikipedia'
140
+ converter.site 'wikipedia'
106
141
  end
107
142
  it 'initializes the instance with option :name' do
108
143
  converter # call it to initialize first
109
144
  Wikilink::Converter::Site.should_receive(:new).with(hash_including(name: 'wikipedia')).once
110
- converter.on_site 'wikipedia'
145
+ converter.site 'wikipedia'
111
146
  end
112
147
  it 'yields the new converter instance' do
113
148
  converter # call it to initialize first
114
149
  Wikilink::Converter::Site.should_receive(:new).once.and_return(site)
115
- converter.on_site('wikipedia') do |site_converter|
150
+ converter.site('wikipedia') do |site_converter|
116
151
  site_converter.should eq(site)
117
152
  end
118
153
  end
@@ -121,7 +156,7 @@ describe Wikilink::Converter do
121
156
  it 'initializes the instance with given options' do
122
157
  converter # call it to initialize first
123
158
  Wikilink::Converter::Site.should_receive(:new).with(hash_including(foo: :bar)).once
124
- converter.on_site 'wikipedia', options
159
+ converter.site 'wikipedia', options
125
160
  end
126
161
  end
127
162
  end
@@ -130,10 +165,10 @@ describe Wikilink::Converter do
130
165
  it 'does not create new instance' do
131
166
  converter # call it to initialize first
132
167
  Wikilink::Converter::Site.should_not_receive :new
133
- converter.on_site site
168
+ converter.site site
134
169
  end
135
170
  it 'yields the object' do
136
- converter.on_site(site) do |site_converter|
171
+ converter.site(site) do |site_converter|
137
172
  site_converter.should eq(site)
138
173
  end
139
174
  end
@@ -152,7 +187,7 @@ describe Wikilink::Converter do
152
187
 
153
188
  context 'with handler registered on action toc' do
154
189
  before {
155
- converter.on_action('toc') do |arg|
190
+ converter.action('toc') do |arg|
156
191
  "Table of Contents#{arg}"
157
192
  end
158
193
  }
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{wikilink-converter}
8
- s.version = "0.1.0"
7
+ s.name = "wikilink-converter"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Ian Yang}]
12
- s.date = %q{2011-12-04}
13
- s.description = %q{convert [[WikiLink]] to <a>}
14
- s.email = %q{me@iany.me}
11
+ s.authors = ["Ian Yang"]
12
+ s.date = "2011-12-06"
13
+ s.description = "convert [[WikiLink]] to <a>"
14
+ s.email = "me@iany.me"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.markdown"
@@ -44,11 +44,11 @@ Gem::Specification.new do |s|
44
44
  "spec/wikilink/converter_spec.rb",
45
45
  "wikilink-converter.gemspec"
46
46
  ]
47
- s.homepage = %q{http://github.com/doitian/wikilink-converter}
48
- s.licenses = [%q{MIT}]
49
- s.require_paths = [%q{lib}]
50
- s.rubygems_version = %q{1.8.6}
51
- s.summary = %q{convert [[WikiLink]] to <a>}
47
+ s.homepage = "http://github.com/doitian/wikilink-converter"
48
+ s.licenses = ["MIT"]
49
+ s.require_paths = ["lib"]
50
+ s.rubygems_version = "1.8.10"
51
+ s.summary = "convert [[WikiLink]] to <a>"
52
52
 
53
53
  if s.respond_to? :specification_version then
54
54
  s.specification_version = 3
@@ -64,8 +64,7 @@ Gem::Specification.new do |s|
64
64
  s.add_development_dependency(%q<guard-bundler>, [">= 0"])
65
65
  s.add_development_dependency(%q<guard-yard>, [">= 0"])
66
66
  s.add_development_dependency(%q<redcarpet>, [">= 0"])
67
- s.add_development_dependency(%q<rb-inotify>, [">= 0"])
68
- s.add_development_dependency(%q<libnotify>, [">= 0"])
67
+ s.add_development_dependency(%q<growl_notify>, [">= 0"])
69
68
  else
70
69
  s.add_dependency(%q<rspec>, [">= 0"])
71
70
  s.add_dependency(%q<yard>, [">= 0"])
@@ -77,8 +76,7 @@ Gem::Specification.new do |s|
77
76
  s.add_dependency(%q<guard-bundler>, [">= 0"])
78
77
  s.add_dependency(%q<guard-yard>, [">= 0"])
79
78
  s.add_dependency(%q<redcarpet>, [">= 0"])
80
- s.add_dependency(%q<rb-inotify>, [">= 0"])
81
- s.add_dependency(%q<libnotify>, [">= 0"])
79
+ s.add_dependency(%q<growl_notify>, [">= 0"])
82
80
  end
83
81
  else
84
82
  s.add_dependency(%q<rspec>, [">= 0"])
@@ -91,8 +89,7 @@ Gem::Specification.new do |s|
91
89
  s.add_dependency(%q<guard-bundler>, [">= 0"])
92
90
  s.add_dependency(%q<guard-yard>, [">= 0"])
93
91
  s.add_dependency(%q<redcarpet>, [">= 0"])
94
- s.add_dependency(%q<rb-inotify>, [">= 0"])
95
- s.add_dependency(%q<libnotify>, [">= 0"])
92
+ s.add_dependency(%q<growl_notify>, [">= 0"])
96
93
  end
97
94
  end
98
95
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikilink-converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-04 00:00:00.000000000Z
12
+ date: 2011-12-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &16725440 !ruby/object:Gem::Requirement
16
+ requirement: &2153445440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *16725440
24
+ version_requirements: *2153445440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yard
27
- requirement: &16724920 !ruby/object:Gem::Requirement
27
+ requirement: &2153444940 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *16724920
35
+ version_requirements: *2153444940
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &16724440 !ruby/object:Gem::Requirement
38
+ requirement: &2153444460 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *16724440
46
+ version_requirements: *2153444460
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &16723920 !ruby/object:Gem::Requirement
49
+ requirement: &2153443960 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *16723920
57
+ version_requirements: *2153443960
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &16723420 !ruby/object:Gem::Requirement
60
+ requirement: &2153443480 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *16723420
68
+ version_requirements: *2153443480
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard
71
- requirement: &16722940 !ruby/object:Gem::Requirement
71
+ requirement: &2153443000 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *16722940
79
+ version_requirements: *2153443000
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: guard-rspec
82
- requirement: &16722440 !ruby/object:Gem::Requirement
82
+ requirement: &2153442520 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *16722440
90
+ version_requirements: *2153442520
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: guard-bundler
93
- requirement: &16721920 !ruby/object:Gem::Requirement
93
+ requirement: &2153442020 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *16721920
101
+ version_requirements: *2153442020
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: guard-yard
104
- requirement: &16721420 !ruby/object:Gem::Requirement
104
+ requirement: &2153441500 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *16721420
112
+ version_requirements: *2153441500
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: redcarpet
115
- requirement: &16720940 !ruby/object:Gem::Requirement
115
+ requirement: &2153440980 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *16720940
123
+ version_requirements: *2153440980
124
124
  - !ruby/object:Gem::Dependency
125
- name: rb-inotify
126
- requirement: &16720420 !ruby/object:Gem::Requirement
125
+ name: growl_notify
126
+ requirement: &2153440420 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,18 +131,7 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *16720420
135
- - !ruby/object:Gem::Dependency
136
- name: libnotify
137
- requirement: &16719920 !ruby/object:Gem::Requirement
138
- none: false
139
- requirements:
140
- - - ! '>='
141
- - !ruby/object:Gem::Version
142
- version: '0'
143
- type: :development
144
- prerelease: false
145
- version_requirements: *16719920
134
+ version_requirements: *2153440420
146
135
  description: convert [[WikiLink]] to <a>
147
136
  email: me@iany.me
148
137
  executables: []
@@ -192,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
192
181
  version: '0'
193
182
  segments:
194
183
  - 0
195
- hash: -3886316938632370921
184
+ hash: -3433314059402378483
196
185
  required_rubygems_version: !ruby/object:Gem::Requirement
197
186
  none: false
198
187
  requirements:
@@ -201,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
190
  version: '0'
202
191
  requirements: []
203
192
  rubyforge_project:
204
- rubygems_version: 1.8.6
193
+ rubygems_version: 1.8.10
205
194
  signing_key:
206
195
  specification_version: 3
207
196
  summary: convert [[WikiLink]] to <a>