Class: Turning::Renderer
- Inherits:
-
Object
- Object
- Turning::Renderer
- Defined in:
- lib/turning/renderer.rb
Instance Method Summary collapse
-
#initialize(controller_path, storage) ⇒ Renderer
constructor
A new instance of Renderer.
- #render_to_file(template_name, path, assigns) ⇒ Object
Constructor Details
#initialize(controller_path, storage) ⇒ Renderer
Returns a new instance of Renderer.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/turning/renderer.rb', line 12 def initialize(controller_path, storage) @controller_path = controller_path @storage = storage @renderable = Class.new(AbstractController::Base) { include AbstractController::Rendering include AbstractController::Layouts include ActionController::Helpers include Rails.application.routes.url_helpers attr_accessor :view_assigns # Search for views based on the controller name attr_accessor :controller_path self.view_paths = ActionController::Base.view_paths # Include all helpers from the application's helper paths def self.helpers_path Rails.application.helpers_paths end helper :all # We can't protect against forgery in static HTML, because it requires a session def protect_against_forgery? false end helper_method :protect_against_forgery? # Look for a "static" layout by default, but don't fail if it doesn't exist def self.name 'StaticController' end layout nil # So that controller.action_name continues to work attr_accessor :action_name }.new @renderable.controller_path = @controller_path end |
Instance Method Details
#render_to_file(template_name, path, assigns) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/turning/renderer.rb', line 50 def render_to_file(template_name, path, assigns) @renderable.view_assigns = assigns @renderable.action_name = template_name contents = @renderable.render_to_string(action: template_name) @storage.put(path, contents) end |