#!/usr/bin/env ruby require File.join(File.dirname(__FILE__), "..", "spec_helper") describe "Macro:" do before do create_project Glyph.run! 'load:all' end after do Glyph.lite_mode = false delete_project end it "snippet" do define_em_macro interpret "Testing a snippet: &[test]." @p.document.output.should == "Testing a snippet: This is a \nTest snippet." interpret("Testing &[wrong].") @p.document.output.should == "Testing [SNIPPET 'wrong' NOT PROCESSED]." Glyph::SNIPPETS[:a] = "this is a em[test] &[b]" Glyph::SNIPPETS[:b] = "and another em[test]" text = "TEST: &[a]" interpret text @p.document.output.should == "TEST: this is a test and another test" # Check snippets with links Glyph::SNIPPETS[:c] = "This is a link to something afterwards: =>[#other]" text = "Test. &[c]. #[other|Test]." output_for(text).should == %{Test. This is a link to something afterwards: Test. Test.} end it "snippet:" do interpret("&[t1] - &:[t1|Test #1] - &[t1]") @p.document.output.should == "[SNIPPET 't1' NOT PROCESSED] - - Test #1" Glyph::SNIPPETS[:t1].should == "Test #1" Glyph::SNIPPETS.delete :t1 end it "condition" do define_em_macro interpret("?[$[document.invalid]|em[test]]") @p.document.output.should == "" interpret("?[$[document.output]|em[test]]") @p.document.output.should == "test" interpret("?[not[eq[$[document.output]|]]|em[test]]") @p.document.output.should == "test" interpret %{?[ or[ eq[$[document.target]|htmls]| not[eq[$[document.author]|x]] ]|em[test]]} @p.document.output.should == "test" # "false" should be regarded as false interpret(%{?[%["test".blank?]|---]}) @p.document.output.should == "" interpret("?[not[match[$[document.source]|/^docu/]]|em[test]]") @p.document.output.should == "" # Invalid regexp lambda { interpret("?[match[$[document.source]|document]em[test]]").document.output }.should raise_error interpret "?[%[lite?]|test]" @p.document.output.should == "" interpret "?[%[!lite?]|test]" @p.document.output.should == "test" interpret "?[%[lite?]|%[\"test\"]]" @p.document.output.should == "" # Condition not satisfied... interpret "?[%[lite?]|%[ Glyph\\['test_config'\\] = true ]]" @p.document.output.should == "" Glyph['test_config'].should_not == true # Condition satisfied... interpret "?[%[!lite?]|%[ Glyph\\['test_config'\\] = true ]]" @p.document.output.should == "true" Glyph['test_config'].should == true end it "condition (else)" do output_for("?[true|OK|NOT OK]").should == "OK" output_for("?[false|OK|NOT OK]").should == "NOT OK" end it "comment" do output_for("--[config:[some_random_setting|test]]").should == "" Glyph[:some_random_setting].should == nil end it "include" do Glyph["filters.by_extension"] = true text = file_load(Glyph::PROJECT/'text/container.textile') interpret text @p.document.output.gsub(/\n|\t/, '').should == %{
…
…