From 17cddce67593c2d8f11ae7b57ab40fc0a9aa218d Mon Sep 17 00:00:00 2001 From: minusfive Date: Sun, 28 Sep 2014 16:39:46 -0400 Subject: [PATCH] Parse asset-hashes on JSON files --- middleman-core/features/asset_hash.feature | 20 ++++++++++++++++++- .../asset-hash-app/source/api.json.erb | 1 + .../asset-hash-app/source/subdir/api.json.erb | 1 + .../middleman-more/extensions/asset_hash.rb | 2 +- 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 middleman-core/fixtures/asset-hash-app/source/api.json.erb create mode 100644 middleman-core/fixtures/asset-hash-app/source/subdir/api.json.erb diff --git a/middleman-core/features/asset_hash.feature b/middleman-core/features/asset_hash.feature index 59c92d29..a6462098 100644 --- a/middleman-core/features/asset_hash.feature +++ b/middleman-core/features/asset_hash.feature @@ -1,5 +1,5 @@ Feature: Assets get a file hash appended to their and references to them are updated - Scenario: Hashed-asset files are produced, and HTML, CSS, and JavaScript gets rewritten to reference the new files + Scenario: Hashed-asset files are produced, and HTML, CSS, JSON and JavaScript gets rewritten to reference the new files Given a successfully built app at "asset-hash-app" When I cd to "build" Then the following files should exist: @@ -14,6 +14,8 @@ Feature: Assets get a file hash appended to their and references to them are upd | index.html | | subdir/index.html | | other/index.html | + | api.json | + | subdir/api.json | And the following files should not exist: | images/100px.png | | images/100px.jpg | @@ -33,6 +35,12 @@ Feature: Assets get a file hash appended to their and references to them are upd And the file "other/index.html" should contain 'href="../stylesheets/site-50eaa978.css"' And the file "other/index.html" should contain 'src="../javascripts/application-1d8d5276.js"' And the file "other/index.html" should contain 'src="../images/100px-5fd6fb90.jpg"' + And the file "api.json" should contain 'images/100px-5fd6fb90.gif' + And the file "api.json" should contain 'images/100px-5fd6fb90.jpg' + And the file "api.json" should contain 'images/100px-1242c368.png' + And the file "subdir/api.json" should contain 'images/100px-5fd6fb90.gif' + And the file "subdir/api.json" should contain 'images/100px-5fd6fb90.jpg' + And the file "subdir/api.json" should contain 'images/100px-1242c368.png' Scenario: Hashed assets work in preview server Given the Server is running at "asset-hash-app" @@ -53,6 +61,14 @@ Feature: Assets get a file hash appended to their and references to them are upd Then I should see "img.src = '/images/100px-5fd6fb90.jpg'" When I go to "/stylesheets/site-50eaa978.css" Then I should see "background-image: url('../images/100px-5fd6fb90.jpg')" + When I go to "/api.json" + Then I should see 'images/100px-5fd6fb90.gif' + And I should see 'images/100px-5fd6fb90.jpg' + And I should see 'images/100px-1242c368.png' + When I go to "/subdir/api.json" + Then I should see 'images/100px-5fd6fb90.gif' + And I should see 'images/100px-5fd6fb90.jpg' + And I should see 'images/100px-1242c368.png' Scenario: Enabling an asset host still produces hashed files and references Given the Server is running at "asset-hash-host-app" @@ -127,6 +143,8 @@ Feature: Assets get a file hash appended to their and references to them are upd | index.html | | subdir/index.html | | other/index.html | + | api.json | + | subdir/api.json | And the following files should not exist: | images/100px-1242c368.png | | images/100px-5fd6fb90.jpg | diff --git a/middleman-core/fixtures/asset-hash-app/source/api.json.erb b/middleman-core/fixtures/asset-hash-app/source/api.json.erb new file mode 100644 index 00000000..bc2af59a --- /dev/null +++ b/middleman-core/fixtures/asset-hash-app/source/api.json.erb @@ -0,0 +1 @@ +<%= {gif: image_path('100px.gif'), jpg: image_path('100px.jpg'), png: image_path('100px.png')}.to_json %> diff --git a/middleman-core/fixtures/asset-hash-app/source/subdir/api.json.erb b/middleman-core/fixtures/asset-hash-app/source/subdir/api.json.erb new file mode 100644 index 00000000..bc2af59a --- /dev/null +++ b/middleman-core/fixtures/asset-hash-app/source/subdir/api.json.erb @@ -0,0 +1 @@ +<%= {gif: image_path('100px.gif'), jpg: image_path('100px.jpg'), png: image_path('100px.png')}.to_json %> diff --git a/middleman-core/lib/middleman-more/extensions/asset_hash.rb b/middleman-core/lib/middleman-more/extensions/asset_hash.rb index a21eba38..ae5bd0fc 100644 --- a/middleman-core/lib/middleman-more/extensions/asset_hash.rb +++ b/middleman-core/lib/middleman-more/extensions/asset_hash.rb @@ -75,7 +75,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension path = ::Middleman::Util.full_path(env['PATH_INFO'], @middleman_app) - if path =~ /(^\/$)|(\.(htm|html|php|css|js)$)/ + if path =~ /(^\/$)|(\.(htm|html|php|css|js|json)$)/ body = ::Middleman::Util.extract_response_text(response) if body status, headers, response = Rack::Response.new(rewrite_paths(body, path), status, headers).finish