]> git.wincent.com - wikitext.git/commitdiff
Use shared parser from Wikitext::Parser rather than String
authorWincent Colaiuta <win@wincent.com>
Tue, 6 Jan 2009 00:40:23 +0000 (01:40 +0100)
committerWincent Colaiuta <win@wincent.com>
Tue, 6 Jan 2009 00:40:23 +0000 (01:40 +0100)
Signed-off-by: Wincent Colaiuta <win@wincent.com>
lib/wikitext/string.rb
spec/parser_spec.rb [new file with mode: 0644]
spec/string_spec.rb

index afc33da4ae4aeadab41d04a7e61dc5d92b4dadfc..69a0041cccc56f06b1a5f63ce559edf311e7103e 100644 (file)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-require 'wikitext'
+require 'wikitext/parser'
 
 class String
-  def self.shared_wikitext_parser
-    @@shared_wikitext_parser ||= Wikitext::Parser.new(:space_to_underscore => true)
-  end
-
   def to_wikitext
-    @@shared_wikitext_parser ||= Wikitext::Parser.new(:space_to_underscore => true)
-    @@shared_wikitext_parser.parse wikitext_preprocess
+    Wikitext::Parser.shared_parser.parse wikitext_preprocess
   end
   alias :w :to_wikitext
 
diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb
new file mode 100644 (file)
index 0000000..dc89618
--- /dev/null
@@ -0,0 +1,40 @@
+#!/usr/bin/env ruby
+# Copyright 2009 Wincent Colaiuta
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+require File.join(File.dirname(__FILE__), 'spec_helper.rb')
+require 'wikitext/parser'
+
+describe Wikitext::Parser do
+  it 'should provide access to the shared parser instance for customization' do
+    Wikitext::Parser.shared_parser.should be_instance_of(Wikitext::Parser)
+  end
+
+  it 'should persist customizations made to shared parser instance' do
+    # fisrt pass
+    parser                             = Wikitext::Parser.shared_parser
+    original_prefix                    = '/images/'
+    parser.img_prefix                  = original_prefix
+    parser.img_prefix.should           == original_prefix
+    parser.parse('{{foo.png}}').should == %Q{<p><img src="/images/foo.png" alt="foo.png" /></p>\n}
+
+    # second pass
+    parser                             = Wikitext::Parser.shared_parser
+    parser.img_prefix.should           == original_prefix
+    new_prefix                         = '/totally-different-prefix/'
+    parser.img_prefix                  = new_prefix
+    parser.img_prefix.should           == new_prefix
+    parser.parse('{{bar.png}}').should == %Q{<p><img src="/totally-different-prefix/bar.png" alt="bar.png" /></p>\n}
+  end
+end
index b209722aaf15c978185616405c437d676065fe04..dacd8228600dbd609995f2318d1c2f38aa36672d 100644 (file)
@@ -24,23 +24,4 @@ describe String, 'wikitext extensions' do
   it 'should provide a w method on all strings' do
     "'''strong'''".w.should == "<p><strong>strong</strong></p>\n"
   end
-
-  it 'should provide access to the shared parser instance for customization' do
-    String.shared_wikitext_parser.should be_instance_of(Wikitext::Parser)
-  end
-
-  it 'should persist customizations made to shared parser instance' do
-    # fisrt pass
-    parser                   = String.shared_wikitext_parser
-    original_prefix          = '/images/'
-    parser.img_prefix        = original_prefix
-    parser.img_prefix.should == original_prefix
-    '{{foo.png}}'.w.should   == %Q{<p><img src="/images/foo.png" alt="foo.png" /></p>\n}
-
-    # second pass
-    new_prefix               = '/totally-different-prefix/'
-    parser.img_prefix        = new_prefix
-    parser.img_prefix.should == new_prefix
-    '{{bar.png}}'.w.should   == %Q{<p><img src="/totally-different-prefix/bar.png" alt="bar.png" /></p>\n}
-  end
 end