Sha256: 11e24a1ddfc4f343cccb7d6473c751da687b00f57accfbbbf0dcbe584307807d

Contents?: true

Size: 717 Bytes

Versions: 4

Compression:

Stored size: 717 Bytes

Contents

module Cell::ViewModel::Escaped
  def self.included(includer)
    includer.extend Property
  end

  module Property
    def property(name, *args)
      super.tap do # super defines #title
        mod = Module.new do
          define_method(name) do |options={}|
            value = super() # call the original #title.
            return value unless value.is_a?(String)
            return value if options[:escape] == false
            escape!(value)
          end
        end
        include mod
      end
    end
  end # Property

  # Can be used as a helper in the cell, too.
  # Feel free to override and use a different escaping implementation.
  def escape!(string)
    ::ERB::Util.html_escape(string)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cells-4.0.3 lib/cell/escaped.rb
cells-4.0.2 lib/cell/escaped.rb
cells-4.0.1 lib/cell/escaped.rb
cells-4.0.0 lib/cell/escaped.rb