class Jpmobile::Resolver
Constants
- DEFAULT_PATTERN
- EXTENSIONS
Public Class Methods
new(path, pattern=nil)
click to toggle source
Calls superclass method
# File lib/jpmobile/resolver.rb, line 6 def initialize(path, pattern=nil) raise ArgumentError, "path already is a Resolver class" if path.is_a?(Resolver) super(path, pattern || DEFAULT_PATTERN) @path = File.expand_path(path) end
Private Instance Methods
find_template_paths(query)
click to toggle source
# File lib/jpmobile/resolver.rb, line 22 def find_template_paths(query) # deals with case-insensitive file systems. sanitizer = Hash.new { |h,dir| h[dir] = Dir["#{dir}/*"] } Dir[query].reject { |filename| File.directory?(filename) || !sanitizer[File.dirname(filename)].include?(filename) } end
query(path, details, formats, outside_app_allowed)
click to toggle source
# File lib/jpmobile/resolver.rb, line 14 def query(path, details, formats, outside_app_allowed) query = build_query(path, details) begin template_paths = find_template_paths query template_paths = reject_files_external_to_app(template_paths) unless outside_app_allowed rescue NoMethodError self.class_eval do def find_template_paths(query) # deals with case-insensitive file systems. sanitizer = Hash.new { |h,dir| h[dir] = Dir["#{dir}/*"] } Dir[query].reject { |filename| File.directory?(filename) || !sanitizer[File.dirname(filename)].include?(filename) } end end retry end template_paths.map { |template| handler, format, variant = extract_handler_and_format_and_variant(template, formats) contents = File.binread(template) if format jpmobile_variant = template.match(/.+#{path}(.+)\.#{format.to_sym.to_s}.*$/) ? $1 : '' virtual_path = jpmobile_variant.blank? ? path.virtual : path.to_str + jpmobile_variant else virtual_path = path.virtual end ActionView::Template.new(contents, File.expand_path(template), handler, :virtual_path => virtual_path, :format => format, :variant => variant, :updated_at => mtime(template) ) } end