Coder Social home page Coder Social logo

asset-pipeline-poem's Introduction

Asset Pipeline Poem

Objective: Practice requiring CSS and JavaScript files in the Rails asset pipeline and precompiling assets.

Terms:

  • Manifest
  • Precompilation
  • Concatenation
  • Compression / Minification
  • Browser Caching
  • MD5 fingerprint

Ode to the Asset Pipeline

Your goal is to reconstruct a simple poem. To get started:

  • Clone this repo, and take any steps necessary to get the app running on your computer.
    • Note that this Rails app doesn't have a database.
  • Start your server, and navigate to localhost:3000 in the browser. You should see a jumbled poem.

The poem should eventually look like this when you're done making changes:

solution_screenshot

Rules

  • You are not allowed to modify any files except app/assets/javascripts/application.js, app/assets/stylesheets/application.css, and config/environments/development.rb (to configure asset precompilation).
  • Try not to use require_tree . anywhere.

Using the Asset Pipeline

The assets you need require will live somewhere in the following locations, inside of your Rails application directory:

app/                   # application specific code
  assets/
    images/
    javascripts/
    stylesheets/
lib/                   # custom libraries
  assets/
    javascripts/
    stylesheets/
vendor/                # third party libraries
  assets/
    javascripts/
    stylesheets/

Each directory has a specific use case. The files you want are scattered across them. Your goal is to find all the files and require them in the correct order!

A solution is in the solution branch.

Bonus: Using Third-Party Code

  1. Note that the Bootstrap CSS and JavaScript libraries are included in views/layouts/application.html.erb using CDN links. Practice requiring the files through the asset pipeline instead:
  • Find and copy the current bootstrap.css URL (see views/layouts/application.html.erb).
  • From the Terminal, run curl -vs BOOTSTRAP_CSS_URL_YOU_COPIED > vendor/assets/stylesheets/bootstrap.min.css
  • Finally, delete the CDN link from application.html.erb, and require the new Bootstrap CSS file in your application.css manifest.
  • Repeat these steps for the Bootstrap JavaScript library.
  • Precompile your assets.

You can also use the front-end package manager Bower to download and install library files.

  1. Downloading the Bootstrap CSS and JavaScript files isn't the only way to use Bootstrap with the Rails asset pipeline! You can also use the bootstrap-sass gem.
  • In application.css and application.js, remove the require statements for Bootstrap, and use the bootstrap-sass gem instead (follow the installation steps in the docs).
  • After installing bootstrap-sass, precompile your assets again.

It's often easier to use a well-documented gem than to to work directly with the asset pipeline. Watch out for gems that haven't been updated in a while, though, or for bad interactions among gems.

A solution for this bonus is in the solution_bootstrap_sass branch.

asset-pipeline-poem's People

Contributors

cameronjacoby avatar bgveenstra avatar awhit012 avatar benhulan avatar nathanallen avatar

Watchers

Emilio Gomez Lavin 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.