sprocketizer 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.
- data/README.rdoc +72 -0
- data/lib/sprocketizer/engine.rb +9 -0
- data/lib/sprocketizer/sprocket.rb +40 -0
- data/lib/sprocketizer/version.rb +3 -0
- data/lib/sprocketizer.rb +1 -0
- metadata +88 -0
data/README.rdoc
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
= Sprocketizer
|
2
|
+
|
3
|
+
== General info
|
4
|
+
|
5
|
+
Sprocketizer stole most of its code from these two projects:
|
6
|
+
|
7
|
+
http://github.com/sstephenson/sprockets-rails
|
8
|
+
http://github.com/coderifous/dancing_with_sprockets
|
9
|
+
|
10
|
+
The major differences are:
|
11
|
+
* It is flexible and configurable.
|
12
|
+
* It is a gem.
|
13
|
+
* It is Rails 3 ONLY.
|
14
|
+
|
15
|
+
== Prerequisites
|
16
|
+
|
17
|
+
The only requirement is the Sprockets gem. Just add this to your Gemfile:
|
18
|
+
|
19
|
+
gem 'sprockets'
|
20
|
+
|
21
|
+
== Installation
|
22
|
+
|
23
|
+
There are two steps to getting Sprocketizer installed. First, add it to your Gemfile:
|
24
|
+
|
25
|
+
gem 'sprocketizer'
|
26
|
+
|
27
|
+
Second, create a sprockets.yml file in your config directory. The default configuration would look like this:
|
28
|
+
|
29
|
+
asset_root: public
|
30
|
+
load_path:
|
31
|
+
- app/javascripts
|
32
|
+
|
33
|
+
Note that you do NOT include a source_file configuration like you would with the sprockets-rails plugin.
|
34
|
+
|
35
|
+
== Usage
|
36
|
+
|
37
|
+
Any javascript file you request that is not in your public/javascripts folder will be generated using sprockets. For example, a request to:
|
38
|
+
|
39
|
+
http://example.com/javascripts/sprockets.js
|
40
|
+
|
41
|
+
will attempt to render the file app/javascripts/sprockets.js using sprockets. You can also reference files in subdirectories with no problem:
|
42
|
+
|
43
|
+
http://example.com/javascripts/sprocket/another_file.js
|
44
|
+
|
45
|
+
will render the file app/javascripts/sprocket/another_file.js
|
46
|
+
|
47
|
+
Finally, you can still use the javascript_include_tag helper from rails since the URL is the same as if the file lived in your public/javascripts folder.
|
48
|
+
|
49
|
+
== Copyright & License
|
50
|
+
|
51
|
+
Copyright (c) 2010 Matt Hodgson
|
52
|
+
|
53
|
+
Permission is hereby granted, free of charge, to any person
|
54
|
+
obtaining a copy of this software and associated documentation
|
55
|
+
files (the "Software"), to deal in the Software without
|
56
|
+
restriction, including without limitation the rights to use,
|
57
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
58
|
+
copies of the Software, and to permit persons to whom the
|
59
|
+
Software is furnished to do so, subject to the following
|
60
|
+
conditions:
|
61
|
+
|
62
|
+
The above copyright notice and this permission notice shall be
|
63
|
+
included in all copies or substantial portions of the Software.
|
64
|
+
|
65
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
66
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
67
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
68
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
69
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
70
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
71
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
72
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Sprocketizer
|
2
|
+
class Sprocket
|
3
|
+
|
4
|
+
def initialize(name)
|
5
|
+
@configuration = configuration_from_convention(name).merge(configuration_from_app)
|
6
|
+
end
|
7
|
+
|
8
|
+
def configuration_from_convention(name)
|
9
|
+
{ :asset_root => "public",
|
10
|
+
:load_path => %w(app/javascripts),
|
11
|
+
:source_files => [ "app/javascripts/#{name}.js" ],
|
12
|
+
:root => Rails.root }
|
13
|
+
end
|
14
|
+
|
15
|
+
def configuration_from_app
|
16
|
+
@app_configuration ||= YAML.load(IO.read(File.join(Rails.root, "config", "sprockets.yml"))) || {}
|
17
|
+
end
|
18
|
+
|
19
|
+
def source
|
20
|
+
secretary.reset! unless source_is_unchanged?
|
21
|
+
secretary.concatenation
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def secretary
|
27
|
+
@secretary ||= Sprockets::Secretary.new(configuration)
|
28
|
+
end
|
29
|
+
|
30
|
+
def source_is_unchanged?
|
31
|
+
previous_source_last_modified, @source_last_modified = @source_last_modified, secretary.source_last_modified
|
32
|
+
previous_source_last_modified == @source_last_modified
|
33
|
+
end
|
34
|
+
|
35
|
+
def configuration
|
36
|
+
@configuration || {}
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/lib/sprocketizer.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'sprocketizer/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sprocketizer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: "1.0"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Matt Hodgson
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-10-08 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - "="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 19
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
- 2
|
32
|
+
version: 1.0.2
|
33
|
+
requirement: *id001
|
34
|
+
type: :runtime
|
35
|
+
name: sprockets
|
36
|
+
description: A gem for integrating Sprockets with Rails 3.
|
37
|
+
email:
|
38
|
+
- mhodgson@scenario4.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- lib/sprocketizer/engine.rb
|
47
|
+
- lib/sprocketizer/sprocket.rb
|
48
|
+
- lib/sprocketizer/version.rb
|
49
|
+
- lib/sprocketizer.rb
|
50
|
+
- README.rdoc
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: http://github.com/mhodgson/sprocketizer
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 23
|
75
|
+
segments:
|
76
|
+
- 1
|
77
|
+
- 3
|
78
|
+
- 6
|
79
|
+
version: 1.3.6
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.3.7
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: A gem for integrating Sprockets with Rails 3.
|
87
|
+
test_files: []
|
88
|
+
|