asset 0.1.9 → 0.1.10
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/asset.gemspec +3 -2
- data/lib/asset.rb +8 -12
- data/lib/assets/item.rb +12 -7
- data/lib/assets/router.rb +14 -9
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6867cd26673824ea72eeb8dd0e1cd71fb23fb380
|
4
|
+
data.tar.gz: 9f38ee1241bf966194b86bc7f6949bfe8878584d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7918c2dae433d1f4ac2fc6dc938d65d5afff0546c1346af8f49bc0ce091a5696e200bf04e4094bb05864550ae3f83699e162869e6f17b9a334a39799cd1769a0
|
7
|
+
data.tar.gz: 3941bea2e41d71310309f9ca9379328ba6ca72abd528752872f77b793f97efb5d235c58567aef44e6d6320056d7b019b03329ccc643929448d3d707b723b80e3
|
data/CHANGELOG.md
CHANGED
data/asset.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'asset'
|
3
|
-
s.version = '0.1.
|
4
|
-
s.date = '2017-01-
|
3
|
+
s.version = '0.1.10'
|
4
|
+
s.date = '2017-01-22'
|
5
5
|
s.summary = "Compress and serve your CSS and JS assets automatically"
|
6
6
|
s.description = "The only thing you need for your assets."
|
7
7
|
s.authors = ["Fugroup Limited"]
|
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
|
11
11
|
s.add_runtime_dependency 'rack', '>= 0'
|
12
12
|
s.add_runtime_dependency 'sass', '>= 0'
|
13
|
+
s.add_runtime_dependency 'therubyracer', '>= 0'
|
13
14
|
s.add_runtime_dependency 'uglifier', '>= 0'
|
14
15
|
|
15
16
|
s.add_development_dependency 'sinatra', '>= 0'
|
data/lib/asset.rb
CHANGED
@@ -6,20 +6,20 @@ require 'yaml'
|
|
6
6
|
# @author: Vidar <vidar@fugroup.net>, Fugroup Ltd.
|
7
7
|
# @license: MIT, contributions are welcome.
|
8
8
|
module Asset
|
9
|
-
|
10
9
|
autoload :Uglifier, 'uglifier'
|
11
10
|
autoload :Sass, 'sass'
|
12
11
|
|
13
12
|
class << self; attr_accessor :mode, :path, :cache, :favicon, :robots, :manifest, :bundle, :images, :listener, :debug; end
|
14
13
|
|
15
14
|
# Default is development
|
16
|
-
@mode = ENV['RACK_ENV'] || '
|
15
|
+
@mode = ENV['RACK_ENV'] || 'production'
|
17
16
|
|
18
17
|
# Where your assets live
|
19
18
|
@path = File.join(Dir.pwd, 'app', 'assets')
|
20
19
|
|
21
|
-
# Where to write the cache, default to
|
22
|
-
@cache = File.join(Dir.pwd, 'tmp')
|
20
|
+
# Where to write the cache, default to /tmp
|
21
|
+
# Set to APP_ROOT: @cache = File.join(Dir.pwd, 'tmp')
|
22
|
+
@cache = '/tmp'
|
23
23
|
|
24
24
|
# Automatically bounce (404) for browser /favicon.ico requests
|
25
25
|
@favicon = true
|
@@ -45,13 +45,9 @@ require_relative 'assets/router'
|
|
45
45
|
|
46
46
|
# Run a listener to automatically reload the assets on change
|
47
47
|
if ::Asset.listener and ::Asset.mode == 'development'
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
listener = Listen.to(::Asset.path) do |modified, added, removed|
|
53
|
-
::Asset::Util.setup!
|
54
|
-
end
|
55
|
-
listener.start
|
48
|
+
begin
|
49
|
+
require 'listen'
|
50
|
+
Listen.to(::Asset.path){|m, a, r| ::Asset::Util.setup!}.start if defined?(Listen)
|
51
|
+
rescue LoadError
|
56
52
|
end
|
57
53
|
end
|
data/lib/assets/item.rb
CHANGED
@@ -26,19 +26,24 @@ module Asset
|
|
26
26
|
File.join('/assets', @type, (p? ? @kpath : @path))
|
27
27
|
end
|
28
28
|
|
29
|
-
# Get the content
|
30
|
-
def content(
|
31
|
-
|
29
|
+
# Get the content, will be compressed in production typically.
|
30
|
+
def content(compress = p?)
|
31
|
+
compress ? cached : joined
|
32
32
|
end
|
33
33
|
|
34
34
|
# The cached content
|
35
35
|
def cached
|
36
|
-
|
36
|
+
@cached ||= (read_cache || write_cache)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Read cache
|
40
|
+
def read_cache
|
41
|
+
File.read(cache_path) rescue nil
|
37
42
|
end
|
38
43
|
|
39
44
|
# Store in cache
|
40
|
-
def write_cache
|
41
|
-
File.open(cache_path, 'w'){|f| f.write(
|
45
|
+
def write_cache
|
46
|
+
compressed.tap{|c| File.open(cache_path, 'w'){|f| f.write(c)}}
|
42
47
|
end
|
43
48
|
|
44
49
|
# Cache path
|
@@ -57,7 +62,7 @@ module Asset
|
|
57
62
|
when 'css'
|
58
63
|
Sass::Engine.new(joined, :syntax => :scss, :cache => false, :style => :compressed).render rescue joined
|
59
64
|
when 'js'
|
60
|
-
Uglifier.compile(joined,
|
65
|
+
Uglifier.compile(joined, :mangle => false, :comments => :none) rescue joined
|
61
66
|
end
|
62
67
|
end
|
63
68
|
|
data/lib/assets/router.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module Asset
|
2
|
+
# The Router class is a small Rack middleware that matches the asset URLs
|
3
|
+
# and serves the content, compressed if you are in production mode.
|
2
4
|
class Router
|
3
5
|
|
4
|
-
# Mime types
|
6
|
+
# Mime types for responses
|
5
7
|
MIME = {'js' => 'application/javascript; charset=UTF-8', 'css' => 'text/css; charset=UTF-8', 'txt' => 'text/plain; charset=UTF-8'}
|
6
8
|
|
7
9
|
# Init
|
@@ -19,17 +21,18 @@ module Asset
|
|
19
21
|
|
20
22
|
# Match /assets?/:type/path
|
21
23
|
when /^(\/assets)?\/(js|css)\/(.+)/
|
24
|
+
# Extract type and path
|
22
25
|
type, path = $2, $3
|
23
|
-
|
26
|
+
|
27
|
+
# Extract digest key if any
|
28
|
+
path =~ /-([a-f0-9]{32})\.(css|js)$/
|
24
29
|
path.gsub!("-#{@key}", '') if (@key = $1)
|
25
30
|
|
26
31
|
# Find the item
|
27
32
|
item = ::Asset.manifest.find{|i| i.path == path and i.type == type}
|
28
33
|
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
found(item)
|
34
|
+
# Return the content or not found
|
35
|
+
item ? found(item) : not_found
|
33
36
|
|
34
37
|
# Bounce favicon requests
|
35
38
|
when (::Asset.favicon and /^\/favicon\.ico$/)
|
@@ -49,12 +52,14 @@ module Asset
|
|
49
52
|
|
50
53
|
# Found
|
51
54
|
def found(item)
|
52
|
-
|
53
|
-
|
55
|
+
content = item.content(!!@key)
|
56
|
+
[ 200, {
|
57
|
+
'Content-Type' => MIME[item.type],
|
58
|
+
'Content-Length' => content.size,
|
54
59
|
'Cache-Control' => 'max-age=86400, public',
|
55
60
|
'Expires' => (Time.now + 86400*30).utc.rfc2822,
|
56
61
|
'Last-Modified' => item.modified.utc.rfc2822
|
57
|
-
|
62
|
+
}, [content]]
|
58
63
|
end
|
59
64
|
|
60
65
|
# Not found
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asset
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fugroup Limited
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: therubyracer
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: uglifier
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|