assets_precompile_enforcer 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Include rake in Gemfile so that `bundle exec rake` doesn't raise an error
4
+ gem 'rake', :group => :test
5
+
6
+ # Specify your gem's dependencies in assets_precompile_enforcer.gemspec
7
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Nathan Broadbent
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,59 @@
1
+ # Assets Precompile Enforcer
2
+
3
+ This gem ensures that developers won't forget to add assets to `config.assets.precompile` while they are developing.
4
+ An exception will be raised if you include an asset via `javascript_include_tag` or `stylesheet_link_tag`,
5
+ and it doesn't match a filter in `config.assets.precompile`.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile, in the `development` group:
10
+
11
+ group :development do
12
+ gem 'assets_precompile_enforcer'
13
+ end
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install assets_precompile_enforcer
22
+
23
+ ## Usage
24
+
25
+ You will need to move your `config.assets.precompile += ...` setting into `config/application.rb`, instead of `config/environments/production.rb`. (This setting needs to be shared across development and production.)
26
+
27
+ You also need to add the following line to `config/environments/development.rb`:
28
+
29
+ config.assets.enforce_precompile = true
30
+
31
+
32
+ You will need to restart your Rails server whenever you make any changes to `config.assets.precompile`.
33
+
34
+
35
+ ## Advanced Usage
36
+
37
+ To avoid restarting your server when you change `config.assets.precompile`, create a new file at: `config/assets_precompile.rb`, containing:
38
+
39
+ unless defined?(OriginalAssetsPrecompile)
40
+ OriginalAssetsPrecompile = Rails.application.config.assets.precompile.dup
41
+ end
42
+ Rails.application.config.assets.precompile = OriginalAssetsPrecompile + %w( extra_assets.js )
43
+
44
+ Add the following lines to `config/application.rb`:
45
+
46
+ # Reload config/assets_precompile when changed
47
+ config.to_prepare { load 'config/assets_precompile.rb' }
48
+ config.watchable_files << 'config/assets_precompile.rb'
49
+
50
+ Now you will be able to make changes to `config/assets_precompile.rb` without needing to restart your server.
51
+
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'assets_precompile_enforcer/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "assets_precompile_enforcer"
8
+ gem.version = AssetsPrecompileEnforcer::VERSION
9
+ gem.authors = ["Nathan Broadbent"]
10
+ gem.email = ["nathan.f77@gmail.com"]
11
+ gem.description = %q{Raises an exception if assets are missing from config.assets.precompile during development}
12
+ gem.summary = %q{Enforces config.assets.precompile in development}
13
+ gem.homepage = "https://github.com/ndbroadbent/assets_precompile_enforcer"
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+ end
@@ -0,0 +1,2 @@
1
+ require "assets_precompile_enforcer/version"
2
+ require "assets_precompile_enforcer/sprockets/helpers/rails_helper"
@@ -0,0 +1,43 @@
1
+ require 'sprockets/helpers/rails_helper'
2
+
3
+ module Sprockets
4
+ module Helpers
5
+ module RailsHelper
6
+ def javascript_include_tag_with_enforced_precompile(*sources)
7
+ sources_without_options(sources).each do |source|
8
+ ensure_asset_will_be_precompiled!(source, 'js') if enforce_precompile?
9
+ end
10
+ javascript_include_tag_without_enforced_precompile(*sources)
11
+ end
12
+ alias_method_chain :javascript_include_tag, :enforced_precompile
13
+
14
+ def stylesheet_link_tag_with_enforced_precompile(*sources)
15
+ sources_without_options(sources).each do |source|
16
+ ensure_asset_will_be_precompiled!(source, 'js') if enforce_precompile?
17
+ end
18
+ stylesheet_link_tag_without_enforced_precompile(*sources)
19
+ end
20
+ alias_method_chain :stylesheet_link_tag, :enforced_precompile
21
+
22
+
23
+ private
24
+
25
+ def sources_without_options(sources)
26
+ sources.last.is_a?(Hash) && sources.last.extractable_options? ? sources[0..-2] : sources
27
+ end
28
+
29
+ def enforce_precompile?
30
+ Rails.application.config.assets.enforce_precompile
31
+ end
32
+
33
+ def ensure_asset_will_be_precompiled!(source, ext)
34
+ asset_file = asset_paths.rewrite_extension(source, nil, ext)
35
+ unless asset_environment.send(:matches_filter, Rails.application.config.assets.precompile, asset_file)
36
+ raise AssetPaths::AssetNotPrecompiledError.new("#{asset_file} must be added to config.assets.precompile, " <<
37
+ "otherwise it won't be precompiled for production!")
38
+ end
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module AssetsPrecompileEnforcer
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: assets_precompile_enforcer
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nathan Broadbent
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-10 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Raises an exception if assets are missing from config.assets.precompile
15
+ during development
16
+ email:
17
+ - nathan.f77@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - assets_precompile_enforcer.gemspec
28
+ - lib/assets_precompile_enforcer.rb
29
+ - lib/assets_precompile_enforcer/sprockets/helpers/rails_helper.rb
30
+ - lib/assets_precompile_enforcer/version.rb
31
+ homepage: https://github.com/ndbroadbent/assets_precompile_enforcer
32
+ licenses:
33
+ - MIT
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ segments:
45
+ - 0
46
+ hash: 2558813322742905652
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ segments:
54
+ - 0
55
+ hash: 2558813322742905652
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.24
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Enforces config.assets.precompile in development
62
+ test_files: []