@@ -22,6 +22,7 @@ class App < Sinatra::Base
22
22
end
23
23
```
24
24
25
+
25
26
## Generic Structure
26
27
27
28
__ Defaults__
@@ -153,85 +154,74 @@ __Level Awesome__
153
154
The previous sections dealt with limited number of assets. What if
154
155
you have vendor assets that need to be served in a particular order?
155
156
157
+ __ This document reflects the usage of Foundation 5.__
158
+
156
159
This section deals with using the foundation framework with
157
160
` sinatra-assetpack ` . The example also uses the ` compass ` gem to start a
158
161
project with the ` zurb-foundation ` framework.
159
162
160
163
```
161
- gem install zurb- foundation
164
+ gem install foundation
162
165
gem install compass
163
166
```
164
167
165
- Complete instructions are not provided here. Follow the Zurb-foundation
166
- link provided in the links section for detailed instructions
167
-
168
- The created project has a structure like this :
168
+ Install the ` npm ` modules of ` bower ` and ` grunt-cli ` . The instructions
169
+ are provided [ here ] ( http://foundation.zurb.com/docs/sass.html ) . Then run
170
+ ` foundation new <project name> ` . This will create a project with the
171
+ following structure:
169
172
170
173
```
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
174
+ bower_components/
175
+ |---- jquery/
176
+ |---- modernizr/
177
+ |---- ...some more libraries ...
178
+ js/
179
+ |---- app.js
180
+ scss/
181
+ |---- _settings.scss
182
+ |---- app.scss
183
+ stylesheets/
184
+ |---- app.css
185
+ config.rb
186
+ index.html
187
+ bower.json
200
188
```
201
189
202
- In this app, the ` .sass ` to ` .css ` conversion is handled by running
190
+ In this app, the ` .sass ` / ` .scss ` to ` .css ` conversion is handled by running
203
191
` 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.
206
-
207
- In this case, the order of the JS files that need to be loaded/merged is :
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:
208
196
209
- 1 . Vendor JS files like jQuery, Modernizr and Zepto.
197
+ 1 . ` bower_components/jquery/dist/jquery.js `
198
+ 2 . ` bower_components/foundation/js/foundation.js `
199
+ 3 . ` bower_components/modernizr/modernizr.js `
210
200
211
- 2 . The "foundation.js" file which defines the ` Foundation ` prototype that
212
- gets used in the rest of the ` foundation.*.js ` files.
201
+ The aim would be to recreate the structure of ` index.html ` in the
202
+ foundation app folder with Sinatra and a ` layout.erb ` file
213
203
214
- 3 . The ` foundation.*.js ` files.
215
-
216
- Any change in the load order and you might see some of the plugins failing.
204
+ Inside our ` app.rb ` , this would be the structure:
217
205
218
206
``` ruby
219
207
assets do
220
208
serve ' /js' , :from => ' javascripts'
221
209
222
- js :foundation , [
223
- ' /js/foundation/foundation.js' ,
224
- ' /js/foundation/foundation.*.js'
210
+ js :modernizr , [
211
+ ' /bower_components/modernizr/modernizr.js' ,
212
+ ]
213
+
214
+ js :libs , [
215
+ ' /bower_components/jquery/dist/jquery.js' ,
216
+ ' /bower_components/foundation/js/foundation.js'
225
217
]
226
218
227
219
js :application , [
228
- ' /js/vendor/*.js' ,
229
220
' /js/app.js'
230
221
]
231
222
232
223
serve ' /css' , :from => ' stylesheets'
233
224
css :application , [
234
- ' /css/normalize.css' ,
235
225
' /css/app.css'
236
226
]
237
227
@@ -240,16 +230,33 @@ assets do
240
230
end
241
231
```
242
232
243
- Inside the view :
233
+ Inside the ` views/layout.erb ` :
244
234
245
235
``` ruby
246
- < %= css :application %>
247
- <%= js :application %>
248
- < %= js :foundation %>
236
+ < !DOCTYPE html>
237
+ < !-- [if IE 9 ]>< html class = " lt-ie10" lang= " en" > < ![endif]- ->
238
+ < html class = " no-js" lang= " en" >
239
+
240
+ < head>
241
+ < meta charset= " utf-8" >
242
+ < meta name= " viewport" content= " width=device-width, initial-scale=1.0" >
243
+ < title> My App < / title>
244
+
245
+ < %= css :application %>
246
+
247
+ <%= js :modernizr %>
248
+ < script src= " js/vendor/modernizr.js" >< / script>
249
+ < / head>
250
+ < body>
251
+ < %= yield %>
252
+
253
+ <%= js :libs %>
254
+ < %= js :application %>
255
+ </body>
256
+ < / html>
249
257
```
250
258
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.
259
+ And you're set!
253
260
254
261
## Merging
255
262
0 commit comments