Class: Inversion::Template::ConfigTag

Inherits:
Tag
  • Object
show all
Includes:
HashUtilities
Defined in:
lib/inversion/template/configtag.rb

Overview

Inversion ‘config’ tag.

A tag that dynamically alters the behavior of the template.

Examples

<?config comment_start: /* ?>
<?config comment_end: */ ?>

<?config
    on_render_error: propagate
    debugging_comments: true
    comment_start: /*
    comment_end: */
?>

<?config { comment_start: "/*", comment_end: "*/" } ?>

Constant Summary

Constants inherited from Tag

Tag::TAG_PLUGIN_PATTERN

Instance Attribute Summary collapse

Attributes inherited from Tag

#body

Attributes inherited from Node

#colnum, #linenum

Instance Method Summary collapse

Methods included from HashUtilities

stringify_keys, symbolify_keys

Methods inherited from Tag

#as_comment_body, create, #derivatives, inherited, load, load_all, #tagname, types, #types

Methods included from MethodUtilities

#singleton_attr_accessor, #singleton_attr_reader, #singleton_attr_writer

Methods included from AbstractClass

included

Methods included from AbstractClass::ClassMethods

#inherited, #pure_virtual

Methods inherited from Node

#after_appending, #after_rendering, #as_comment_body, #is_container?, #location, #render

Constructor Details

#initialize(body, linenum = nil, colnum = nil) ⇒ ConfigTag

Create a new ConfigTag with the specified body.

[View source]

36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/inversion/template/configtag.rb', line 36

def initialize( body, linenum=nil, colnum=nil )
	raise Inversion::ParseError, 'Empty config settings' if
		body.nil? || body.strip.empty?

	opts = if defined?( SafeYAML ) then
			YAML.load( body, safe: true )
		else
			YAML.load( body )
		end

	@options = symbolify_keys( opts )

	super
end

Instance Attribute Details

#optionsObject (readonly)

The config options that will be modified


57
58
59
# File 'lib/inversion/template/configtag.rb', line 57

def options
  @options
end

Instance Method Details

#before_appending(parsestate) ⇒ Object

Override the options in the parsestate when the config is appended to the tree.

[View source]

62
63
64
# File 'lib/inversion/template/configtag.rb', line 62

def before_appending( parsestate )
	parsestate.options.merge!( self.options )
end

#before_rendering(renderstate) ⇒ Object

Override the options in the renderstate when the config is rendered.

[View source]

68
69
70
# File 'lib/inversion/template/configtag.rb', line 68

def before_rendering( renderstate )
	renderstate.options.merge!( self.options )
end