Commits

Michael Granger committed 1b4030a

Fix propagation of config tags into subtemplates (fixes #1)

Comments (0)

Files changed (3)

lib/inversion/template.rb

 
 	### Default config values
 	DEFAULT_CONFIG = {
+		# Loading/parsing options
 		:ignore_unknown_tags => true,
 		:template_paths      => [],
+		:stat_delay          => 0,
 
+		# Rendering options
 		:on_render_error     => :comment,
 		:debugging_comments  => false,
 		:comment_start       => '<!-- ',
 		:comment_end         => ' -->',
 		:escape_format       => :html,
 		:strip_tag_lines     => true,
-		:stat_delay          => 0
 	}.freeze
 
 
 	### template is being rendered inside another template).
 	def render( parentstate=nil, &block )
 		self.log.info "rendering template 0x%08x" % [ self.object_id/2 ]
-		state = Inversion::RenderState.new( parentstate, self.attributes, self.options, &block )
+		opts = self.options
+		opts.merge!( parentstate.options ) if parentstate
+
+		state = Inversion::RenderState.new( parentstate, self.attributes, opts, &block )
 
 		# self.log.debug "  rendering node tree: %p" % [ @node_tree ]
 		self.walk_tree {|node| state << node }

spec/data/unknown-tag.tmpl

+<!-- $Id$ -->
+<?unknown This is an unknown tag type ?>
+<?comment Some stuff. ?>
+Stuff
+<?end comment ?>

spec/inversion/template/configtag_spec.rb

 
 	before( :all ) do
 		setup_logging( :fatal )
+		Inversion::Template.template_paths << 'spec/data'
 	end
 
 	after( :all ) do
+		Inversion::Template.template_paths.delete( 'spec/data' )
 		reset_logging()
 	end
 
             comment_end: "*/"
 		YAML
 		tag = Inversion::Template::ConfigTag.new( yaml )
-		tag.options.should == {
+
+		expect( tag.options ).to eq({
 			:on_render_error    => 'propagate',
 			:debugging_comments => true,
 			:comment_start      => '/*',
 			:comment_end        => '*/'
-		}
+		})
 	end
 
 	# <?config { comment_start: "/*", comment_end: "*/" } ?>
 	it "can contain multiple configuration settings using an inline hash" do
 		tag = Inversion::Template::ConfigTag.new( '{ comment_start: "/*", comment_end: "*/" }' )
-		tag.options.should == { :comment_start => '/*', :comment_end => '*/' }
+		expect( tag.options ).to eq({ :comment_start => '/*', :comment_end => '*/' })
 	end
 
 	it "renders invisibly" do
 		tag = Inversion::Template::ConfigTag.new( 'comment_start: /*' )
 		state = Inversion::RenderState.new
-		tag.render( state ).should == nil
+
+		expect( tag.render(state) ).to be nil
 	end
 
 	it "raises an error on an empty body" do
 		something else
 		TEMPLATE
 		tmpl = Inversion::Template.new( source )
-		tmpl.render.should include( "<!-- If: { template.foo } -->" )
+
+		expect( tmpl.render ).to include( "<!-- If: { template.foo } -->" )
+	end
+
+	it "propagates options to subtemplates during parsing" do
+		source = <<-TEMPLATE
+		<?config ignore_unknown_tags: false ?>
+		<?include unknown-tag.tmpl ?>
+		TEMPLATE
+		expect {
+			Inversion::Template.new( source )
+		}.to raise_error( Inversion::ParseError, /unknown tag "unknown"/i )
+	end
+
+	it "propagates options to subtemplates during rendering" do
+		source = <<-TEMPLATE
+		<?config debugging_comments: true ?>
+		<?attr subtemplate ?>
+		TEMPLATE
+		tmpl = Inversion::Template.new( source )
+		tmpl.subtemplate = Inversion::Template.load( 'unknown-tag.tmpl' )
+
+		expect( tmpl.render ).to match( /commented out 1 nodes on line 3: some stuff/i )
 	end
 
 end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.