html-pipeline-wiki-link 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.0.4
4
+
5
+ * Add handling for special characters and leading or trailing whitespace.
6
+ * Add tests for base URL settings.
7
+ * Fix bug with multiple links in succession.
8
+
3
9
  ## 0.0.3
4
10
 
5
11
  * Fixed erroneous gem description.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- html-pipeline-wiki-link (0.0.3)
4
+ html-pipeline-wiki-link (0.0.4)
5
5
  html-pipeline (>= 0.0.8)
6
6
 
7
7
  GEM
@@ -10,7 +10,7 @@ GEM
10
10
  activesupport (3.2.12)
11
11
  i18n (~> 0.6)
12
12
  multi_json (~> 1.0)
13
- escape_utils (0.3.1)
13
+ escape_utils (0.3.2)
14
14
  gemoji (1.4.0)
15
15
  github-markdown (0.5.3)
16
16
  html-pipeline (0.0.8)
data/README.md CHANGED
@@ -35,7 +35,7 @@ filter = HTML::Pipeline::WikiLinkFilter.new('Some text with a [[Link]] in it.')
35
35
  filter.call
36
36
  ```
37
37
 
38
- Filters can be combined into a pipeline which causes each filter to hand its output to the next filter's input. For example, you could support wiki links in markdown by creating a pipeline like this:
38
+ Filters can be combined into a pipeline which causes each filter to hand its output to the next filter's input. For example, you could support wiki links in Markdown by creating a pipeline like this:
39
39
 
40
40
  ```ruby
41
41
  pipeline = HTML::Pipeline.new [
@@ -48,13 +48,18 @@ This is some **Markdown** with a [[Link]] in it!
48
48
  CODE
49
49
  ```
50
50
 
51
+ The wiki link filter supports the standard link types:
52
+
53
+ * `[[Link]]`
54
+ * `[[Link|Description]]`
55
+
51
56
  <!--
52
57
  ## Troubleshooting
53
58
  -->
54
59
 
55
60
  ## Development
56
61
 
57
- To see what has changed in recent versions of Lifted Wiki, see the [CHANGELOG](CHANGELOG.md).
62
+ To see what has changed in recent versions of the wiki link gem, see the [CHANGELOG](CHANGELOG.md).
58
63
 
59
64
  ## Core Team Members
60
65
 
@@ -66,11 +71,11 @@ To see what has changed in recent versions of Lifted Wiki, see the [CHANGELOG](C
66
71
 
67
72
  <!-- ### Other questions
68
73
 
69
- Feel free to chat with the Lifted Wiki core team (and many other users) on IRC in the [#project](irc://irc.freenode.net/project) channel on Freenode, or via email on the [Project mailing list]().
74
+ Feel free to chat with the wiki link gem core team (and many other users) on IRC in the [#project](irc://irc.freenode.net/project) channel on Freenode, or via email on the [Project mailing list]().
70
75
  -->
71
76
 
72
77
  ## Copyright
73
78
 
74
79
  Copyright © 2013 Lee Dohm, Lifted Studios. See [LICENSE](LICENSE.md) for details.
75
80
 
76
- Project is a member of the [OSS Manifesto](http://ossmanifesto.com/).
81
+ Project is a member of the [OSS Manifesto](http://ossmanifesto.org/).
data/Rakefile CHANGED
@@ -38,10 +38,12 @@ Rake::TestTask.new('spec') do |spec|
38
38
  # spec.warning = true
39
39
  end
40
40
 
41
- YARD::Rake::YardocTask.new
41
+ YARD::Rake::YardocTask.new do |t|
42
+ t.options = ['--markup', 'markdown', '--files', 'CHANGELOG.md,CONTRIBUTING.md,LICENSE.md']
43
+ end
42
44
 
43
45
  desc 'Build gem'
44
- task :build do
46
+ task :build => :default do
45
47
  sh "mkdir -p pkg"
46
48
  sh "gem build #{gemspec_file}"
47
49
  sh "mv #{gem_file} pkg"
@@ -29,8 +29,8 @@ Gem::Specification.new do |s|
29
29
 
30
30
  s.add_development_dependency('minitest', '~> 3.0')
31
31
  s.add_development_dependency('rake', '~> 10.0')
32
- s.add_development_dependency('redcarpet')
33
- s.add_development_dependency('yard', '~> 0.8')
32
+ s.add_development_dependency('redcarpet') # For Markdown formatting of YARD documentation
33
+ s.add_development_dependency('yard', '~> 0.8') # For documentation
34
34
 
35
35
  s.files = `git ls-files`.
36
36
  split("\n").
@@ -6,7 +6,7 @@ module HTML
6
6
  class Pipeline
7
7
  module WikiLink
8
8
  # Version number for the Lifted Wiki gem.
9
- VERSION = '0.0.3'
9
+ VERSION = '0.0.4'
10
10
  end
11
11
  end
12
12
  end
@@ -3,6 +3,7 @@
3
3
  #
4
4
 
5
5
  require 'html/pipeline'
6
+ require 'open-uri'
6
7
 
7
8
  module HTML
8
9
  class Pipeline
@@ -23,39 +24,40 @@ module HTML
23
24
  @base_url = context[:base_url] if context[:base_url]
24
25
  @space_replacement = context[:space_replacement] if context[:space_replacement]
25
26
  end
27
+
28
+ unless @base_url.empty? || @base_url =~ /\/$/
29
+ @base_url += '/'
30
+ end
26
31
  end
27
32
 
28
33
  # Performs the translation and returns the updated text.
29
34
  #
30
35
  # @return [String] Updated text with translated wiki links.
31
36
  def call
32
- html.gsub(/\[\[([^|]*)(\|(.*))?\]\]/) do
37
+ html.gsub(/\[\[([^\]|]*)(\|([^\]]*))?\]\]/) do
33
38
  link = $1
34
39
  desc = $3 ? $3 : $1
35
40
 
36
- link = convert_whitespace(link)
37
- desc = collapse_whitespace(desc)
38
-
39
- "<a href=\"#{@base_url}#{link}\">#{desc}</a>"
41
+ "<a href=\"#{to_link link}\">#{to_description desc}</a>"
40
42
  end
41
43
  end
42
44
 
43
45
  private
44
46
 
45
- # Collapses multiple whitespace characters into a single space.
47
+ # Converts the given text into an appropriate link description.
46
48
  #
47
- # @param text Text within which to collapse whitespace.
48
- # @return Text with collapsed whitespace.
49
- def collapse_whitespace(text)
50
- text.gsub(/\s+/, ' ')
49
+ # @param text Proposed description text.
50
+ # @return Updated text for use as a link description.
51
+ def to_description(text)
52
+ text.strip.gsub(/\s+/, ' ')
51
53
  end
52
54
 
53
- # Converts spaces to underscores in the given text.
55
+ # Converts the given text into an appropriate link.
54
56
  #
55
- # @param text Text within which to replace spaces.
56
- # @return Text with spaces replaced with underscores.
57
- def convert_whitespace(text)
58
- text.gsub(/\s+/, @space_replacement)
57
+ # @param text Proposed link text.
58
+ # @return Updated text to use as a link.
59
+ def to_link(text)
60
+ URI::encode(@base_url + text.strip.gsub(/\s+/, @space_replacement))
59
61
  end
60
62
  end
61
63
  end
@@ -81,4 +81,76 @@ describe HTML::Pipeline::WikiLinkFilter do
81
81
 
82
82
  text.must_equal '<a href="/A*Link*With*Spaces">A Link With Spaces</a>'
83
83
  end
84
- end
84
+
85
+ it 'must urlencode special characters in the link but not in the description' do
86
+ filter = new_filter('[[{}\]]')
87
+
88
+ text = filter.call
89
+
90
+ text.must_equal '<a href="/%7B%7D%5C">{}\</a>'
91
+ end
92
+
93
+ it 'must strip whitespace from the ends of a link' do
94
+ filter = new_filter('[[ Link ]]')
95
+
96
+ text = filter.call
97
+
98
+ text.must_equal '<a href="/Link">Link</a>'
99
+ end
100
+
101
+ it 'must strip whitespace from the ends of a description' do
102
+ filter = new_filter('[[Link| Description ]]')
103
+
104
+ text = filter.call
105
+
106
+ text.must_equal '<a href="/Link">Description</a>'
107
+ end
108
+
109
+ it 'prepends the link with another string when given a :base_url parameter' do
110
+ filter = new_filter('[[Link]]', :base_url => '/foo/bar/')
111
+
112
+ text = filter.call
113
+
114
+ text.must_equal '<a href="/foo/bar/Link">Link</a>'
115
+ end
116
+
117
+ it 'properly joins the base_url with the link' do
118
+ filter = new_filter('[[Link]]', :base_url => 'foo/bar')
119
+
120
+ text = filter.call
121
+
122
+ text.must_equal '<a href="foo/bar/Link">Link</a>'
123
+ end
124
+
125
+ it 'replaces with underscores when nil is given as a space replacement' do
126
+ filter = new_filter('[[A Link With Spaces]]', :space_replacement => nil)
127
+
128
+ text = filter.call
129
+
130
+ text.must_equal '<a href="/A_Link_With_Spaces">A Link With Spaces</a>'
131
+ end
132
+
133
+ it 'uses a single forward slash when nil is given as a base URL' do
134
+ filter = new_filter('[[Link]]', :base_url => nil)
135
+
136
+ text = filter.call
137
+
138
+ text.must_equal '<a href="/Link">Link</a>'
139
+ end
140
+
141
+ it 'converts two links on the same line into two links, not one big one with brackets inside' do
142
+ filter = new_filter('[[Link One]] and [[Link Two]]')
143
+
144
+ text = filter.call
145
+
146
+ text.must_equal '<a href="/Link_One">Link One</a> and <a href="/Link_Two">Link Two</a>'
147
+ end
148
+
149
+ it 'converts two links with descriptions into two links' do
150
+ filter = new_filter('[[Link|Link One]] and [[Link|Link Two]]')
151
+
152
+ text = filter.call
153
+
154
+ text.must_equal '<a href="/Link">Link One</a> and <a href="/Link">Link Two</a>'
155
+ end
156
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html-pipeline-wiki-link
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-02 00:00:00.000000000 Z
12
+ date: 2013-03-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: html-pipeline
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  version: '0'
131
131
  requirements: []
132
132
  rubyforge_project:
133
- rubygems_version: 1.8.24
133
+ rubygems_version: 1.8.23
134
134
  signing_key:
135
135
  specification_version: 2
136
136
  summary: An HTML::Pipeline filter for WikiMedia-style wiki links.