class Assette::Server
Methods for finding files are ugly, should fix someday
Attributes
path[R]
Public Class Methods
call(env)
click to toggle source
# File lib/assette/server.rb, line 104 def call(env) s = new(env) s.rack_resp end
new(env)
click to toggle source
# File lib/assette/server.rb, line 5 def initialize(env) @env = env @path = env["PATH_INFO"] @params = env["QUERY_STRING"].split('&').inject({}) do |resp,v| k,v = v.split('=') if v == '1' || v.nil? v = true elsif v == '0' v = false end resp[k.to_sym] = v resp end # Assette.config.asset_path end
Public Instance Methods
content_type()
click to toggle source
# File lib/assette/server.rb, line 55 def content_type path_mime_type ? path_mime_type.content_type : 'text/plain' end
find_compiled_file()
click to toggle source
# File lib/assette/server.rb, line 25 def find_compiled_file f = nil Assette.config.file_paths.each do |p| Assette::Reader.possible_targets(File.join(p,path)).each do |pp| Assette.logger.debug('Checking for compiled file') {pp} f = Assette::File.rack_resp_if_exists( pp, @params.merge(:env => @env) ) Assette.logger.info("Found File") {"Compiled file at #{pp}"} if f break if f end break if f end f end
find_file()
click to toggle source
# File lib/assette/server.rb, line 59 def find_file f = nil Assette.config.file_paths.each do |p| new_path = File.join(p,path) if File.exist?(new_path) new_path = File.join(Dir.pwd,new_path) Assette.logger.info("Found File") {"Raw file at #{new_path}"} f = Rack::File.new(p).call(@env) end break if f end f end
has_registered_reader?()
click to toggle source
# File lib/assette/server.rb, line 47 def has_registered_reader? !Assette::Reader::OUTPUTS[path_extension.to_sym].empty? end
looking_for_template?()
click to toggle source
# File lib/assette/server.rb, line 76 def looking_for_template? m = path.match(/__templates\/(.+)/) m[1].gsub(/.js$/,'').split(':') if m end
path_extension()
click to toggle source
# File lib/assette/server.rb, line 42 def path_extension m = path.match(/\.(\w+)$/) m ? m[1] : :none end
path_mime_type()
click to toggle source
# File lib/assette/server.rb, line 51 def path_mime_type @path_mime_type ||= MIME::Types.type_for(path).first end
rack_resp()
click to toggle source
# File lib/assette/server.rb, line 81 def rack_resp if templates = looking_for_template? set = TemplateSet.new(templates) return [200,{"Content-Type" => Reader::Js.mime_type.content_type},[set.compile]] end begin if has_registered_reader? && (f = find_compiled_file) f elsif f = find_file f else possible_paths = Assette.config.file_paths.collect do |p| File.join(Dir.pwd,p,path) end [404,{"Content-Type" => "text/plain"},["File Not Found\n#{possible_paths.join("\n")}"]] end end end