class Jpmobile::Resolver

Public Instance Methods

build_path(name, prefix, partial, details) click to toggle source
# File lib/jpmobile/resolver.rb, line 8
def build_path(name, prefix, partial, details)
  path = ""
  path << "#{prefix}/" unless prefix.empty?
  path << (partial ? "_#{name}" : name)
  path
end
find_templates(name, prefix, partial, details) click to toggle source
# File lib/jpmobile/resolver.rb, line 3
def find_templates(name, prefix, partial, details)
  path = build_path(name, prefix, partial, details)
  query(path, EXTENSIONS.map { |ext| details[ext] }, details[:formats], details[:mobile])
end
query(path, exts, formats, mobile) click to toggle source
# File lib/jpmobile/resolver.rb, line 15
def query(path, exts, formats, mobile)
  query = File.join(@path, path)
  query << '{' << mobile.map {|v| "_#{v}"}.join(',') << ',}' if mobile and mobile.respond_to?(:map)
  exts.each do |ext|
    query << '{' << ext.map {|e| e && ".#{e}" }.join(',') << ',}'
  end

  query.gsub!(/\{\.html,/, "{.html,.text.html,")
  query.gsub!(/\{\.text,/, "{.text,.text.plain,")

  Dir[query].reject { |p| File.directory?(p) }.map do |p|
    handler, format = extract_handler_and_format(p, formats)

    contents = File.open(p, "rb") {|io| io.read }
    variant = p.match(/.+#{path}(.+)\.#{format.to_sym.to_s}.*$/) ? $1 : ''

    ActionView::Template.new(contents, File.expand_path(p), handler,
      :virtual_path => path + variant, :format => format)
  end
end