Thanks to @arthur_chiu and his post on how to integrate sprockets in Padrino with sprockets-helpers, i’ve create my version
:D:D:D
1) Create padrino-sprockets in config/sprockets.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | module Padrino::Sprockets def self.registered(base) base.set :sprockets, ::Sprockets::Environment.new(Padrino.root) # Add folder base.sprockets.append_path 'assets/javascripts' base.sprockets.append_path 'assets/stylesheets' base.sprockets.append_path 'assets/images' base.set :digest_assets, true # compress file if PADRINO_ENV == 'development' base.sprockets.js_compressor = Uglifier.new(mangle: true) base.sprockets.css_compressor = YUI::CssCompressor.new end # sprockets-helpers base.helpers Sprockets::Helpers # We can configure `sprockets-helpers` to find the correct assets for us. Sprockets::Helpers.configure do |config| manifest_path = File.join(Padrino.root,'public','assets','manifest.json') config.environment = base.sprockets config.prefix = '/assets' config.manifest = Sprockets::Manifest.new(base.sprockets, manifest_path) config.digest = true config.public_path = base.public_folder end # call sprockets :D if PADRINO_ENV == 'development' base.get '/assets/*splat' do env['PATH_INFO'].gsub!(%r{\A/?assets}, '') settings.sprockets.call(env) end end end end |
In this file you need add all your asset’s folder..
2) Load this file at startup application:
config/boot.rb
1 2 3 4 5 | # after this line Bundler.require(:default, PADRINO_ENV) # add this require Padrino.root('config/sprockets') |
3) register Padrino::Sprockets in your application
1 2 3 4 5 6 | Module Foo class App < Padrino::Application register Padrino::Sprockets end end |
4) Use js,css sprockets version in you layout, es:
layout.slim
1 | link href= stylesheet_path('app') media="screen" type="text/css" rel="stylesheet" |
instead
1 | = stylesheet_link_tag :app |
5) Use Rakefile to create asstes to pre-compilation
:D
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | PADRINO_ENV = ENV['PADRINO_ENV'] ||= ENV['RACK_ENV'] ||= 'development' unless defined?(PADRINO_ENV) require 'bundler/setup' require 'padrino-core/cli/rake' require 'sprockets/../rake/sprocketstask' Bundler.require(PADRINO_ENV) require File.expand_path("../config/boot.rb", __FILE__) PadrinoTasks.use(:database) PadrinoTasks.use(:minirecord) PadrinoTasks.init # Use fake application module FakeSprock class App < Padrino::Application register Padrino::Sprockets end end SPROCKETS = FakeSprock::App.sprockets # or your real app name # SPROCKETS = RealAppName::App.sprockets Rake::SprocketsTask.new do |t| manifest_path = File.join(Padrino.root,'public','assets') t.environment = SPROCKETS t.output = File.join(Padrino.root,'public','assets') t.manifest = Sprockets::Manifest.new(SPROCKETS, manifest_path) t.assets = %w[app.js app.css *.png *.gif *.jpg] end |
and call it with
1 | rake assets |
To conitnue use stylesheet_link_tag and javascript_include_tag, need to close this issue
Thanks again at @padrino-core.
Special tanks:
DAddYE
@arthur_chiu

WaYdotNET -







