class Padrino::Sprockets::App
Attributes
assets[R]
Public Class Methods
new(app, options={})
click to toggle source
# File lib/padrino/sprockets.rb, line 41 def initialize(app, options={}) @app = app @root = options[:root] @output = options[:output] url = options[:url] || 'assets' @matcher = /^\/#{url}\/*/ setup_environment(options[:minify], options[:paths] || []) end
Public Instance Methods
call(env)
click to toggle source
# File lib/padrino/sprockets.rb, line 81 def call(env) if @matcher =~ env["PATH_INFO"] env['PATH_INFO'].sub!(@matcher,'') @assets.call(env) else @app.call(env) end end
precompile(bundles)
click to toggle source
# File lib/padrino/sprockets.rb, line 65 def precompile(bundles) output_dir = Pathname(@output) bundles.each do |file| tmp = file.to_s.split('/') kind = {"css"=>"stylesheets", "js"=>"javascripts"}[file.to_s.split(".").last] prefix, basename = tmp[0...-1].unshift(kind || 'assets').join("/"), tmp[-1] path, dir = output_dir.join(prefix, basename), output_dir.join(prefix) FileUtils.mkpath(dir) unless Dir.exist?(dir) # clean up first File.delete(path) if File.exist?(path) # compile asset = @assets.find_asset(file) asset.write_to(path) end end
setup_environment(minify=false, extra_paths=[])
click to toggle source
# File lib/padrino/sprockets.rb, line 50 def setup_environment(minify=false, extra_paths=[]) @assets = ::Sprockets::Environment.new(@root) @assets.append_path 'assets/javascripts' @assets.append_path 'assets/stylesheets' if minify @assets.css_compressor = YUI::CssCompressor.new @assets.js_compressor = YUI::JavaScriptCompressor.new(munge: true) end extra_paths.each do |sprocket_path| @assets.append_path sprocket_path end end