Sha256: caf61f4af338a959218e5ed3439db565ac3a7573d63bf0905731a028ad7d35b2

Contents?: true

Size: 786 Bytes

Versions: 10

Compression:

Stored size: 786 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.
  require "erb"
  def escape!(string)
    ::ERB::Util.html_escape(string)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
cells-4.1.8 lib/cell/escaped.rb
cells-4.1.7 lib/cell/escaped.rb
cells-4.1.6 lib/cell/escaped.rb
cells-4.1.5 lib/cell/escaped.rb
cells-4.1.4 lib/cell/escaped.rb
cells-4.1.3 lib/cell/escaped.rb
cells-4.1.2 lib/cell/escaped.rb
cells-4.1.1 lib/cell/escaped.rb
cells-4.1.0 lib/cell/escaped.rb
cells-4.1.0.rc1 lib/cell/escaped.rb