sprockets-standalone 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: b8e9f6ac3e8f85cf287ea6dfbacf6a08aba5f99c
4
+ data.tar.gz: d4c5ccf8289a5fcab7f440486477afef57d798ea
5
+ SHA512:
6
+ metadata.gz: 420a85498a000269a84538180da92b00c92a1c709e7dddba022f06bc2267dc9da5a4daf5b54b224560d12e9f63c8e112002988a517ee609476928a4c56ef2fab
7
+ data.tar.gz: 2d07ec52eead8c489ffe7c67002ec1fd80aedc8061a7589aea2af5a6921829983b13e9a92a93cf842dd82fb60fca345ee2e6f8a83fb8b15ab58b1a47c69b56bc
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jan Graichen
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,65 @@
1
+ # Sprockets::Standalone
2
+
3
+ Rack task library for using Sprockets standalone.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sprockets-standalone'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sprockets-standalone
18
+
19
+ ## Usage
20
+
21
+ Require sprockets-standalone in your Rakefile and define the task:
22
+
23
+ ```
24
+ require 'sprockets/standalone'
25
+
26
+ Sprockets::Standalone::RakeTask.new(:assets) do |task, sprockets|
27
+ task.assets = %w(app.js app.css *.png *.svg *.woff)
28
+ task.sources = %w(app/assets vendor/assets)
29
+ task.output = File.expand_path('../assets', __FILE__)
30
+ task.compress = false
31
+ task.digest = false
32
+
33
+ sprockets.js_compressor = :uglifier
34
+ sprockets.css_compressor = :sass
35
+ end
36
+ ```
37
+
38
+ You can give a name to the task that will be used for namespacing. The example above will generate the rake tasks`assets:compile`, `assets:clobber` and `assets:clean`. Default value for name is `assets`.
39
+
40
+ If you pass a block you can configure additional parameters:
41
+
42
+ 1) `task.assets` - Defines the list of assets that should be compiled for you. By default it contains `application.js`, `application.css` and `*.png`, `*.jpg`, `*.gif`.
43
+
44
+ 2) `task.source` - Defines a list of source directories. The specified paths will be added to sprockets' include path. If you want a sprockets directory structure similar to Rails you need to add all paths: `task.sources = %w(app/assets/javascripts app/assets/stylesheets app/assets/images)`.
45
+
46
+ 3) `task.output` - Define output directory. Default is `dist`.
47
+
48
+ 4) `task.compress` - Set to true if you want pre-compressed assets. Default is false.
49
+
50
+ 5) `task.digest` - Set to true if you want to include a file digest in the file name of generated assets. Default is false.
51
+
52
+ 6) `task.environment` - Set custom sprockets environment.
53
+
54
+ You can also customize the sprockets environment in the block to configure additional preprocessors or compressors.
55
+
56
+ Note: Sprockets-standalone will always use a manifest.json even when asset digests are turned off. The manifest.json will be used to track changes. If you manually change the generated assets that will not be override when compiling assets unless there is also a change if the matching source files.
57
+ You will need to remove generated assets (`rake assets:clobber`) to force regeneration of all assets.
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it ( http://github.com/jgraichen/sprockets-standalone/fork )
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create new Pull Request
@@ -0,0 +1,5 @@
1
+ module Sprockets
2
+ module Standalone
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,140 @@
1
+ require "sprockets/standalone/version"
2
+ require "rake"
3
+ require "rake/tasklib"
4
+ require "sprockets"
5
+
6
+ module Sprockets
7
+ module Standalone
8
+ class RakeTask < ::Rake::TaskLib
9
+ # List of sprocket file targets that
10
+ # should be compiled.
11
+ attr_accessor :assets
12
+
13
+ # List of source directories. This is a convenience
14
+ # method as it will add all available sub-directories
15
+ # like `stylesheets`, `javascripts` to sprockets
16
+ # include path.
17
+ #
18
+ # Example: If you have a typical sprockets directory
19
+ # layout like `src/assets/stylesheets`,
20
+ # `src/assets/javascripts` all you need to add to
21
+ # `source` is `src/assets`.
22
+ attr_accessor :sources
23
+
24
+ # Set output directory. Defaults to `dist` in current
25
+ # working directory.
26
+ attr_accessor :output
27
+
28
+ # If assets should include digest. Default is false.
29
+ attr_accessor :digest
30
+
31
+ # `Environment` instance used for finding assets.
32
+ attr_accessor :environment
33
+
34
+ def index
35
+ @index ||= environment.index if environment
36
+ end
37
+
38
+ def manifest
39
+ @manifest ||= Sprockets::Standalone::Manifest.new index, File.join(output, "manifest.json")
40
+ end
41
+
42
+ def initialize(*args)
43
+ @namespace = args.shift || :assets
44
+ @assets = %w(application.js application.css *.png *.jpg *.gif)
45
+ @sources = []
46
+ @output = File.expand_path('dist', Dir.pwd)
47
+ @digest = false
48
+ @compress = false
49
+
50
+ @environment = Sprockets::Environment.new(Dir.pwd) do |env|
51
+ env.logger = Logger.new $stdout
52
+ env.logger.level = Logger::INFO
53
+ end
54
+
55
+ yield self, environment if block_given?
56
+
57
+ Array(sources).each { |source| environment.append_path source }
58
+
59
+ manifest.compress_assets = !!@compress
60
+ manifest.digest_assets = !!@digest
61
+
62
+ namespace @namespace do
63
+ desc 'Compile assets'
64
+ task :compile do
65
+ manifest.compile *Array(assets)
66
+ end
67
+
68
+ desc 'Remove all assets'
69
+ task :clobber do
70
+ manifest.clobber
71
+ end
72
+
73
+ desc 'Clean old assets'
74
+ task :clean do
75
+ manifest.clean
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ class Manifest < ::Sprockets::Manifest
82
+ attr_writer :digest_assets
83
+ def digest_assets?
84
+ !!@digest_assets
85
+ end
86
+
87
+ attr_writer :compress_assets
88
+ def compress_assets?
89
+ !!@compress_assets
90
+ end
91
+
92
+ def compile(*args)
93
+ unless environment
94
+ raise Error, "manifest requires environment for compilation"
95
+ end
96
+
97
+ paths = environment.each_logical_path(*args).to_a +
98
+ args.flatten.select { |fn| Pathname.new(fn).absolute? if fn.is_a?(String)}
99
+
100
+ if (missing_paths = (args.reject{|p| p.include?('*')} - paths)).any?
101
+ missing_paths.each do |path|
102
+ logger.warn "Asset #{path} not found."
103
+ end
104
+ end
105
+
106
+ paths.each do |path|
107
+ if asset = find_asset(path)
108
+ compile_asset asset
109
+ end
110
+ end
111
+ save
112
+ paths
113
+ end
114
+
115
+ def compile_asset(asset)
116
+ path = digest_assets? ? asset.digest_path : asset.logical_path
117
+ target = File.join(dir, path)
118
+
119
+ if files[path] && (digest = files[path]['digest'])
120
+ if digest == asset.digest && File.exists?(target)
121
+ logger.info "Skipping #{target}, up-to-date"
122
+ return
123
+ end
124
+ end
125
+
126
+ files[path] = {
127
+ 'logical_path' => asset.logical_path,
128
+ 'mtime' => asset.mtime.iso8601,
129
+ 'size' => asset.bytesize,
130
+ 'digest' => asset.digest
131
+ }
132
+ assets[asset.logical_path] = path
133
+
134
+ logger.info "Writing #{target}"
135
+ asset.write_to target
136
+ asset.write_to "#{target}.gz" if asset.is_a?(BundledAsset) && compress_assets?
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sprockets/standalone/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sprockets-standalone"
8
+ spec.version = Sprockets::Standalone::VERSION
9
+ spec.authors = ["Jan Graichen"]
10
+ spec.email = ["jg@altimos.de"]
11
+ spec.summary = %q{Rack task library for using Sprockets standalone.}
12
+ spec.description = %q{Rack task library for using Sprockets standalone.}
13
+ spec.homepage = "https://github.com/jgraichen/sprockets-standalone"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = Dir["**/*"].grep(%r{^((bin|lib|spec)/|.*\.gemspec|.*LICENSE.*|.*README.*)})
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rake"
22
+ spec.add_dependency "sprockets", "~> 2.10"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.4"
25
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sprockets-standalone
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jan Graichen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sprockets
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.10'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '2.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.4'
55
+ description: Rack task library for using Sprockets standalone.
56
+ email:
57
+ - jg@altimos.de
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - README.md
63
+ - lib/sprockets/standalone/version.rb
64
+ - lib/sprockets/standalone.rb
65
+ - sprockets-standalone.gemspec
66
+ - LICENSE.txt
67
+ homepage: https://github.com/jgraichen/sprockets-standalone
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.1.11
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Rack task library for using Sprockets standalone.
91
+ test_files: []