asset 0.1.14 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0748263acb1dc8fa7dafafbaf46759c4e50a28c8
4
- data.tar.gz: f993ae2401bcf3a5dda14a78b9e67490d1148ccb
3
+ metadata.gz: 06536e51676a5659bbf7bdc27bd0813377ad92bd
4
+ data.tar.gz: d81786f8d07370fc9da801f684d65002ef0bfb9a
5
5
  SHA512:
6
- metadata.gz: dd4706519a5da6af9626ccf4baa1464dd754b84f57bdc01835f0f7dbef39f4fe2e0df82aa462be2b620fc385a9821be9ab189bfa399b7fa86f9e34205a37194b
7
- data.tar.gz: acc00c0c65be0bbb717b927725c1c4175c8809e6b0a7e70edf17fae68540c78f1bdb65575ed44d4b278501d66e6fb7c1ca4d91782fd1cb7c6908affc0efacf72
6
+ metadata.gz: 89dcb3239bc7c159af662f557648792ea372ab399e24b449547c53343fae4bbbe3f139256d4f3adb1a678da577ade6f6c1b4cbe11d0bfbfbd41c9050db2015c2
7
+ data.tar.gz: 51592460d1f4cdc4f3a13c26efbb957894d7dcc51cca1270d9ed97c53163da38ee7c0c4fec04abc208a2eeb8a74f179868e16f00f404e58d5f64c51fb4844ee1
@@ -1,3 +1,9 @@
1
+ **Version 0.2.0** - *2017-02-01*
2
+
3
+ - Using atomic_write, adding activesupport as dependency
4
+ - Fixed mime types
5
+ - Adjusted caching
6
+
1
7
  **Version 0.1.14** - *2017-01-27*
2
8
 
3
9
  - Setting bundle last modified to max bundle modified time
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
- use Asset::Router # Include the Asset middleware router
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):
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'asset'
3
- s.version = '0.1.14'
4
- s.date = '2017-01-27'
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'
@@ -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 /tmp
21
- # Set to APP_ROOT: @cache = File.join(Dir.pwd, 'tmp')
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
@@ -43,7 +43,7 @@ module Asset
43
43
 
44
44
  # Store in cache
45
45
  def write_cache
46
- compressed.tap{|c| File.open(cache_path, 'w'){|f| f.write(c)}}
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
@@ -4,7 +4,7 @@ module Asset
4
4
  class Router
5
5
 
6
6
  # Mime types for responses
7
- MIME = {'js' => 'application/javascript; charset=UTF-8', 'css' => 'text/css; charset=UTF-8', 'txt' => 'text/plain; charset=UTF-8'}
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, public',
58
- 'Expires' => (Time.now + 86400*30).utc.rfc2822,
59
- 'Last-Modified' => item.modified.utc.rfc2822
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
 
@@ -63,5 +63,9 @@ module Asset
63
63
  Hash[*img.flatten]
64
64
  end
65
65
 
66
+ # Production mode?
67
+ def self.p?
68
+ %w[staging production].include?(::Asset.mode)
69
+ end
66
70
  end
67
71
  end
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.14
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-27 00:00:00.000000000 Z
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