wptemplates 0.0.3
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/.gitignore +20 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +92 -0
- data/README.rdoc +8 -0
- data/Rakefile +4 -0
- data/lib/wptemplates.rb +20 -0
- data/lib/wptemplates/ast.rb +91 -0
- data/lib/wptemplates/parser.rb +112 -0
- data/lib/wptemplates/preprocessor.rb +17 -0
- data/lib/wptemplates/regexes.rb +95 -0
- data/lib/wptemplates/utils.rb +38 -0
- data/lib/wptemplates/version.rb +3 -0
- data/spec/regexes_spec.rb +458 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/utils_spec.rb +90 -0
- data/spec/wptemplates_links_spec.rb +249 -0
- data/spec/wptemplates_mixed_spec.rb +82 -0
- data/spec/wptemplates_templates_spec.rb +161 -0
- data/spec/wptemplates_text_spec.rb +75 -0
- data/tasks/browser.rake +4 -0
- data/tasks/bundler_gem.rake +1 -0
- data/tasks/console.rake +7 -0
- data/tasks/irbrc.rb +22 -0
- data/tasks/rdoc.rake +16 -0
- data/tasks/readme_examples.rake +23 -0
- data/tasks/readme_html.rake +22 -0
- data/tasks/rspec.rake +10 -0
- data/wptemplates.gemspec +29 -0
- metadata +167 -0
    
        data/spec/spec_helper.rb
    ADDED
    
    | @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            # This file was generated by the `rspec --init` command. Conventionally, all
         | 
| 2 | 
            +
            # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
         | 
| 3 | 
            +
            # Require this file using `require "spec_helper"` to ensure that it is only
         | 
| 4 | 
            +
            # loaded once.
         | 
| 5 | 
            +
            #
         | 
| 6 | 
            +
            # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            require 'simplecov'
         | 
| 9 | 
            +
            SimpleCov.start
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            RSpec.configure do |config|
         | 
| 12 | 
            +
              config.treat_symbols_as_metadata_keys_with_true_values = true
         | 
| 13 | 
            +
              config.run_all_when_everything_filtered = true
         | 
| 14 | 
            +
              config.filter_run :focus
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              # Run specs in random order to surface order dependencies. If you find an
         | 
| 17 | 
            +
              # order dependency and want to debug it, you can fix the order by providing
         | 
| 18 | 
            +
              # the seed, which is printed after each run.
         | 
| 19 | 
            +
              #     --seed 1234
         | 
| 20 | 
            +
              config.order = 'random'
         | 
| 21 | 
            +
            end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            require 'wptemplates'
         | 
    
        data/spec/utils_spec.rb
    ADDED
    
    | @@ -0,0 +1,90 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Wptemplates::Utils do
         | 
| 4 | 
            +
              
         | 
| 5 | 
            +
              describe '.normalize_link' do
         | 
| 6 | 
            +
                context 'when anchor is false' do
         | 
| 7 | 
            +
                  it 'removes spare spaces and underscores ' do
         | 
| 8 | 
            +
                    expect(subject.normalize_link(" Jimbo_ __ Wales__")).to eq("Jimbo Wales")
         | 
| 9 | 
            +
                  end
         | 
| 10 | 
            +
                  it 'removes spare spaces and underscores around namespace nekudotayim' do
         | 
| 11 | 
            +
                    pending "not sure if to implement here" do
         | 
| 12 | 
            +
                      expect(subject.normalize_link("_User_: Jimbo_ __ Wales__")).to eq("User:Jimbo Wales")
         | 
| 13 | 
            +
                    end
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
                  it 'capitalizes the first letter' do
         | 
| 16 | 
            +
                    expect(subject.normalize_link("foo")).to eq("Foo")
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                  it 'preserves case of the other letters' do
         | 
| 19 | 
            +
                    expect(subject.normalize_link("fOo")).to eq("FOo")
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
                  it 'normalizes case of namespace prefix' do
         | 
| 22 | 
            +
                    pending "not sure if to implement here" do
         | 
| 23 | 
            +
                      expect(subject.normalize_link("fOoO:Bar")).to eq("Fooo:Bar")
         | 
| 24 | 
            +
                    end
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
                context 'when anchor is true' do
         | 
| 28 | 
            +
                  it 'removes spare spaces and underscores ' do
         | 
| 29 | 
            +
                    expect(subject.normalize_link(" Jimbo_ __  Wales__", true)).to eq("Jimbo Wales")
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
                  it 'preserves case of all the letters' do
         | 
| 32 | 
            +
                    expect(subject.normalize_link("fOo", true)).to eq("fOo")
         | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
              
         | 
| 37 | 
            +
              describe '.normalize_linklabel' do
         | 
| 38 | 
            +
                it 'removes spare spaces but not underscores' do
         | 
| 39 | 
            +
                  expect(subject.normalize_linklabel(" Jimbo_  __ Wales__")).to eq("Jimbo_ __ Wales__")
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
                it 'preserves case of all the letters' do
         | 
| 42 | 
            +
                  expect(subject.normalize_linklabel("dJango")).to eq("dJango")
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
              
         | 
| 46 | 
            +
              describe '.symbolize' do
         | 
| 47 | 
            +
                it "symbolizes strings" do
         | 
| 48 | 
            +
                  expect(subject.symbolize(" foo ")).to eq(:foo)
         | 
| 49 | 
            +
                  expect(subject.symbolize("_foo_")).to eq(:foo)
         | 
| 50 | 
            +
                  expect(subject.symbolize("foo")).to eq(:foo)
         | 
| 51 | 
            +
                  expect(subject.symbolize("FOO")).to eq(:foo)
         | 
| 52 | 
            +
                  expect(subject.symbolize("FoO")).to eq(:foo)
         | 
| 53 | 
            +
                  expect(subject.symbolize("foo bar")).to eq(:foo_bar)
         | 
| 54 | 
            +
                  expect(subject.symbolize("Foo BAR")).to eq(:foo_bar)
         | 
| 55 | 
            +
                  expect(subject.symbolize("foo_bar")).to eq(:foo_bar)
         | 
| 56 | 
            +
                  expect(subject.symbolize("foo__bar")).to eq(:foo_bar)
         | 
| 57 | 
            +
                  expect(subject.symbolize("fooBar")).to eq(:foobar)
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
              end
         | 
| 60 | 
            +
              
         | 
| 61 | 
            +
              describe '.fixpoint' do
         | 
| 62 | 
            +
                it 'returns nil when immideatly given nil' do
         | 
| 63 | 
            +
                  expect(subject.fixpoint {nil}).to be_nil
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
                it 'returns the start value when passed the identity' do
         | 
| 66 | 
            +
                  expect(subject.fixpoint(start: 5) { |x| x } ).to eq(5)
         | 
| 67 | 
            +
                  expect(subject.fixpoint(start: "haha") { |x| x } ).to eq("haha")
         | 
| 68 | 
            +
                end
         | 
| 69 | 
            +
                it 'finds the fixpoint of some string algorithm' do
         | 
| 70 | 
            +
                  expect(subject.fixpoint(start: "haha") { |x| y=x.clone; y[0,1]=""; y } ).to eq("")
         | 
| 71 | 
            +
                end
         | 
| 72 | 
            +
                it 'finds the fixpoint of some string algorithm with outer var' do
         | 
| 73 | 
            +
                  x = "haha lol"
         | 
| 74 | 
            +
                  expect(subject.fixpoint { x[0,1]=""; x.clone }).to eq("")
         | 
| 75 | 
            +
                  expect(x).to eq("")
         | 
| 76 | 
            +
                end
         | 
| 77 | 
            +
                it 'finds the fixpoint of cos' do
         | 
| 78 | 
            +
                  expect(subject.fixpoint(start: 10) { |x| Math.cos(x) }).to be_within(1.0e-6).of(0.739085)
         | 
| 79 | 
            +
                end
         | 
| 80 | 
            +
                it 'finds the fixpoint of some string algorithm by cloning' do
         | 
| 81 | 
            +
                  expect(subject.fixpoint(start: "haha", clone: true) { |x| y=x; y[0,1]=""; y } ).to eq("")
         | 
| 82 | 
            +
                end
         | 
| 83 | 
            +
                it 'finds the fixpoint of some string algorithm with outer var by cloning' do
         | 
| 84 | 
            +
                  x = "haha lol"
         | 
| 85 | 
            +
                  expect(subject.fixpoint(clone: true){ x[0,1]=""; x }).to eq("")
         | 
| 86 | 
            +
                  expect(x).to eq("")
         | 
| 87 | 
            +
                end
         | 
| 88 | 
            +
              end
         | 
| 89 | 
            +
              
         | 
| 90 | 
            +
            end
         | 
| @@ -0,0 +1,249 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Wptemplates do
         | 
| 4 | 
            +
              
         | 
| 5 | 
            +
              it "parses a basic link without any additions" do
         | 
| 6 | 
            +
                parsed = subject.parse("[[foo]]")
         | 
| 7 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 8 | 
            +
                expect(parsed.text).to eq("foo")
         | 
| 9 | 
            +
                expect(parsed.links).to eq([parsed[0]])
         | 
| 10 | 
            +
                expect(parsed.all_links).to eq([parsed[0]])
         | 
| 11 | 
            +
                expect(parsed[0].text).to eq("foo")
         | 
| 12 | 
            +
                expect(parsed[0].link).to eq("Foo")
         | 
| 13 | 
            +
                expect(parsed[0].links).to eq([parsed[0]])
         | 
| 14 | 
            +
                expect(parsed[0].all_links).to eq([parsed[0]])
         | 
| 15 | 
            +
                expect(parsed[0].anchor).to be_nil
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
              
         | 
| 18 | 
            +
              it "parses a basic link with anchor" do
         | 
| 19 | 
            +
                parsed = subject.parse("[[foo#bar]]")
         | 
| 20 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 21 | 
            +
                expect(parsed.text).to eq("foo#bar")
         | 
| 22 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 23 | 
            +
                expect(parsed[0].text).to eq("foo#bar")
         | 
| 24 | 
            +
                expect(parsed[0].link).to eq("Foo")
         | 
| 25 | 
            +
                expect(parsed[0].anchor).to eq("bar")
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
              
         | 
| 28 | 
            +
              it "parses a link with postfix chars" do
         | 
| 29 | 
            +
                parsed = subject.parse("[[foo]]nx")
         | 
| 30 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 31 | 
            +
                expect(parsed.text).to eq("foonx")
         | 
| 32 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 33 | 
            +
                expect(parsed[0].text).to eq("foonx")
         | 
| 34 | 
            +
                expect(parsed[0].link).to eq("Foo")
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
              
         | 
| 37 | 
            +
              it "parses a link with a pipe" do
         | 
| 38 | 
            +
                parsed = subject.parse("[[foo|bar]]")
         | 
| 39 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 40 | 
            +
                expect(parsed.text).to eq("bar")
         | 
| 41 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 42 | 
            +
                expect(parsed[0].text).to eq("bar")
         | 
| 43 | 
            +
                expect(parsed[0].link).to eq("Foo")
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
              
         | 
| 46 | 
            +
              it "parses a link with pipe and postfix chars" do
         | 
| 47 | 
            +
                parsed = subject.parse("[[foo|bar]]ny")
         | 
| 48 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 49 | 
            +
                expect(parsed.text).to eq("barny")
         | 
| 50 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 51 | 
            +
                expect(parsed[0].text).to eq("barny")
         | 
| 52 | 
            +
                expect(parsed[0].link).to eq("Foo")
         | 
| 53 | 
            +
              end
         | 
| 54 | 
            +
              
         | 
| 55 | 
            +
              it "parses a link with a pipe" do
         | 
| 56 | 
            +
                parsed = subject.parse("[[foo|bar]]")
         | 
| 57 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 58 | 
            +
                expect(parsed.text).to eq("bar")
         | 
| 59 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 60 | 
            +
                expect(parsed[0].text).to eq("bar")
         | 
| 61 | 
            +
                expect(parsed[0].link).to eq("Foo")
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
              
         | 
| 64 | 
            +
              it "parses a link with pipe trick for comma" do
         | 
| 65 | 
            +
                parsed = subject.parse("[[Boston, Massachusetts|]]")
         | 
| 66 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 67 | 
            +
                expect(parsed.text).to eq("Boston")
         | 
| 68 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 69 | 
            +
                expect(parsed[0].text).to eq("Boston")
         | 
| 70 | 
            +
                expect(parsed[0].link).to eq("Boston, Massachusetts")
         | 
| 71 | 
            +
              end
         | 
| 72 | 
            +
              
         | 
| 73 | 
            +
              it "parses a link with pipe trick for parens" do
         | 
| 74 | 
            +
                parsed = subject.parse("[[Pipe (computing)|]]")
         | 
| 75 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 76 | 
            +
                expect(parsed.text).to eq("Pipe")
         | 
| 77 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 78 | 
            +
                expect(parsed[0].text).to eq("Pipe")
         | 
| 79 | 
            +
                expect(parsed[0].link).to eq("Pipe (computing)")
         | 
| 80 | 
            +
              end
         | 
| 81 | 
            +
              
         | 
| 82 | 
            +
              it "parses a link with pipe trick for parens and comma" do
         | 
| 83 | 
            +
                parsed = subject.parse("[[Yours, Mine and Ours (1968 film)|]]")
         | 
| 84 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 85 | 
            +
                expect(parsed.text).to eq("Yours, Mine and Ours")
         | 
| 86 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 87 | 
            +
                expect(parsed[0].text).to eq("Yours, Mine and Ours")
         | 
| 88 | 
            +
                expect(parsed[0].link).to eq("Yours, Mine and Ours (1968 film)")
         | 
| 89 | 
            +
              end
         | 
| 90 | 
            +
              
         | 
| 91 | 
            +
              it "parses a link with pipe trick for multiple commas" do
         | 
| 92 | 
            +
                parsed = subject.parse("[[Il Buono, il Brutto, il Cattivo|]]")
         | 
| 93 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 94 | 
            +
                expect(parsed.text).to eq("Il Buono")
         | 
| 95 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 96 | 
            +
                expect(parsed[0].text).to eq("Il Buono")
         | 
| 97 | 
            +
                expect(parsed[0].link).to eq("Il Buono, il Brutto, il Cattivo")
         | 
| 98 | 
            +
              end
         | 
| 99 | 
            +
              
         | 
| 100 | 
            +
              it "parses a link without pipe trick when no space after comma" do
         | 
| 101 | 
            +
                parsed = subject.parse("[[a,b|]]")
         | 
| 102 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 103 | 
            +
                expect(parsed.text).to eq("a,b")
         | 
| 104 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 105 | 
            +
                expect(parsed[0].text).to eq("a,b")
         | 
| 106 | 
            +
                expect(parsed[0].link).to eq("A,b")
         | 
| 107 | 
            +
              end
         | 
| 108 | 
            +
              
         | 
| 109 | 
            +
              it "parses a link without pipe trick when parens are not matched" do
         | 
| 110 | 
            +
                parsed = subject.parse("[[a(b|]]")
         | 
| 111 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 112 | 
            +
                expect(parsed.text).to eq("a(b")
         | 
| 113 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 114 | 
            +
                expect(parsed[0].text).to eq("a(b")
         | 
| 115 | 
            +
                expect(parsed[0].link).to eq("A(b")
         | 
| 116 | 
            +
              end
         | 
| 117 | 
            +
              
         | 
| 118 | 
            +
              it "parses a link without pipe trick when there is something after parens" do
         | 
| 119 | 
            +
                parsed = subject.parse("[[a (b) c|]]")
         | 
| 120 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 121 | 
            +
                expect(parsed.text).to eq("a (b) c")
         | 
| 122 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 123 | 
            +
                expect(parsed[0].text).to eq("a (b) c")
         | 
| 124 | 
            +
                expect(parsed[0].link).to eq("A (b) c")
         | 
| 125 | 
            +
              end
         | 
| 126 | 
            +
              
         | 
| 127 | 
            +
              it "parses a link with pipe trick when there is something after parens but there are commas" do
         | 
| 128 | 
            +
                parsed = subject.parse("[[a(b), c|]]")
         | 
| 129 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 130 | 
            +
                expect(parsed.text).to eq("a")
         | 
| 131 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 132 | 
            +
                expect(parsed[0].text).to eq("a")
         | 
| 133 | 
            +
                expect(parsed[0].link).to eq("A(b), c")
         | 
| 134 | 
            +
              end
         | 
| 135 | 
            +
              
         | 
| 136 | 
            +
              it "parses a link with pipe trick when where is something other than comma after parens an then more commas" do
         | 
| 137 | 
            +
                parsed = subject.parse("[[a(b)x, c|]]")
         | 
| 138 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 139 | 
            +
                expect(parsed.text).to eq("a(b)x")
         | 
| 140 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 141 | 
            +
                expect(parsed[0].text).to eq("a(b)x")
         | 
| 142 | 
            +
                expect(parsed[0].link).to eq("A(b)x, c")
         | 
| 143 | 
            +
              end
         | 
| 144 | 
            +
              
         | 
| 145 | 
            +
              it "parses a link with pipe trick when where is something after parens but there are commas before" do
         | 
| 146 | 
            +
                parsed = subject.parse("[[a, (b)c|]]")
         | 
| 147 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 148 | 
            +
                expect(parsed.text).to eq("a")
         | 
| 149 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 150 | 
            +
                expect(parsed[0].text).to eq("a")
         | 
| 151 | 
            +
                expect(parsed[0].link).to eq("A, (b)c")
         | 
| 152 | 
            +
              end
         | 
| 153 | 
            +
              
         | 
| 154 | 
            +
              it "parses appends the lettes to a link with pipe trick (comma)" do
         | 
| 155 | 
            +
                parsed = subject.parse("[[a , c|]]n")
         | 
| 156 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 157 | 
            +
                expect(parsed.text).to eq("a n")
         | 
| 158 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 159 | 
            +
                expect(parsed[0].text).to eq("a n")
         | 
| 160 | 
            +
                expect(parsed[0].link).to eq("A , c")
         | 
| 161 | 
            +
              end
         | 
| 162 | 
            +
              
         | 
| 163 | 
            +
              it "parses appends the lettes to a link with pipe trick (parens)" do
         | 
| 164 | 
            +
                parsed = subject.parse("[[a (2014)|]]n")
         | 
| 165 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 166 | 
            +
                expect(parsed.text).to eq("an")
         | 
| 167 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 168 | 
            +
                expect(parsed[0].text).to eq("an")
         | 
| 169 | 
            +
                expect(parsed[0].link).to eq("A (2014)")
         | 
| 170 | 
            +
              end
         | 
| 171 | 
            +
              
         | 
| 172 | 
            +
              it "normalizes whitespace in link text" do
         | 
| 173 | 
            +
                parsed = subject.parse("[[ a  b __ c .  d  ]]")
         | 
| 174 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 175 | 
            +
                expect(parsed.text).to eq("a b __ c . d")
         | 
| 176 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 177 | 
            +
                expect(parsed[0].text).to eq("a b __ c . d")
         | 
| 178 | 
            +
                expect(parsed[0].link).to eq("A b c . d")
         | 
| 179 | 
            +
              end
         | 
| 180 | 
            +
              
         | 
| 181 | 
            +
              it "ignores unclosed links" do
         | 
| 182 | 
            +
                parsed = subject.parse("[[a")
         | 
| 183 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 184 | 
            +
                expect(parsed.text).to eq("[[a")
         | 
| 185 | 
            +
                expect(parsed.links.length).to eq(0)
         | 
| 186 | 
            +
              end
         | 
| 187 | 
            +
              
         | 
| 188 | 
            +
              it "ignores unclosed links up to a newline" do
         | 
| 189 | 
            +
                parsed = subject.parse("[[a\nb]]")
         | 
| 190 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 191 | 
            +
                expect(parsed.text).to eq("[[a\nb]]")
         | 
| 192 | 
            +
                expect(parsed.links.length).to eq(0)
         | 
| 193 | 
            +
              end
         | 
| 194 | 
            +
              
         | 
| 195 | 
            +
              it "matches ending brackets non-greedy" do
         | 
| 196 | 
            +
                parsed = subject.parse("[[a]]b]]c")
         | 
| 197 | 
            +
                expect(parsed.length).to eq(2)
         | 
| 198 | 
            +
                expect(parsed.text).to eq("ab]]c")
         | 
| 199 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 200 | 
            +
                expect(parsed[0].text).to eq("ab")
         | 
| 201 | 
            +
                expect(parsed[0].link).to eq("A")
         | 
| 202 | 
            +
              end
         | 
| 203 | 
            +
              
         | 
| 204 | 
            +
              it "continures the pipe trick stripping a lot" do
         | 
| 205 | 
            +
                parsed = subject.parse("[[x(d), (d), (d), d(b), c|]]")
         | 
| 206 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 207 | 
            +
                expect(parsed.text).to eq("x")
         | 
| 208 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 209 | 
            +
                expect(parsed[0].text).to eq("x")
         | 
| 210 | 
            +
                expect(parsed[0].link).to eq("X(d), (d), (d), d(b), c")
         | 
| 211 | 
            +
              end
         | 
| 212 | 
            +
              
         | 
| 213 | 
            +
              it "may contain pipes in the description" do
         | 
| 214 | 
            +
                parsed = subject.parse("[[a|b|c]]d")
         | 
| 215 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 216 | 
            +
                expect(parsed.text).to eq("b|cd")
         | 
| 217 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 218 | 
            +
                expect(parsed[0].text).to eq("b|cd")
         | 
| 219 | 
            +
                expect(parsed[0].link).to eq("A")
         | 
| 220 | 
            +
              end
         | 
| 221 | 
            +
              
         | 
| 222 | 
            +
              it "removes html comments between a links tags" do
         | 
| 223 | 
            +
                parsed = subject.parse("[[a|<!-- ]] -->b<!-- [[a| -->]]")
         | 
| 224 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 225 | 
            +
                expect(parsed.text).to eq("b")
         | 
| 226 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 227 | 
            +
                expect(parsed[0].text).to eq("b")
         | 
| 228 | 
            +
                expect(parsed[0].link).to eq("A")
         | 
| 229 | 
            +
              end
         | 
| 230 | 
            +
              
         | 
| 231 | 
            +
              it "removes html comments around a links pipe" do
         | 
| 232 | 
            +
                parsed = subject.parse("[[a<!-- | -->b]]")
         | 
| 233 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 234 | 
            +
                expect(parsed.text).to eq("ab")
         | 
| 235 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 236 | 
            +
                expect(parsed[0].text).to eq("ab")
         | 
| 237 | 
            +
                expect(parsed[0].link).to eq("Ab")
         | 
| 238 | 
            +
              end
         | 
| 239 | 
            +
              
         | 
| 240 | 
            +
              it "removes multiline html comments in links" do
         | 
| 241 | 
            +
                parsed = subject.parse("[[a<!-- \n\n\n -->b]]")
         | 
| 242 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 243 | 
            +
                expect(parsed.text).to eq("ab")
         | 
| 244 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 245 | 
            +
                expect(parsed[0].text).to eq("ab")
         | 
| 246 | 
            +
                expect(parsed[0].link).to eq("Ab")
         | 
| 247 | 
            +
              end
         | 
| 248 | 
            +
              
         | 
| 249 | 
            +
            end
         | 
| @@ -0,0 +1,82 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Wptemplates do
         | 
| 4 | 
            +
              
         | 
| 5 | 
            +
              it "parses the empty string" do
         | 
| 6 | 
            +
                parsed = subject.parse("")
         | 
| 7 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 8 | 
            +
                expect(parsed.text).to eq("")
         | 
| 9 | 
            +
                expect(parsed.links.length).to eq(0)
         | 
| 10 | 
            +
                expect(parsed.templates.length).to eq(0)
         | 
| 11 | 
            +
                expect(parsed.all_links.length).to eq(0)
         | 
| 12 | 
            +
                expect(parsed.all_templates.length).to eq(0)
         | 
| 13 | 
            +
                expect(parsed[0].text).to eq("")
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
              
         | 
| 16 | 
            +
              it "parses link, text, template" do
         | 
| 17 | 
            +
                parsed = subject.parse("[[foo]] bar {{baz}}")
         | 
| 18 | 
            +
                expect(parsed.length).to eq(3)
         | 
| 19 | 
            +
                expect(parsed.text).to eq("foo bar ")
         | 
| 20 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 21 | 
            +
                expect(parsed[0].text).to eq("foo")
         | 
| 22 | 
            +
                expect(parsed[0].link).to eq("Foo")
         | 
| 23 | 
            +
                expect(parsed[1].text).to eq(" bar ")
         | 
| 24 | 
            +
                expect(parsed[2].text).to eq("")
         | 
| 25 | 
            +
                expect(parsed[2].name).to eq(:baz)
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
              
         | 
| 28 | 
            +
              it "parses template, text, link" do
         | 
| 29 | 
            +
                parsed = subject.parse("{{baz}} bar [[foo]]")
         | 
| 30 | 
            +
                expect(parsed.length).to eq(3)
         | 
| 31 | 
            +
                expect(parsed.text).to eq(" bar foo")
         | 
| 32 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 33 | 
            +
                expect(parsed[0].text).to eq("")
         | 
| 34 | 
            +
                expect(parsed[0].name).to eq(:baz)
         | 
| 35 | 
            +
                expect(parsed[1].text).to eq(" bar ")
         | 
| 36 | 
            +
                expect(parsed[2].text).to eq("foo")
         | 
| 37 | 
            +
                expect(parsed[2].link).to eq("Foo")
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
              
         | 
| 40 | 
            +
              it "parses a link in a template" do
         | 
| 41 | 
            +
                parsed = subject.parse("{{baz|[[foo]]}}")
         | 
| 42 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 43 | 
            +
                expect(parsed.text).to eq("")
         | 
| 44 | 
            +
                expect(parsed.all_links.length).to eq(1)
         | 
| 45 | 
            +
                expect(parsed.all_templates.length).to eq(1)
         | 
| 46 | 
            +
                expect(parsed.templates.length).to eq(1)
         | 
| 47 | 
            +
                expect(parsed[0].text).to eq("")
         | 
| 48 | 
            +
                expect(parsed[0].name).to eq(:baz)
         | 
| 49 | 
            +
                expect(parsed[0].params.keys).to eq([0])
         | 
| 50 | 
            +
                expect(parsed[0].params[0].length).to eq(1)
         | 
| 51 | 
            +
                expect(parsed[0].params[0].links.length).to eq(1)
         | 
| 52 | 
            +
                expect(parsed[0].params[0][0].text).to eq("foo")
         | 
| 53 | 
            +
                expect(parsed[0].params[0][0].link).to eq("Foo")
         | 
| 54 | 
            +
              end
         | 
| 55 | 
            +
              
         | 
| 56 | 
            +
              it "parses a link in a template with whitespace removed" do
         | 
| 57 | 
            +
                parsed = subject.parse("{{baz|p = [[foo]] }}")
         | 
| 58 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 59 | 
            +
                expect(parsed.text).to eq("")
         | 
| 60 | 
            +
                expect(parsed.templates.length).to eq(1)
         | 
| 61 | 
            +
                expect(parsed[0].text).to eq("")
         | 
| 62 | 
            +
                expect(parsed[0].name).to eq(:baz)
         | 
| 63 | 
            +
                expect(parsed[0].params.keys).to eq([:p])
         | 
| 64 | 
            +
                expect(parsed[0].params[:p].text).to eq("foo")
         | 
| 65 | 
            +
                expect(parsed[0].params[:p].length).to eq(1)
         | 
| 66 | 
            +
                expect(parsed[0].params[:p].links.length).to eq(1)
         | 
| 67 | 
            +
                expect(parsed[0].params[:p][0].text).to eq("foo")
         | 
| 68 | 
            +
                expect(parsed[0].params[:p][0].link).to eq("Foo")
         | 
| 69 | 
            +
              end
         | 
| 70 | 
            +
              
         | 
| 71 | 
            +
              it "parses text, link, letters, link" do
         | 
| 72 | 
            +
                parsed = subject.parse("bar [[foo]]ny baz")
         | 
| 73 | 
            +
                expect(parsed.length).to eq(3)
         | 
| 74 | 
            +
                expect(parsed.text).to eq("bar foony baz")
         | 
| 75 | 
            +
                expect(parsed.links.length).to eq(1)
         | 
| 76 | 
            +
                expect(parsed[0].text).to eq("bar ")
         | 
| 77 | 
            +
                expect(parsed[1].text).to eq("foony")
         | 
| 78 | 
            +
                expect(parsed[1].link).to eq("Foo")
         | 
| 79 | 
            +
                expect(parsed[2].text).to eq(" baz")
         | 
| 80 | 
            +
              end
         | 
| 81 | 
            +
              
         | 
| 82 | 
            +
            end
         | 
| @@ -0,0 +1,161 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Wptemplates do
         | 
| 4 | 
            +
              
         | 
| 5 | 
            +
              it "parses a template without any parameters" do
         | 
| 6 | 
            +
                parsed = subject.parse("{{foo}}")
         | 
| 7 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 8 | 
            +
                expect(parsed.text).to eq("")
         | 
| 9 | 
            +
                expect(parsed[0].text).to eq("")
         | 
| 10 | 
            +
                expect(parsed.templates.length).to eq(1)
         | 
| 11 | 
            +
                expect(parsed[0].name).to eq(:foo)
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
              
         | 
| 14 | 
            +
              it "parses a template with numeric parameters" do
         | 
| 15 | 
            +
                parsed = subject.parse("{{foo|a|b|c}}")
         | 
| 16 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 17 | 
            +
                expect(parsed.text).to eq("")
         | 
| 18 | 
            +
                expect(parsed[0].text).to eq("")
         | 
| 19 | 
            +
                expect(parsed.templates.length).to eq(1)
         | 
| 20 | 
            +
                expect(parsed[0].name).to eq(:foo)
         | 
| 21 | 
            +
                p = parsed[0].params
         | 
| 22 | 
            +
                expect(p.keys).to eq([0,1,2])
         | 
| 23 | 
            +
                expect(p[0].length).to eq(1)
         | 
| 24 | 
            +
                expect(p[0].text).to eq("a")
         | 
| 25 | 
            +
                expect(p[0][0].text).to eq("a")
         | 
| 26 | 
            +
                expect(p[1].length).to eq(1)
         | 
| 27 | 
            +
                expect(p[1].text).to eq("b")
         | 
| 28 | 
            +
                expect(p[1][0].text).to eq("b")
         | 
| 29 | 
            +
                expect(p[2].length).to eq(1)
         | 
| 30 | 
            +
                expect(p[2].text).to eq("c")
         | 
| 31 | 
            +
                expect(p[2][0].text).to eq("c")
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
              
         | 
| 34 | 
            +
              it "parses a template with named parameters" do
         | 
| 35 | 
            +
                parsed = subject.parse("{{foo| a = x |b = y \n|c= z z }}")
         | 
| 36 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 37 | 
            +
                expect(parsed.text).to eq("")
         | 
| 38 | 
            +
                expect(parsed[0].text).to eq("")
         | 
| 39 | 
            +
                expect(parsed.templates.length).to eq(1)
         | 
| 40 | 
            +
                expect(parsed[0].name).to eq(:foo)
         | 
| 41 | 
            +
                p = parsed[0].params
         | 
| 42 | 
            +
                expect(p.keys).to eq([:a,:b,:c])
         | 
| 43 | 
            +
                expect(p[:a].length).to eq(1)
         | 
| 44 | 
            +
                expect(p[:a].text).to eq("x")
         | 
| 45 | 
            +
                expect(p[:a][0].text).to eq("x")
         | 
| 46 | 
            +
                expect(p[:b].length).to eq(1)
         | 
| 47 | 
            +
                expect(p[:b].text).to eq("y")
         | 
| 48 | 
            +
                expect(p[:b][0].text).to eq("y")
         | 
| 49 | 
            +
                expect(p[:c].length).to eq(1)
         | 
| 50 | 
            +
                expect(p[:c].text).to eq("z z")
         | 
| 51 | 
            +
                expect(p[:c][0].text).to eq("z z")
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
              
         | 
| 54 | 
            +
              it "doesn't have problems with empty numeric parameters" do
         | 
| 55 | 
            +
                parsed = subject.parse("{{foo|}}")
         | 
| 56 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 57 | 
            +
                p = parsed[0].params
         | 
| 58 | 
            +
                expect(p.keys).to eq([0])
         | 
| 59 | 
            +
                expect(p[0].length).to eq(1)
         | 
| 60 | 
            +
                expect(p[0].text).to eq("")
         | 
| 61 | 
            +
                expect(p[0][0].text).to eq("")
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
              
         | 
| 64 | 
            +
              it "doesn't have problems with empty valued named parameters" do
         | 
| 65 | 
            +
                parsed = subject.parse("{{foo|b=}}")
         | 
| 66 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 67 | 
            +
                p = parsed[0].params
         | 
| 68 | 
            +
                expect(p.keys).to eq([:b])
         | 
| 69 | 
            +
                expect(p[:b].length).to eq(1)
         | 
| 70 | 
            +
                expect(p[:b].text).to eq("")
         | 
| 71 | 
            +
                expect(p[:b][0].text).to eq("")
         | 
| 72 | 
            +
              end
         | 
| 73 | 
            +
              
         | 
| 74 | 
            +
              it "doesn't have problems with white spece only valued named parameters" do
         | 
| 75 | 
            +
                parsed = subject.parse("{{foo|c= }}")
         | 
| 76 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 77 | 
            +
                p = parsed[0].params
         | 
| 78 | 
            +
                expect(p.keys).to eq([:c])
         | 
| 79 | 
            +
                expect(p[:c].length).to eq(1)
         | 
| 80 | 
            +
                expect(p[:c].text).to eq("")
         | 
| 81 | 
            +
                expect(p[:c][0].text).to eq("")
         | 
| 82 | 
            +
              end
         | 
| 83 | 
            +
              
         | 
| 84 | 
            +
              it "doesn't have problems with empty name parameters" do
         | 
| 85 | 
            +
                parsed = subject.parse("{{foo|=3}}")
         | 
| 86 | 
            +
                p = parsed[0].params
         | 
| 87 | 
            +
                expect(p[:""].length).to eq(1)
         | 
| 88 | 
            +
                expect(p[:""].text).to eq("3")
         | 
| 89 | 
            +
                expect(p[:""][0].text).to eq("3")
         | 
| 90 | 
            +
              end
         | 
| 91 | 
            +
              
         | 
| 92 | 
            +
              it "doesn't have problems with mixed empty stuff" do
         | 
| 93 | 
            +
                parsed = subject.parse("{{foo||b=|c= |=3}}")
         | 
| 94 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 95 | 
            +
                p = parsed[0].params
         | 
| 96 | 
            +
                expect(p.keys).to eq([0,:b,:c,:""])
         | 
| 97 | 
            +
                expect(p[0].length).to eq(1)
         | 
| 98 | 
            +
                expect(p[0].text).to eq("")
         | 
| 99 | 
            +
                expect(p[0][0].text).to eq("")
         | 
| 100 | 
            +
                expect(p[:b].length).to eq(1)
         | 
| 101 | 
            +
                expect(p[:b].text).to eq("")
         | 
| 102 | 
            +
                expect(p[:b][0].text).to eq("")
         | 
| 103 | 
            +
                expect(p[:c].length).to eq(1)
         | 
| 104 | 
            +
                expect(p[:c].text).to eq("")
         | 
| 105 | 
            +
                expect(p[:c][0].text).to eq("")
         | 
| 106 | 
            +
                expect(p[:""].length).to eq(1)
         | 
| 107 | 
            +
                expect(p[:""].text).to eq("3")
         | 
| 108 | 
            +
                expect(p[:""][0].text).to eq("3")
         | 
| 109 | 
            +
              end
         | 
| 110 | 
            +
              
         | 
| 111 | 
            +
              it "parses nested templates" do
         | 
| 112 | 
            +
                parsed = subject.parse("{{foo| a = {{bar|j|k}} |b = y {{baz|p=q}} y2 \n|c= z z }}")
         | 
| 113 | 
            +
                expect(parsed.length).to eq(1)
         | 
| 114 | 
            +
                expect(parsed.text).to eq("")
         | 
| 115 | 
            +
                expect(parsed[0].text).to eq("")
         | 
| 116 | 
            +
                expect(parsed.templates.length).to eq(1)
         | 
| 117 | 
            +
                expect(parsed.all_templates.length).to eq(3)
         | 
| 118 | 
            +
                expect(parsed[0].name).to eq(:foo)
         | 
| 119 | 
            +
                p = parsed[0].params
         | 
| 120 | 
            +
                expect(p.keys).to eq([:a,:b,:c])
         | 
| 121 | 
            +
                expect(p[:a].templates.length).to eq(1)
         | 
| 122 | 
            +
                expect(p[:a].text).to eq("")
         | 
| 123 | 
            +
                expect(p[:a].templates[0].name).to eq(:bar)
         | 
| 124 | 
            +
                expect(p[:a].templates[0].params.keys).to eq([0,1])
         | 
| 125 | 
            +
                expect(p[:a].templates[0].params[0].text).to eq("j")
         | 
| 126 | 
            +
                expect(p[:a].templates[0].params[1].text).to eq("k")
         | 
| 127 | 
            +
                expect(p[:b].length).to eq(3)
         | 
| 128 | 
            +
                expect(p[:b].templates.length).to eq(1)
         | 
| 129 | 
            +
                expect(p[:b].text).to eq("y  y2")
         | 
| 130 | 
            +
                expect(p[:b][0].text).to eq("y ")
         | 
| 131 | 
            +
                expect(p[:b][2].text).to eq(" y2")
         | 
| 132 | 
            +
                expect(p[:b].templates[0].name).to eq(:baz)
         | 
| 133 | 
            +
                expect(p[:b].templates[0].params.keys).to eq([:p])
         | 
| 134 | 
            +
                expect(p[:b].templates[0].params[:p].text).to eq("q")
         | 
| 135 | 
            +
                expect(p[:c].length).to eq(1)
         | 
| 136 | 
            +
                expect(p[:c].text).to eq("z z")
         | 
| 137 | 
            +
                expect(p[:c][0].text).to eq("z z")
         | 
| 138 | 
            +
              end
         | 
| 139 | 
            +
              
         | 
| 140 | 
            +
              it "barkes about unclosed templates" do
         | 
| 141 | 
            +
                expect { subject.parse("{{foo") }.to raise_error
         | 
| 142 | 
            +
                expect { subject.parse("{{foo}}{{") }.to raise_error
         | 
| 143 | 
            +
              end
         | 
| 144 | 
            +
              
         | 
| 145 | 
            +
              it "does not bark when {{ is in the name though" do
         | 
| 146 | 
            +
                expect(subject.parse("{{{{foo}}")[0].name).to eq(:"{{foo")
         | 
| 147 | 
            +
              end
         | 
| 148 | 
            +
              
         | 
| 149 | 
            +
              it "finds nested templates" do
         | 
| 150 | 
            +
                parsed = subject.parse("{{foo| a = {{bar|j|k}} |b = y {{foo|p=q}} y2 \n|c= z z }}")
         | 
| 151 | 
            +
                expect(parsed.template_of :foo).to eq(parsed.templates[0])
         | 
| 152 | 
            +
                expect(parsed.templates_of :foo).to eq([parsed.templates[0]])
         | 
| 153 | 
            +
                expect(parsed.deep_template_of :foo).to eq(parsed.templates[0])
         | 
| 154 | 
            +
                expect(parsed.all_templates_of :foo).to eq([parsed.templates[0], parsed.templates[0].params[:b].templates[0]])
         | 
| 155 | 
            +
                expect(parsed.template_of :bar).to be_nil
         | 
| 156 | 
            +
                expect(parsed.templates_of :bar).to eq([])
         | 
| 157 | 
            +
                expect(parsed.deep_template_of :bar).to eq(parsed.templates[0].params[:a].templates[0])
         | 
| 158 | 
            +
                expect(parsed.all_templates_of :bar).to eq([parsed.templates[0].params[:a].templates[0]])
         | 
| 159 | 
            +
              end
         | 
| 160 | 
            +
              
         | 
| 161 | 
            +
            end
         |