architecture-js 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/Gemfile +0 -1
  2. data/Gemfile.lock +0 -2
  3. data/README.md +9 -2
  4. data/Rakefile +0 -1
  5. data/VERSION +1 -1
  6. data/architecture-js.gemspec +41 -8
  7. data/lib/architecture-js/dependencies.rb +0 -2
  8. data/lib/architecture-js/project.rb +6 -2
  9. data/lib/architecture-js.rb +2 -0
  10. data/lib/sprockets/CHANGELOG +22 -0
  11. data/lib/sprockets/LICENSE +20 -0
  12. data/lib/sprockets/README.markdown +230 -0
  13. data/lib/sprockets/lib/sprockets/concatenation.rb +36 -0
  14. data/lib/sprockets/lib/sprockets/environment.rb +52 -0
  15. data/lib/sprockets/lib/sprockets/error.rb +5 -0
  16. data/lib/sprockets/lib/sprockets/pathname.rb +37 -0
  17. data/lib/sprockets/lib/sprockets/preprocessor.rb +96 -0
  18. data/lib/sprockets/lib/sprockets/secretary.rb +110 -0
  19. data/lib/sprockets/lib/sprockets/source_file.rb +56 -0
  20. data/lib/sprockets/lib/sprockets/source_line.rb +85 -0
  21. data/lib/sprockets/lib/sprockets/version.rb +9 -0
  22. data/lib/sprockets/lib/sprockets.rb +42 -0
  23. data/lib/sprockets/test/fixtures/assets/images/script_with_assets/one.png +1 -0
  24. data/lib/sprockets/test/fixtures/assets/images/script_with_assets/two.png +1 -0
  25. data/lib/sprockets/test/fixtures/assets/stylesheets/script_with_assets.css +1 -0
  26. data/lib/sprockets/test/fixtures/constants.yml +1 -0
  27. data/lib/sprockets/test/fixtures/double_slash_comments_that_are_not_requires_should_be_ignored_when_strip_comments_is_false.js +8 -0
  28. data/lib/sprockets/test/fixtures/double_slash_comments_that_are_not_requires_should_be_removed_by_default.js +2 -0
  29. data/lib/sprockets/test/fixtures/multiline_comments_should_be_removed_by_default.js +4 -0
  30. data/lib/sprockets/test/fixtures/requiring_a_file_after_it_has_already_been_required_should_do_nothing.js +5 -0
  31. data/lib/sprockets/test/fixtures/requiring_a_file_that_does_not_exist_should_raise_an_error.js +1 -0
  32. data/lib/sprockets/test/fixtures/requiring_a_single_file_should_replace_the_require_comment_with_the_file_contents.js +3 -0
  33. data/lib/sprockets/test/fixtures/requiring_the_current_file_should_do_nothing.js +1 -0
  34. data/lib/sprockets/test/fixtures/src/constants.yml +3 -0
  35. data/lib/sprockets/test/fixtures/src/foo/bar.js +4 -0
  36. data/lib/sprockets/test/fixtures/src/foo/foo.js +1 -0
  37. data/lib/sprockets/test/fixtures/src/foo.js +1 -0
  38. data/lib/sprockets/test/fixtures/src/script_with_assets.js +3 -0
  39. data/lib/sprockets/test/fixtures/src/script_with_comments.js +13 -0
  40. data/lib/sprockets/test/test_concatenation.rb +28 -0
  41. data/lib/sprockets/test/test_environment.rb +64 -0
  42. data/lib/sprockets/test/test_helper.rb +55 -0
  43. data/lib/sprockets/test/test_pathname.rb +43 -0
  44. data/lib/sprockets/test/test_preprocessor.rb +107 -0
  45. data/lib/sprockets/test/test_secretary.rb +89 -0
  46. data/lib/sprockets/test/test_source_file.rb +34 -0
  47. data/lib/sprockets/test/test_source_line.rb +89 -0
  48. data/spec/fixtures/underscore_template.js +5 -0
  49. data/spec/project_spec.rb +22 -0
  50. metadata +60 -43
data/Gemfile CHANGED
@@ -2,7 +2,6 @@ source "http://rubygems.org"
2
2
 
3
3
  gem "fssm", "~> 0.2.8.1"
4
4
  gem "jsmin", "~> 1.0.1"
5
- gem "sprockets", "1.0.2"
6
5
 
7
6
  group :test do
8
7
  gem "simplecov", "~> 0.5.4", :require => false
data/Gemfile.lock CHANGED
@@ -29,7 +29,6 @@ GEM
29
29
  multi_json (~> 1.0.3)
30
30
  simplecov-html (~> 0.5.3)
31
31
  simplecov-html (0.5.3)
32
- sprockets (1.0.2)
33
32
 
34
33
  PLATFORMS
35
34
  ruby
@@ -43,4 +42,3 @@ DEPENDENCIES
43
42
  jsmin (~> 1.0.1)
44
43
  rspec (~> 2.8.0)
45
44
  simplecov (~> 0.5.4)
46
- sprockets (= 1.0.2)
data/README.md CHANGED
@@ -2,9 +2,16 @@
2
2
 
3
3
  ##About
4
4
 
5
- ArchitectureJS is a suite of tools to help you build and manage complex javascript applications and frameworks. With ArchitectureJS you can create project scaffolding, manage third-party packages, compile, and compress your javascript application, all in real time as you write plain old vanilla javascript. In addition to large applications, ArchitectureJS is perfect for developing your own javascript frameworks and libraries.
5
+ ArchitectureJS is a suite of tools to help you build and manage complex javascript applications and frameworks. With ArchitectureJS you can create project scaffolding, manage third-party packages, compile, and compress your javascript application, all in real time as you write plain old vanilla javascript. In addition to large applications, ArchitectureJS is perfect for developing your own javascript frameworks and libraries. ArchitectureJS contains the following components which help you build modern javascript applications and frameworks:
6
6
 
7
- ###contributing to architecture.js
7
+ * JavaScript Compiler (Sprockets 1.0.2)
8
+ * JavaScript Compressor (JSMin)
9
+ * Scaffold generation using editable templates
10
+ * Custom local JavaScript package management
11
+ * Realtime file monitoring utility to compile your application while you code
12
+ * Project-specific configuration to manage defaults and dependencies
13
+
14
+ ##Contributing to architecture.js
8
15
 
9
16
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
10
17
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
data/Rakefile CHANGED
@@ -23,7 +23,6 @@ Jeweler::Tasks.new do |gem|
23
23
  # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
24
  gem.add_runtime_dependency 'jsmin'
25
25
  gem.add_runtime_dependency 'fssm'
26
- gem.add_runtime_dependency 'sprockets', '1.0.2'
27
26
  # gem.add_development_dependency 'rspec', '> 1.2.3'
28
27
  end
29
28
  Jeweler::RubygemsDotOrgTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.13
1
+ 0.1.14
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "architecture-js"
8
- s.version = "0.1.13"
8
+ s.version = "0.1.14"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dayton Nolan"]
12
- s.date = "2012-02-17"
12
+ s.date = "2012-02-18"
13
13
  s.description = "Architecture.js helps you generate scaffolding, manage third-party packages, compile, and compress your application."
14
14
  s.email = "daytonn@gmail.com"
15
15
  s.executables = ["architect"]
@@ -36,6 +36,44 @@ Gem::Specification.new do |s|
36
36
  "lib/architecture-js/helpers.rb",
37
37
  "lib/architecture-js/notification.rb",
38
38
  "lib/architecture-js/project.rb",
39
+ "lib/sprockets/CHANGELOG",
40
+ "lib/sprockets/LICENSE",
41
+ "lib/sprockets/README.markdown",
42
+ "lib/sprockets/lib/sprockets.rb",
43
+ "lib/sprockets/lib/sprockets/concatenation.rb",
44
+ "lib/sprockets/lib/sprockets/environment.rb",
45
+ "lib/sprockets/lib/sprockets/error.rb",
46
+ "lib/sprockets/lib/sprockets/pathname.rb",
47
+ "lib/sprockets/lib/sprockets/preprocessor.rb",
48
+ "lib/sprockets/lib/sprockets/secretary.rb",
49
+ "lib/sprockets/lib/sprockets/source_file.rb",
50
+ "lib/sprockets/lib/sprockets/source_line.rb",
51
+ "lib/sprockets/lib/sprockets/version.rb",
52
+ "lib/sprockets/test/fixtures/assets/images/script_with_assets/one.png",
53
+ "lib/sprockets/test/fixtures/assets/images/script_with_assets/two.png",
54
+ "lib/sprockets/test/fixtures/assets/stylesheets/script_with_assets.css",
55
+ "lib/sprockets/test/fixtures/constants.yml",
56
+ "lib/sprockets/test/fixtures/double_slash_comments_that_are_not_requires_should_be_ignored_when_strip_comments_is_false.js",
57
+ "lib/sprockets/test/fixtures/double_slash_comments_that_are_not_requires_should_be_removed_by_default.js",
58
+ "lib/sprockets/test/fixtures/multiline_comments_should_be_removed_by_default.js",
59
+ "lib/sprockets/test/fixtures/requiring_a_file_after_it_has_already_been_required_should_do_nothing.js",
60
+ "lib/sprockets/test/fixtures/requiring_a_file_that_does_not_exist_should_raise_an_error.js",
61
+ "lib/sprockets/test/fixtures/requiring_a_single_file_should_replace_the_require_comment_with_the_file_contents.js",
62
+ "lib/sprockets/test/fixtures/requiring_the_current_file_should_do_nothing.js",
63
+ "lib/sprockets/test/fixtures/src/constants.yml",
64
+ "lib/sprockets/test/fixtures/src/foo.js",
65
+ "lib/sprockets/test/fixtures/src/foo/bar.js",
66
+ "lib/sprockets/test/fixtures/src/foo/foo.js",
67
+ "lib/sprockets/test/fixtures/src/script_with_assets.js",
68
+ "lib/sprockets/test/fixtures/src/script_with_comments.js",
69
+ "lib/sprockets/test/test_concatenation.rb",
70
+ "lib/sprockets/test/test_environment.rb",
71
+ "lib/sprockets/test/test_helper.rb",
72
+ "lib/sprockets/test/test_pathname.rb",
73
+ "lib/sprockets/test/test_preprocessor.rb",
74
+ "lib/sprockets/test/test_secretary.rb",
75
+ "lib/sprockets/test/test_source_file.rb",
76
+ "lib/sprockets/test/test_source_line.rb",
39
77
  "repository/modjs/plugins/jquery-elements.js",
40
78
  "spec/.DS_Store",
41
79
  "spec/architect_spec.rb",
@@ -58,6 +96,7 @@ Gem::Specification.new do |s|
58
96
  "spec/fixtures/test_framework.rb",
59
97
  "spec/fixtures/test_template_options.js",
60
98
  "spec/fixtures/test_template_two.js",
99
+ "spec/fixtures/underscore_template.js",
61
100
  "spec/fixtures/update.architecture",
62
101
  "spec/fixtures/update.js",
63
102
  "spec/generator_spec.rb",
@@ -79,7 +118,6 @@ Gem::Specification.new do |s|
79
118
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
80
119
  s.add_runtime_dependency(%q<fssm>, ["~> 0.2.8.1"])
81
120
  s.add_runtime_dependency(%q<jsmin>, ["~> 1.0.1"])
82
- s.add_runtime_dependency(%q<sprockets>, ["= 1.0.2"])
83
121
  s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
84
122
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
85
123
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
@@ -87,11 +125,9 @@ Gem::Specification.new do |s|
87
125
  s.add_development_dependency(%q<autotest-growl>, ["~> 0.2.16"])
88
126
  s.add_runtime_dependency(%q<jsmin>, [">= 0"])
89
127
  s.add_runtime_dependency(%q<fssm>, [">= 0"])
90
- s.add_runtime_dependency(%q<sprockets>, ["= 1.0.2"])
91
128
  else
92
129
  s.add_dependency(%q<fssm>, ["~> 0.2.8.1"])
93
130
  s.add_dependency(%q<jsmin>, ["~> 1.0.1"])
94
- s.add_dependency(%q<sprockets>, ["= 1.0.2"])
95
131
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
96
132
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
97
133
  s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
@@ -99,12 +135,10 @@ Gem::Specification.new do |s|
99
135
  s.add_dependency(%q<autotest-growl>, ["~> 0.2.16"])
100
136
  s.add_dependency(%q<jsmin>, [">= 0"])
101
137
  s.add_dependency(%q<fssm>, [">= 0"])
102
- s.add_dependency(%q<sprockets>, ["= 1.0.2"])
103
138
  end
104
139
  else
105
140
  s.add_dependency(%q<fssm>, ["~> 0.2.8.1"])
106
141
  s.add_dependency(%q<jsmin>, ["~> 1.0.1"])
107
- s.add_dependency(%q<sprockets>, ["= 1.0.2"])
108
142
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
109
143
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
110
144
  s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
@@ -112,7 +146,6 @@ Gem::Specification.new do |s|
112
146
  s.add_dependency(%q<autotest-growl>, ["~> 0.2.16"])
113
147
  s.add_dependency(%q<jsmin>, [">= 0"])
114
148
  s.add_dependency(%q<fssm>, [">= 0"])
115
- s.add_dependency(%q<sprockets>, ["= 1.0.2"])
116
149
  end
117
150
  end
118
151
 
@@ -2,7 +2,6 @@ begin
2
2
  require 'yaml'
3
3
  require 'jsmin'
4
4
  require 'tempfile'
5
- require 'sprockets'
6
5
  require 'fileutils'
7
6
  require 'time'
8
7
  require 'erb'
@@ -11,7 +10,6 @@ rescue LoadError
11
10
  require 'yaml'
12
11
  require 'jsmin'
13
12
  require 'tempfile'
14
- require 'sprockets'
15
13
  require 'fileutils'
16
14
  require 'time'
17
15
  require 'erb'
@@ -8,7 +8,8 @@ module ArchitectureJS
8
8
  :directories,
9
9
  :template_directories,
10
10
  :generator,
11
- :config
11
+ :config,
12
+ :raise_errors
12
13
 
13
14
  def self.new_from_config(path)
14
15
  config_file = Dir.entries(path).select {|f| f =~ /\.architecture$/ }.first
@@ -25,6 +26,7 @@ module ArchitectureJS
25
26
 
26
27
  def initialize(config, root = nil)
27
28
  raise "#{self.class}.new({ name: 'myapp' }, options): config[:name] is undefined" unless config[:name]
29
+ @raise_errors = false
28
30
  @config_file = "#{config[:name].downcase}.architecture"
29
31
  root ||= Dir.getwd
30
32
  @root = File.expand_path(root)
@@ -124,7 +126,8 @@ module ArchitectureJS
124
126
  root: ArchitectureJS::base_directory,
125
127
  asset_root: @config[:asset_root],
126
128
  load_path: ['repository'],
127
- source_files: [file_path]
129
+ source_files: [file_path],
130
+ interpolate_constants: false
128
131
  )
129
132
 
130
133
  compiled_file = sprockets.concatenation
@@ -136,6 +139,7 @@ module ArchitectureJS
136
139
  rescue Exception => error
137
140
  @errors = true
138
141
  puts ArchitectureJS::Notification.error "Sprockets error: #{error.message}"
142
+ raise if @raise_errors
139
143
  end
140
144
 
141
145
  def compress_application
@@ -45,6 +45,8 @@ module ArchitectureJS
45
45
  FRAMEWORKS = Hash.new
46
46
  end
47
47
 
48
+ require "sprockets/lib/sprockets"
49
+
48
50
  %w(dependencies generator notification project architect).each do |lib|
49
51
  require "architecture-js/#{lib}"
50
52
  end
@@ -0,0 +1,22 @@
1
+ * Add a :strip_comments option to Secretary that is passed through to its Preprocessor. [#12 state:resolved]
2
+
3
+
4
+ *1.0.2* (February 24, 2009)
5
+
6
+ * Update the sprockets-rails installation instructions to use `script/plugin`. [#7 state:resolved]
7
+
8
+ * Fix Secretary#source_last_modified not to raise an exception when one of the preprocessor's source files has been moved or deleted. (Jonathan Goldman) [#10 state:resolved]
9
+
10
+ * Avoid hanging when preprocessing minified source files. (Maciej Pasternacki) [#9 state:resolved]
11
+
12
+
13
+ *1.0.1* (February 19, 2009)
14
+
15
+ * Change the CGI output generation environment variable name to "sprockets_generate_output_file" and use the right path in Concatenation#save_to.
16
+
17
+ * Prefer "vendor/gems/sprockets/lib" to "vendor/sprockets/lib" when looking for an externaled Sprockets checkout in nph-sprockets.cgi.
18
+
19
+
20
+ *1.0.0* (February 17, 2009)
21
+
22
+ * Initial public release.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Sam Stephenson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,230 @@
1
+ Sprockets
2
+ =========
3
+
4
+ [http://getsprockets.org/](http://getsprockets.org/)
5
+
6
+ Sprockets is a Ruby library that preprocesses and concatenates JavaScript source files. It takes any number of source files and preprocesses them line-by-line in order to build a single concatenation. Specially formatted lines act as directives to the Sprockets preprocessor, telling it to require the contents of another file or library first or to provide a set of asset files (such as images or stylesheets) to the document root. Sprockets attempts to fulfill required dependencies by searching a set of directories called the load path.
7
+
8
+
9
+ ## Why use Sprockets?
10
+
11
+ **Extract reusable code and share it across multiple web sites or applications.** Sprockets makes it easy to extract JavaScript plugins from your site or application and share them across your portfolio. Use your SCM to check out plugin repositories directly into your site or application. Then tell Sprockets to add the plugins to your load path. Support for asset provisioning lets you bundle CSS and images with JavaScript plugins, too.
12
+
13
+ **Speed up your site by automatically concatenating JavaScript into a single file for production.** Concatenating your site's JavaScript means all your source code is cached in the browser on the first hit. It also means you reduce the number of HTTP requests necessary to load a single page. When combined with gzip compression on the web server, concatenation is the fastest way to serve JavaScript to your users.
14
+
15
+ **Organize your JavaScript source code into multiple commented files and directories.** Finally, an end to navigating long, difficult-to-maintain JavaScript source files. With Sprockets, JavaScript source code can live anywhere on your system, even outside your site's or application's document root. You're free to split source code up into multiple files and organize those files into directories during development. You can also add as many comments as you want&mdash;they'll be stripped from the resulting output.
16
+
17
+ **Use bleeding-edge framework and library code in your application.** If you use and contribute to open-source JavaScript frameworks and libraries that use Sprockets, like [Prototype](http://www.prototypejs.org/) and [script.aculo.us](http://script.aculo.us/), the build processes for those scripts can be integrated directly into your application. That makes it possible to track the latest development versions of your framework and library dependencies by adding their repositories to your application's Sprockets load path.
18
+
19
+ **Sprockets is compatible with the PDoc JavaScript documentation system and the JavaScript framework of your choice.** If you document your JavaScript source code with [PDoc](http://www.pdoc.org/), Sprockets will automatically strip documentation comments from the resulting concatenated output. You can use any JavaScript framework you like in your site or application&mdash;Sprockets is framework-agnostic.
20
+
21
+
22
+ ## Installing Sprockets
23
+
24
+ Sprockets is written in Ruby and has no runtime dependencies apart from the Ruby standard library. You can install it with RubyGems:
25
+
26
+ $ gem install --remote sprockets
27
+
28
+ This will also install the `sprocketize` command-line utility.
29
+
30
+
31
+ ## Sprocketizing your source code
32
+
33
+ Sprockets takes any number of _source files_ and preprocesses them line-by-line in order to build a single _concatenation_. Specially formatted lines act as _directives_ to the Sprockets preprocessor, telling it to _require_ the contents of another file or library first or to _provide_ a set of asset files to the document root. Sprockets attempts to fulfill required dependencies by searching a set of directories called the _load path_.
34
+
35
+ ### How Sprockets handles comments
36
+
37
+ Use single-line <nobr>(`//`)</nobr> comments in JavaScript source files for comments that don't need to appear in the resulting concatenated output. Use multiple-line <nobr>(`/* ... */`)</nobr> comments for comments that _should_ appear in the resulting concatenated output, like copyright notices or descriptive headers. PDoc <nobr>(`/** ... **/`)</nobr> documentation comments will not be included in the resulting concatenation.
38
+
39
+ Comments beginning with `//=` are treated by Sprockets as _directives_. Sprockets currently understands two directives, `require` and `provide`.
40
+
41
+ ### Specifying dependencies with the `require` directive
42
+
43
+ Use the `require` directive to tell Sprockets that another JavaScript source file should be inserted into the concatenation before continuing to preprocess the current source file. If the specified source file has already been required, Sprockets ignores the directive.
44
+
45
+ The format of a `require` directive determines how Sprockets looks for the dependent source file. If you place the name of the source file in angle brackets:
46
+
47
+ //= require <prototype>
48
+
49
+ Sprockets will search your load path, in order, for a file named `prototype.js`, and begin preprocessing the first match it finds. (An error will be raised if a matching file can't be found.) If you place the name of the source file in quotes:
50
+
51
+ //= require "date_helper"
52
+
53
+ Sprockets will _not_ search the load path, but will instead look for a file named `date_helper.js` in the same directory as the current source file. In general, it is a good idea to use quotes to refer to related files, and angle brackets to refer to packages, libraries, or third-party code that may live in a different location.
54
+
55
+ You can refer to files in subdirectories with the `require` directive. For example:
56
+
57
+ //= require <behavior/hover_observer>
58
+
59
+ Sprockets will search the load path for a file named `hover_observer.js` in a directory named `behavior`.
60
+
61
+ ### Bundling assets with the `provide` directive
62
+
63
+ Sometimes it is necessary to include associated stylesheets, images, or even HTML files with a JavaScript plugin. Sprockets lets you specify that a JavaScript source file depends on a set of assets, and offers a routine for copying all dependent assets into the document root.
64
+
65
+ The `provide` directive tells Sprockets that the current source file depends on the set of assets in the named directory. For example, say you have a plugin with the following directory structure:
66
+
67
+ plugins/color_picker/assets/images/color_picker/arrow.png
68
+ plugins/color_picker/assets/images/color_picker/circle.png
69
+ plugins/color_picker/assets/images/color_picker/hue.png
70
+ plugins/color_picker/assets/images/color_picker/saturation_and_brightness.png
71
+ plugins/color_picker/assets/stylesheets/color_picker.css
72
+ plugins/color_picker/src/color.js
73
+ plugins/color_picker/src/color_picker.js
74
+
75
+ Assume `plugins/color_picker/src/` is in your Sprockets load path. `plugins/color_picker/src/color_picker.js` might look like this:
76
+
77
+ //= require "color"
78
+ //= provide "../assets"
79
+
80
+ When `<color_picker>` is required in your application, its `provide` directive will tell Sprockets that all files in the `plugins/color_picker/assets/` directory should be copied into the web server's document root.
81
+
82
+ ### Inserting string constants with `<%= ... %>`
83
+
84
+ You may need to parameterize and insert constants into your source code. Sprockets lets you define such constants in a special file called `constants.yml` that lives in your load path. This file is formatted as a [YAML](http://yaml.org/spec/1.2/) hash.
85
+
86
+ Continuing the `color_picker` example, assume `plugins/color_picker/src/constants.yml` contains the following:
87
+
88
+ COLOR_PICKER_VERSION: 1.0.0
89
+ COLOR_PICKER_AUTHOR: Sam Stephenson <sam@example.org>
90
+
91
+ The constants are specified in a single place, and you can now insert them into your source code without repetition:
92
+
93
+ /* Color Picker plugin, version <%= COLOR_PICKER_VERSION %>
94
+ * (c) 2009 <%= COLOR_PICKER_AUTHOR %>
95
+ * Distributed under the terms of an MIT-style license */
96
+
97
+ var ColorPicker = {
98
+ VERSION: '<%= COLOR_PICKER_VERSION %>',
99
+ ...
100
+ };
101
+
102
+ The resulting concatenated output will have the constant values substituted in place:
103
+
104
+ /* Color Picker plugin, version 1.0.0
105
+ * (c) 2009 Sam Stephenson <sam@example.org>
106
+ * Distributed under the terms of an MIT-style license */
107
+
108
+ var ColorPicker = {
109
+ VERSION: '1.0.0',
110
+ ...
111
+ };
112
+
113
+ Constants share a global namespace, so you can refer to constants defined anywhere in your load path. If a constant is not found, Sprockets raises an error and halts further preprocessing.
114
+
115
+
116
+ ## Using Sprockets
117
+
118
+ Sprockets is distributed as a Ruby library. It comes with a command-line tool called `sprocketize` for generating concatenations and installing provided assets. You can also use the `sprockets-rails` plugin to sprocketize your Rails application. A simple CGI is bundled with Sprockets for use in other environments.
119
+
120
+ ### Sprockets as a Ruby library
121
+
122
+ The simplest way to use Sprockets from Ruby is with the `Sprockets::Secretary` class. A `Secretary` handles the job of setting up a Sprockets environment, creating a preprocessor, loading your application's source files, and generating the resulting concatenation.
123
+
124
+ You can pass the following options to `Sprockets::Secretary.new`:
125
+
126
+ * `:root` - Specifies the Sprockets root, or the base location for all directories specified in the load path and source files required by the preprocessor. Defaults to `"."` (the current working directory).
127
+ * `:asset_root` - Specifies the application's document root, or the directory from which the web server serves its files.
128
+ * `:load_path` - An ordered array of directory names (either absolute paths, or paths relative to the Sprockets root) where Sprockets will search for required JavaScript dependencies.
129
+ * `:source_files` - An ordered array of JavaScript source files (either absolute paths, or paths relative to the Sprockets root) that Sprockets will require one-by-one to build the resulting concatenation.
130
+ * `:expand_paths` - Specifies whether or not Sprockets will expand filenames in the `load_path` and `source_files` arrays according to shell glob rules (e.g. `:load_path => ["vendor/sprockets/*/src"]` or `:source_files => ["app/javascripts/**/*.js"]`). Defaults to `true`; set it to `false` if you do _not_ want shell expansion applied to paths.
131
+
132
+ Once you have a `Secretary` object, you can call its `concatenation` method to get a `Sprockets::Concatenation` object back. You can also call its `install_assets` method to install provided assets into the directory specified by the `:asset_root` option.
133
+
134
+ Example:
135
+
136
+ secretary = Sprockets::Secretary.new(
137
+ :asset_root => "public",
138
+ :load_path => ["vendor/sprockets/*/src", "vendor/plugins/*/javascripts"],
139
+ :source_files => ["app/javascripts/application.js", "app/javascripts/**/*.js"]
140
+ )
141
+
142
+ # Generate a Sprockets::Concatenation object from the source files
143
+ concatenation = secretary.concatenation
144
+ # Write the concatenation to disk
145
+ concatenation.save_to("public/sprockets.js")
146
+
147
+ # Install provided assets into the asset root
148
+ secretary.install_assets
149
+
150
+ You can ask the `Secretary` for the most recent last-modified time of all the source files that make up the concatenation with the `source_last_modified` method. Use this in conjunction with the `reset!` method to reuse a `Secretary` instance across multiple requests and only regenerate concatenations when the source file has changed.
151
+
152
+ ### Using `sprocketize` from the command line
153
+
154
+ The `sprocketize` command is a simple wrapper around `Sprockets::Secretary`. It takes any number of source files (specified as command-line arguments) and preprocesses them according to the options you pass. Then it prints the resulting concatenation to standard output, where it can be redirected to a file or piped to another program for further processing.
155
+
156
+ You can pass the following command-line options to `sprocketize`:
157
+
158
+ -C, --directory=DIRECTORY Change to DIRECTORY before doing anything
159
+ -I, --include-dir=DIRECTORY Adds the directory to the Sprockets load path
160
+ -a, --asset-root=DIRECTORY Copy provided assets into DIRECTORY
161
+ -h, --help Shows this help message
162
+ -v, --version Shows version
163
+
164
+ Example:
165
+
166
+ $ sprocketize -I app/javascripts \
167
+ -I vendor/sprockets/prototype/src \
168
+ -I vendor/sprockets/color_picker/src \
169
+ --asset-root=public \
170
+ app/javascripts/*.js > public/sprockets.js
171
+
172
+ ### Using the `sprockets-rails` plugin in your Rails application
173
+
174
+ The [`sprockets-rails`](http://github.com/sstephenson/sprockets-rails/tree/master) plugin (distributed separately) sets up your Rails application for use with Sprockets. To install it, first install the `sprockets` RubyGem, then check out a copy of the `sprockets-rails` repository into your `vendor/plugins/` directory. When you run the bundled `install.rb` script, `sprockets-rails` will create two new directories in your application and copy a configuration file into your `config/` directory.
175
+
176
+ `sprockets-rails` includes a controller named `SprocketsController` that renders your application's Sprockets concatenation. When caching is enabled, e.g. in production mode, `SprocketsController` uses Rails page caching to save the concatenated output to `public/sprockets.js` the first time it is requested. When caching is disabled, e.g. in development mode, `SprocketsController` will render a fresh concatenation any time a source file changes.
177
+
178
+ To source Sprockets' JavaScript concatenation from your HTML templates, use the provided `sprockets_include_tag` helper.
179
+
180
+ `sprockets-rails` also includes a set of Rake tasks for generating the concatenation (`rake sprockets:install_script`) and installing provided assets (`rake sprockets:install_assets`). Run `sprockets:install_assets` any time you add or update a Sprockets plugin in your application. Add `sprockets:install_script` as a [Capistrano](http://www.capify.org/) post-deploy hook to generate the Sprockets concatenation on your servers automatically at deploy time.
181
+
182
+ Here's a walkthrough of the installation process:
183
+
184
+ 1. `gem install --remote sprockets`
185
+
186
+ 2. `script/plugin install git://github.com/sstephenson/sprockets-rails.git`
187
+
188
+ You now have `app/javascripts/` and `vendor/sprockets/` directories in your application, as well as a `config/sprockets.yml` file.
189
+
190
+ 3. Edit your `config/routes.rb` file to add routes for `SprocketsController`:
191
+
192
+ ActionController::Routing::Routes.draw do |map|
193
+ # Add the following line:
194
+ SprocketsApplication.routes(map)
195
+ ...
196
+ end
197
+
198
+ 4. Move your JavaScript source files from `public/javascripts/` into `app/javascripts/`. All files in all subdirectories of `app/javascripts/` will be required by Sprockets in alphabetical order, with the exception of `app/javascripts/application.js`, which is required _before any other file_. (You can change this behavior by editing the `source_files` line of `config/sprockets.yml`.)
199
+
200
+ 5. Adjust your HTML templates to call `<%= sprockets_include_tag %>` instead of `<%= javascript_include_tag ... %>`.
201
+
202
+ Once `sprockets-rails` is installed, you can check out Sprockets plugins into the `vendor/sprockets/` directory. By default, `sprockets-rails` configures Sprockets' load path to search `vendor/sprockets/*/src/`, as well as `vendor/plugins/*/javascripts/`. This means that the `javascripts/` directories of Rails plugins are automatically installed into your Sprockets load path.
203
+
204
+ ### Using the bundled Sprockets CGI script
205
+
206
+ Sprockets comes with a simple CGI script for serving JavaScript outside of a Ruby environment. You can find it, along with brief documentation and installation instructions, as `ext/nph-sprockets.cgi` in your copy of the Sprockets source code. (If you installed Sprockets with RubyGems, you can find the location of the Sprockets source code with the `gem which sprockets` command.)
207
+
208
+
209
+ ## Contributing to Sprockets
210
+
211
+ The Sprockets source code is hosted on [GitHub](http://github.com/). Check out a working copy with [Git](http://git-scm.com/):
212
+
213
+ $ git clone git://github.com/sstephenson/sprockets.git
214
+
215
+ You can fork the Sprockets project on GitHub, commit your changes, and [send a pull request](http://github.com/guides/pull-requests) if you'd like your feature or bug fix to be considered for the next release. Please make sure to update the unit tests as well.
216
+
217
+ ### Reporting bugs
218
+
219
+ If you find a bug in Sprockets and aren't feeling motivated to fix it yourself, you can file a ticket at the [Sprockets Lighthouse project](http://prototype.lighthouseapp.com/projects/8888-sprockets).
220
+
221
+
222
+ ## License
223
+
224
+ Copyright &copy; 2009 Sam Stephenson.
225
+
226
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
227
+
228
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
229
+
230
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ module Sprockets
2
+ class Concatenation
3
+ attr_reader :source_lines
4
+
5
+ def initialize
6
+ @source_lines = []
7
+ @source_file_mtimes = {}
8
+ end
9
+
10
+ def record(source_line)
11
+ source_lines << source_line
12
+ record_mtime_for(source_line.source_file)
13
+ source_line
14
+ end
15
+
16
+ def to_s
17
+ source_lines.join
18
+ end
19
+
20
+ def mtime
21
+ @source_file_mtimes.values.max
22
+ end
23
+
24
+ def save_to(filename)
25
+ timestamp = mtime
26
+ File.open(filename, "w") { |file| file.write(to_s) }
27
+ File.utime(timestamp, timestamp, filename)
28
+ true
29
+ end
30
+
31
+ protected
32
+ def record_mtime_for(source_file)
33
+ @source_file_mtimes[source_file] ||= source_file.mtime
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,52 @@
1
+ module Sprockets
2
+ class Environment
3
+ attr_reader :root, :load_path
4
+
5
+ def initialize(root, load_path = [])
6
+ @load_path = [@root = Pathname.new(self, root)]
7
+
8
+ load_path.reverse_each do |location|
9
+ register_load_location(location)
10
+ end
11
+ end
12
+
13
+ def pathname_from(location)
14
+ Pathname.new(self, absolute_location_from(location))
15
+ end
16
+
17
+ def register_load_location(location)
18
+ pathname = pathname_from(location)
19
+ load_path.delete(pathname)
20
+ load_path.unshift(pathname)
21
+ location
22
+ end
23
+
24
+ def find(location)
25
+ if Sprockets.absolute?(location) && File.exists?(location)
26
+ pathname_from(location)
27
+ else
28
+ find_all(location).first
29
+ end
30
+ end
31
+
32
+ def constants(reload = false)
33
+ @constants = nil if reload
34
+ @constants ||= find_all("constants.yml").inject({}) do |constants, pathname|
35
+ contents = YAML.load(pathname.contents) rescue nil
36
+ contents = {} unless contents.is_a?(Hash)
37
+ constants.merge(contents)
38
+ end
39
+ end
40
+
41
+ protected
42
+ def absolute_location_from(location)
43
+ location = location.to_s
44
+ location = File.join(root.absolute_location, location) unless Sprockets.absolute?(location)
45
+ File.expand_path(location)
46
+ end
47
+
48
+ def find_all(location)
49
+ load_path.map { |pathname| pathname.find(location) }.compact
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ module Sprockets
2
+ class Error < ::StandardError; end
3
+ class LoadError < Error; end
4
+ class UndefinedConstantError < Error; end
5
+ end
@@ -0,0 +1,37 @@
1
+ module Sprockets
2
+ class Pathname
3
+ attr_reader :environment, :absolute_location
4
+
5
+ def initialize(environment, absolute_location)
6
+ @environment = environment
7
+ @absolute_location = File.expand_path(absolute_location)
8
+ end
9
+
10
+ # Returns a Pathname for the location relative to this pathname's absolute location.
11
+ def find(location, kind = :file)
12
+ location = File.join(absolute_location, location)
13
+ File.send("#{kind}?", location) ? Pathname.new(environment, location) : nil
14
+ end
15
+
16
+ def parent_pathname
17
+ Pathname.new(environment, File.dirname(absolute_location))
18
+ end
19
+
20
+ def source_file
21
+ SourceFile.new(environment, self)
22
+ end
23
+
24
+ def contents
25
+ IO.read(absolute_location)
26
+ end
27
+
28
+ def ==(pathname)
29
+ environment == pathname.environment &&
30
+ absolute_location == pathname.absolute_location
31
+ end
32
+
33
+ def to_s
34
+ absolute_location
35
+ end
36
+ end
37
+ end