wikitext 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/ext/parser.c CHANGED
@@ -905,7 +905,7 @@ VALUE Wikitext_parser_initialize(int argc, VALUE *argv, VALUE self)
905
905
  VALUE mailto_class = rb_str_new2("mailto");
906
906
  VALUE internal_link_prefix = rb_str_new2("/wiki/");
907
907
  VALUE img_prefix = rb_str_new2("/images/");
908
- VALUE space_to_underscore = Qfalse;
908
+ VALUE space_to_underscore = Qtrue;
909
909
  VALUE treat_slash_as_special = Qtrue;
910
910
  VALUE minimum_fulltext_token_length = INT2NUM(3);
911
911
 
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright 2009 Wincent Colaiuta
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ require 'wikitext'
17
+
18
+ module Wikitext
19
+ class Parser
20
+ def self.shared_parser
21
+ @@shared_parser_instance ||= new
22
+ end
23
+ end # class Parser
24
+ end # module Wikitext
25
+
@@ -1,4 +1,4 @@
1
- # Copyright 2008 Wincent Colaiuta
1
+ # Copyright 2008-2009 Wincent Colaiuta
2
2
  # This program is free software: you can redistribute it and/or modify
3
3
  # it under the terms of the GNU General Public License as published by
4
4
  # the Free Software Foundation, either version 3 of the License, or
@@ -12,12 +12,11 @@
12
12
  # You should have received a copy of the GNU General Public License
13
13
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
14
14
 
15
- require 'wikitext'
15
+ require 'wikitext/parser'
16
16
 
17
17
  class String
18
18
  def to_wikitext
19
- @@shared_wikitext_parser ||= Wikitext::Parser.new(:space_to_underscore => true)
20
- @@shared_wikitext_parser.parse wikitext_preprocess
19
+ Wikitext::Parser.shared_parser.parse wikitext_preprocess
21
20
  end
22
21
  alias :w :to_wikitext
23
22
 
@@ -25,6 +24,7 @@ private
25
24
 
26
25
  # for now do this in pure Ruby
27
26
  # if speed later becomes a concern can whip up a Ragel C extension to do it
27
+ # TODO: make this customizable (accept a lambda that performs preprocessing)
28
28
  def wikitext_preprocess
29
29
  gsub /\b(bug|issue|request|ticket) #(\d+)/i, '[[issues/\2|\1 #\2]]'
30
30
  end
@@ -13,5 +13,5 @@
13
13
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
14
14
 
15
15
  module Wikitext
16
- VERSION = '1.3.1'
16
+ VERSION = '1.3.2'
17
17
  end # module Wikitext
@@ -271,7 +271,7 @@ describe Wikitext::Parser, 'with large slab of input text' do
271
271
  # So add one long-running spec to hopefully catch any GC and memory-related bugs.
272
272
  it 'should work correctly during long runs (when Garbage Collection runs)' do
273
273
  input = "a <strong>simple</strong> ''test'' of the [[wikitext parser]]"
274
- expected = %Q{<p>a <strong>simple</strong> <em>test</em> of the <a href="/wiki/wikitext%20parser">wikitext parser</a></p>\n}
274
+ expected = %Q{<p>a <strong>simple</strong> <em>test</em> of the <a href="/wiki/wikitext_parser">wikitext parser</a></p>\n}
275
275
  100_000.times { @parser.parse(input).should == expected }
276
276
  end
277
277
  end
@@ -18,7 +18,7 @@ require 'wikitext'
18
18
 
19
19
  describe Wikitext::Parser, 'internal links (space to underscore off)' do
20
20
  before do
21
- @parser = Wikitext::Parser.new
21
+ @parser = Wikitext::Parser.new :space_to_underscore => false
22
22
  end
23
23
 
24
24
  it 'should pass through unexpected link end tokens literally' do
@@ -447,7 +447,6 @@ end
447
447
  describe Wikitext::Parser, 'internal links (space to underscore on)' do
448
448
  before do
449
449
  @parser = Wikitext::Parser.new
450
- @parser.space_to_underscore = true
451
450
  end
452
451
 
453
452
  it 'should pass through unexpected link end tokens literally' do
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright 2009 Wincent Colaiuta
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ require File.join(File.dirname(__FILE__), 'spec_helper.rb')
17
+ require 'wikitext/nil_class'
18
+
19
+ describe NilClass, 'wikitext extensions' do
20
+ it 'should provide a to_wikitext method on the nil singleton' do
21
+ nil.to_wikitext.should == ''
22
+ end
23
+
24
+ it 'should provide a w method on the nil singleton' do
25
+ nil.w.should == ''
26
+ end
27
+ end
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright 2009 Wincent Colaiuta
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ require File.join(File.dirname(__FILE__), 'spec_helper.rb')
17
+ require 'wikitext/parser'
18
+
19
+ describe Wikitext::Parser do
20
+ it 'should provide access to the shared parser instance for customization' do
21
+ Wikitext::Parser.shared_parser.should be_instance_of(Wikitext::Parser)
22
+ end
23
+
24
+ it 'should persist customizations made to shared parser instance' do
25
+ # fisrt pass
26
+ parser = Wikitext::Parser.shared_parser
27
+ original_prefix = '/images/'
28
+ parser.img_prefix = original_prefix
29
+ parser.img_prefix.should == original_prefix
30
+ parser.parse('{{foo.png}}').should == %Q{<p><img src="/images/foo.png" alt="foo.png" /></p>\n}
31
+
32
+ # second pass
33
+ parser = Wikitext::Parser.shared_parser
34
+ parser.img_prefix.should == original_prefix
35
+ new_prefix = '/totally-different-prefix/'
36
+ parser.img_prefix = new_prefix
37
+ parser.img_prefix.should == new_prefix
38
+ parser.parse('{{bar.png}}').should == %Q{<p><img src="/totally-different-prefix/bar.png" alt="bar.png" /></p>\n}
39
+ end
40
+ end
@@ -38,7 +38,7 @@ describe Wikitext::Parser, 'regressions' do
38
38
  <li>punto 1</li>
39
39
  <li>punto 2</li>
40
40
  </ul>
41
- <p>Y <a href="/wiki/otro%20articulo">otro articulo</a>.</p>
41
+ <p>Y <a href="/wiki/otro_articulo">otro articulo</a>.</p>
42
42
  END
43
43
  @parser.parse(input).should == expected
44
44
  end
@@ -94,7 +94,7 @@ describe Wikitext::Parser, 'regressions' do
94
94
  END
95
95
  expected = dedent <<-END
96
96
  <ol>
97
- <li>Turn off the <a href="/wiki/Movable%20Type">Movable Type</a> search function; use Google instead (it's better anyway) with a form something like this:</li>
97
+ <li>Turn off the <a href="/wiki/Movable_Type">Movable Type</a> search function; use Google instead (it's better anyway) with a form something like this:</li>
98
98
  </ol>
99
99
  <pre>&lt;form method=&quot;get&quot;...&gt;</pre>
100
100
  END
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright 2009 Wincent Colaiuta
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ require File.join(File.dirname(__FILE__), 'spec_helper.rb')
17
+ require 'wikitext/string'
18
+
19
+ describe String, 'wikitext extensions' do
20
+ it 'should provide a to_wikitext method on all strings' do
21
+ "'''strong'''".to_wikitext.should == "<p><strong>strong</strong></p>\n"
22
+ end
23
+
24
+ it 'should provide a w method on all strings' do
25
+ "'''strong'''".w.should == "<p><strong>strong</strong></p>\n"
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright 2009 Wincent Colaiuta
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ require File.join(File.dirname(__FILE__), 'spec_helper.rb')
17
+ require 'wikitext/version'
18
+
19
+ describe Wikitext, 'versioning' do
20
+ it 'should provide a version string' do
21
+ Wikitext::VERSION.should be_instance_of(String)
22
+ end
23
+ end
@@ -45,8 +45,8 @@ describe Wikitext::Parser do
45
45
  @parser.img_prefix.should == '/images/'
46
46
  end
47
47
 
48
- it 'should turn space-to-underscore off by default' do
49
- @parser.space_to_underscore.should == false
48
+ it 'should turn space-to-underscore on by default' do
49
+ @parser.space_to_underscore.should == true
50
50
  end
51
51
 
52
52
  it 'should treat slash as special by default' do
@@ -81,7 +81,7 @@ describe Wikitext::Parser do
81
81
  end
82
82
 
83
83
  it 'should allow overriding of space-to-underscore' do
84
- Wikitext::Parser.new(:space_to_underscore => true).space_to_underscore.should == true
84
+ Wikitext::Parser.new(:space_to_underscore => false).space_to_underscore.should == false
85
85
  end
86
86
 
87
87
  it 'should allow overriding of treat slash as special' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikitext
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wincent Colaiuta
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-05 00:00:00 +01:00
12
+ date: 2009-01-06 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -43,18 +43,22 @@ files:
43
43
  - spec/line_endings_spec.rb
44
44
  - spec/link_encoding_spec.rb
45
45
  - spec/link_sanitizing_spec.rb
46
+ - spec/nil_class_spec.rb
46
47
  - spec/nowiki_spec.rb
47
48
  - spec/p_spec.rb
49
+ - spec/parser_spec.rb
48
50
  - spec/pre_spec.rb
49
51
  - spec/rails_spec.rb
50
52
  - spec/regressions_spec.rb
51
53
  - spec/spec_helper.rb
54
+ - spec/string_spec.rb
52
55
  - spec/strong_em_spec.rb
53
56
  - spec/strong_spec.rb
54
57
  - spec/tokenizing_spec.rb
55
58
  - spec/trash
56
59
  - spec/tt_spec.rb
57
60
  - spec/ul_spec.rb
61
+ - spec/version_spec.rb
58
62
  - spec/wikitext_spec.rb
59
63
  - ext/extconf.rb
60
64
  - ext/ary.c
@@ -72,6 +76,7 @@ files:
72
76
  - ext/wikitext_ragel.h
73
77
  - ext/depend
74
78
  - lib/wikitext/nil_class.rb
79
+ - lib/wikitext/parser.rb
75
80
  - lib/wikitext/rails.rb
76
81
  - lib/wikitext/string.rb
77
82
  - lib/wikitext/version.rb