Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the asset pipeline with file groups

In the Rails docs for the asset pipeline, it states:

The default behavior in Rails 3.1 and onward is to concatenate all files into one master file each for JS and CSS. However, you can separate files or groups of files if required (see below)

How exactly do you separate the files into groups as indicated? For example, if I've got an application that also has an admin area, I'd like to create three compiled files:

shared.css (both front- and back-end use this)
application.css (front-end only)
admin.css (back-end only)

The default combines all my files into application.css.

like image 615
typeoneerror Avatar asked Feb 22 '23 08:02

typeoneerror


1 Answers

You will need to create a manifest for each area. For example:

admin.css:

/*
 *= require shared/nomalize
 *= require shared/960.css
 *= require admin/base
 *= require admin/tables
 */

shared.css:

/*
 *= require shared/nomalize
 *= require shared/960.css
 *= require public/base
 *= require public/branding
 */

You are free to make folders to hold shared, public and admin CSS and require these as required. You will have to remove require_tree directives from any manifests

Reference these in your layouts:

<%= stylesheet_link_tag "application" %>
<%= stylesheet_link_tag "admin" %>

and add the addittional manifests to the precompile array:

config.assets.precompile += ['admin.js', 'admin.css']
like image 189
Richard Hulse Avatar answered Feb 24 '23 23:02

Richard Hulse