assets_live_compile 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -5
- data/assets_live_compile.gemspec +1 -1
- data/lib/assets_live_compile.rb +17 -11
- data/lib/sprockets/cache/assets_live_compile_store.rb +26 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d95961ea4f5f654297c681787f51f8d9d5a1f62
|
4
|
+
data.tar.gz: d1dae004759ca1a837e5598d426b30b6bcfcf3ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd0254b974221ca2f8a366309b3feee61aefdaf96a82458dfd7d1488a74a67c4dd4c93440c2705ddd8cbebc2c8f54b3798337e70ee0d281a08272f6c858637fc
|
7
|
+
data.tar.gz: 7908f11e3402a70b92d5b9c3d40af37d07de2f415d99e53025f3e1ef2f71e254f9ae02d6f306eaa9c86973815ba9fb31179804cdb2925f6e86484cb6b2b46d4d
|
data/README.md
CHANGED
@@ -1,16 +1,40 @@
|
|
1
1
|
assets_live_compile
|
2
|
-
|
2
|
+
===================
|
3
3
|
Compile and save assets on demand instead of using `rake assets:precompile`
|
4
4
|
|
5
|
-
This works just like `rake assets:precompile` but is triggered on the asset HTTP request, so the cost of compilation is due to the first asset request.
|
5
|
+
This works just like `rake assets:precompile` but is triggered on the asset HTTP request, so the cost of compilation is due to the first asset request.
|
6
|
+
|
7
|
+
`assets_live_compile` will save the file on `public/assets`, exactly how `rake assets:precompile` would do. Next time Nginx will find the static asset there and the Rails app won't be reached.
|
6
8
|
|
7
9
|
Compile your assets by doing a warm up request :)
|
8
10
|
|
9
11
|
Configuration
|
10
12
|
-------------
|
13
|
+
Add it to your Gemfile:
|
14
|
+
```ruby
|
15
|
+
group :assets do
|
16
|
+
gem 'assets_live_compile'
|
17
|
+
...
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
On `config/application.rb`, load the `:assets` group of the `Gemfile`:
|
22
|
+
```ruby
|
23
|
+
Bundler.require :default, :assets, Rails.env
|
24
|
+
```
|
11
25
|
|
12
|
-
|
13
|
-
config.assets.compile = true
|
14
|
-
config.assets.cache_store = :assets_live_compile_store
|
26
|
+
Then configure `config/environments/production.rb`,
|
15
27
|
|
28
|
+
On Rails 4:
|
29
|
+
```ruby
|
30
|
+
config.assets.serve_static_assets = true
|
31
|
+
config.assets.configure do |env|
|
32
|
+
env.cache = Sprockets::Cache::AssetsLiveCompileStore.new
|
33
|
+
end
|
34
|
+
```
|
16
35
|
|
36
|
+
On Rails 3:
|
37
|
+
```ruby
|
38
|
+
config.assets.serve_static_assets = true
|
39
|
+
config.assets.cache_store = :assets_live_compile_store
|
40
|
+
```
|
data/assets_live_compile.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "assets_live_compile"
|
5
5
|
s.license = "LGPL-3.0"
|
6
|
-
s.version = '0.
|
6
|
+
s.version = '0.2.0'
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.authors = ["Braulio Bhavamitra"]
|
9
9
|
s.email = ["brauliobo@gmail.com"]
|
data/lib/assets_live_compile.rb
CHANGED
@@ -1,18 +1,24 @@
|
|
1
|
-
require 'active_support/cache'
|
2
1
|
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
if Rails::VERSION::STRING > '4.0.0'
|
3
|
+
require 'sprockets/cache/assets_live_compile_store'
|
4
|
+
else
|
5
|
+
require 'active_support/cache'
|
6
|
+
require 'active_support/cache/assets_live_compile_store'
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
module ActiveSupport
|
9
|
+
module Cache
|
10
|
+
autoload :AssetsLiveCompileStore, 'active_support/cache/assets_live_compile_store'
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
class Entry
|
13
|
+
attr_accessor :original_value
|
14
|
+
|
15
|
+
def initialize_with_original_value value, options = {}
|
16
|
+
@original_value = value
|
17
|
+
initialize_without_original_value value, options
|
18
|
+
end
|
19
|
+
alias_method_chain :initialize, :original_value
|
15
20
|
|
21
|
+
end
|
16
22
|
end
|
17
23
|
end
|
18
24
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'sprockets/cache/file_store'
|
2
|
+
|
3
|
+
module Sprockets
|
4
|
+
class Cache
|
5
|
+
class AssetsLiveCompileStore
|
6
|
+
|
7
|
+
def initialize options = {}
|
8
|
+
@root = "#{::Rails.root}/public/assets"
|
9
|
+
end
|
10
|
+
|
11
|
+
def get key
|
12
|
+
# no-op, maybe warn to serve it statically
|
13
|
+
end
|
14
|
+
|
15
|
+
def set key, attributes
|
16
|
+
return unless attributes.is_a? Hash and (logical_path = attributes[:logical_path]).present?
|
17
|
+
return if logical_path.index '.self.' and !::Rails.application.config.assets.debug
|
18
|
+
asset = Sprockets::Asset.new nil, attributes
|
19
|
+
path = File.join @root, asset.digest_path.strip
|
20
|
+
FileUtils.mkdir_p File.dirname(path)
|
21
|
+
File.open(path, 'wb'){ |f| f.write asset.source }
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assets_live_compile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Braulio Bhavamitra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- assets_live_compile.gemspec
|
52
52
|
- lib/active_support/cache/assets_live_compile_store.rb
|
53
53
|
- lib/assets_live_compile.rb
|
54
|
+
- lib/sprockets/cache/assets_live_compile_store.rb
|
54
55
|
homepage: http://github.com/coletivoEITA/assets_live_compile
|
55
56
|
licenses:
|
56
57
|
- LGPL-3.0
|
@@ -71,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
72
|
version: '0'
|
72
73
|
requirements: []
|
73
74
|
rubyforge_project:
|
74
|
-
rubygems_version: 2.4.
|
75
|
+
rubygems_version: 2.4.5.1
|
75
76
|
signing_key:
|
76
77
|
specification_version: 4
|
77
78
|
summary: Compile and save assets on demand instead of using rake assets:precompile
|