Inversion::Escaping

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

escape( output, render_state ) click to toggle source

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

# File lib/inversion/mixins.rb, line 211
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
escape_html( output ) click to toggle source

Escape the given output using HTML entity-encoding.

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.