Skip to content

Commit

Permalink
Adds support for declaring a view path
Browse files Browse the repository at this point in the history
  • Loading branch information
nesquena committed Apr 12, 2011
1 parent 25b3837 commit 8cca37c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/rabl/engine.rb
@@ -1,7 +1,7 @@
module Rabl
class Engine
# Constructs a new ejs engine based on given vars, handler and declarations
# Rabl::Engine.new("...source...", { :format => "xml" })
# Rabl::Engine.new("...source...", { :format => "xml", :root => true, :view_path => "/path/to/views" })
def initialize(source, options={})
@_source = source
@_options = options.reverse_merge(:format => "json")
Expand All @@ -13,7 +13,7 @@ def render(scope, locals, &block)
@_locals = locals
@_scope = scope
@_options = @_options.merge(:scope => @_scope, :locals => @_locals, :engine => self)
self.copy_instance_variables_from(@_scope, [:@assigns, :@helpers]);
self.copy_instance_variables_from(@_scope, [:@assigns, :@helpers])
@_object = locals[:object] || self.default_object
instance_eval(@_source) if @_source.present?
instance_eval(&block) if block_given?
Expand Down Expand Up @@ -118,7 +118,7 @@ def is_record?(obj)
def fetch_source(file)
root_path = Rails.root if defined?(Rails)
root_path = Padrino.root if defined?(Padrino)
view_path = File.join(root_path, "app/views/")
view_path = @_options[:view_path] || File.join(root_path, "app/views/")
file_path = Dir[File.join(view_path, file + "*.rabl")].first
File.read(file_path) if file_path
end
Expand Down

0 comments on commit 8cca37c

Please sign in to comment.