rack-pipeline 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NGMzODZiZDA2MWQwZmI0MjE3OGE1NDc2MGRhMjFhZDgzZjI5MDI5YQ==
5
- data.tar.gz: !binary |-
6
- YzA0ZGQ1NjU0ODA4YTFlMzcwOTcwYWI3MDBmYWVmN2VhY2M2NDU1NQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZDRhYzM1YjRjZDNkZTI3ZTczOWE5NTZhMzM1MTQ1YzUyZTg5Njg5N2YyYjRj
10
- NDQ2OTBlODgzY2EzZTQwNTQwZGI4MzM1NjI0ZDk5Nzg4MGU3MGYyMmJjZDI3
11
- NTQxOTNmMTMxNTUyZWE1ZjU2NmM0MWQyMmZhMzMwYTcyN2YxNjM=
12
- data.tar.gz: !binary |-
13
- YWExNzc0YzRhZGNkZTlmZDgxMDMwZDY1MWMwMTM1OWI5NmY4ZjBjN2JhOWI1
14
- YWQ2NThjYWFlOThhZDMwYjQ0NDIzMGRmYjFiZTY3NzIxOWQ5MjZiOGViNDNk
15
- OTUxMDA4ZjNjZTMyMTVjZWExOTgyZTVjOWRjM2ZhNGQzNTg1OWY=
2
+ SHA1:
3
+ metadata.gz: 296420a355353f27d4acf162dc4b1190c8929d76
4
+ data.tar.gz: ab491a3ecd555cb76e354c32bde07ec0928a51f9
5
+ SHA512:
6
+ metadata.gz: f4ac3afb4cd65c98415dce496c53dcacee63881f0e43ce684551555327d4790122cde98bbc4a4ec2b669947b1161d6969333c96de024c4f05205e42c80ddafe9
7
+ data.tar.gz: c260d5d346cfbb565a7a88c6031bdfde3b0ee6eb9ae8fcf0853548d054f6d151dc468831bcfdee8a4921e299c2a9580e0795ea252700f3ddffc2ce4851e853de
@@ -15,9 +15,9 @@ module RackPipeline
15
15
  STATIC_TYPES = { '.js' => :js, '.css' => :css }.freeze
16
16
  CONTENT_TYPES = { '.js' => 'application/javascript', '.css' => 'text/css' }.freeze
17
17
 
18
- def assets_for( pipes, type, opts = {} )
18
+ def assets_for(pipes, type, opts = {})
19
19
  Array(pipes).inject([]) do |all,pipe|
20
- all += Array( combine? ? "#{pipe}.#{type}" : assets[type][pipe].keys )
20
+ all += Array(combine? ? "#{pipe}.#{type}" : assets[type][pipe].keys)
21
21
  end.compact.uniq
22
22
  end
23
23
 
@@ -48,7 +48,7 @@ module RackPipeline
48
48
  def call(env)
49
49
  env['rack-pipeline'] = self
50
50
  if file_path = prepare_pipe(env['PATH_INFO'])
51
- serve_file( file_path, env['HTTP_IF_MODIFIED_SINCE'] )
51
+ serve_file(file_path, env['HTTP_IF_MODIFIED_SINCE'])
52
52
  else
53
53
  @app.call(env)
54
54
  end
@@ -59,7 +59,7 @@ module RackPipeline
59
59
 
60
60
  private
61
61
 
62
- def serve_file( file, mtime )
62
+ def serve_file(file, mtime)
63
63
  headers = { 'Last-Modified' => File.mtime(file).httpdate }
64
64
  if mtime == headers['Last-Modified']
65
65
  [304, headers, []]
@@ -73,7 +73,7 @@ module RackPipeline
73
73
  raise MustRepopulate
74
74
  end
75
75
 
76
- def static_type( file )
76
+ def static_type(file)
77
77
  if file.kind_of? String
78
78
  STATIC_TYPES[file] || STATIC_TYPES[File.extname(file)]
79
79
  else
@@ -81,52 +81,53 @@ module RackPipeline
81
81
  end
82
82
  end
83
83
 
84
- def content_type( file )
84
+ def content_type(file)
85
85
  CONTENT_TYPES[File.extname(file)] || 'text'
86
86
  end
87
87
 
88
- def prepare_pipe( path_info )
89
- file = path_info.sub( /^\/(.*)\??.*$/, '\1' )
88
+ def prepare_pipe(path_info)
89
+ file = path_info.sub(/^\/(.*)\??.*$/, '\1')
90
90
  type = static_type(file) or return nil
91
91
  unless ready_file = get_or_compile(file, type)
92
92
  pipename = File.basename(file, '.*').to_sym
93
93
  if assets[type] && assets[type][pipename]
94
- ready_file = combine( assets[type][pipename], File.basename(file) )
94
+ ready_file = combine(assets[type][pipename], File.basename(file))
95
95
  end
96
96
  end
97
- compress ready_file
97
+ compress(ready_file, ready_file) if ready_file
98
98
  rescue Errno::ENOENT
99
99
  raise MustRepopulate
100
100
  end
101
101
 
102
- def get_or_compile( source, type )
102
+ def get_or_compile(source, type)
103
103
  result = nil
104
104
  assets[type].each do |pipe,files|
105
- result = case files[source]
106
- when :raw
107
- source
108
- when :source
109
- compile( source, File.basename(source, '.*') + ".#{type}" )
110
- end
105
+ result =
106
+ case files[source]
107
+ when :raw
108
+ source
109
+ when :source
110
+ compile(source, File.basename(source, '.*') + ".#{type}")
111
+ end
111
112
  break if result
112
113
  end
113
114
  result
114
115
  end
115
116
 
116
- def file_kind( file )
117
+ def file_kind(file)
117
118
  static_type(file) ? :raw : :source
118
119
  end
119
120
 
120
- def extract_files( globs )
121
+ def extract_files(globs)
121
122
  Array(globs).each_with_object({}) do |glob,all|
122
123
  Dir.glob(glob).sort.each do |file|
123
- all[file] = file_kind( file )
124
+ all[file] = file_kind(file)
124
125
  end
125
126
  end
126
127
  end
127
128
 
128
129
  def populate_pipelines
129
- fail( SystemStackError, 'too many RackPipeline generations' ) if @generations > 5
130
+ fail SystemStackError, 'too many RackPipeline generations' if @generations > 5
130
131
  @generations += 1
131
132
  STATIC_TYPES.each do |extname,type|
132
133
  pipes = settings[type]
@@ -3,8 +3,8 @@ require 'fileutils'
3
3
 
4
4
  module RackPipeline
5
5
  module Caching
6
- def cache_target( source, target )
7
- target_path = File.join( settings[:temp], "#{File.basename(target)}.#{calculate_hash(source)}#{File.extname(target)}" )
6
+ def cache_target(source, target)
7
+ target_path = File.join(settings[:temp], "#{File.basename(target)}.#{calculate_hash(source)}#{File.extname(target)}")
8
8
  if File.file?(target_path)
9
9
  target_path
10
10
  else
@@ -18,18 +18,18 @@ module RackPipeline
18
18
  settings[:temp]
19
19
  else
20
20
  require 'tmpdir'
21
- File.join( Dir.tmpdir, 'RackPipeline' )
21
+ File.join(Dir.tmpdir, 'RackPipeline')
22
22
  end
23
23
  FileUtils.mkdir_p temp
24
24
  settings[:temp] = temp
25
25
  end
26
26
 
27
- def cleanup_cache( target )
28
- FileUtils.rm Dir.glob( File.join( settings[:temp], File.basename(target) ) + '.*' )
27
+ def cleanup_cache(target)
28
+ FileUtils.rm Dir.glob(File.join(settings[:temp], File.basename(target)) + '.*')
29
29
  end
30
30
 
31
- def calculate_hash( sources )
32
- Digest::MD5.hexdigest(Array(sources).inject(''){ |all,(file,_)| all << "#{file}:#{File.mtime(file)}" })
31
+ def calculate_hash(sources)
32
+ Digest::MD5.hexdigest(Array(sources).inject(''){ |all,(file,_)| all << "#{file}:#{File.mtime(file).to_i}" })
33
33
  end
34
34
  end
35
35
  end
@@ -1,6 +1,6 @@
1
1
  module RackPipeline
2
2
  module Compiling
3
- def self.process( source, target )
3
+ def self.process(source, target)
4
4
  nil
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  module RackPipeline
2
2
  module Compressing
3
- def self.process( source, target )
3
+ def self.process(source, target)
4
4
  nil
5
5
  end
6
6
  end
@@ -1,38 +1,32 @@
1
+ require 'fileutils'
2
+
1
3
  module RackPipeline
2
4
  module Processing
3
5
  def combine?
4
6
  settings[:combine]
5
7
  end
6
8
 
7
- def compress?
8
- settings[:compress]
9
- end
10
-
11
- def combine( sources, target )
12
- cache_target( sources, target ) do |target_path|
9
+ def combine(sources, target)
10
+ cache_target(sources, target) do |target_path|
13
11
  body = sources.inject('') do |all,(source,kind)|
14
12
  all << File.read(get_or_compile(source, static_type(target))).encode('utf-8') + "\n\n"
15
13
  end
16
- File.write( target_path, body )
14
+ File.write(target_path, body)
17
15
  target_path
18
16
  end
19
17
  end
20
18
 
21
- def compress( source )
22
- if compress? && defined?(Compressor)
23
- Compressor.process source
24
- else
25
- source
19
+ def compress(source, target)
20
+ return source unless settings[:compress] && defined?(Compressor)
21
+ cache_target(source, target) do |target_path|
22
+ Compressor.process(source, target_path)
26
23
  end
27
24
  end
28
25
 
29
- def compile( source, target )
30
- cache_target( source, target ) do |target_path|
31
- compiled_file = if defined? Compiler
32
- Compiler.process source, target_path
33
- end
34
- raise LoadError, "compiler for #{source} => #{target}" unless compiled_file
35
- compiled_file
26
+ def compile(source, target)
27
+ fail LoadError, "no compiler for #{source} => #{target}" unless defined?(Compiler)
28
+ cache_target(source, target) do |target_path|
29
+ Compiler.process(source, target_path)
36
30
  end
37
31
  end
38
32
  end
@@ -4,17 +4,19 @@ module RackPipeline
4
4
  app.use RackPipeline::Base, app.respond_to?(:pipeline) ? app.pipeline : {}
5
5
  app.helpers Helpers
6
6
  end
7
+
7
8
  module Helpers
8
- def pipeline( pipes = [ :app ], types = [ :css, :js ], opts = {} )
9
+ def pipeline(pipes = [ :app ], types = [ :css, :js ], opts = {})
9
10
  Array(types).map do |type|
10
- assets = env['rack-pipeline'].assets_for( pipes, type, opts )
11
+ assets = env['rack-pipeline'].assets_for(pipes, type, opts)
11
12
  assets.map do |asset|
12
- pipe_tag( type, asset )
13
+ pipe_tag(type, asset)
13
14
  end.join("\n")
14
15
  end.join("\n")
15
16
  end
16
17
 
17
- def pipe_tag( type, asset )
18
+ def pipe_tag(type, asset)
19
+ asset += cache_buster(asset)
18
20
  case type.to_sym
19
21
  when :css
20
22
  %(<link href="#{request.script_name}/#{asset}" rel="stylesheet">)
@@ -22,6 +24,24 @@ module RackPipeline
22
24
  %(<script src="#{request.script_name}/#{asset}"></script>)
23
25
  end
24
26
  end
27
+
28
+ def cache_buster(file)
29
+ if File.file?(file)
30
+ "?#{File.mtime(file).to_i}"
31
+ else
32
+ temp = if respond_to?(:settings) && settings.respond_to?(:pipeline) && settings.pipeline[:temp]
33
+ settings.pipeline[:temp]
34
+ else
35
+ require 'tmpdir'
36
+ File.join(Dir.tmpdir, 'RackPipeline')
37
+ end
38
+ mtimes = []
39
+ Dir.glob(File.join(temp,file+'.*')).each do |cached_file|
40
+ mtimes << File.mtime(cached_file).to_i
41
+ end
42
+ "?#{mtimes.max || Time.now.to_i}"
43
+ end
44
+ end
25
45
  end
26
46
  end
27
47
  end
@@ -1,3 +1,3 @@
1
1
  module RackPipeline
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-pipeline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Bochkariov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-20 00:00:00.000000000 Z
11
+ date: 2014-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rack-test
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: awesome_print
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: Asset pipeline for ruby Rack
@@ -87,8 +87,8 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - .gitignore
91
- - .travis.yml
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
92
  - Gemfile
93
93
  - LICENSE.txt
94
94
  - README.md
@@ -119,17 +119,17 @@ require_paths:
119
119
  - lib
120
120
  required_ruby_version: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ! '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  requirements:
127
- - - ! '>='
127
+ - - ">="
128
128
  - !ruby/object:Gem::Version
129
129
  version: '0'
130
130
  requirements: []
131
131
  rubyforge_project:
132
- rubygems_version: 2.0.6
132
+ rubygems_version: 2.2.1
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: A Rack middleware to serve javascript and stylesheet assets for ruby web