middleman-more 3.0.4 → 3.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -84,4 +84,23 @@ Feature: Assets get a file hash appended to their and references to them are upd
84
84
  font-size: 18px !important
85
85
  """
86
86
  When I go to "/partials/"
87
- Then I should see 'href="../stylesheets/uses_partials-e8c3d4eb.css'
87
+ Then I should see 'href="../stylesheets/uses_partials-e8c3d4eb.css'
88
+
89
+ Scenario: The asset hash should change when a Rack-based filter changes
90
+ Given a fixture app "asset-hash-app"
91
+ And a file named "config.rb" with:
92
+ """
93
+ activate :asset_hash
94
+ activate :relative_assets
95
+ activate :directory_indexes
96
+ require 'lib/middleware.rb'
97
+ use Middleware
98
+ """
99
+ Given the Server is running at "asset-hash-app"
100
+ When I go to "/"
101
+ Then I should see 'href="stylesheets/site-5770af52.css'
102
+ When I go to "stylesheets/site-5770af52.css"
103
+ Then I should see 'background-image'
104
+ Then I should see 'Added by Rack filter'
105
+ When I go to "stylesheets/site-50eaa978.css"
106
+ Then I should see 'Not Found'
@@ -0,0 +1,16 @@
1
+ class Middleware
2
+ def initialize(app)
3
+ @app = app
4
+ end
5
+
6
+ def call(env)
7
+ status, headers, response = @app.call(env)
8
+ body = ''
9
+ response.each {|part| body += part }
10
+ if (env["PATH_INFO"] =~ /css$/)
11
+ body += "\n/* Added by Rack filter */"
12
+ status, headers, response = Rack::Response.new(body, status, headers).finish
13
+ end
14
+ [status, headers, response]
15
+ end
16
+ end
@@ -29,20 +29,18 @@ module Middleman
29
29
  module Helpers
30
30
  # Output a stylesheet link tag based on the current path
31
31
  #
32
- # @param [String] separator How to break up path in parts
33
32
  # @return [String]
34
- def auto_stylesheet_link_tag(separator="/")
35
- auto_tag(:css, separator) do |path|
33
+ def auto_stylesheet_link_tag
34
+ auto_tag(:css) do |path|
36
35
  stylesheet_link_tag path
37
36
  end
38
37
  end
39
38
 
40
39
  # Output a javascript tag based on the current path
41
40
  #
42
- # @param [String] separator How to break up path in parts
43
41
  # @return [String]
44
- def auto_javascript_include_tag(separator="/")
45
- auto_tag(:js, separator) do |path|
42
+ def auto_javascript_include_tag
43
+ auto_tag(:js) do |path|
46
44
  javascript_include_tag path
47
45
  end
48
46
  end
@@ -53,7 +51,7 @@ module Middleman
53
51
  # @param [String] separator How to break up path in parts
54
52
  # @param [String] asset_dir Where to look for assets
55
53
  # @return [void]
56
- def auto_tag(asset_ext, separator="/", asset_dir=nil)
54
+ def auto_tag(asset_ext, asset_dir=nil)
57
55
  if asset_dir.nil?
58
56
  asset_dir = case asset_ext
59
57
  when :js then js_dir
@@ -63,12 +61,10 @@ module Middleman
63
61
 
64
62
  # If the basename of the request as no extension, assume we are serving a
65
63
  # directory and join index_file to the path.
66
- path = full_path(current_path.dup)
67
- path = path.sub(%r{^/}, '')
64
+ path = File.join(asset_dir, current_path)
68
65
  path = path.gsub(File.extname(path), ".#{asset_ext}")
69
- path = path.gsub("/", separator)
70
66
 
71
- yield path if sitemap.find_resource_by_path(File.join(asset_dir, path))
67
+ yield path if sitemap.find_resource_by_path(path)
72
68
  end
73
69
 
74
70
  # Generate body css classes based on the current path
@@ -130,7 +126,7 @@ module Middleman
130
126
  args[url_arg_index] = url.url
131
127
  elsif url.include? '://'
132
128
  raise "Can't use the relative option with an external URL" if relative
133
- else
129
+ elsif current_resource
134
130
  # Handle relative urls
135
131
  current_source_dir = Pathname('/' + current_resource.path).dirname
136
132
 
@@ -14,6 +14,7 @@ module Middleman
14
14
  :asset_hash,
15
15
  AssetHashManager.new(self, exts, ignore)
16
16
  )
17
+
17
18
  use Middleware, :exts => exts, :middleman_app => self, :ignore => ignore
18
19
  end
19
20
  end
@@ -36,7 +37,12 @@ module Middleman
36
37
  next if @ignore.any? { |ignore| Middleman::Util.path_match(ignore, resource.destination_path) }
37
38
 
38
39
  if resource.template? # if it's a template, render it out
39
- digest = Digest::SHA1.hexdigest(resource.render)[0..7]
40
+ # Render through the Rack interface so middleware and mounted apps get a shot
41
+ rack_client = ::Rack::Test::Session.new(@app.class)
42
+ response = rack_client.get(URI.escape(resource.destination_path), {}, { "bypass_asset_hash" => true })
43
+ raise "#{resource.path} should be in the sitemap!" unless response.status == 200
44
+
45
+ digest = Digest::SHA1.hexdigest(response.body)[0..7]
40
46
  else # if it's a static file, just hash it
41
47
  digest = Digest::SHA1.file(resource.source_file).hexdigest[0..7]
42
48
  end
@@ -60,6 +66,9 @@ module Middleman
60
66
  def call(env)
61
67
  status, headers, response = @rack_app.call(env)
62
68
 
69
+ # We don't want to use this middleware when rendering files to figure out their hash!
70
+ return [status, headers, response] if env["bypass_asset_hash"]
71
+
63
72
  path = @middleman_app.full_path(env["PATH_INFO"])
64
73
  dirpath = Pathname.new(File.dirname(path))
65
74
 
@@ -10,7 +10,7 @@ module Middleman
10
10
 
11
11
  # Once registered
12
12
  def registered(app)
13
- app.ready do
13
+ app.after_configuration do
14
14
  sitemap.register_resource_list_manipulator(
15
15
  :directory_indexes,
16
16
  DirectoryIndexManager.new(self)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-more
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.4
4
+ version: 3.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-13 00:00:00.000000000 Z
13
+ date: 2012-09-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: middleman-core
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 3.0.4
22
+ version: 3.0.5
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,7 +27,7 @@ dependencies:
27
27
  requirements:
28
28
  - - '='
29
29
  - !ruby/object:Gem::Version
30
- version: 3.0.4
30
+ version: 3.0.5
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: uglifier
33
33
  requirement: !ruby/object:Gem::Requirement
@@ -246,6 +246,7 @@ files:
246
246
  - features/twitter-bootstrap-compile.feature
247
247
  - features/wildcard_page_helper.feature
248
248
  - fixtures/asset-hash-app/config.rb
249
+ - fixtures/asset-hash-app/lib/middleware.rb
249
250
  - fixtures/asset-hash-app/source/apple-touch-icon.png
250
251
  - fixtures/asset-hash-app/source/favicon.ico
251
252
  - fixtures/asset-hash-app/source/images/100px.gif
@@ -631,7 +632,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
631
632
  version: '0'
632
633
  segments:
633
634
  - 0
634
- hash: 1858392272674889223
635
+ hash: 4494710196171968679
635
636
  required_rubygems_version: !ruby/object:Gem::Requirement
636
637
  none: false
637
638
  requirements:
@@ -640,10 +641,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
640
641
  version: '0'
641
642
  segments:
642
643
  - 0
643
- hash: 1858392272674889223
644
+ hash: 4494710196171968679
644
645
  requirements: []
645
646
  rubyforge_project:
646
- rubygems_version: 1.8.23
647
+ rubygems_version: 1.8.24
647
648
  signing_key:
648
649
  specification_version: 3
649
650
  summary: Hand-crafted frontend development
@@ -692,6 +693,7 @@ test_files:
692
693
  - features/twitter-bootstrap-compile.feature
693
694
  - features/wildcard_page_helper.feature
694
695
  - fixtures/asset-hash-app/config.rb
696
+ - fixtures/asset-hash-app/lib/middleware.rb
695
697
  - fixtures/asset-hash-app/source/apple-touch-icon.png
696
698
  - fixtures/asset-hash-app/source/favicon.ico
697
699
  - fixtures/asset-hash-app/source/images/100px.gif