inversion 0.12.3 → 0.14.0
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +2 -1
- data.tar.gz.sig +0 -0
- data/ChangeLog +305 -9
- data/Examples.rdoc +134 -0
- data/GettingStarted.rdoc +44 -0
- data/Guide.rdoc +47 -0
- data/History.rdoc +15 -0
- data/Manifest.txt +7 -2
- data/README.rdoc +9 -10
- data/Rakefile +23 -10
- data/Tags.rdoc +561 -0
- data/lib/inversion.rb +2 -2
- data/lib/inversion/renderstate.rb +46 -11
- data/lib/inversion/template.rb +85 -7
- data/lib/inversion/template/attrtag.rb +1 -1
- data/lib/inversion/template/begintag.rb +8 -8
- data/lib/inversion/template/fragmenttag.rb +60 -0
- data/lib/inversion/template/rescuetag.rb +1 -1
- data/spec/{lib/helpers.rb → helpers.rb} +7 -30
- data/spec/inversion/mixins_spec.rb +55 -65
- data/spec/inversion/monkeypatches_spec.rb +2 -12
- data/spec/inversion/parser_spec.rb +34 -44
- data/spec/inversion/renderstate_spec.rb +123 -69
- data/spec/inversion/sinatra_spec.rb +6 -19
- data/spec/inversion/template/attrtag_spec.rb +56 -76
- data/spec/inversion/template/begintag_spec.rb +24 -41
- data/spec/inversion/template/calltag_spec.rb +1 -18
- data/spec/inversion/template/codetag_spec.rb +6 -24
- data/spec/inversion/template/commenttag_spec.rb +9 -27
- data/spec/inversion/template/configtag_spec.rb +5 -16
- data/spec/inversion/template/containertag_spec.rb +4 -21
- data/spec/inversion/template/defaulttag_spec.rb +6 -23
- data/spec/inversion/template/elsetag_spec.rb +9 -26
- data/spec/inversion/template/elsiftag_spec.rb +7 -24
- data/spec/inversion/template/endtag_spec.rb +6 -23
- data/spec/inversion/template/escapetag_spec.rb +10 -25
- data/spec/inversion/template/fortag_spec.rb +20 -37
- data/spec/inversion/template/fragmenttag_spec.rb +40 -0
- data/spec/inversion/template/iftag_spec.rb +23 -40
- data/spec/inversion/template/importtag_spec.rb +8 -25
- data/spec/inversion/template/includetag_spec.rb +27 -42
- data/spec/inversion/template/node_spec.rb +6 -15
- data/spec/inversion/template/pptag_spec.rb +10 -23
- data/spec/inversion/template/publishtag_spec.rb +4 -21
- data/spec/inversion/template/rescuetag_spec.rb +12 -29
- data/spec/inversion/template/subscribetag_spec.rb +8 -25
- data/spec/inversion/template/tag_spec.rb +24 -37
- data/spec/inversion/template/textnode_spec.rb +8 -24
- data/spec/inversion/template/timedeltatag_spec.rb +31 -43
- data/spec/inversion/template/unlesstag_spec.rb +7 -24
- data/spec/inversion/template/uriencodetag_spec.rb +6 -23
- data/spec/inversion/template/yieldtag_spec.rb +3 -20
- data/spec/inversion/template_spec.rb +155 -108
- data/spec/inversion/tilt_spec.rb +7 -16
- data/spec/inversion_spec.rb +7 -22
- metadata +63 -40
- metadata.gz.sig +0 -0
- data/spec/lib/constants.rb +0 -9
| @@ -1,17 +1,8 @@ | |
| 1 1 | 
             
            #!/usr/bin/env rspec -cfd -b
         | 
| 2 2 | 
             
            # vim: set noet nosta sw=4 ts=4 :
         | 
| 3 3 |  | 
| 4 | 
            -
             | 
| 5 | 
            -
            	require 'pathname'
         | 
| 6 | 
            -
            	basedir = Pathname( __FILE__ ).dirname.parent.parent.parent
         | 
| 7 | 
            -
            	libdir = basedir + 'lib'
         | 
| 4 | 
            +
            require_relative '../../helpers'
         | 
| 8 5 |  | 
| 9 | 
            -
            	$LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
         | 
| 10 | 
            -
            	$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
         | 
| 11 | 
            -
            }
         | 
| 12 | 
            -
             | 
| 13 | 
            -
            require 'rspec'
         | 
| 14 | 
            -
            require 'spec/lib/helpers'
         | 
| 15 6 | 
             
            require 'inversion/template/fortag'
         | 
| 16 7 | 
             
            require 'inversion/template/textnode'
         | 
| 17 8 | 
             
            require 'inversion/template/endtag'
         | 
| @@ -19,22 +10,14 @@ require 'inversion/renderstate' | |
| 19 10 |  | 
| 20 11 | 
             
            describe Inversion::Template::EndTag do
         | 
| 21 12 |  | 
| 22 | 
            -
            	before( :all ) do
         | 
| 23 | 
            -
            		setup_logging( :fatal )
         | 
| 24 | 
            -
            	end
         | 
| 25 | 
            -
             | 
| 26 13 | 
             
            	before( :each ) do
         | 
| 27 14 | 
             
            		@tag = Inversion::Template::EndTag.new
         | 
| 28 15 | 
             
            	end
         | 
| 29 16 |  | 
| 30 | 
            -
            	after( :all ) do
         | 
| 31 | 
            -
            		reset_logging()
         | 
| 32 | 
            -
            	end
         | 
| 33 | 
            -
             | 
| 34 17 |  | 
| 35 18 | 
             
            	it "doesn't render as anything" do
         | 
| 36 19 | 
             
            		renderstate = Inversion::RenderState.new
         | 
| 37 | 
            -
            		@tag.render( | 
| 20 | 
            +
            		expect( @tag.render(renderstate) ).to be_nil()
         | 
| 38 21 | 
             
            	end
         | 
| 39 22 |  | 
| 40 23 | 
             
            	it "can render itself as a comment body that outputs what it closes" do
         | 
| @@ -42,14 +25,14 @@ describe Inversion::Template::EndTag do | |
| 42 25 | 
             
            		template = Inversion::Template.
         | 
| 43 26 | 
             
            			new( "<?for foo in bar ?>Chunkers<?end ?>", :debugging_comments => true )
         | 
| 44 27 | 
             
            		template.bar = [ :an_item ]
         | 
| 45 | 
            -
            		template.render. | 
| 28 | 
            +
            		expect( template.render ).to match( /<!-- End of For: { foo IN template.bar } -->/ )
         | 
| 46 29 | 
             
            	end
         | 
| 47 30 |  | 
| 48 31 | 
             
            	it "closes the parse state's currently-open container node before it's appended" do
         | 
| 49 32 | 
             
            		container = double( "container node", :tagname => 'for', :location => nil )
         | 
| 50 | 
            -
            		parserstate =  | 
| 33 | 
            +
            		parserstate = double( "parser state" )
         | 
| 51 34 |  | 
| 52 | 
            -
            		parserstate. | 
| 35 | 
            +
            		expect( parserstate ).to receive( :pop ).and_return( container )
         | 
| 53 36 |  | 
| 54 37 | 
             
            		@tag.before_appending( parserstate )
         | 
| 55 38 | 
             
            	end
         | 
| @@ -67,7 +50,7 @@ describe Inversion::Template::EndTag do | |
| 67 50 |  | 
| 68 51 | 
             
            			expect {
         | 
| 69 52 | 
             
            				@tag.before_appending( state )
         | 
| 70 | 
            -
            			}.to  | 
| 53 | 
            +
            			}.to raise_error( Inversion::ParseError, /unbalanced/i )
         | 
| 71 54 | 
             
            		end
         | 
| 72 55 |  | 
| 73 56 | 
             
            	end
         | 
| @@ -1,59 +1,44 @@ | |
| 1 1 | 
             
            #!/usr/bin/env rspec -cfd -b
         | 
| 2 2 | 
             
            # vim: set noet nosta sw=4 ts=4 :
         | 
| 3 3 |  | 
| 4 | 
            -
             | 
| 5 | 
            -
            	require 'pathname'
         | 
| 6 | 
            -
            	basedir = Pathname( __FILE__ ).dirname.parent.parent.parent
         | 
| 7 | 
            -
            	libdir = basedir + 'lib'
         | 
| 4 | 
            +
            require_relative '../../helpers'
         | 
| 8 5 |  | 
| 9 | 
            -
            	$LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
         | 
| 10 | 
            -
            	$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
         | 
| 11 | 
            -
            }
         | 
| 12 | 
            -
             | 
| 13 | 
            -
            require 'rspec'
         | 
| 14 | 
            -
            require 'spec/lib/helpers'
         | 
| 15 6 | 
             
            require 'inversion/template/escapetag'
         | 
| 16 7 |  | 
| 17 8 | 
             
            describe Inversion::Template::EscapeTag do
         | 
| 18 9 |  | 
| 19 | 
            -
            	before( :all ) do
         | 
| 20 | 
            -
            		setup_logging( :fatal )
         | 
| 21 | 
            -
            	end
         | 
| 22 | 
            -
             | 
| 23 | 
            -
            	after( :all ) do
         | 
| 24 | 
            -
            		reset_logging()
         | 
| 25 | 
            -
            	end
         | 
| 26 | 
            -
             | 
| 27 10 | 
             
            	before( :each ) do
         | 
| 28 | 
            -
            		@attribute_object =  | 
| 11 | 
            +
            		@attribute_object = double( "template attribute" )
         | 
| 29 12 | 
             
            	end
         | 
| 30 13 |  | 
| 31 14 |  | 
| 32 15 | 
             
            	it "defaults to escaping as HTML" do
         | 
| 33 16 | 
             
            		template = Inversion::Template.new( 'this is <?escape foo.bar ?>' )
         | 
| 34 17 | 
             
            		template.foo = @attribute_object
         | 
| 35 | 
            -
            		@attribute_object. | 
| 18 | 
            +
            		expect( @attribute_object ).to receive( :bar ).with( no_args() ).
         | 
| 36 19 | 
             
            			and_return( "<the good, the bad, & the ugly>" )
         | 
| 37 20 |  | 
| 38 | 
            -
            		template.render. | 
| 21 | 
            +
            		expect( template.render ).to eq( "this is <the good, the bad, & the ugly>" )
         | 
| 39 22 | 
             
            	end
         | 
| 40 23 |  | 
| 41 24 | 
             
            	it "raises an Inversion::OptionsError if the config specifies an unsupported format" do
         | 
| 42 25 | 
             
            		template = Inversion::Template.new( 'this is <?escape foo.bar ?>',
         | 
| 43 26 | 
             
            				:escape_format => :clowns, :on_render_error => :propagate )
         | 
| 44 27 | 
             
            		template.foo = @attribute_object
         | 
| 45 | 
            -
            		@attribute_object. | 
| 28 | 
            +
            		expect( @attribute_object ).to receive( :bar ).with( no_args() ).
         | 
| 46 29 | 
             
            			and_return( "<the good, the bad, & the ugly>" )
         | 
| 47 30 |  | 
| 48 | 
            -
            		expect { | 
| 31 | 
            +
            		expect {
         | 
| 32 | 
            +
            			template.render
         | 
| 33 | 
            +
            		}.to raise_error( Inversion::OptionsError, /no such escape format/i )
         | 
| 49 34 | 
             
            	end
         | 
| 50 35 |  | 
| 51 36 | 
             
            	it "escapes as HTML if the format is set to :html" do
         | 
| 52 37 | 
             
            		template = Inversion::Template.new( 'this is <?escape foo.bar ?>', :escape_format => :html )
         | 
| 53 38 | 
             
            		template.foo = @attribute_object
         | 
| 54 | 
            -
            		@attribute_object. | 
| 39 | 
            +
            		expect( @attribute_object ).to receive( :bar ).with( no_args() ).
         | 
| 55 40 | 
             
            			and_return( "<the good, the bad, & the ugly>" )
         | 
| 56 41 |  | 
| 57 | 
            -
            		template.render. | 
| 42 | 
            +
            		expect( template.render ).to eq( "this is <the good, the bad, & the ugly>" )
         | 
| 58 43 | 
             
            	end
         | 
| 59 44 | 
             
            end
         | 
| @@ -1,18 +1,9 @@ | |
| 1 1 | 
             
            #!/usr/bin/env rspec -cfd -b
         | 
| 2 2 | 
             
            # vim: set noet nosta sw=4 ts=4 :
         | 
| 3 3 |  | 
| 4 | 
            -
             | 
| 5 | 
            -
            	require 'pathname'
         | 
| 6 | 
            -
            	basedir = Pathname( __FILE__ ).dirname.parent.parent.parent
         | 
| 7 | 
            -
            	libdir = basedir + 'lib'
         | 
| 4 | 
            +
            require_relative '../../helpers'
         | 
| 8 5 |  | 
| 9 | 
            -
            	$LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
         | 
| 10 | 
            -
            	$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
         | 
| 11 | 
            -
            }
         | 
| 12 | 
            -
             | 
| 13 | 
            -
            require 'rspec'
         | 
| 14 6 | 
             
            require 'ostruct'
         | 
| 15 | 
            -
            require 'spec/lib/helpers'
         | 
| 16 7 | 
             
            require 'inversion/template/fortag'
         | 
| 17 8 | 
             
            require 'inversion/template/attrtag'
         | 
| 18 9 | 
             
            require 'inversion/template/textnode'
         | 
| @@ -20,25 +11,17 @@ require 'inversion/renderstate' | |
| 20 11 |  | 
| 21 12 | 
             
            describe Inversion::Template::ForTag do
         | 
| 22 13 |  | 
| 23 | 
            -
            	before( :all ) do
         | 
| 24 | 
            -
            		setup_logging( :fatal )
         | 
| 25 | 
            -
            	end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
            	after( :all ) do
         | 
| 28 | 
            -
            		reset_logging()
         | 
| 29 | 
            -
            	end
         | 
| 30 | 
            -
             | 
| 31 14 |  | 
| 32 15 | 
             
            	it "knows which identifiers should be added to the template" do
         | 
| 33 16 | 
             
            		tag = Inversion::Template::ForTag.new( 'foo in bar' )
         | 
| 34 | 
            -
            		tag.identifiers. | 
| 17 | 
            +
            		expect( tag.identifiers ).to eq( [ :bar ] )
         | 
| 35 18 | 
             
            	end
         | 
| 36 19 |  | 
| 37 20 | 
             
            	it "can iterate over single items of a collection attribute" do
         | 
| 38 21 | 
             
            		tag = Inversion::Template::ForTag.new( 'foo in bar' )
         | 
| 39 22 |  | 
| 40 | 
            -
            		tag.block_args. | 
| 41 | 
            -
            		tag.enumerator. | 
| 23 | 
            +
            		expect( tag.block_args ).to eq( [ :foo ] )
         | 
| 24 | 
            +
            		expect( tag.enumerator ).to eq( 'bar' )
         | 
| 42 25 | 
             
            	end
         | 
| 43 26 |  | 
| 44 27 | 
             
            	it "should render as nothing if the corresponding attribute in the template is unset" do
         | 
| @@ -52,7 +35,7 @@ describe Inversion::Template::ForTag do | |
| 52 35 | 
             
            		tag << Inversion::Template::AttrTag.new( 'foo' )
         | 
| 53 36 | 
             
            		tag << Inversion::Template::TextNode.new( ']' )
         | 
| 54 37 |  | 
| 55 | 
            -
            		tag.render( render_state ). | 
| 38 | 
            +
            		expect( tag.render( render_state ) ).to be_nil()
         | 
| 56 39 | 
             
            	end
         | 
| 57 40 |  | 
| 58 41 | 
             
            	it "renders each of its subnodes for each iteration, replacing its " +
         | 
| @@ -68,7 +51,7 @@ describe Inversion::Template::ForTag do | |
| 68 51 | 
             
            		tag << Inversion::Template::TextNode.new( ']' )
         | 
| 69 52 |  | 
| 70 53 | 
             
            		tag.render( render_state )
         | 
| 71 | 
            -
            		render_state.to_s. | 
| 54 | 
            +
            		expect( render_state.to_s ).to eq( "[monkey][goat]" )
         | 
| 72 55 | 
             
            	end
         | 
| 73 56 |  | 
| 74 57 | 
             
            	it "supports nested iterators" do
         | 
| @@ -88,7 +71,7 @@ describe Inversion::Template::ForTag do | |
| 88 71 | 
             
            		outer << inner
         | 
| 89 72 |  | 
| 90 73 | 
             
            		outer.render( render_state )
         | 
| 91 | 
            -
            		render_state.to_s. | 
| 74 | 
            +
            		expect( render_state.to_s ).to eq( "[x, o][x, x][o, o][o, x]" )
         | 
| 92 75 | 
             
            	end
         | 
| 93 76 |  | 
| 94 77 | 
             
            	it "supports iterating over a range" do
         | 
| @@ -101,13 +84,13 @@ describe Inversion::Template::ForTag do | |
| 101 84 |  | 
| 102 85 | 
             
            		render_state = Inversion::RenderState.new( :rng => 0..10 )
         | 
| 103 86 | 
             
            		tag.render( render_state )
         | 
| 104 | 
            -
            		render_state.to_s. | 
| 87 | 
            +
            		expect( render_state.to_s ).to eq( "0 1 2 3 4 5 6 7 8 9 10 " )
         | 
| 105 88 | 
             
            	end
         | 
| 106 89 |  | 
| 107 90 | 
             
            	it "raises a ParseError if a keyword other than 'in' is used" do
         | 
| 108 91 | 
             
            		expect {
         | 
| 109 92 | 
             
            			Inversion::Template::ForTag.new( 'foo begin bar' )
         | 
| 110 | 
            -
            		}.to  | 
| 93 | 
            +
            		}.to raise_error( Inversion::ParseError, /invalid/i )
         | 
| 111 94 | 
             
            	end
         | 
| 112 95 |  | 
| 113 96 | 
             
            	context "multidimensional collections" do
         | 
| @@ -115,16 +98,16 @@ describe Inversion::Template::ForTag do | |
| 115 98 | 
             
            		it "can be expanded into multiple block arguments" do
         | 
| 116 99 | 
             
            			tag = Inversion::Template::ForTag.new( 'splip, splorp in splap' )
         | 
| 117 100 |  | 
| 118 | 
            -
            			tag.block_args. | 
| 119 | 
            -
            			tag.enumerator. | 
| 101 | 
            +
            			expect( tag.block_args ).to eq( [ :splip, :splorp ] )
         | 
| 102 | 
            +
            			expect( tag.enumerator ).to eq( 'splap' )
         | 
| 120 103 | 
             
            		end
         | 
| 121 104 |  | 
| 122 105 |  | 
| 123 106 | 
             
            		it "can be expanded into multiple block arguments (sans spaces)" do
         | 
| 124 107 | 
             
            			tag = Inversion::Template::ForTag.new( 'splip,splorp,sploop in splap' )
         | 
| 125 108 |  | 
| 126 | 
            -
            			tag.block_args. | 
| 127 | 
            -
            			tag.enumerator. | 
| 109 | 
            +
            			expect( tag.block_args ).to eq( [ :splip, :splorp, :sploop ] )
         | 
| 110 | 
            +
            			expect( tag.enumerator ).to eq( 'splap' )
         | 
| 128 111 | 
             
            		end
         | 
| 129 112 |  | 
| 130 113 | 
             
            		it "can be expanded into multiple block arguments from hash pairs" do
         | 
| @@ -137,13 +120,13 @@ describe Inversion::Template::ForTag do | |
| 137 120 | 
             
            			tag << Inversion::Template::AttrTag.new( 'value' )
         | 
| 138 121 | 
             
            			tag << Inversion::Template::TextNode.new( ']' )
         | 
| 139 122 |  | 
| 140 | 
            -
            			tag.block_args. | 
| 141 | 
            -
            			tag.enumerator. | 
| 123 | 
            +
            			expect( tag.block_args ).to eq( [ :key, :value ] )
         | 
| 124 | 
            +
            			expect( tag.enumerator ).to eq( 'splap' )
         | 
| 142 125 |  | 
| 143 126 | 
             
            			render_state = Inversion::RenderState.new( :splap => {'one' => 'uno', 'two' => 'dos'} )
         | 
| 144 127 | 
             
            			tag.render( render_state )
         | 
| 145 128 |  | 
| 146 | 
            -
            			render_state.to_s. | 
| 129 | 
            +
            			expect( render_state.to_s ).to eq( '[one translates to uno][two translates to dos]' )
         | 
| 147 130 | 
             
            		end
         | 
| 148 131 |  | 
| 149 132 | 
             
            		it "can be expanded into multiple block arguments with complex values" do
         | 
| @@ -166,8 +149,8 @@ describe Inversion::Template::ForTag do | |
| 166 149 | 
             
            			render_state = Inversion::RenderState.new( :method_list => method_list )
         | 
| 167 150 | 
             
            			tree.first.render( render_state )
         | 
| 168 151 |  | 
| 169 | 
            -
            			render_state.to_s. | 
| 170 | 
            -
            			render_state.to_s. | 
| 152 | 
            +
            			expect( render_state.to_s ).to match( /foo \(3\) => foo\s+AKA: foom, foom_detail/ )
         | 
| 153 | 
            +
            			expect( render_state.to_s ).to match( /ch \(1\) => ch/ )
         | 
| 171 154 | 
             
            		end
         | 
| 172 155 |  | 
| 173 156 | 
             
            		it "preserves an array of subhashes" do
         | 
| @@ -185,7 +168,7 @@ describe Inversion::Template::ForTag do | |
| 185 168 | 
             
            			render_state = Inversion::RenderState.new( :the_hash => the_hash )
         | 
| 186 169 | 
             
            			tree.first.render( render_state )
         | 
| 187 170 |  | 
| 188 | 
            -
            			render_state.to_s. | 
| 171 | 
            +
            			expect( render_state.to_s ).to match( /Subhash is a Hash/i )
         | 
| 189 172 | 
             
            		end
         | 
| 190 173 |  | 
| 191 174 | 
             
            	end
         | 
| @@ -220,7 +203,7 @@ describe Inversion::Template::ForTag do | |
| 220 203 | 
             
            			tmpl.frame = frame
         | 
| 221 204 | 
             
            			output = tmpl.render
         | 
| 222 205 |  | 
| 223 | 
            -
            			output.gsub( /\t+/, '' ). | 
| 206 | 
            +
            			expect( output.gsub( /\t+/, '' ) ).to eq( (<<-END_OUTPUT).gsub( /\t+/, '' ) )
         | 
| 224 207 | 
             
            			<section class="hexdump">
         | 
| 225 208 | 
             
            				<span class="row">0x00000000:
         | 
| 226 209 | 
             
            				 <code>0x89</code>
         | 
| @@ -0,0 +1,40 @@ | |
| 1 | 
            +
            #!/usr/bin/env rspec -cfd -b
         | 
| 2 | 
            +
            # vim: set noet nosta sw=4 ts=4 :
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            require_relative '../../helpers'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            require 'inversion/template/fragmenttag'
         | 
| 7 | 
            +
            require 'inversion/template/attrtag'
         | 
| 8 | 
            +
            require 'inversion/template/textnode'
         | 
| 9 | 
            +
            require 'inversion/renderstate'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            describe Inversion::Template::FragmentTag do
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            	it "raises a parse error if the body isn't a simple attribute" do
         | 
| 14 | 
            +
            		expect {
         | 
| 15 | 
            +
            			Inversion::Template::FragmentTag.new( 'something-else' )
         | 
| 16 | 
            +
            		}.to raise_error( Inversion::ParseError, /malformed key/i )
         | 
| 17 | 
            +
            	end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
             | 
| 20 | 
            +
            	it "doesn't render its contents in the template it's declared in" do
         | 
| 21 | 
            +
            		expect(
         | 
| 22 | 
            +
            			Inversion::Template.new( "<?fragment foo ?>Fatty BoomBoom<?end ?>" ).render
         | 
| 23 | 
            +
            		).to eq( '' )
         | 
| 24 | 
            +
            	end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
             | 
| 27 | 
            +
            	it "sets the attribute on the template object when rendered" do
         | 
| 28 | 
            +
            		tmpl = Inversion::Template.new(
         | 
| 29 | 
            +
            			'<?fragment subject ?>Order #<?attr order_number ?><?end?>-- <?attr subject ?> --'
         | 
| 30 | 
            +
            		)
         | 
| 31 | 
            +
             | 
| 32 | 
            +
            		tmpl.order_number = '2121bf8c4'
         | 
| 33 | 
            +
            		output = tmpl.render
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            		expect( output ).to eq( "-- Order #2121bf8c4 --" )
         | 
| 36 | 
            +
            		expect( tmpl.fragments[:subject] ).to eq( "Order #2121bf8c4" )
         | 
| 37 | 
            +
            	end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            end
         | 
| 40 | 
            +
             | 
| @@ -1,31 +1,14 @@ | |
| 1 1 | 
             
            #!/usr/bin/env rspec -cfd -b
         | 
| 2 2 | 
             
            # vim: set noet nosta sw=4 ts=4 :
         | 
| 3 3 |  | 
| 4 | 
            -
             | 
| 5 | 
            -
            	require 'pathname'
         | 
| 6 | 
            -
            	basedir = Pathname( __FILE__ ).dirname.parent.parent.parent
         | 
| 7 | 
            -
            	libdir = basedir + 'lib'
         | 
| 4 | 
            +
            require_relative '../../helpers'
         | 
| 8 5 |  | 
| 9 | 
            -
            	$LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
         | 
| 10 | 
            -
            	$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
         | 
| 11 | 
            -
            }
         | 
| 12 | 
            -
             | 
| 13 | 
            -
            require 'rspec'
         | 
| 14 | 
            -
            require 'spec/lib/helpers'
         | 
| 15 6 | 
             
            require 'inversion/template/iftag'
         | 
| 16 7 | 
             
            require 'inversion/template/textnode'
         | 
| 17 8 | 
             
            require 'inversion/renderstate'
         | 
| 18 9 |  | 
| 19 10 | 
             
            describe Inversion::Template::IfTag do
         | 
| 20 11 |  | 
| 21 | 
            -
            	before( :all ) do
         | 
| 22 | 
            -
            		setup_logging( :fatal )
         | 
| 23 | 
            -
            	end
         | 
| 24 | 
            -
             | 
| 25 | 
            -
            	after( :all ) do
         | 
| 26 | 
            -
            		reset_logging()
         | 
| 27 | 
            -
            	end
         | 
| 28 | 
            -
             | 
| 29 12 |  | 
| 30 13 | 
             
            	it "renders its contents if its attribute is true" do
         | 
| 31 14 | 
             
            		tag = Inversion::Template::IfTag.new( 'attribute' )
         | 
| @@ -33,7 +16,7 @@ describe Inversion::Template::IfTag do | |
| 33 16 |  | 
| 34 17 | 
             
            		renderstate = Inversion::RenderState.new( :attribute => true )
         | 
| 35 18 | 
             
            		tag.render( renderstate )
         | 
| 36 | 
            -
            		renderstate.to_s. | 
| 19 | 
            +
            		expect( renderstate.to_s ).to eq( 'the body' )
         | 
| 37 20 | 
             
            	end
         | 
| 38 21 |  | 
| 39 22 |  | 
| @@ -43,7 +26,7 @@ describe Inversion::Template::IfTag do | |
| 43 26 |  | 
| 44 27 | 
             
            		renderstate = Inversion::RenderState.new( :attribute => {:foo => 1} )
         | 
| 45 28 | 
             
            		tag.render( renderstate )
         | 
| 46 | 
            -
            		renderstate.to_s. | 
| 29 | 
            +
            		expect( renderstate.to_s ).to eq( 'the body' )
         | 
| 47 30 | 
             
            	end
         | 
| 48 31 |  | 
| 49 32 | 
             
            	it "doesn't render its contents if its attribute is false" do
         | 
| @@ -52,7 +35,7 @@ describe Inversion::Template::IfTag do | |
| 52 35 |  | 
| 53 36 | 
             
            		renderstate = Inversion::RenderState.new( :attribute => nil )
         | 
| 54 37 | 
             
            		tag.render( renderstate )
         | 
| 55 | 
            -
            		renderstate.to_s. | 
| 38 | 
            +
            		expect( renderstate.to_s ).to eq( '' )
         | 
| 56 39 | 
             
            	end
         | 
| 57 40 |  | 
| 58 41 | 
             
            	it "doesn't render its contents if its methodchain is false" do
         | 
| @@ -61,7 +44,7 @@ describe Inversion::Template::IfTag do | |
| 61 44 |  | 
| 62 45 | 
             
            		renderstate = Inversion::RenderState.new( :attribute => {:bar => 1} )
         | 
| 63 46 | 
             
            		tag.render( renderstate )
         | 
| 64 | 
            -
            		renderstate.to_s. | 
| 47 | 
            +
            		expect( renderstate.to_s ).to eq( '' )
         | 
| 65 48 | 
             
            	end
         | 
| 66 49 |  | 
| 67 50 | 
             
            	it "works inside an iterator (ticket #3)" do
         | 
| @@ -73,8 +56,8 @@ describe Inversion::Template::IfTag do | |
| 73 56 |  | 
| 74 57 | 
             
            		template.items = [ true, false ]
         | 
| 75 58 |  | 
| 76 | 
            -
            		template.render. | 
| 77 | 
            -
            		template.render. | 
| 59 | 
            +
            		expect( template.render ).to include( "Item: Yep." )
         | 
| 60 | 
            +
            		expect( template.render ).to include( "Item: Nope." )
         | 
| 78 61 | 
             
            	end
         | 
| 79 62 |  | 
| 80 63 |  | 
| @@ -91,13 +74,13 @@ describe Inversion::Template::IfTag do | |
| 91 74 | 
             
            		it "only renders the first half of the contents if its attribute is true" do
         | 
| 92 75 | 
             
            			renderstate = Inversion::RenderState.new( :attribute => true )
         | 
| 93 76 | 
             
            			@tag.render( renderstate )
         | 
| 94 | 
            -
            			renderstate.to_s. | 
| 77 | 
            +
            			expect( renderstate.to_s ).to eq( 'the body before else' )
         | 
| 95 78 | 
             
            		end
         | 
| 96 79 |  | 
| 97 80 | 
             
            		it "only renders the second half of the contents if its attribute is true" do
         | 
| 98 81 | 
             
            			renderstate = Inversion::RenderState.new( :attribute => false )
         | 
| 99 82 | 
             
            			@tag.render( renderstate )
         | 
| 100 | 
            -
            			renderstate.to_s. | 
| 83 | 
            +
            			expect( renderstate.to_s ).to eq( 'the body after else' )
         | 
| 101 84 | 
             
            		end
         | 
| 102 85 |  | 
| 103 86 | 
             
            	end
         | 
| @@ -116,21 +99,21 @@ describe Inversion::Template::IfTag do | |
| 116 99 | 
             
            		it "only renders the first third of the contents if its attribute is true" do
         | 
| 117 100 | 
             
            			renderstate = Inversion::RenderState.new( :attribute => true )
         | 
| 118 101 | 
             
            			@tag.render( renderstate )
         | 
| 119 | 
            -
            			renderstate.to_s. | 
| 102 | 
            +
            			expect( renderstate.to_s ).to eq( 'the body before elsif' )
         | 
| 120 103 | 
             
            		end
         | 
| 121 104 |  | 
| 122 105 | 
             
            		it "only renders the second third of the contents if the attribute is false and the " +
         | 
| 123 106 | 
             
            		   "elsif's attribute is true" do
         | 
| 124 107 | 
             
            			renderstate = Inversion::RenderState.new( :attribute => false, :elsifattribute => true )
         | 
| 125 108 | 
             
            			@tag.render( renderstate )
         | 
| 126 | 
            -
            			renderstate.to_s. | 
| 109 | 
            +
            			expect( renderstate.to_s ).to eq( 'the body after elsif' )
         | 
| 127 110 | 
             
            		end
         | 
| 128 111 |  | 
| 129 112 | 
             
            		it "only renders the last third of the contents if both the attribute and the elsif's " +
         | 
| 130 113 | 
             
            		   "attribute are false" do
         | 
| 131 114 | 
             
            			renderstate = Inversion::RenderState.new( :attribute => false, :elsifattribute => false )
         | 
| 132 115 | 
             
            			@tag.render( renderstate )
         | 
| 133 | 
            -
            			renderstate.to_s. | 
| 116 | 
            +
            			expect( renderstate.to_s ).to eq( 'the body after else' )
         | 
| 134 117 | 
             
            		end
         | 
| 135 118 |  | 
| 136 119 | 
             
            	end
         | 
| @@ -148,20 +131,20 @@ describe Inversion::Template::IfTag do | |
| 148 131 | 
             
            		it "only renders the first half of the contents if its attribute is true" do
         | 
| 149 132 | 
             
            			renderstate = Inversion::RenderState.new( :attribute => true )
         | 
| 150 133 | 
             
            			@tag.render( renderstate )
         | 
| 151 | 
            -
            			renderstate.to_s. | 
| 134 | 
            +
            			expect( renderstate.to_s ).to eq( 'the body before elsif' )
         | 
| 152 135 | 
             
            		end
         | 
| 153 136 |  | 
| 154 137 | 
             
            		it "only renders the second half of the contents if the attribute is false and the " +
         | 
| 155 138 | 
             
            		   "elsif's attribute is true" do
         | 
| 156 139 | 
             
            			renderstate = Inversion::RenderState.new( :attribute => false, :elsifattribute => true )
         | 
| 157 140 | 
             
            			@tag.render( renderstate )
         | 
| 158 | 
            -
            			renderstate.to_s. | 
| 141 | 
            +
            			expect( renderstate.to_s ).to eq( 'the body after elsif' )
         | 
| 159 142 | 
             
            		end
         | 
| 160 143 |  | 
| 161 144 | 
             
            		it "doesn't render anything if both the attribute and the elsif's attribute are false" do
         | 
| 162 145 | 
             
            			renderstate = Inversion::RenderState.new( :attribute => false, :elsifattribute => false )
         | 
| 163 146 | 
             
            			@tag.render( renderstate )
         | 
| 164 | 
            -
            			renderstate.to_s. | 
| 147 | 
            +
            			expect( renderstate.to_s ).to eq( '' )
         | 
| 165 148 | 
             
            		end
         | 
| 166 149 |  | 
| 167 150 | 
             
            	end
         | 
| @@ -181,27 +164,27 @@ describe Inversion::Template::IfTag do | |
| 181 164 | 
             
            		it "only renders the first third of the contents if its attribute is true" do
         | 
| 182 165 | 
             
            			renderstate = Inversion::RenderState.new( :attribute => true )
         | 
| 183 166 | 
             
            			@tag.render( renderstate )
         | 
| 184 | 
            -
            			renderstate.to_s. | 
| 167 | 
            +
            			expect( renderstate.to_s ).to eq( 'the body before elsif' )
         | 
| 185 168 | 
             
            		end
         | 
| 186 169 |  | 
| 187 170 | 
             
            		it "only renders the second third of the contents if the attribute is false and the " +
         | 
| 188 171 | 
             
            		   "first elsif's attribute is true" do
         | 
| 189 172 | 
             
            			renderstate = Inversion::RenderState.new( :elsifattribute => true )
         | 
| 190 173 | 
             
            			@tag.render( renderstate )
         | 
| 191 | 
            -
            			renderstate.to_s. | 
| 174 | 
            +
            			expect( renderstate.to_s ).to eq( 'the body after elsif1' )
         | 
| 192 175 | 
             
            		end
         | 
| 193 176 |  | 
| 194 177 | 
             
            		it "only renders the last third of the contents if both the attribute and the first elsif's " +
         | 
| 195 178 | 
             
            		   "attribute are false, but the second elsif's attribute is true" do
         | 
| 196 179 | 
             
            			renderstate = Inversion::RenderState.new( :elsifattribute2 => true )
         | 
| 197 180 | 
             
            			@tag.render( renderstate )
         | 
| 198 | 
            -
            			renderstate.to_s. | 
| 181 | 
            +
            			expect( renderstate.to_s ).to eq( 'the body after elsif2' )
         | 
| 199 182 | 
             
            		end
         | 
| 200 183 |  | 
| 201 184 | 
             
            		it "doesn't render anything if all three attributes are false" do
         | 
| 202 185 | 
             
            			renderstate = Inversion::RenderState.new
         | 
| 203 186 | 
             
            			@tag.render( renderstate )
         | 
| 204 | 
            -
            			renderstate.to_s. | 
| 187 | 
            +
            			expect( renderstate.to_s ).to eq( '' )
         | 
| 205 188 | 
             
            		end
         | 
| 206 189 |  | 
| 207 190 | 
             
            	end
         | 
| @@ -223,27 +206,27 @@ describe Inversion::Template::IfTag do | |
| 223 206 | 
             
            		it "only renders the first quarter of the contents if its attribute is true" do
         | 
| 224 207 | 
             
            			renderstate = Inversion::RenderState.new( :attribute => true )
         | 
| 225 208 | 
             
            			@tag.render( renderstate )
         | 
| 226 | 
            -
            			renderstate.to_s. | 
| 209 | 
            +
            			expect( renderstate.to_s ).to eq( 'the body before elsif' )
         | 
| 227 210 | 
             
            		end
         | 
| 228 211 |  | 
| 229 212 | 
             
            		it "only renders the second quarter of the contents if the attribute is false and the " +
         | 
| 230 213 | 
             
            		   "first elsif's attribute is true" do
         | 
| 231 214 | 
             
            			renderstate = Inversion::RenderState.new( :elsifattribute => true )
         | 
| 232 215 | 
             
            			@tag.render( renderstate )
         | 
| 233 | 
            -
            			renderstate.to_s. | 
| 216 | 
            +
            			expect( renderstate.to_s ).to eq( 'the body after elsif1' )
         | 
| 234 217 | 
             
            		end
         | 
| 235 218 |  | 
| 236 219 | 
             
            		it "only renders the third quarter of the contents if both the attribute and the first elsif's " +
         | 
| 237 220 | 
             
            		   "attribute are false, but the second elsif's attribute is true" do
         | 
| 238 221 | 
             
            			renderstate = Inversion::RenderState.new( :elsifattribute2 => true )
         | 
| 239 222 | 
             
            			@tag.render( renderstate )
         | 
| 240 | 
            -
            			renderstate.to_s. | 
| 223 | 
            +
            			expect( renderstate.to_s ).to eq( 'the body after elsif2' )
         | 
| 241 224 | 
             
            		end
         | 
| 242 225 |  | 
| 243 226 | 
             
            		it "renders the last quarter of the contents if all three attributes are false" do
         | 
| 244 227 | 
             
            			renderstate = Inversion::RenderState.new
         | 
| 245 228 | 
             
            			@tag.render( renderstate )
         | 
| 246 | 
            -
            			renderstate.to_s. | 
| 229 | 
            +
            			expect( renderstate.to_s ).to eq( 'the body after else' )
         | 
| 247 230 | 
             
            		end
         | 
| 248 231 |  | 
| 249 232 | 
             
            	end
         |