wikilink-converter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,177 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Wikilink::Converter do
4
+ CURRENT_SITE = Wikilink::Converter::CURRENT_SITE
5
+
6
+ let(:converter) { Wikilink::Converter.new }
7
+
8
+ describe '#run' do
9
+ subject { converter.method(:run) }
10
+ it 'does nothing when text does not contain wikilink' do
11
+ subject.should convert("Hello World").to('Hello World')
12
+ end
13
+ it 'converts wikilink to element A' do
14
+ subject.should convert('[[Home]]').to('<a href="/Home">Home</a>')
15
+ end
16
+ it 'converts multiple wikilinks to elements A' do
17
+ subject.should convert('[[Home]] [[Page]]').
18
+ to('<a href="/Home">Home</a> <a href="/Page">Page</a>')
19
+ end
20
+ it 'converts escaped \\[[wikilink]] to [[wikilink]]' do
21
+ subject.should convert('\\[[Hello]] World').to('[[Hello]] World')
22
+ end
23
+ it 'ignores [[ and ]] in different lines' do
24
+ subject.should convert("[[Hel\nlo]]").to("[[Hel\nlo]]")
25
+ end
26
+ it 'ignores wikilink with last character is :' do
27
+ subject.should convert("[[:digit:]]").to("[[:digit:]]")
28
+ end
29
+ it 'ignores wikilink with last character is :' do
30
+ subject.should convert("[[:digit:]]").to("[[:digit:]]")
31
+ end
32
+ it 'ignores wikilink which path starts with [' do
33
+ subject.should convert("[[[test]]").to("[[[test]]")
34
+ end
35
+ it 'ignores wikilink which path starts with ]' do
36
+ subject.should convert("[[]test]]").to("[[]test]]")
37
+ end
38
+
39
+ context 'in namespace topics' do
40
+ context 'with default handler' do
41
+ before do
42
+ converter.on('topics', Wikilink::Converter::Namespace::Default)
43
+ end
44
+ it { should convert('[[topics:World]]').to('<a href="/World">topics:World</a>') }
45
+ end
46
+ end
47
+
48
+ context 'with site wiki' do
49
+ let(:wiki) { double(:wiki) }
50
+ before { converter.site('wiki', wiki) }
51
+ subject { converter.method(:run) }
52
+
53
+ it 'use link to external wiki' do
54
+ wiki.should_receive(:run).with(any_args).and_return('<a>works</a>')
55
+ subject.should convert('[[wiki:Ruby]]').to('<a>works</a>')
56
+ end
57
+ end
58
+
59
+ describe 'pipe trick' do
60
+ it { should convert('[[Hello|]]').to('<a href="/Hello">Hello</a>') }
61
+ it { should convert('[[Hello/World|]]').to('<a href="/Hello/World">World</a>') }
62
+
63
+ context 'in namespace topics' do
64
+ context 'with default handler' do
65
+ before do
66
+ converter.on('topics', Wikilink::Converter::Namespace::Default)
67
+ end
68
+ it { should convert('[[topics:World|]]').to('<a href="/World">World</a>') }
69
+ it { should convert('[[:topics:World|]]').to('<a href="/World">World</a>') }
70
+ end
71
+ end
72
+ end
73
+ end
74
+
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'
79
+ end
80
+ end
81
+
82
+ describe '#on_site' do
83
+ let(:default_site) { double(:default_site).as_null_object }
84
+ let(:site) { double(:site).as_null_object }
85
+ before { Wikilink::Converter::Site.stub(:new) { default_site } }
86
+ let(:converter) { Wikilink::Converter.new }
87
+
88
+ context 'without any arguments' do
89
+ it 'does not create new instance' do
90
+ converter # call it to initialize first
91
+ Wikilink::Converter::Site.should_not_receive :new
92
+ converter.on_site
93
+ end
94
+ it 'yields the default site converter' do
95
+ converter.on_site do |site_converter|
96
+ site_converter.should eq(default_site)
97
+ end
98
+ end
99
+ end
100
+
101
+ context 'with site name' do
102
+ it 'creates a new instance of Wikilink::Converter::Site as the site converter' do
103
+ converter # call it to initialize first
104
+ Wikilink::Converter::Site.should_receive(:new).once
105
+ converter.on_site 'wikipedia'
106
+ end
107
+ it 'initializes the instance with option :name' do
108
+ converter # call it to initialize first
109
+ Wikilink::Converter::Site.should_receive(:new).with(hash_including(name: 'wikipedia')).once
110
+ converter.on_site 'wikipedia'
111
+ end
112
+ it 'yields the new converter instance' do
113
+ converter # call it to initialize first
114
+ Wikilink::Converter::Site.should_receive(:new).once.and_return(site)
115
+ converter.on_site('wikipedia') do |site_converter|
116
+ site_converter.should eq(site)
117
+ end
118
+ end
119
+ context 'and options' do
120
+ let(:options) { { foo: :bar } }
121
+ it 'initializes the instance with given options' do
122
+ converter # call it to initialize first
123
+ Wikilink::Converter::Site.should_receive(:new).with(hash_including(foo: :bar)).once
124
+ converter.on_site 'wikipedia', options
125
+ end
126
+ end
127
+ end
128
+
129
+ context 'with object' do
130
+ it 'does not create new instance' do
131
+ converter # call it to initialize first
132
+ Wikilink::Converter::Site.should_not_receive :new
133
+ converter.on_site site
134
+ end
135
+ it 'yields the object' do
136
+ converter.on_site(site) do |site_converter|
137
+ site_converter.should eq(site)
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+ describe '#execute' do
144
+ subject { converter.method(:execute) }
145
+
146
+ it 'does nothing without any registered action handlers' do
147
+ subject.should convert('{{toc}}').to('{{toc}}')
148
+ end
149
+ it 'converts escaped \\{{magicwords}} to {{magicwords}}' do
150
+ subject.should convert('\\{{toc}}').to('{{toc}}')
151
+ end
152
+
153
+ context 'with handler registered on action toc' do
154
+ before {
155
+ converter.on_action('toc') do |arg|
156
+ "Table of Contents#{arg}"
157
+ end
158
+ }
159
+
160
+ it 'uses the handler to process {{toc}}' do
161
+ subject.should convert('{{toc}}').to('Table of Contents')
162
+ end
163
+ it 'passes content after colon as argument to handler' do
164
+ subject.should convert('{{toc: rocks}}').to('Table of Contents rocks')
165
+ end
166
+ it 'ignores {{ and }} in different lines' do
167
+ subject.should convert("{{toc:\nrocks}}").to("{{toc:\nrocks}}")
168
+ end
169
+ it 'ignores magicwords which last character is colon' do
170
+ subject.should convert("{{toc:}}").to("{{toc:}}")
171
+ end
172
+ it 'ignores other unregistered actions' do
173
+ subject.should convert("{{delete:all:site}}").to("{{delete:all:site}}")
174
+ end
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,98 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{wikilink-converter}
8
+ s.version = "0.1.0"
9
+
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}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ ".travis.yml",
23
+ ".yardopts",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "Guardfile",
27
+ "LICENSE.txt",
28
+ "README.markdown",
29
+ "Rakefile",
30
+ "VERSION",
31
+ "lib/wikilink-converter.rb",
32
+ "lib/wikilink/converter.rb",
33
+ "lib/wikilink/converter/namespace.rb",
34
+ "lib/wikilink/converter/site.rb",
35
+ "lib/wikilink/converter/sites/ruby_china.rb",
36
+ "lib/wikilink/converter/sites/wikipedia.rb",
37
+ "lib/wikilink/converter/utils.rb",
38
+ "spec/spec_helper.rb",
39
+ "spec/support/matchers.rb",
40
+ "spec/wikilink/converter/namespace_spec.rb",
41
+ "spec/wikilink/converter/site_spec.rb",
42
+ "spec/wikilink/converter/sites/ruby_china_spec.rb",
43
+ "spec/wikilink/converter/sites/wikipedia_spec.rb",
44
+ "spec/wikilink/converter_spec.rb",
45
+ "wikilink-converter.gemspec"
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>}
52
+
53
+ if s.respond_to? :specification_version then
54
+ s.specification_version = 3
55
+
56
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
+ s.add_development_dependency(%q<rspec>, [">= 0"])
58
+ s.add_development_dependency(%q<yard>, [">= 0"])
59
+ s.add_development_dependency(%q<bundler>, [">= 0"])
60
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
61
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
62
+ s.add_development_dependency(%q<guard>, [">= 0"])
63
+ s.add_development_dependency(%q<guard-rspec>, [">= 0"])
64
+ s.add_development_dependency(%q<guard-bundler>, [">= 0"])
65
+ s.add_development_dependency(%q<guard-yard>, [">= 0"])
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"])
69
+ else
70
+ s.add_dependency(%q<rspec>, [">= 0"])
71
+ s.add_dependency(%q<yard>, [">= 0"])
72
+ s.add_dependency(%q<bundler>, [">= 0"])
73
+ s.add_dependency(%q<jeweler>, [">= 0"])
74
+ s.add_dependency(%q<simplecov>, [">= 0"])
75
+ s.add_dependency(%q<guard>, [">= 0"])
76
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
77
+ s.add_dependency(%q<guard-bundler>, [">= 0"])
78
+ s.add_dependency(%q<guard-yard>, [">= 0"])
79
+ s.add_dependency(%q<redcarpet>, [">= 0"])
80
+ s.add_dependency(%q<rb-inotify>, [">= 0"])
81
+ s.add_dependency(%q<libnotify>, [">= 0"])
82
+ end
83
+ else
84
+ s.add_dependency(%q<rspec>, [">= 0"])
85
+ s.add_dependency(%q<yard>, [">= 0"])
86
+ s.add_dependency(%q<bundler>, [">= 0"])
87
+ s.add_dependency(%q<jeweler>, [">= 0"])
88
+ s.add_dependency(%q<simplecov>, [">= 0"])
89
+ s.add_dependency(%q<guard>, [">= 0"])
90
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
91
+ s.add_dependency(%q<guard-bundler>, [">= 0"])
92
+ s.add_dependency(%q<guard-yard>, [">= 0"])
93
+ s.add_dependency(%q<redcarpet>, [">= 0"])
94
+ s.add_dependency(%q<rb-inotify>, [">= 0"])
95
+ s.add_dependency(%q<libnotify>, [">= 0"])
96
+ end
97
+ end
98
+
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wikilink-converter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ian Yang
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-04 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &16725440 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *16725440
25
+ - !ruby/object:Gem::Dependency
26
+ name: yard
27
+ requirement: &16724920 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *16724920
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &16724440 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *16724440
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &16723920 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *16723920
58
+ - !ruby/object:Gem::Dependency
59
+ name: simplecov
60
+ requirement: &16723420 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *16723420
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard
71
+ requirement: &16722940 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *16722940
80
+ - !ruby/object:Gem::Dependency
81
+ name: guard-rspec
82
+ requirement: &16722440 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *16722440
91
+ - !ruby/object:Gem::Dependency
92
+ name: guard-bundler
93
+ requirement: &16721920 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *16721920
102
+ - !ruby/object:Gem::Dependency
103
+ name: guard-yard
104
+ requirement: &16721420 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *16721420
113
+ - !ruby/object:Gem::Dependency
114
+ name: redcarpet
115
+ requirement: &16720940 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *16720940
124
+ - !ruby/object:Gem::Dependency
125
+ name: rb-inotify
126
+ requirement: &16720420 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
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
146
+ description: convert [[WikiLink]] to <a>
147
+ email: me@iany.me
148
+ executables: []
149
+ extensions: []
150
+ extra_rdoc_files:
151
+ - LICENSE.txt
152
+ - README.markdown
153
+ files:
154
+ - .document
155
+ - .rspec
156
+ - .travis.yml
157
+ - .yardopts
158
+ - Gemfile
159
+ - Gemfile.lock
160
+ - Guardfile
161
+ - LICENSE.txt
162
+ - README.markdown
163
+ - Rakefile
164
+ - VERSION
165
+ - lib/wikilink-converter.rb
166
+ - lib/wikilink/converter.rb
167
+ - lib/wikilink/converter/namespace.rb
168
+ - lib/wikilink/converter/site.rb
169
+ - lib/wikilink/converter/sites/ruby_china.rb
170
+ - lib/wikilink/converter/sites/wikipedia.rb
171
+ - lib/wikilink/converter/utils.rb
172
+ - spec/spec_helper.rb
173
+ - spec/support/matchers.rb
174
+ - spec/wikilink/converter/namespace_spec.rb
175
+ - spec/wikilink/converter/site_spec.rb
176
+ - spec/wikilink/converter/sites/ruby_china_spec.rb
177
+ - spec/wikilink/converter/sites/wikipedia_spec.rb
178
+ - spec/wikilink/converter_spec.rb
179
+ - wikilink-converter.gemspec
180
+ homepage: http://github.com/doitian/wikilink-converter
181
+ licenses:
182
+ - MIT
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ none: false
189
+ requirements:
190
+ - - ! '>='
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ segments:
194
+ - 0
195
+ hash: -3886316938632370921
196
+ required_rubygems_version: !ruby/object:Gem::Requirement
197
+ none: false
198
+ requirements:
199
+ - - ! '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ requirements: []
203
+ rubyforge_project:
204
+ rubygems_version: 1.8.6
205
+ signing_key:
206
+ specification_version: 3
207
+ summary: convert [[WikiLink]] to <a>
208
+ test_files: []