sprockets-require_module 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4dd0e9142cec7e3f633ae65d35b656919e477a40
4
+ data.tar.gz: 46a3c3c364483e3e6b73f0fac28a4d0bac0f30e1
5
+ SHA512:
6
+ metadata.gz: a322efb479999d3c04a5a77ea7444c338a1c6b72f5faf32e9f2e3047f596a7feb0d8de124cffe12c91690daa73d93a4350a2680aaa97adb1eae59f49331acf0c
7
+ data.tar.gz: 9e7b044775d05c102973ad7cd858b0eab26f3d138dc4c7d258250efda85ff52f2c1fae7ee947736829977ed16457a81590eaad1416099452eae2d3457c3cbf2a
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 Rolf van de Krol
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.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Sprockets Require Module
2
+ Sprockets Require Module provides a sprocket directive `require_module` that allows wrapping a number of assets in a module and requiring them at once.
3
+
4
+ ## Installation
5
+
6
+ In order to install `sprockets-require_module` into your project, add
7
+
8
+ ```ruby
9
+ gem "sprockets-require_module"
10
+ ```
11
+
12
+ to your `Gemfile`.
13
+
14
+ ## Usage
15
+
16
+ Provide a module that has an `assets` method. For example:
17
+
18
+ ```ruby
19
+ module MyProject
20
+ module Assets
21
+ extend self
22
+
23
+ def assets
24
+ ['myproject/core', 'myproject/something_else']
25
+ end
26
+ end
27
+ end
28
+ ```
29
+
30
+ Make sure the module is either loaded or auto loadable.
31
+
32
+ In a sprockets manifest, add a reference to this module, like this:
33
+
34
+ ```js
35
+ //= require_module my_project/assets
36
+ ```
37
+
38
+ The module does not have to be an actual module. As long as it is a constant that has an `assets` method, it's fine. So it can be class too.
39
+
40
+ The `assets` method should return an `Enumerable`.
41
+
42
+ ### Asset caching
43
+
44
+ Sprockets caches all asset files, also on development, to prevent unnecessary asset compilation. This behavior conflicts a bit with this gem. Luckily Sprockets allows us to register files that are dependencies of the assets. When these dependencies change, the assets that depend on them, are recompiled.
45
+
46
+ By default Sprockets Require Module registers the file that defines the `assets` method as a dependency. That means that in the example `MyProject::Assets` module, you can change the list of returned asset paths and it will all update perfectly well, because Sprockets will detect that the file where the module is defined has been altered and will invalidate the relevant cache parts.
47
+
48
+ If you create a more complicated implementation, you might need to spend a little more effort to make sure Sprockets cache does not prevent asset recompilation. If you for example create a class that receives it's paths from another part of the application, you will need to mark those other parts as dependencies.
49
+
50
+ If the constant that you mention in your `require_module` directive has an `asset_dependencies` method, the return value of this method is used as the list of dependencies, instead of the default behavior.
@@ -0,0 +1 @@
1
+ require 'sprockets/require_module'
@@ -0,0 +1,24 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext/string/inflections'
3
+
4
+ require 'sprockets'
5
+
6
+ Sprockets::DirectiveProcessor.class_eval do
7
+ protected
8
+ def process_require_module_directive name
9
+ mod = name.camelize.constantize
10
+ mod.assets.each do |path|
11
+ context.require_asset(path)
12
+ end
13
+
14
+ if mod.respond_to? :asset_dependencies
15
+ dependencies = mod.asset_dependencies
16
+ else
17
+ dependencies = [mod.method(:assets).source_location.first]
18
+ end
19
+
20
+ dependencies.each do |path|
21
+ context.depend_on(path)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ module Sprockets
2
+ module RequireModule
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sprockets-require_module
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Rolf van de Krol
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sprockets
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ description: Sprockets directive require_module to keep a list of assets outside a
42
+ sprocket manifest in a module
43
+ email:
44
+ - info@rolfvandekrol.nl
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - LICENSE
50
+ - README.md
51
+ - lib/sprockets-require_module.rb
52
+ - lib/sprockets/require_module.rb
53
+ - lib/sprockets/require_module/version.rb
54
+ homepage: https://github.com/rolfvandekrol/sprockets-require_module
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.2.2
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Sprockets Require Module
78
+ test_files: []