Examples:
require 'hanami/view'
class Map
attr_reader :locations
def initialize(locations)
@locations = locations
end
def location_names
@locations.join(', ')
end
end
class MapPresenter
include Hanami::Presenter
def count
locations.count
end
def location_names
super.upcase
end
def inspect_object
@object.inspect
end
end
map = Map.new(['Rome', 'Boston'])
presenter = MapPresenter.new(map)
puts presenter.locations
puts presenter.count
puts presenter.location_names
puts presenter.inspect_object
require 'hanami/view'
User = Struct.new(:first_name, :last_name)
class UserPresenter
include Hanami::Presenter
def full_name
[first_name, last_name].join(' ')
end
def raw_first_name
_raw first_name
end
end
first_name = '<script>alert('xss')</script>'
user = User.new(first_name, nil)
presenter = UserPresenter.new(user)
presenter.full_name
# => "<script>alert('xss')</script>"
presenter.raw_full_name
# => "<script>alert('xss')</script>"