Skip to content

Commit 5261e0d

Browse files
committed
Update AssetPack recipe to use Foundation 5
1 parent c0d3eeb commit 5261e0d

File tree

1 file changed

+63
-56
lines changed

1 file changed

+63
-56
lines changed

asset_management/sinatra_assetpack.md

Lines changed: 63 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class App < Sinatra::Base
2222
end
2323
```
2424

25+
2526
## Generic Structure
2627

2728
__Defaults__
@@ -153,85 +154,74 @@ __Level Awesome__
153154
The previous sections dealt with limited number of assets. What if
154155
you have vendor assets that need to be served in a particular order?
155156

157+
__This document reflects the usage of Foundation 5.__
158+
156159
This section deals with using the foundation framework with
157160
`sinatra-assetpack`. The example also uses the `compass` gem to start a
158161
project with the `zurb-foundation` framework.
159162

160163
```
161-
gem install zurb-foundation
164+
gem install foundation
162165
gem install compass
163166
```
164167

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:
169172

170173
```
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
200188
```
201189

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
203191
`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:
208196

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`
210200

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
213203

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:
217205

218206
```ruby
219207
assets do
220208
serve '/js', :from => 'javascripts'
221209

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'
225217
]
226218

227219
js :application, [
228-
'/js/vendor/*.js',
229220
'/js/app.js'
230221
]
231222

232223
serve '/css', :from => 'stylesheets'
233224
css :application, [
234-
'/css/normalize.css',
235225
'/css/app.css'
236226
]
237227

@@ -240,16 +230,33 @@ assets do
240230
end
241231
```
242232

243-
Inside the view:
233+
Inside the `views/layout.erb`:
244234

245235
```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>
249257
```
250258

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!
253260

254261
## Merging
255262

0 commit comments

Comments
 (0)