lotus-assets 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b3e434213fe995ad8342588945c086ff5077cde
4
- data.tar.gz: c827143864b274c540ba6da28ab1cefc9e1a8989
3
+ metadata.gz: a53af544bb09106a98a6312c6cb3e3be1efd9882
4
+ data.tar.gz: 3229cdb6681442576d81f5eeebe77f3aa642aae7
5
5
  SHA512:
6
- metadata.gz: c9de806ba02278bc4edd777b7308add0cd03abea340abf514811e88dd7fe10bf18c86859dce5b31f61150a4d2b8509d208316ec486a0a19ee2c5c886e3eeb519
7
- data.tar.gz: 0f10b4fc1f8cab3800bf53b84b26838ed499cfedded2be1230f5efd3b3126fbfac9363a5172726dc2f6bae8a7be0c8212808074677064d6eba1debc66cd174dd
6
+ metadata.gz: 77811692964b34196c8ce9f510db15c32885f02103563dea34a37ac71478cc86a06577ff66c42fb54a25eb34bc3beeb6a3e37bf7f6d221cc0e72b120bdc65eb0
7
+ data.tar.gz: a371359ce3d45cfcec912a5159b65abb532db329e3b52c320192e4b9e031007b33a213ebcee0bef20aa5d76ffc1e69a250e44bd0faccc78610f51486a45087fe
@@ -0,0 +1,19 @@
1
+ # Lotus::Assets
2
+ Assets management for Ruby web applications
3
+
4
+ ## v0.1.0 - 2016-01-12
5
+ ### Added
6
+ - [Luca Guidi] Configurable assets compressors
7
+ - [Luca Guidi] Builtin JavaScript and stylesheet compressors
8
+ - [deepj & Michael Deol] Added `Lotus::Assets::Helpers#favicon`
9
+ - [Leigh Halliday] Added `Lotus::Assets::Helpers#video`
10
+ - [Kleber Correia] Added `Lotus::Assets::Helpers#audio`
11
+ - [Gonzalo Rodríguez-Baltanás Díaz] Added `Lotus::Assets::Helpers#image`
12
+ - [Luca Guidi] Added `Lotus::Assets::Helpers#javascript` and `#stylesheet`
13
+ - [Luca Guidi] Added `Lotus::Assets::Helpers#asset_path` and `#asset_url`
14
+ - [Luca Guidi] "CDN Mode" let helpers to generate CDN URLs (eg. `https://123.cloudfront.net/assets/application-d1829dc353b734e3adc24855693b70f9.js`)
15
+ - [Luca Guidi] "Digest Mode" let helpers to generate digest URLs (eg. `/assets/application-d1829dc353b734e3adc24855693b70f9.js`)
16
+ - [Luca Guidi] Added `lotus-assets` command to precompile assets at the deploy time
17
+ - [Luca Guidi] Added support for third party gems that want to ship gemified assets for Lotus
18
+ - [Luca Guidi] Assets preprocessors (eg. Sass, ES6, CoffeeScript, Opal, JSX)
19
+ - [Luca Guidi] Official support for Ruby 2.0+
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Luca Guidi
1
+ Copyright © 2014-2016 Luca Guidi
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,29 +1,451 @@
1
1
  # Lotus::Assets
2
2
 
3
- TODO: Write a gem description
3
+ Assets management for Ruby web projects
4
+
5
+ ## Status
6
+
7
+ [![Gem Version](http://img.shields.io/gem/v/lotus-assets.svg)](https://badge.fury.io/rb/lotus-assets)
8
+ [![Build Status](http://img.shields.io/travis/lotus/assets/master.svg)](https://travis-ci.org/lotus/assets?branch=master)
9
+ [![Coverage](http://img.shields.io/coveralls/lotus/assets/master.svg)](https://coveralls.io/r/lotus/assets)
10
+ [![Code Climate](http://img.shields.io/codeclimate/github/lotus/assets.svg)](https://codeclimate.com/github/lotus/assets)
11
+ [![Dependencies](http://img.shields.io/gemnasium/lotus/assets.svg)](https://gemnasium.com/lotus/assets)
12
+ [![Inline Docs](http://inch-ci.org/github/lotus/assets.svg)](http://inch-ci.org/github/lotus/assets)
13
+
14
+ ## Contact
15
+
16
+ * Home page: http://lotusrb.org
17
+ * Community: http://lotusrb.org/community
18
+ * Guides: http://lotusrb.org/guides
19
+ * Mailing List: http://lotusrb.org/mailing-list
20
+ * API Doc: http://rdoc.info/gems/lotus-assets
21
+ * Bugs/Issues: https://github.com/lotus/assets/issues
22
+ * Support: http://stackoverflow.com/questions/tagged/lotus-ruby
23
+ * Forum: https://discuss.lotusrb.org
24
+ * Chat: http://chat.lotusrb.org
25
+
26
+ ## Rubies
27
+
28
+ __Lotus::Assets__ supports Ruby (MRI) 2+
4
29
 
5
30
  ## Installation
6
31
 
7
32
  Add this line to your application's Gemfile:
8
33
 
9
- gem 'lotus-assets'
34
+ ```ruby
35
+ gem 'lotus-assets'
36
+ ```
10
37
 
11
38
  And then execute:
12
39
 
13
- $ bundle
40
+ ```shell
41
+ $ bundle
42
+ ```
14
43
 
15
44
  Or install it yourself as:
16
45
 
17
- $ gem install lotus-assets
46
+ ```shell
47
+ $ gem install lotus-assets
48
+ ```
18
49
 
19
50
  ## Usage
20
51
 
21
- TODO: Write usage instructions here
52
+ ### Helpers
53
+
54
+ The framework offers assets specific helpers to be used in templates.
55
+ They resolve one or multiple sources into corresponding HTML tags.
56
+ Those sources can be the name of the local asset or an absolute URL.
57
+
58
+ Given the following template:
59
+
60
+ ```erb
61
+ <!doctype HTML>
62
+ <html>
63
+ <head>
64
+ <title>Assets example</title>
65
+ <%= stylesheet 'reset', 'grid', 'main' %>
66
+ </head>
67
+
68
+ <body>
69
+ <!-- ... -->
70
+ <%= javascript 'https://code.jquery.com/jquery-2.1.1.min.js', 'application' %>
71
+ <%= javascript 'modals' %>
72
+ </body>
73
+ </html>
74
+ ```
75
+
76
+ It will output this markup.
77
+
78
+ ```html
79
+ <!doctype HTML>
80
+ <html>
81
+ <head>
82
+ <title>Assets example</title>
83
+ <link href="/assets/reset.css" type="text/css" rel="stylesheet">
84
+ <link href="/assets/grid.css" type="text/css" rel="stylesheet">
85
+ <link href="/assets/main.css" type="text/css" rel="stylesheet">
86
+ </head>
87
+
88
+ <body>
89
+ <!-- ... -->
90
+ <script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
91
+ <script src="/assets/application.js" type="text/javascript"></script>
92
+ <script src="/assets/modals.js" type="text/javascript"></script>
93
+ </body>
94
+ </html>
95
+ ```
96
+
97
+ Let's have a look at the corresponding Ruby code.
98
+ In this example we use ERb, but remember that `Lotus::Assets` is compatible with
99
+ all the rendering engines such as HAML, Slim, Mustache, etc..
100
+
101
+ ```ruby
102
+ require 'erb'
103
+ require 'lotus/assets'
104
+ require 'lotus/assets/helpers'
105
+
106
+ class View
107
+ include Lotus::Assets::Helpers
108
+
109
+ def initialize
110
+ @template = File.read('template.erb')
111
+ @engine = ERB.new(@template)
112
+ end
113
+
114
+ def render
115
+ @engine.result(binding)
116
+ end
117
+ end
118
+
119
+ View.new.render # => HTML markup
120
+ ```
121
+
122
+ For advanced configurations, please have a look at
123
+ [`Lotus::Assets::Configuration`](https://github.com/lotus/assets/blob/master/lib/lotus/assets/configuration.rb).
124
+
125
+ ### Available Helpers
126
+
127
+ This gems ships with the following helpers:
128
+
129
+ * `javascript`
130
+ * `stylesheet`
131
+ * `favicon`
132
+ * `image`
133
+ * `video`
134
+ * `audio`
135
+ * `asset_path`
136
+ * `asset_url`
137
+
138
+ ### Development mode
139
+
140
+ `Lotus::Assets` can help you during the development process of your application.
141
+ It can manage multiple source directories for each asset type or run a
142
+ preprocessor for you.
143
+
144
+ #### Sources
145
+
146
+ Imagine to have your application's javascripts under `app/assets/javascripts` and that
147
+ those assets depends on a vendored version of jQuery.
148
+
149
+ ```ruby
150
+ require 'lotus/assets'
151
+
152
+ Lotus::Assets.configure do
153
+ compile true
154
+
155
+ sources << [
156
+ 'app/assets',
157
+ 'vendor/jquery'
158
+ ]
159
+ end
160
+ ```
161
+
162
+ When from a template you do:
163
+
164
+ ```erb
165
+ <%= javascript 'jquery', 'jquery-ui', 'login' %>
166
+ ```
167
+
168
+ `Lotus::Assets` looks at the defined sources and **lazily copies** those files
169
+ under `public/assets` (by default), before the markup is generated.
170
+
171
+ Your public directory will have the following structure.
172
+
173
+ ```shell
174
+ % tree public
175
+ public/
176
+ └── assets
177
+ ├── jquery.js
178
+ ├── jquery-ui.js
179
+ └── login.js
180
+
181
+ ```
182
+
183
+ **Please remember that sources are recursively looked up in order of declaration.**
184
+
185
+ If in the example above we had a `jquery.js` under `app/assets/javascripts/**/*.js`
186
+ that file would be copied into the public directory instead of the one under
187
+ `vendor/jquery`. The reason is because we declared `app/assets/javascripts` first.
188
+
189
+ #### Preprocessors
190
+
191
+ `Lotus::Assets` is able to run assets preprocessors and **lazily compile** them
192
+ under `public/assets` (by default), before the markup is generated.
193
+
194
+ Imagine to have `main.css.scss` under `app/assets/stylesheets` and `reset.css` under
195
+ `vendor/stylesheets`.
196
+
197
+ **The extensions structure is important.**
198
+ The first one is mandatory and it's used to understand which asset type we are
199
+ handling: `.css` for stylesheets.
200
+ The second one is optional and it's for a preprocessor: `.scss` for Sass.
201
+
202
+ ```ruby
203
+ require 'sass'
204
+ require 'lotus/assets'
205
+
206
+ Lotus::Assets.configure do
207
+ compile true
208
+
209
+ sources << [
210
+ 'assets',
211
+ 'vendor/assets'
212
+ ]
213
+ end
214
+ ```
215
+
216
+ When from a template you do:
217
+
218
+ ```erb
219
+ <%= stylesheet 'reset', 'main' %>
220
+ ```
221
+
222
+ Your public directory will have the following structure.
223
+
224
+ ```shell
225
+ % tree public
226
+ public/
227
+ └── assets
228
+ ├── reset.css
229
+ └── main.css
230
+ ```
231
+
232
+ ### Preprocessors engines
233
+
234
+ `Lotus::Assets` uses [Tilt](https://github.com/rtomayko/tilt) to provide support for the most common preprocessors, such as [Sass](http://sass-lang.com/) (including `sassc-ruby`), [Less](http://lesscss.org/), ES6, [JSX](https://jsx.github.io/), [CoffeScript](http://coffeescript.org), [Opal](http://opalrb.org), [Handlebars](http://handlebarsjs.com), [JBuilder](https://github.com/rails/jbuilder).
235
+
236
+ In order to use one or more of them, be sure to include the corresponding gem into your `Gemfile` and require the library.
237
+
238
+ #### EcmaScript 6
239
+
240
+ We strongly suggest to use [EcmaScript 6](http://es6-features.org/) for your next project.
241
+ It isn't fully [supported](https://kangax.github.io/compat-table/es6/) yet by browser vendors, but it's the future of JavaScript.
242
+
243
+ As of today, you need to transpile ES6 code into something understandable by current browsers, which is ES5.
244
+ For this purpose we support [Babel](https://babeljs.io).
245
+
246
+ ### Deployment
247
+
248
+ `Lotus::Assets` ships with an executable (`lotus-assets`), which can be used to precompile assets and make them cacheable by browsers (via checksum suffix).
249
+
250
+ Let's say we have an application that has main file that requires the entire code (`config/environment.rb`), a gem that brings Ember.js code, and the following sources:
251
+
252
+ ```shell
253
+ % tree .
254
+ ├── apps
255
+ │   ├── admin
256
+ │   │   ├── assets
257
+ │   │   │   └── js
258
+ │   │   │   ├── application.js
259
+ │   │   │   └── zepto.js
260
+ # ...
261
+ │   ├── metrics
262
+ │   │   ├── assets
263
+ │   │   │   └── javascripts
264
+ │   │   │   └── dashboard.js
265
+ # ...
266
+ │   └── web
267
+ │   ├── assets
268
+ │   │   ├── images
269
+ │   │   │   └── bookshelf.jpg
270
+ │   │   └── javascripts
271
+ │   │   └── application.js
272
+ # ...
273
+ │   └── vendor
274
+ │   └── assets
275
+ │   └── javascripts
276
+ │   └── jquery.js
277
+ └── config
278
+    └── environment.rb
279
+ ```
280
+
281
+ In order to deploy, we can run:
282
+
283
+ ```shell
284
+ bundle exec lotus-assets --config=config/environment.rb
285
+ ```
286
+
287
+ It will output:
288
+
289
+ ```shell
290
+ tree public
291
+ public
292
+ ├── assets
293
+ │   ├── admin
294
+ │   │   ├── application-28a6b886de2372ee3922fcaf3f78f2d8.js
295
+ │   │   ├── application.js
296
+ │   │   ├── ember-b2d6de1e99c79a0e52cf5c205aa2e07a.js
297
+ │   │   ├── ember-source-e74117fc6ba74418b2601ffff9eb1568.js
298
+ │   │   ├── ember-source.js
299
+ │   │   ├── ember.js
300
+ │   │   ├── zepto-ca736a378613d484138dec4e69be99b6.js
301
+ │   │   └── zepto.js
302
+ │   ├── application-d1829dc353b734e3adc24855693b70f9.js
303
+ │   ├── application.js
304
+ │   ├── bookshelf-237ecbedf745af5a477e380f0232039a.jpg
305
+ │   ├── bookshelf.jpg
306
+ │   ├── ember-b2d6de1e99c79a0e52cf5c205aa2e07a.js
307
+ │   ├── ember-source-e74117fc6ba74418b2601ffff9eb1568.js
308
+ │   ├── ember-source.js
309
+ │   ├── ember.js
310
+ │   ├── jquery-05277a4edea56b7f82a4c1442159e183.js
311
+ │   ├── jquery.js
312
+ │   └── metrics
313
+ │   ├── dashboard-7766a63ececc63a7a629bfb0666e9c62.js
314
+ │   ├── dashboard.js
315
+ │   ├── ember-b2d6de1e99c79a0e52cf5c205aa2e07a.js
316
+ │   ├── ember-source-e74117fc6ba74418b2601ffff9eb1568.js
317
+ │   ├── ember-source.js
318
+ │   └── ember.js
319
+ └── assets.json
320
+ ```
321
+
322
+ #### Compressors
323
+
324
+ Minification is a process that shrink file size in production, by removing unnecessary spaces and characters.
325
+ The goal of this step, is to have lighter assets to be served faster to the browsers.
326
+
327
+ Lotus supports JavaScript and stylesheets minifiers.
328
+
329
+ Because this framework relies on external gems for minification, this feature is **turned off by default**.
330
+
331
+ To do so we need to specify which gem we want to use and add it to our `Gemfile`.
332
+
333
+ ##### JavaScript Compressors
334
+
335
+ Lotus can use the following compressors (aka minifiers) for JavaScript.
336
+
337
+ * `:builtin` - Ruby based implementation of jsmin. It doesn't require any external gem.
338
+ * `:yui` - [YUI Compressor](http://yui.github.io/yuicompressor), it depends on [`yui-compressor`](https://rubygems.org/gems/yui-compressor) gem and iπt requires Java 1.4+
339
+ * `:uglifier` - [UglifyJS](http://lisperator.net/uglifyjs), it depends on [`uglifier`](https://rubygems.org/gems/uglifier) gem and it requires Node.js
340
+ * `:closure` - [Google Closure Compiler](https://developers.google.com/closure/compiler), it depends on [`closure-compiler`](https://rubygems.org/gems/closure-compiler) gem and it requires Java
341
+
342
+ ```ruby
343
+ Lotus::Assets.configure do
344
+ javascript_compressor :uglifier
345
+ end
346
+ ```
347
+
348
+ ##### Stylesheet Compressors
349
+
350
+ Lotus can use the following compressors (aka minifiers) for Stylesheet.
351
+
352
+ * `:builtin` - Ruby based compressor. It doesn't require any external gem. It's fast, but not an efficient compressor.
353
+ * `:yui` - [YUI Compressor](http://yui.github.io/yuicompressor), it depends on [`yui-compressor`](https://rubygems.org/gems/yui-compressor) gem and iπt requires Java 1.4+
354
+ * `:sass` - [Sass](http://sass-lang.com/), it depends on [`sass`](https://rubygems.org/gems/sass) gem
355
+
356
+ ```ruby
357
+ Lotus::Assets.configure do
358
+ stylesheet_compressor :sass
359
+ end
360
+ ```
361
+
362
+ ##### Custom Compressors
363
+
364
+ We can specify our own minifiers:
365
+
366
+ ```ruby
367
+ Lotus::Assets.configure do
368
+ javascript_compressor MyJavascriptCompressor.new
369
+ stylesheet_compressor MyStylesheetCompressor.new
370
+ end
371
+ ```
372
+
373
+ ### Digest Mode
374
+
375
+ This is a mode that can be activated via the configuration and it's suitable for production environments.
376
+
377
+ ```ruby
378
+ Lotus::Assets.configure do
379
+ digest true
380
+ end
381
+ ```
382
+
383
+ Once turned on, it will look at `/public/assets.json`, and helpers such as `javascript` will return a relative URL that includes the digest of the asset.
384
+
385
+ ```erb
386
+ <%= javascript 'application' %>
387
+ ```
388
+
389
+ ```html
390
+ <script src="/assets/application-d1829dc353b734e3adc24855693b70f9.js" type="text/javascript"></script>
391
+ ```
392
+
393
+ ### CDN Mode
394
+
395
+ A Lotus project can serve assets via CDN.
396
+
397
+ ```ruby
398
+ Lotus::Assets.configure do
399
+ scheme 'https'
400
+ host '123.cloudfront.net'
401
+ port 443
402
+ cdn true
403
+ end
404
+ ```
405
+
406
+ Since now on, helpers will return the CDN absolute URL for the asset.
407
+
408
+ ```erb
409
+ <%= javascript 'application' %>
410
+ ```
411
+
412
+ ```html
413
+ <script src="https://123.cloudfront.net/assets/application-d1829dc353b734e3adc24855693b70f9.js" type="text/javascript"></script>
414
+ ```
415
+
416
+ ## Third party gems
417
+
418
+ Developers can maintain gems that distribute assets for Lotus. For instance `lotus-ember` or `lotus-jquery`.
419
+
420
+ As a gem developer, you must add one or more paths, where the assets are stored inside the gem.
421
+
422
+ ```ruby
423
+ # lib/lotus/jquery.rb
424
+ Lotus::Assets.sources << '/path/to/jquery'
425
+ ```
426
+
427
+ ## Running tests
428
+
429
+ * Make sure you have one of [ExecJS](https://github.com/rails/execjs)
430
+ supported runtime on your machine.
431
+ * Java 1.4+
432
+
433
+ ```sh
434
+ bundle exec rake test
435
+ ```
436
+
437
+ ## Versioning
438
+
439
+ __Lotus::Assets__ uses [Semantic Versioning 2.0.0](http://semver.org)
22
440
 
23
441
  ## Contributing
24
442
 
25
- 1. Fork it ( https://github.com/[my-github-username]/lotus-assets/fork )
443
+ 1. Fork it ( https://github.com/lotus/assets/fork )
26
444
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
445
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
446
  4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create a new Pull Request
447
+ 5. Create new Pull Request
448
+
449
+ ## Copyright
450
+
451
+ Copyright © 2014-2016 Luca Guidi – Released under MIT License