Sha256: b870c1ed5d20c27ceb68b359d519c69e4476efb16a0bcb8daba2a49938dc892c

Contents?: true

Size: 770 Bytes

Versions: 2

Compression:

Stored size: 770 Bytes

Contents

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

  module Property
    def property(*names)
      super.tap do # super defines #title
        mod = Module.new do
          names.each do |name|
            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
        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

2 entries across 2 versions & 1 rubygems

Version Path
cells-4.0.5 lib/cell/escaped.rb
cells-4.0.4 lib/cell/escaped.rb