2012-02-29 01:30:22 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
|
|
|
|
|
|
|
# This code based on https://github.com/ihoka/viewtastic
|
|
|
|
module RosaPresenter
|
|
|
|
class Base
|
|
|
|
include ActionDispatch::Routing::UrlFor
|
|
|
|
include ActionView::Helpers::UrlHelper
|
|
|
|
include ActionView::Helpers::TextHelper
|
2012-09-06 18:09:10 +01:00
|
|
|
include ActionView::Helpers::JavaScriptHelper
|
2012-02-29 01:30:22 +00:00
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
|
|
|
|
def initialize(item, opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
def controller
|
|
|
|
Thread.current[:rosa_presenter_controller]
|
|
|
|
end
|
|
|
|
|
2012-03-21 21:51:39 +00:00
|
|
|
def helpers
|
|
|
|
controller.view_context
|
|
|
|
end
|
|
|
|
|
2012-02-29 01:30:22 +00:00
|
|
|
# TODO it needs to be refactored!
|
|
|
|
class << self
|
|
|
|
def present(item, opts, &block)
|
|
|
|
block.call(self.new(item, opts))
|
|
|
|
end
|
|
|
|
|
|
|
|
def present_collection(collection, &block)
|
|
|
|
res = collection.map {|e| self.new(*e)}
|
|
|
|
if block.present?
|
|
|
|
res = res.inject('') do |akk, presenter|
|
|
|
|
akk << block.call(presenter)
|
|
|
|
akk
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return res
|
|
|
|
end
|
|
|
|
|
|
|
|
def controller=(value) #:nodoc:
|
|
|
|
Thread.current[:rosa_presenter_controller] = value
|
|
|
|
end
|
|
|
|
|
|
|
|
def controller #:nodoc:
|
|
|
|
Thread.current[:rosa_presenter_controller]
|
|
|
|
end
|
|
|
|
|
|
|
|
def activated? #:nodoc:
|
|
|
|
!controller.nil?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def t(*args)
|
|
|
|
I18n.translate(*args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def l(*args)
|
|
|
|
I18n.localize(*args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|