Skip to content

Commit 64672a6

Browse files
committed
Mention the CSS compilation bug in Assetpack
- If any css element contains a url link declaration to a non-standard HTTP URI, Sinatra-Assetpack crashes and the css file will not get loaded. There is a PR pending for this issue at rstacruz/sinatra-assetpack#152. - Foundation's 'form.scss' component uses an SVG background image that is loaded via the declaration `background-image: url('...')` where the URI is a data uri. [http://css-tricks.com/using-svg/) , http://css-tricks.com/data-uris/]. - Hence, the example shows loading only the JS files via Assetpack. The CSS file is linked directly in the HTML without any further processing.
1 parent 5261e0d commit 64672a6

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

asset_management/sinatra_assetpack.md

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ __This document reflects the usage of Foundation 5.__
158158

159159
This section deals with using the foundation framework with
160160
`sinatra-assetpack`. The example also uses the `compass` gem to start a
161-
project with the `zurb-foundation` framework.
161+
project with the `Zurb-Foundation` framework.
162+
A sample project is available at
163+
[sinatra_assetpack_foundation_sample](https://github.com/kgrz/sinatra_assetpack_foundation_sample)
164+
162165

163166
```
164167
gem install foundation
@@ -189,10 +192,32 @@ bower.json
189192

190193
In this app, the `.sass`/`.scss` to `.css` conversion is handled by running
191194
`compass watch` which compiles the `.scss` files whenever it detects a
192-
change. In short, we need to use the css file from the `stylesheet`
193-
directory and app-related Javascript files from `js` folder. We also
194-
need to require the libraries in the `bower_components` folder. More
195-
specifically, we will use the following files:
195+
change. Note that as of Sinatra-Assetpack version `0.3.2`, any URL
196+
element inside a css file will cause the processor to crash and
197+
Foundation 5 uses one such declaration. So, for this example, we will
198+
ignore the management of CSS files via Sinatra-Assetpack and load it
199+
directly from the app. To do this, the compass app needs to output the
200+
compiled CSS into a `public/stylesheets` folder. Let's ensure that's
201+
done by creating a `public` directory and changing the `config.rb`
202+
settings to the following:
203+
204+
205+
```ruby
206+
# config.rb
207+
add_import_path "bower_components/foundation/scss" # unchanged
208+
209+
http_path = "/" # unchanged
210+
css_dir = "public/stylesheets"
211+
sass_dir = "scss" # unchanged
212+
images_dir = "images" # unchanged
213+
javascripts_dir = "js" # unchanged
214+
```
215+
216+
Now, when we run `compass watch`, the compiled `app.css` will be placed
217+
in the `public/stylesheets` directory. That minor change completed, we
218+
need to load the app-related JavaScript files from the `js` folder. We
219+
also need to require the libraries in the `bower_components` folder.
220+
More specifically, we will use the following files:
196221

197222
1. `bower_components/jquery/dist/jquery.js`
198223
2. `bower_components/foundation/js/foundation.js`
@@ -205,7 +230,8 @@ Inside our `app.rb`, this would be the structure:
205230

206231
```ruby
207232
assets do
208-
serve '/js', :from => 'javascripts'
233+
serve '/js', from: 'js'
234+
serve '/bower_components', from: 'bower_components'
209235

210236
js :modernizr, [
211237
'/bower_components/modernizr/modernizr.js',
@@ -220,13 +246,7 @@ assets do
220246
'/js/app.js'
221247
]
222248

223-
serve '/css', :from => 'stylesheets'
224-
css :application, [
225-
'/css/app.css'
226-
]
227-
228249
js_compression :jsmin
229-
css_compression :sass
230250
end
231251
```
232252

@@ -241,11 +261,9 @@ Inside the `views/layout.erb`:
241261
<meta charset="utf-8">
242262
<meta name="viewport" content="width=device-width, initial-scale=1.0">
243263
<title>My App</title>
244-
245-
<%= css :application %>
264+
<link rel="stylesheet" href="/stylesheets/app.css"/>
246265

247266
<%= js :modernizr %>
248-
<script src="js/vendor/modernizr.js"></script>
249267
</head>
250268
<body>
251269
<%= yield %>

0 commit comments

Comments
 (0)