@@ -153,103 +153,130 @@ __Level Awesome__
153
153
The previous sections dealt with limited number of assets. What if
154
154
you have vendor assets that need to be served in a particular order?
155
155
156
+ __ This document reflects the usage of Foundation 5.__
157
+
156
158
This section deals with using the foundation framework with
157
159
` sinatra-assetpack ` . The example also uses the ` compass ` gem to start a
158
- project with the ` zurb-foundation ` framework.
160
+ project with the ` Zurb-Foundation ` framework.
161
+ A sample project is available at
162
+ [ sinatra_assetpack_foundation_sample] ( https://github.com/kgrz/sinatra_assetpack_foundation_sample )
163
+
159
164
160
165
```
161
- gem install zurb- foundation
166
+ gem install foundation
162
167
gem install compass
163
168
```
164
169
165
- Complete instructions are not provided here. Follow the Zurb-foundation
166
- link provided in the links section for detailed instructions
170
+ Install the ` npm ` modules of ` bower ` and ` grunt-cli ` . The instructions
171
+ are provided [ here] ( http://foundation.zurb.com/docs/sass.html ) . Then
172
+ run:
167
173
168
- The created project has a structure like this:
174
+ foundation new <project name>
175
+
176
+ This will create a project with the following structure:
169
177
170
178
```
171
- ├── javascripts
172
- │ ├── foundation
173
- │ │ ├── foundation.alerts.js
174
- │ │ ├── foundation.clearing.js
175
- │ │ ├── foundation.cookie.js
176
- │ │ ├── foundation.dropdown.js
177
- │ │ ├── foundation.forms.js
178
- │ │ ├── foundation.joyride.js
179
- │ │ ├── foundation.js
180
- │ │ ├── foundation.magellan.js
181
- │ │ ├── foundation.orbit.js
182
- │ │ ├── foundation.placeholder.js
183
- │ │ ├── foundation.reveal.js
184
- │ │ ├── foundation.section.js
185
- │ │ ├── foundation.tooltips.js
186
- │ │ └── foundation.topbar.js
187
- │ └── vendor
188
- │ ├── custom.modernizr.js
189
- │ ├── jquery.js
190
- │ └── zepto.js
191
- | |__ app.js
192
- ├── sass
193
- │ ├── _settings.scss
194
- │ ├── app.scss
195
- │ └── normalize.scss
196
- └── stylesheets
197
- | ├── app.css
198
- | └── normalize.css
199
- myapp.rb
179
+ bower_components/
180
+ |---- jquery/
181
+ |---- modernizr/
182
+ |---- ...some more libraries ...
183
+ js/
184
+ |---- app.js
185
+ scss/
186
+ |---- _settings.scss
187
+ |---- app.scss
188
+ stylesheets/
189
+ |---- app.css
190
+ config.rb
191
+ index.html
192
+ bower.json
200
193
```
201
194
202
- In this app, the ` .sass ` to ` .css ` conversion is handled by running
195
+ In this app, the ` .sass ` / ` .scss ` to ` .css ` conversion is handled by running
203
196
` compass watch ` which compiles the ` .scss ` files whenever it detects a
204
- change. So, we'll ignore the conversion for now. The concentration would
205
- be on how to configure the app to get the files in a particular order.
197
+ change. Note that as of Sinatra-Assetpack version ` 0.3.2 ` , any URL
198
+ element inside a css file will cause the processor to crash and
199
+ Foundation 5 uses one such declaration. So, for this example, we will
200
+ ignore the management of CSS files via Sinatra-Assetpack and load it
201
+ directly from the app. To do this, the compass app needs to output the
202
+ compiled CSS into a ` public/stylesheets ` folder. Let's ensure that's
203
+ done by creating a ` public ` directory and changing the ` config.rb `
204
+ settings to the following:
206
205
207
- In this case, the order of the JS files that need to be loaded/merged is:
208
206
209
- 1 . Vendor JS files like jQuery, Modernizr and Zepto.
207
+ ``` ruby
208
+ # config.rb
209
+ add_import_path " bower_components/foundation/scss" # unchanged
210
+
211
+ http_path = " /" # unchanged
212
+ css_dir = " public/stylesheets"
213
+ sass_dir = " scss" # unchanged
214
+ images_dir = " images" # unchanged
215
+ javascripts_dir = " js" # unchanged
216
+ ```
210
217
211
- 2 . The "foundation.js" file which defines the ` Foundation ` prototype that
212
- gets used in the rest of the ` foundation.*.js ` files.
218
+ Now, when we run ` compass watch ` , the compiled ` app.css ` will be placed
219
+ in the ` public/stylesheets ` directory. That minor change completed, we
220
+ need to load the app-related JavaScript files from the ` js ` folder. We
221
+ also need to require the libraries in the ` bower_components ` folder.
222
+ More specifically, we will use the following files:
213
223
214
- 3 . The ` foundation.*.js ` files.
224
+ 1 . ` bower_components/jquery/dist/jquery.js `
225
+ 2 . ` bower_components/foundation/js/foundation.js `
226
+ 3 . ` bower_components/modernizr/modernizr.js `
215
227
216
- Any change in the load order and you might see some of the plugins failing.
228
+ The aim would be to recreate the structure of ` index.html ` in the
229
+ foundation app folder with Sinatra and a ` layout.erb ` file
230
+
231
+ Inside our ` app.rb ` , this would be the structure:
217
232
218
233
``` ruby
219
234
assets do
220
- serve ' /js' , :from => ' javascripts'
235
+ serve ' /js' , from: ' js'
236
+ serve ' /bower_components' , from: ' bower_components'
221
237
222
- js :foundation , [
223
- ' /js/foundation/foundation.js' ,
224
- ' /js/foundation/foundation.*.js'
238
+ js :modernizr , [
239
+ ' /bower_components/modernizr/modernizr.js' ,
240
+ ]
241
+
242
+ js :libs , [
243
+ ' /bower_components/jquery/dist/jquery.js' ,
244
+ ' /bower_components/foundation/js/foundation.js'
225
245
]
226
246
227
247
js :application , [
228
- ' /js/vendor/*.js' ,
229
248
' /js/app.js'
230
249
]
231
250
232
- serve ' /css' , :from => ' stylesheets'
233
- css :application , [
234
- ' /css/normalize.css' ,
235
- ' /css/app.css'
236
- ]
237
-
238
251
js_compression :jsmin
239
- css_compression :sass
240
252
end
241
253
```
242
254
243
- Inside the view :
255
+ Inside the ` views/layout.erb ` :
244
256
245
257
``` ruby
246
- < %= css :application %>
247
- <%= js :application %>
248
- < %= js :foundation %>
258
+ < !DOCTYPE html>
259
+ < !-- [if IE 9 ]>< html class = " lt-ie10" lang= " en" > < ![endif]- ->
260
+ < html class = " no-js" lang= " en" >
261
+
262
+ < head>
263
+ < meta charset= " utf-8" >
264
+ < meta name= " viewport" content= " width=device-width, initial-scale=1.0" >
265
+ < title> My App < / title>
266
+ < link rel= " stylesheet" href= " /stylesheets/app.css" / >
267
+
268
+ < %= js :modernizr %>
269
+ </head>
270
+ < body>
271
+ < %= yield %>
272
+
273
+ <%= js :libs %>
274
+ < %= js :application %>
275
+ </body>
276
+ < / html>
249
277
```
250
278
251
- Do this, and you'll see that the files are loaded properly and there will be
252
- no JS errors in the browser's console.
279
+ And you're set!
253
280
254
281
## Merging
255
282
0 commit comments