asset 0.1.14 → 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/CHANGELOG.md +6 -0
- data/README.md +7 -1
- data/asset.gemspec +3 -2
- data/lib/asset.rb +4 -3
- data/lib/assets/item.rb +7 -6
- data/lib/assets/router.rb +4 -4
- data/lib/assets/util.rb +4 -0
- 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: 06536e51676a5659bbf7bdc27bd0813377ad92bd
|
4
|
+
data.tar.gz: d81786f8d07370fc9da801f684d65002ef0bfb9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89dcb3239bc7c159af662f557648792ea372ab399e24b449547c53343fae4bbbe3f139256d4f3adb1a678da577ade6f6c1b4cbe11d0bfbfbd41c9050db2015c2
|
7
|
+
data.tar.gz: 51592460d1f4cdc4f3a13c26efbb957894d7dcc51cca1270d9ed97c53163da38ee7c0c4fec04abc208a2eeb8a74f179868e16f00f404e58d5f64c51fb4844ee1
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -83,7 +83,12 @@ use Asset::Router
|
|
83
83
|
|
84
84
|
# Set up middleware stack
|
85
85
|
app = Rack::Builder.new do
|
86
|
-
|
86
|
+
|
87
|
+
# Use Rack::Cache to enable 304 for last modified
|
88
|
+
use Rack::Cache
|
89
|
+
|
90
|
+
# Include the Asset middleware router
|
91
|
+
use Asset::Router
|
87
92
|
|
88
93
|
# Use this setup to have files served from /assets/images and /assets/fonts
|
89
94
|
use Rack::Static, :urls => ['/images', '/fonts'], :root => APP_ASSETS,
|
@@ -94,6 +99,7 @@ app = Rack::Builder.new do
|
|
94
99
|
run App # Your app goes here
|
95
100
|
end
|
96
101
|
|
102
|
+
# Run app
|
97
103
|
run app
|
98
104
|
|
99
105
|
# Files will be available here on your server (HTTP):
|
data/asset.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'asset'
|
3
|
-
s.version = '0.
|
4
|
-
s.date = '2017-01
|
3
|
+
s.version = '0.2.0'
|
4
|
+
s.date = '2017-02-01'
|
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"]
|
@@ -12,6 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.add_runtime_dependency 'sass', '>= 0'
|
13
13
|
s.add_runtime_dependency 'therubyracer', '>= 0'
|
14
14
|
s.add_runtime_dependency 'uglifier', '>= 0'
|
15
|
+
s.add_runtime_dependency 'activesupport', '>= 0'
|
15
16
|
|
16
17
|
s.add_development_dependency 'sinatra', '>= 0'
|
17
18
|
s.add_development_dependency 'puma', '>= 0'
|
data/lib/asset.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'rack'
|
2
2
|
require 'yaml'
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/core_ext'
|
3
5
|
|
4
6
|
# Asset packer, middleware and helpers
|
5
7
|
# @homepage: https://github.com/fugroup/asset
|
@@ -17,9 +19,8 @@ module Asset
|
|
17
19
|
# Where your assets live
|
18
20
|
@path = File.join(Dir.pwd, 'app', 'assets')
|
19
21
|
|
20
|
-
# Where to write the cache, default to
|
21
|
-
|
22
|
-
@cache = '/tmp'
|
22
|
+
# Where to write the cache, default to ./tmp
|
23
|
+
@cache = File.join(Dir.pwd, 'tmp')
|
23
24
|
|
24
25
|
# Automatically bounce (404) for browser /favicon.ico requests
|
25
26
|
@favicon = true
|
data/lib/assets/item.rb
CHANGED
@@ -43,7 +43,7 @@ module Asset
|
|
43
43
|
|
44
44
|
# Store in cache
|
45
45
|
def write_cache
|
46
|
-
compressed.tap{|c| File.
|
46
|
+
compressed.tap{|c| File.atomic_write(cache_path){|f| f.write(c)}}
|
47
47
|
end
|
48
48
|
|
49
49
|
# Cache path
|
@@ -71,15 +71,16 @@ module Asset
|
|
71
71
|
@joined ||= files.map{|f| File.read(File.join(::Asset.path, @type, f))}.join
|
72
72
|
end
|
73
73
|
|
74
|
-
# Production mode?
|
75
|
-
def p?
|
76
|
-
%w[staging production].include?(::Asset.mode)
|
77
|
-
end
|
78
|
-
|
79
74
|
# Print data
|
80
75
|
def print
|
81
76
|
[:path, :type, :key, :name, :modified, :files, :content].map{|r| "#{r.upcase}: #{send(r).inspect}"}.join("\n")
|
82
77
|
end
|
83
78
|
|
79
|
+
private
|
80
|
+
|
81
|
+
# Production mode?
|
82
|
+
def p?
|
83
|
+
::Asset::Util.p?
|
84
|
+
end
|
84
85
|
end
|
85
86
|
end
|
data/lib/assets/router.rb
CHANGED
@@ -4,7 +4,7 @@ module Asset
|
|
4
4
|
class Router
|
5
5
|
|
6
6
|
# Mime types for responses
|
7
|
-
MIME = {'js' => 'application/javascript;
|
7
|
+
MIME = {'js' => 'application/javascript;charset=utf-8', 'css' => 'text/css;charset=utf-8', 'txt' => 'text/plain;charset=utf-8'}
|
8
8
|
|
9
9
|
# Init
|
10
10
|
def initialize(app)
|
@@ -54,9 +54,9 @@ module Asset
|
|
54
54
|
content = item.content(!!@key)
|
55
55
|
[ 200, {'Content-Type' => MIME[item.type],
|
56
56
|
'Content-Length' => content.size,
|
57
|
-
'Cache-Control' => 'max-age=86400
|
58
|
-
'Expires' => (Time.now + 86400*30).
|
59
|
-
'Last-Modified' => item.modified.
|
57
|
+
'Cache-Control' => 'public, max-age=86400',
|
58
|
+
'Expires' => (Time.now.utc + (86400 * 30)).httpdate,
|
59
|
+
'Last-Modified' => item.modified.httpdate,
|
60
60
|
}, [content]]
|
61
61
|
end
|
62
62
|
|
data/lib/assets/util.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
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-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: sinatra
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|