Giter VIP home page Giter VIP logo

asset-pipeline-example's Introduction

Asset Pipeline Example

Example Rails 3.2 app showing how to: use the asset pipeline, scare unicorns, and activate epic rainbows.

Features:

  • Laying out SASS files using @import instead of the Sprockets require directive (as per the note in the README for sass-rails)
  • Laying out JS files using require_tree
  • JST and eco templates w/ Backbone
  • data-uri'd assets
  • Referencing an asset from both CSS and JS (see the link[rel] in the app layout)
  • Tasteful use of Comic Sans with a subtle yet beautiful text-shadow

Running

bundle install
rake assets:precompile
rails s

Re-enabling development asset compilation

You'll see the bottom of development.rb has two lines copied from production.rb to test and demonstrate production asset compilation.

To change this back to normal behaviour simply comment out the two lines at the bottom of development.rb, run rake assets:clean, and restart the rails server.

Reloading assets after precompilation

If you're running with config.assets.compile = false and run rake assets:compile you'll need to restart the server to see changes. This is because the public/assets/digest.yml is loaded only on application boot.

Discussion points

Avoiding Sprockets directives in SASS

As per the note in the README for sass-rails–the Gem that Rails loads from your Gemfile which adds SASS support to the asset pipeline–you should never use the Sprockets require directives in your CSS.

SASS (when used through sass-rails) can do everything the Sprockets directives can with the bonus of playing well with @import and @extend.

Vendor and lib assets

I've included vendor fies directly in the assets directly (e.g. app/assets/javascripts/vendor), but Rails also looks in vendor/assets, lib/assets, and Gem lib paths. I like to take ownership of all assets, third-party or otherwise, and keep them together in app/assets. This is just personal preference and you can place them in vendor/assets and lib/assets if you wish.

asset-pipeline-example's People

Contributors

sj26 avatar toolmantim avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.