Module: Lotus::View::Escape

Defined in:
lib/lotus/view/escape.rb

Overview

Auto escape logic for views and presenters.

Since:

  • 0.4.0

Defined Under Namespace

Modules: InstanceMethods Classes: Presenter

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Module extended override

Since:

  • 0.4.0



153
154
155
156
157
158
159
160
161
# File 'lib/lotus/view/escape.rb', line 153

def self.extended(base)
  base.class_eval do
    include ::Lotus::Utils::ClassAttribute
    include ::Lotus::View::Escape::InstanceMethods

    class_attribute :autoescape_methods
    self.autoescape_methods = {}
  end
end

.html(input) ⇒ Object, String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Escape the given input if it’s a string, otherwise return the oject as it is.

Parameters:

  • input (Object)

    the input

Returns:

  • (Object, String)

    the escaped string or the given object

Since:

  • 0.4.0



140
141
142
143
144
145
146
147
# File 'lib/lotus/view/escape.rb', line 140

def self.html(input)
  case input
  when String
    Utils::Escape.html(input)
  else
    input
  end
end

Instance Method Details

#method_added(method_name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Wraps concrete view methods with escape logic.

Since:

  • 0.4.0



167
168
169
170
171
172
173
174
175
176
177
# File 'lib/lotus/view/escape.rb', line 167

def method_added(method_name)
  unless autoescape_methods[method_name]
    prepend Module.new {
      module_eval %{
        def #{ method_name }(*args, &blk); ::Lotus::View::Escape.html super; end
      }
    }

    autoescape_methods[method_name] = true
  end
end