requirejs_optimizer 0.0.5

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.
Files changed (93) hide show
  1. data/.gitignore +21 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +12 -0
  4. data/Gemfile +17 -0
  5. data/LICENSE +22 -0
  6. data/README.md +135 -0
  7. data/Rakefile +17 -0
  8. data/bin/r.js +9822 -0
  9. data/lib/generators/install_generator.rb +26 -0
  10. data/lib/generators/templates/README +8 -0
  11. data/lib/generators/templates/main.js.coffee +3 -0
  12. data/lib/generators/templates/require.build.js +6 -0
  13. data/lib/requirejs_optimizer/build.rb +21 -0
  14. data/lib/requirejs_optimizer/errors.rb +21 -0
  15. data/lib/requirejs_optimizer/railtie.rb +32 -0
  16. data/lib/requirejs_optimizer/rake/task.rb +50 -0
  17. data/lib/requirejs_optimizer/rake/utils.rb +32 -0
  18. data/lib/requirejs_optimizer/step/base.rb +19 -0
  19. data/lib/requirejs_optimizer/step/clean.rb +15 -0
  20. data/lib/requirejs_optimizer/step/compress.rb +21 -0
  21. data/lib/requirejs_optimizer/step/digestify.rb +27 -0
  22. data/lib/requirejs_optimizer/step/finalize.rb +16 -0
  23. data/lib/requirejs_optimizer/step/manifest.rb +31 -0
  24. data/lib/requirejs_optimizer/step/optimize.rb +26 -0
  25. data/lib/requirejs_optimizer/step/prepare.rb +32 -0
  26. data/lib/requirejs_optimizer/version.rb +3 -0
  27. data/lib/requirejs_optimizer.rb +49 -0
  28. data/requirejs_optimizer.gemspec +20 -0
  29. data/spec/integrations/rake_task_spec.rb +31 -0
  30. data/spec/lib/requirejs_optimizer/rake/task_spec.rb +19 -0
  31. data/spec/lib/requirejs_optimizer/rake/utils_spec.rb +78 -0
  32. data/spec/lib/requirejs_optimizer/step/clean_spec.rb +23 -0
  33. data/spec/lib/requirejs_optimizer/step/compress_spec.rb +26 -0
  34. data/spec/lib/requirejs_optimizer/step/digestify_spec.rb +70 -0
  35. data/spec/lib/requirejs_optimizer/step/finalize_spec.rb +33 -0
  36. data/spec/lib/requirejs_optimizer/step/manifest_spec.rb +37 -0
  37. data/spec/lib/requirejs_optimizer/step/optimize_spec.rb +42 -0
  38. data/spec/lib/requirejs_optimizer/step/prepare_spec.rb +53 -0
  39. data/spec/lib/requirejs_optimizer_spec.rb +24 -0
  40. data/spec/rails_app/.gitignore +15 -0
  41. data/spec/rails_app/README.rdoc +261 -0
  42. data/spec/rails_app/Rakefile +7 -0
  43. data/spec/rails_app/app/assets/images/rails.png +0 -0
  44. data/spec/rails_app/app/assets/javascripts/application.js +15 -0
  45. data/spec/rails_app/app/assets/javascripts/modules/bar/two.coffee +2 -0
  46. data/spec/rails_app/app/assets/javascripts/modules/baz/three.coffee +2 -0
  47. data/spec/rails_app/app/assets/javascripts/modules/foo/one.coffee +2 -0
  48. data/spec/rails_app/app/assets/javascripts/modules/main.coffee +1 -0
  49. data/spec/rails_app/app/assets/javascripts/modules/require.build.js +6 -0
  50. data/spec/rails_app/app/assets/stylesheets/application.css +13 -0
  51. data/spec/rails_app/app/controllers/application_controller.rb +3 -0
  52. data/spec/rails_app/app/helpers/application_helper.rb +2 -0
  53. data/spec/rails_app/app/mailers/.gitkeep +0 -0
  54. data/spec/rails_app/app/models/.gitkeep +0 -0
  55. data/spec/rails_app/app/views/layouts/application.html.erb +14 -0
  56. data/spec/rails_app/config/application.rb +59 -0
  57. data/spec/rails_app/config/boot.rb +7 -0
  58. data/spec/rails_app/config/database.yml +25 -0
  59. data/spec/rails_app/config/environment.rb +5 -0
  60. data/spec/rails_app/config/environments/development.rb +37 -0
  61. data/spec/rails_app/config/environments/production.rb +67 -0
  62. data/spec/rails_app/config/environments/test.rb +37 -0
  63. data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  64. data/spec/rails_app/config/initializers/inflections.rb +15 -0
  65. data/spec/rails_app/config/initializers/mime_types.rb +5 -0
  66. data/spec/rails_app/config/initializers/secret_token.rb +7 -0
  67. data/spec/rails_app/config/initializers/session_store.rb +8 -0
  68. data/spec/rails_app/config/initializers/wrap_parameters.rb +14 -0
  69. data/spec/rails_app/config/locales/en.yml +5 -0
  70. data/spec/rails_app/config/routes.rb +58 -0
  71. data/spec/rails_app/config.ru +4 -0
  72. data/spec/rails_app/db/seeds.rb +7 -0
  73. data/spec/rails_app/lib/assets/.gitkeep +0 -0
  74. data/spec/rails_app/lib/tasks/.gitkeep +0 -0
  75. data/spec/rails_app/log/.gitkeep +0 -0
  76. data/spec/rails_app/public/404.html +26 -0
  77. data/spec/rails_app/public/422.html +26 -0
  78. data/spec/rails_app/public/500.html +25 -0
  79. data/spec/rails_app/public/favicon.ico +0 -0
  80. data/spec/rails_app/public/index.html +241 -0
  81. data/spec/rails_app/public/robots.txt +5 -0
  82. data/spec/rails_app/script/rails +6 -0
  83. data/spec/rails_app/test/fixtures/.gitkeep +0 -0
  84. data/spec/rails_app/test/functional/.gitkeep +0 -0
  85. data/spec/rails_app/test/integration/.gitkeep +0 -0
  86. data/spec/rails_app/test/performance/browsing_test.rb +12 -0
  87. data/spec/rails_app/test/test_helper.rb +13 -0
  88. data/spec/rails_app/test/unit/.gitkeep +0 -0
  89. data/spec/rails_app/vendor/assets/javascripts/.gitkeep +0 -0
  90. data/spec/rails_app/vendor/assets/stylesheets/.gitkeep +0 -0
  91. data/spec/rails_app/vendor/plugins/.gitkeep +0 -0
  92. data/spec/spec_helper.rb +12 -0
  93. metadata +224 -0
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rvmrc
19
+ spec/rails_app/public/assets
20
+ spec/rails_app/tmp
21
+ spec/rails_app/log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ script: "rake"
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ branches:
6
+ only:
7
+ - master
8
+ notifications:
9
+ email:
10
+ recipients:
11
+ - jesseltrimble@gmail.com
12
+ - jesse.trimble@factorylabs.com
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in requirejs_optimizer.gemspec
4
+ gemspec
5
+
6
+ gem 'jquery-rails'
7
+
8
+ group :assets do
9
+ gem 'sass-rails'
10
+ gem 'coffee-rails'
11
+ gem 'uglifier'
12
+ end
13
+
14
+ group :development, :test do
15
+ gem 'autotest'
16
+ gem 'pry'
17
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jesse Trimble
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,135 @@
1
+ # RequirejsOptimizer
2
+
3
+ [![Build Status](https://secure.travis-ci.org/jtrim/requirejs_optimizer.png?branch=master)](http://travis-ci.org/jtrim/requirejs_optimizer)
4
+
5
+ R.js optimization to go with your require.js modules, all under the asset
6
+ pipeline.
7
+
8
+ This lib is an extention to the functionality already provided by the asset pipeline. It takes the result of a full `assets:precompile` and applies the peformance benefits of optimization through R.js.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'requirejs_optimizer'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install requirejs_optimizer
23
+
24
+ Once the gem is installed, run the install generator:
25
+
26
+ $ rails g requirejs_optimizer:install
27
+
28
+ It'll ask you what your main module name should be, but will default to `main` if left blank.
29
+ This is referring to the file that will be the main entry point for doing your initial requires.
30
+
31
+ Once you've ran the install generator, you'll have the following directory/file additions:
32
+
33
+ app
34
+ ↳ assets
35
+ ↳ javascripts
36
+ ↳ modules # new
37
+ ↳ README # new
38
+ ↳ main.js.coffee # new
39
+ ↳ require.build.js # new
40
+
41
+ `require.build.js` is the require.js project build file used by r.js. Read more about this [here](http://requirejs.org/docs/optimization.html#wholeproject).
42
+
43
+ For an example build file that contains all available options, check [this](https://github.com/jrburke/r.js/blob/master/build/example.build.js) out.
44
+
45
+ ## Usage
46
+
47
+ Note::This gem does *not* provide `require.js` for use in your app - you can get that [here](http://requirejs.org/docs/download.html#requirejs).
48
+
49
+ rake assets:precompile
50
+
51
+ This runs the normal rails `assets:precompile` cycle, then:
52
+
53
+ - Copies `public/assets` to `tmp/assets`
54
+ - Removes all existing digestified and gzipped files
55
+ - Runs the `r.js` optimization tool with the build file in `app/assets/javascripts/modules/require.build.js`
56
+ - Re-digests all files
57
+ - Re-gzips all js/css files
58
+ - Writes a new `manifest.yml` file
59
+ - Copies the resulting build back to `pubilc/assets`
60
+
61
+ #### Quick rundown on require.js, require.build.js and folder structure
62
+
63
+ Given the following build file that lives under
64
+ `app/assets/javascripts/modules/require.build.js`:
65
+
66
+ ({
67
+ appDir: "../../../../tmp/assets"
68
+ , baseUrl: "./modules"
69
+ , dir: "../../../../tmp/assets/build"
70
+ , name: "main"
71
+ })
72
+
73
+ You should have your main require.js module live in `app/assets/javascripts/modules/main.js(.coffee)`.
74
+
75
+ Given the following contents in `main.js.coffee`:
76
+
77
+ require ["one/foo", "two/bar"], (foo, bar) -> # ...
78
+
79
+ You should have two modules:
80
+
81
+ - `app/assets/javascripts/modules/one/foo.js.coffee`
82
+ - `app/assets/javascripts/modules/two/bar.js.coffee`
83
+
84
+ After running `rake assets:precompile`, modules `foo` and `bar` will be compiled into `main.js`
85
+
86
+
87
+ ## Contributing
88
+
89
+ 1. Fork it
90
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
91
+ 3. Commit your changes *with* tests (`git commit -am 'Added some feature'`)
92
+ 4. Push to the branch (`git push origin my-new-feature`)
93
+ 5. Create new Pull Request
94
+
95
+ ---
96
+
97
+ <a name="details"></a>
98
+ ## Detailed topics
99
+
100
+ #### How it's modifying the environment
101
+
102
+ This lib does a few things to the environment on initialize:
103
+
104
+ - It adds *all* files under `app/assets/javascripts/modules` to
105
+ `config.assets.precompile`. The result is each file under this
106
+ directory is compiled individually. This is done because R.js
107
+ needs these files for dependency tracing on build layers.
108
+ - It turns off Sprockets' js and css compression via
109
+ `config.assets.compress = false` in favor of letting R.js run
110
+ the assets through the compression mechanism defined in your
111
+ build file (uglify by default, see
112
+ [here](https://github.com/jrburke/r.js/blob/master/build/example.build.js))
113
+ - It makes available a few rake tasks:
114
+
115
+ rake requirejs # copy `public/assets` to `tmp` and perform the build,
116
+ # then copy the build result back to `public/assets`
117
+
118
+ rake requirejs:clean # remove the `tmp` build directory (`tmp/assets` by default)
119
+
120
+ rake requirejs:nocopy # runs `requirejs`, just without the final
121
+ # => `public/assets` step
122
+
123
+ - It extends `assets:precompile` by appending the actions of the
124
+ `requirejs` rake task to `assets:precompile:nondigest`.
125
+
126
+ **Details...**
127
+
128
+ Overriding `assets:precompile:nondigest` in stead of `assets:precompile`
129
+ allows asset precompilation to happen on Heroku. It's not entirely
130
+ clear why the former works and the latter doesn't.
131
+
132
+ Also, if you want to run the vanilla `assets:precompile` without R.js
133
+ optimization, this should do the trick:
134
+
135
+ NO_RJS=true rake assets:precompile
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ desc "Run all unit tests"
6
+ RSpec::Core::RakeTask.new("spec:unit") do |t|
7
+ t.rspec_opts = %w[--color]
8
+ t.pattern = "spec/lib/**/*_spec.rb"
9
+ end
10
+
11
+ desc "Run all integration tests"
12
+ RSpec::Core::RakeTask.new("spec:integration") do |t|
13
+ t.rspec_opts = %w[--color]
14
+ t.pattern = "spec/integrations/**/*_spec.rb"
15
+ end
16
+
17
+ task :default => ["spec:unit", "spec:integration"]