Real Open

real estate open sourced

A blog by

things I made ----------------
Appraisal Flow
Powered by Obtvse and Rails

Padrino Asset Pipeline the Easy Way

pipeline

While most of my experience has been with Rails, I keep finding myself coming back to Sinatra due to its simplicity and concise DSL. I especially like how Sinatra handles routing. But being a minimalistic Ruby web framework, there are some things missing which help web-app developers work efficiently like helpers, generators and database rake tasks.

godfather

The Godfather

Padrino ("Godfather" in Italian) is an elegant compromise between the ungainly thing that Rails has become and the simplicity of Sinatra. It retains the DSL and beauty of Sinatra while adding Rails-like helpers and tools. There's a pretty good book aptly titled "Padrino Book" (PDF here) that walks you though creating a "Job Posting" app. A fair word of warning: this book is a work-in-progress and is only about 75% complete.

Drawing

Sprockets

In the book, the author Matthias Guenther, uses the padrino-sprockets gem to create an asset pipeline similar to Rails that is not available out of the box with Padrino. Unfortunately I was not able to get this working despite trying several methods. However, I came across a better solution that requires even less setup called padrino-pipeline that works well. The following steps explain how to set up padrino-pipeline:

Install padrino-pipeline in your gem file and bundle install. Create an assets folder under the app folder (i.e., appname/app/assets) with the following sub-folders:

appname/app/assets/javascripts
appname/app/assets/stylesheets
appname/app/assets/images
appname/app/assets/fonts

In the javascripts folder, create an application.js file with just the following which brings all other javascripts under javascripts.

//= require_tree .

Similar for stylesheets (application.css)

/*
 *= require_self
 *= require_tree .
*/

In the app/app.rb file, add:

module Example
  class App < Padrino::Application
    ...
    ...
    register Padrino::Pipeline
    configure_assets do |config|
      config.pipeline = Padrino::Pipeline::Sprockets
      config.prefix = '/public'
    end
  end
end

And there you have a Rails-like asset pipeline using rack-based Sprockets for Padrino using with padrino-pipeline. This actually installs and configures Sprockets for you! You can alternatively use sinatra-assetpack, which I might try on my next Padrino app.

Did you enjoy this post? Find out when the next one is ready: keep me in the loop

  • Tweet
Back to Blog