Module: Rabl::Sources
Instance Method Summary collapse
-
#fetch_source(file, options = {}) ⇒ Object
Returns source for a given relative file fetch_source(“show”, :view_path => “…”) => “…contents…”.
Methods included from Helpers
#collection_root_name, #context_scope, #data_name, #data_object, #data_object_attribute, #determine_object_root, #fetch_result_from_cache, #is_collection?, #is_name_value?, #is_object?, #object_root_name, #object_to_engine, #template_cache_configured?, #view_path, #write_result_to_cache
Instance Method Details
#fetch_source(file, options = {}) ⇒ Object
Returns source for a given relative file fetch_source(“show”, :view_path => “…”) => “…contents…”
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rabl/sources.rb', line 7 def fetch_source(file, = {}) view_paths = Array([:view_path]) + Array(Rabl.configuration.view_paths) Rabl.source_cache(file, view_paths) do file_path = \ if defined?(Padrino) && context_scope.respond_to?(:settings) && context_scope.respond_to?(:resolve_template) fetch_padrino_source(file, ) elsif defined?(Rails) && context_scope.respond_to?(:view_paths) _view_paths = view_paths + Array(context_scope.view_paths.to_a) fetch_rails_source(file, ) || fetch_manual_template(_view_paths, file) elsif defined?(Sinatra) && context_scope.respond_to?(:settings) && context_scope.settings.respond_to?(:views) fetch_sinatra_source(file, ) else # generic template resolution fetch_manual_template(view_paths, file) end unless File.exist?(file_path.to_s) raise "Cannot find rabl template '#{file}' within registered (#{view_paths.map(&:to_s).inspect}) view paths!" end [File.read(file_path.to_s), file_path.to_s] end end |