Inversion::

Escaping

module

A mixin that adds configurable escaping to a tag class.

class MyTag < Inversion::Template::Tag
    include Inversion::Escaping

    def render( renderstate )
        val = self.get_rendered_value
        return self.escape( val.to_s, renderstate )
    end
end

To add a new kind of escaping to Inversion, add a escape_<formatname> method to this module similar to escape_html.

Constants

DEFAULT_ESCAPE_FORMAT

The fallback escape format

Public Instance Methods

anchor
escape( output, render_state )

Escape the output using the format specified by the given render_state's config.

# File lib/inversion/mixins.rb, line 134
def escape( output, render_state )
        format = render_state.options[:escape_format] || DEFAULT_ESCAPE_FORMAT
        return output if format == :none

        unless self.respond_to?( "escape_#{format}" )
                self.log.error "Format %p not supported. To add support, define a #escape_%s to %s" %
                        [ format, format, __FILE__ ]
                raise Inversion::OptionsError, "No such escape format %p" % [ format ]
        end

        return self.__send__( "escape_#{format}", output )
end
anchor
escape_html( output )

Escape the given output using HTML entity-encoding.

# File lib/inversion/mixins.rb, line 149
def escape_html( output )
        return output.to_s.
                gsub( /&/, '&amp;' ).
                gsub( /</, '&lt;' ).
                gsub( />/, '&gt;' )
end