diff --git a/.rubocop.yml b/.rubocop.yml
index dbd74993..c92b709f 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -67,3 +67,5 @@ Style/MultilineBlockChain:
Enabled: false
Style/SpecialGlobalVars:
Enabled: false
+Style/FrozenStringLiteralComment:
+ Enabled: false
diff --git a/.travis.yml b/.travis.yml
index e6bc197b..ac5a7f06 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,8 +7,6 @@ rvm:
- ruby-head
- 2.3.1
- 2.2.4
- - 2.1
- - 2.0
os:
- linux
# - osx
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7e4e2f4b..148aa2e2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,14 +1,41 @@
master
===
-# 4.2.0
+# 4.1.13
-* Remove Rack support in favor of `resource.filters << proc { |oldbody| newbody }`
-* Expose `development?` and `production?` helpers to template context.
+* Change how config options are passed to Thor. Removes new Thor warnings from #2017
+
+# 4.1.12
+
+* Fix broken `ignore { |p| true }` form.
+
+# 4.1.11
+
+* Upgrade to Rack 2.
+
+# 4.1.10
+
+* Fix unicode issues in URL deeplinks.
+* Add prefix option to asset_hash (#1949)
+
+# 4.1.9
+
+* Fix `--watcher-*` CLI flags.
+* Allow spaces in paths to work with `link_to`. Fixes #1914
+* Add support for dotenv
+* Fix asset_url with asset_hash (#1919)
+* Allow partial lookups without a current_resource (#1912)
# 4.1.8
+* Expose `development?` and `production?` helpers to template context.
+* require the `try` core extension (#1911)
+* Fix contract for Sitemap::Store.register_resource_list_manipulator (#1907)
+* Loosen contract on Resource#source_file to Maybe[String] (#1906)
* Let collection loops access ConfigContext for helpers. #1879
+* Use https:// to clone templates (#1901)
+* Allow numbers to be unique page_ids (#1886)
+* Prevent infinite loop when encountering files where base filename is a possible templating engine
# 4.1.7
diff --git a/Gemfile b/Gemfile
index f14eb3b1..db4043a0 100644
--- a/Gemfile
+++ b/Gemfile
@@ -9,6 +9,12 @@ gem 'byebug'
gem 'aruba', '~> 0.7.4', require: false
gem 'rspec', '~> 3.0', require: false
gem 'cucumber', '~> 2.0', require: false
+gem 'addressable', '~> 2.4.0', require: false
+
+# Pry tools
+gem 'pry'
+gem 'pry-stack_explorer'
+gem 'pry-rescue'
# Optional middleman dependencies, included for tests
gem 'haml', '>= 4.0.5', require: false
@@ -18,7 +24,7 @@ gem 'kramdown', '~> 1.2', require: false
gem 'slim', '>= 2.0', require: false
gem 'liquid', '>= 2.6', require: false
gem 'stylus', '>= 1.0', require: false
-gem 'sinatra', '>= 1.4', require: false
+gem 'sinatra', '>= 2.0.0.beta2', require: false
gem 'redcarpet', '>= 3.1', require: false
# Dns server to test preview server
@@ -26,7 +32,7 @@ gem 'rubydns', '~> 1.0.1', require: false
# To test javascript
gem 'poltergeist', '~> 1.8', require: false
-gem 'phantomjs', '~> 1.9.8.0', require: false
+gem 'phantomjs', '~> 2.1.1.0', require: false
# For less, note there is no compatible JS runtime for windows
gem 'therubyrhino', '>= 2.0', platforms: :jruby
diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md
new file mode 100644
index 00000000..6d2dc0e0
--- /dev/null
+++ b/ISSUE_TEMPLATE.md
@@ -0,0 +1,9 @@
+## Expected behavior and actual behavior
+
+## Steps to reproduce the problem (from a clean middleman installation)
+
+## Additional information
+
+- Ruby version:
+- Middleman version:
+- OS version:
diff --git a/middleman-cli/bin/middleman b/middleman-cli/bin/middleman
index b5d1921d..8b381a08 100755
--- a/middleman-cli/bin/middleman
+++ b/middleman-cli/bin/middleman
@@ -9,6 +9,9 @@ end
require "middleman-core/load_paths"
Middleman.setup_load_paths
+require 'dotenv'
+::Dotenv.load
+
require 'middleman-core'
require 'middleman-core/logger'
@@ -22,12 +25,10 @@ module Middleman::Cli
if setting.default.is_a?(String) || setting.default.is_a?(NilClass)
base.class_option setting.key,
type: :string,
- default: :undefined,
desc: setting.description
elsif setting.default.is_a?(TrueClass) || setting.default.is_a?(FalseClass)
base.class_option setting.key,
type: :boolean,
- default: :undefined,
desc: setting.description
end
end
@@ -46,6 +47,8 @@ end
::Middleman::Logger.singleton(3)
::Middleman::Cli.config = ::Middleman::Application.new do
+ #
+ config[:environment] = (ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development').to_sym
config[:mode] = :config
config[:exit_before_ready] = true
config[:watcher_disable] = true
diff --git a/middleman-cli/lib/middleman-cli/build.rb b/middleman-cli/lib/middleman-cli/build.rb
index 7d5dd3af..9e521dde 100644
--- a/middleman-cli/lib/middleman-cli/build.rb
+++ b/middleman-cli/lib/middleman-cli/build.rb
@@ -10,7 +10,7 @@ module Middleman::Cli
class_option :environment,
aliases: '-e',
- default: :production
+ default: ENV['MM_ENV'] || ENV['RACK_ENV'] || :production
class_option :clean,
type: :boolean,
default: true,
@@ -29,7 +29,7 @@ module Middleman::Cli
default: false,
desc: 'Print debug messages'
class_option :instrument,
- type: :string,
+ type: :boolean,
default: false,
desc: 'Print instrument messages'
class_option :profile,
@@ -64,7 +64,7 @@ module Middleman::Cli
config[:mode] = :build
config[:show_exceptions] = false
config[:cli_options] = cli_options.each_with_object({}) do |(k, v), sum|
- sum[k] = v unless v == :undefined
+ sum[k] = v
end
end
diff --git a/middleman-cli/lib/middleman-cli/init.rb b/middleman-cli/lib/middleman-cli/init.rb
index f1c1927e..e8e5770c 100644
--- a/middleman-cli/lib/middleman-cli/init.rb
+++ b/middleman-cli/lib/middleman-cli/init.rb
@@ -113,7 +113,7 @@ module Middleman::Cli
end
def repository_path(repo)
- repo.include?('://') || repo.include?('git@') ? repo : "git://github.com/#{repo}.git"
+ repo.include?('://') || repo.include?('git@') ? repo : "https://github.com/#{repo}.git"
end
# Add to CLI
diff --git a/middleman-cli/lib/middleman-cli/server.rb b/middleman-cli/lib/middleman-cli/server.rb
index 479f53bd..85e75a9f 100644
--- a/middleman-cli/lib/middleman-cli/server.rb
+++ b/middleman-cli/lib/middleman-cli/server.rb
@@ -17,7 +17,7 @@ module Middleman::Cli
default: false,
desc: 'Print debug messages'
class_option :instrument,
- type: :string,
+ type: :boolean,
default: false,
desc: 'Print instrument messages'
class_option :profile,
diff --git a/middleman-cli/middleman-cli.gemspec b/middleman-cli/middleman-cli.gemspec
index f2719efc..e9447a9c 100644
--- a/middleman-cli/middleman-cli.gemspec
+++ b/middleman-cli/middleman-cli.gemspec
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -z -- {fixtures,features}/*`.split("\0")
s.executable = 'middleman'
s.require_path = 'lib'
- s.required_ruby_version = '>= 2.0.0'
+ s.required_ruby_version = '>= 2.2.0'
# CLI
s.add_dependency('thor', ['>= 0.17.0', '< 2.0'])
diff --git a/middleman-core/features/asset_hash.feature b/middleman-core/features/asset_hash.feature
index 6b92777c..7c173800 100644
--- a/middleman-core/features/asset_hash.feature
+++ b/middleman-core/features/asset_hash.feature
@@ -188,6 +188,23 @@ Feature: Assets get file hashes appended to them and references to them are upda
When I go to "/partials/"
Then I should see 'href="../stylesheets/uses_partials-ec347271.css'
+ Scenario: The asset hash should change when a Rack-based filter changes
+ Given a fixture app "asset-hash-app"
+ And a file named "config.rb" with:
+ """
+ activate :asset_hash
+ activate :relative_assets
+ activate :directory_indexes
+ require 'lib/middleware.rb'
+ use ::Middleware
+ """
+ Given the Server is running at "asset-hash-app"
+ When I go to "/"
+ Then I should see 'href="stylesheets/site-5ad7def0.css'
+ When I go to "stylesheets/site-5ad7def0.css"
+ Then I should see 'background-image: url("../images/100px-5fd6fb90.jpg")'
+ Then I should see 'Added by Rack filter'
+
Scenario: Hashed-asset files are not produced for ignored paths
Given a fixture app "asset-hash-app"
And a file named "config.rb" with:
@@ -291,3 +308,17 @@ Feature: Assets get file hashes appended to them and references to them are upda
| javascripts/application.js.map |
And the file "javascripts/application-4553338c.js" should contain "//# sourceMappingURL=application.js-22cc2b5f.map"
+
+ Scenario: Hashes can contain a prefix
+ Given a successfully built app at "asset-hash-prefix"
+ When I cd to "build"
+ Then the following files should exist:
+ | index.html |
+ | javascripts/application-myprefix-4553338c.js |
+ | javascripts/application.js-myprefix-22cc2b5f.map |
+ | index.html |
+ And the following files should not exist:
+ | javascripts/application.js |
+ | javascripts/application.js.map |
+
+ And the file "javascripts/application-myprefix-4553338c.js" should contain "//# sourceMappingURL=application.js-myprefix-22cc2b5f.map"
diff --git a/middleman-core/features/asset_host.feature b/middleman-core/features/asset_host.feature
index 646f1154..0433b61b 100644
--- a/middleman-core/features/asset_host.feature
+++ b/middleman-core/features/asset_host.feature
@@ -25,7 +25,8 @@ Feature: Alternate between multiple asset hosts
And a file named "config.rb" with:
"""
activate :asset_host, host: Proc.new { |asset|
- "http://assets%d.example.com" % (asset.hash % 4)
+ hash = Digest::MD5.digest(asset).bytes.map!(&:ord).reduce(&:+)
+ "http://assets%d.example.com" % (hash % 4)
}
"""
And the Server is running
diff --git a/middleman-core/features/endpoints.feature b/middleman-core/features/endpoints.feature
deleted file mode 100644
index 1ff6aaf6..00000000
--- a/middleman-core/features/endpoints.feature
+++ /dev/null
@@ -1,17 +0,0 @@
-Feature: Generic block based pages
-
- Scenario: Static Ruby Endpoints
- Given an empty app
- And a file named "config.rb" with:
- """
- endpoint "hello.html" do
- "world"
- end
- """
- And a file named "source/index.html.erb" with:
- """
- Hi
- """
- And the Server is running at "empty_app"
- When I go to "/hello.html"
- Then I should see "world"
diff --git a/middleman-core/features/extension_api_deprecations.feature b/middleman-core/features/extension_api_deprecations.feature
index 15f447ac..8c9dd216 100644
--- a/middleman-core/features/extension_api_deprecations.feature
+++ b/middleman-core/features/extension_api_deprecations.feature
@@ -3,9 +3,8 @@ Feature: Extension author could use some hooks
Scenario: When build
Given a fixture app "extension-api-deprecations-app"
When I run `middleman build`
- And the exit status should be 0
+ Then the exit status should be 0
And the output should contain "`set :layout` is deprecated"
- And the output should contain "Project built successfully"
And the file "build/index.html" should contain "In Index"
And the file "build/index.html" should not contain "In Layout"
diff --git a/middleman-core/features/extension_hooks.feature b/middleman-core/features/extension_hooks.feature
index 11a05557..1dedd9a9 100644
--- a/middleman-core/features/extension_hooks.feature
+++ b/middleman-core/features/extension_hooks.feature
@@ -7,6 +7,7 @@ Feature: Extension author could use some hooks
And the output should contain "/// after_configuration ///"
And the output should contain "/// ready ///"
And the output should contain "/// before_build ///"
+ And the output should contain "/// before ///"
And the output should contain "/// before_render ///"
And the output should contain "/// after_render ///"
And the output should contain "/// after_build ///"
diff --git a/middleman-core/features/helpers_link_to.feature b/middleman-core/features/helpers_link_to.feature
index 90b6f08a..fe8e8530 100644
--- a/middleman-core/features/helpers_link_to.feature
+++ b/middleman-core/features/helpers_link_to.feature
@@ -40,19 +40,29 @@ Feature: link_to helper
"""
absolute: <%= link_to "Needs Index", "/needs_index.html", relative: true %>
relative: <%= link_to "Relative", "needs_index.html", relative: true %>
+
+ absolute spaces: <%= link_to "Spaces Index", "/evil spaces.html", relative: true %>
+ relative spaces: <%= link_to "Spaces Relative", "evil spaces.html", relative: true %>
"""
And a file named "source/link_to/sub.html.erb" with:
"""
absolute: <%= link_to "Needs Index", "/needs_index.html", relative: true %>
relative: <%= link_to "Relative", "../needs_index.html", relative: true %>
+
+ absolute spaces: <%= link_to "Spaces Index", "/evil spaces.html", relative: true %>
+ relative spaces: <%= link_to "Spaces Relative", "../evil spaces.html", relative: true %>
"""
And the Server is running at "indexable-app"
When I go to "/link_to.html"
Then I should see 'absolute: Needs Index'
Then I should see 'relative: Relative'
+ Then I should see 'absolute spaces: Spaces Index'
+ Then I should see 'relative spaces: Spaces Relative'
When I go to "/link_to/sub.html"
Then I should see 'absolute: Needs Index'
Then I should see 'relative: Relative'
+ Then I should see 'absolute spaces: Spaces Index'
+ Then I should see 'relative spaces: Spaces Relative'
Scenario: link_to relative works with strip_index_file
Given a fixture app "indexable-app"
@@ -113,7 +123,7 @@ Feature: link_to helper
When I go to "/link_to/sub.html"
Then I should see 'absolute: Needs Index'
Then I should see 'relative: Relative'
-
+
Scenario: link_to knows about directory indexes
Given a fixture app "indexable-app"
And a file named "source/link_to.html.erb" with:
diff --git a/middleman-core/features/i18n_link_to.feature b/middleman-core/features/i18n_link_to.feature
index a10787c4..9d3f0682 100644
--- a/middleman-core/features/i18n_link_to.feature
+++ b/middleman-core/features/i18n_link_to.feature
@@ -4,7 +4,7 @@ Feature: i18n Paths
Given a fixture app "empty-app"
And a file named "data/pages.yml" with:
"""
- - hello.html
+ - hello.html
"""
And a file named "locales/en.yml" with:
"""
@@ -50,24 +50,24 @@ Feature: i18n Paths
Given the Server is running at "empty-app"
When I go to "/hello.html"
Then I should see "Page: Hello"
- Then I should see 'Current Home'
- Then I should see 'Other Home'
- Then I should see 'Home: Current Block'
- Then I should see 'Home: Other Block'
- Then I should see 'Current hello.html'
- Then I should see 'Other hello.html'
- Then I should see 'Current Block'
- Then I should see 'Other Block'
+ Then I should see 'Current Home'
+ Then I should see 'Other Home'
+ Then I should see 'Home: Current Block'
+ Then I should see 'Home: Other Block'
+ Then I should see 'Current hello.html'
+ Then I should see 'Other hello.html'
+ Then I should see 'Current Block'
+ Then I should see 'Other Block'
When I go to "/es/hola.html"
Then I should see "Page: Hola"
- Then I should see 'Current Home'
- Then I should see 'Other Home'
- Then I should see 'Home: Current Block'
- Then I should see 'Home: Other Block'
- Then I should see 'Current hello.html'
- Then I should see 'Other hello.html'
- Then I should see 'Current Block'
- Then I should see 'Other Block'
+ Then I should see 'Current Home'
+ Then I should see 'Other Home'
+ Then I should see 'Home: Current Block'
+ Then I should see 'Home: Other Block'
+ Then I should see 'Current hello.html'
+ Then I should see 'Other hello.html'
+ Then I should see 'Current Block'
+ Then I should see 'Other Block'
Scenario: link_to is i18n aware and supports relative_links
Given a fixture app "empty-app"
@@ -124,30 +124,30 @@ Feature: i18n Paths
Then I should see "assets/css/main.css"
When I go to "/hello.html"
Then I should see "Page: Hello"
- Then I should see 'Current Home'
- Then I should see 'Other Home'
- Then I should see 'Home: Current Block'
- Then I should see 'Home: Other Block'
- Then I should see 'Current hello.html'
- Then I should see 'Other hello.html'
- Then I should see 'Current Block'
- Then I should see 'Other Block'
+ Then I should see 'Current Home'
+ Then I should see 'Other Home'
+ Then I should see 'Home: Current Block'
+ Then I should see 'Home: Other Block'
+ Then I should see 'Current hello.html'
+ Then I should see 'Other hello.html'
+ Then I should see 'Current Block'
+ Then I should see 'Other Block'
When I go to "/es/hola.html"
Then I should see "Page: Hola"
- Then I should see 'Current Home'
- Then I should see 'Other Home'
- Then I should see 'Home: Current Block'
- Then I should see 'Home: Other Block'
- Then I should see 'Current hello.html'
- Then I should see 'Other hello.html'
- Then I should see 'Current Block'
- Then I should see 'Other Block'
+ Then I should see 'Current Home'
+ Then I should see 'Other Home'
+ Then I should see 'Home: Current Block'
+ Then I should see 'Home: Other Block'
+ Then I should see 'Current hello.html'
+ Then I should see 'Other hello.html'
+ Then I should see 'Current Block'
+ Then I should see 'Other Block'
Scenario: url_for is i18n aware
Given a fixture app "empty-app"
And a file named "data/pages.yml" with:
"""
- - hello.html
+ - hello.html
- article.html
"""
And a file named "locales/en.yml" with:
diff --git a/middleman-core/features/markdown_redcarpet_in_slim.feature b/middleman-core/features/markdown_redcarpet_in_slim.feature
new file mode 100644
index 00000000..250c6857
--- /dev/null
+++ b/middleman-core/features/markdown_redcarpet_in_slim.feature
@@ -0,0 +1,41 @@
+Feature: Markdown support in Slim
+ In order to test support of the Slim markdown filter
+
+ Scenario: Markdown filter in Slim works
+ Given a fixture app "markdown-in-slim-app"
+ And a file named "config.rb" with:
+ """
+ set :markdown_engine, :redcarpet
+ activate :directory_indexes
+ """
+ And a file named "source/markdown_filter.html.slim" with:
+ """
+ markdown:
+ # H1
+
+ paragraph
+ """
+ Given the Server is running at "markdown-in-slim-app"
+ When I go to "/markdown_filter/"
+ Then I should see ">H1"
+ Then I should see "
paragraph
"
+
+
+ Scenario: Markdown filter in Slim uses our link_to and image_tag helpers
+ Given a fixture app "markdown-in-slim-app"
+ And a file named "config.rb" with:
+ """
+ set :markdown_engine, :redcarpet
+ activate :directory_indexes
+ """
+ And a file named "source/link_and_image.html.slim" with:
+ """
+ markdown:
+ [A link](/link_target.html)
+
+ 
+ """
+ Given the Server is running at "markdown-in-slim-app"
+ When I go to "/link_and_image/"
+ Then I should see "/link_target/"
+ Then I should see 'src="/images/blank.gif"'
diff --git a/middleman-core/features/mount_rack.feature b/middleman-core/features/mount_rack.feature
new file mode 100644
index 00000000..dcb83146
--- /dev/null
+++ b/middleman-core/features/mount_rack.feature
@@ -0,0 +1,65 @@
+Feature: Support Rack apps mounted using map
+
+ Scenario: Mounted Rack App at /sinatra
+ Given the Server is running at "sinatra-app"
+ When I go to "/"
+ Then I should see "Hello World (Middleman)"
+ When I go to "/sinatra/"
+ Then I should see "Hello World (Sinatra)"
+
+ Scenario: Built Mounted Rack App at /sinatra
+ Given a successfully built app at "sinatra-app"
+ When I cd to "build"
+ Then the following files should exist:
+ | index.html |
+ Then the following files should not exist:
+ | sinatra/index.html |
+ | sinatra/index2.html |
+
+ Scenario: Static Ruby Endpoints
+ Given a fixture app "sinatra-app"
+ And a file named "config.rb" with:
+ """
+ endpoint "hello.html" do
+ "world"
+ end
+ """
+ And the Server is running at "sinatra-app"
+ When I go to "/hello.html"
+ Then I should see "world"
+
+ Scenario: Built Mounted Rack App at /sinatra (including rack endpoints)
+ Given a fixture app "sinatra-app"
+ And a file named "config.rb" with:
+ """
+ require "sinatra"
+
+ class MySinatra < Sinatra::Base
+ get "/" do
+ "Hello World (Sinatra)"
+ end
+ get "/derp.html" do
+ "De doo"
+ end
+ end
+
+ map "/sinatra" do
+ run MySinatra
+ end
+
+ endpoint "sinatra/index2.html", path: "/sinatra/"
+
+ endpoint "dedoo.html", path: "/sinatra/derp.html"
+
+ endpoint "hello.html" do
+ "world"
+ end
+ """
+ And a successfully built app at "sinatra-app"
+ When I cd to "build"
+ Then the following files should exist:
+ | index.html |
+ | sinatra/index2.html |
+ | dedoo.html |
+ And the file "sinatra/index2.html" should contain 'Hello World (Sinatra)'
+ And the file "dedoo.html" should contain 'De doo'
\ No newline at end of file
diff --git a/middleman-core/features/page-id.feature b/middleman-core/features/page-id.feature
index 63dd6fad..74d08cb5 100644
--- a/middleman-core/features/page-id.feature
+++ b/middleman-core/features/page-id.feature
@@ -3,14 +3,60 @@ Feature: Page IDs
Scenario: link_to works with blocks (erb)
Given the Server is running at "page-id-app"
When I go to "/index.html"
- Then I should see "I am: index.html"
+ Then I should see "I am: index"
And I should see "URL1: /fm.html"
And I should see "URL2: /2.html"
And I should see 'URL3: Hi'
And I should see 'URL4: Sym'
+ And I should see 'URL5: Imp'
+ And I should see 'URL6: Foldern'
+ And I should see 'URL7: Feed'
When I go to "/fm.html"
Then I should see "I am: frontmatter"
+ When I go to "/implicit.html"
+ Then I should see "I am: implicit"
+ When I go to "/feed.xml"
+ Then I should see "I am: feed.xml"
+ When I go to "/folder/foldern.html"
+ Then I should see "I am: folder/foldern"
+
+ When I go to "/1.html"
+ Then I should see "I am: page1"
+ When I go to "/2.html"
+ Then I should see "I am: page2"
+ When I go to "/3.html"
+ Then I should see "I am: page3"
+
+ When I go to "/overwrites/from-default.html"
+ Then I should see "I am: something-else"
+
+ When I go to "/overwrites/from-frontmatter.html"
+ Then I should see "I am: from_frontmatter"
+
+ Scenario: Override page ID derivation with a proc
+ Given a fixture app "page-id-app"
+ And app "page-id-app" is using config "proc"
+ And the Server is running at "page-id-app"
+
+ When I go to "/index.html"
+ Then I should see "I am: index.html-foo"
+ And I should see "URL1: /fm.html"
+ And I should see "URL2: /2.html"
+ And I should see 'URL3: Hi'
+ And I should see 'URL4: Sym'
+ And I should see 'URL8: Imp'
+ And I should see 'URL9: Foldern'
+ And I should see 'URL10: Feed'
+
+ When I go to "/fm.html"
+ Then I should see "I am: frontmatter"
+ When I go to "/implicit.html"
+ Then I should see "I am: implicit.html-foo"
+ When I go to "/feed.xml"
+ Then I should see "I am: feed.xml-foo"
+ When I go to "/folder/foldern.html"
+ Then I should see "I am: folder/foldern.html-foo"
When I go to "/1.html"
Then I should see "I am: page1"
diff --git a/middleman-core/features/relative_assets.feature b/middleman-core/features/relative_assets.feature
index ea6cbff0..ba131396 100644
--- a/middleman-core/features/relative_assets.feature
+++ b/middleman-core/features/relative_assets.feature
@@ -120,7 +120,7 @@ Feature: Relative Assets
"""
And the Server is running at "relative-assets-app"
When I go to "/sub/image_tag.html"
- Then I should see '
'
+ Then I should see '
'
+ Then I should see '
+ The Middleman!
+<% end %>
+
+Testing the sitemap hashing
+
diff --git a/middleman-core/fixtures/asset-hash-prefix/source/javascripts/application.js b/middleman-core/fixtures/asset-hash-prefix/source/javascripts/application.js
new file mode 100644
index 00000000..c72f8572
--- /dev/null
+++ b/middleman-core/fixtures/asset-hash-prefix/source/javascripts/application.js
@@ -0,0 +1,2 @@
+function foo(){var message="HEY THERE FRIEND!";var para=document.createElement("p");para.innerHTML=message;var body=document.getElementsByTagName("body")[0];body.insertBefore(para,body.firstChild)}window.onload=foo;
+//# sourceMappingURL=application.js.map
diff --git a/middleman-core/fixtures/asset-hash-prefix/source/javascripts/application.js.map b/middleman-core/fixtures/asset-hash-prefix/source/javascripts/application.js.map
new file mode 100644
index 00000000..6a5acd5c
--- /dev/null
+++ b/middleman-core/fixtures/asset-hash-prefix/source/javascripts/application.js.map
@@ -0,0 +1 @@
+{"version":3,"sources":["source/javascripts/application.js"],"names":["foo","message","para","document","createElement","innerHTML","body","getElementsByTagName","insertBefore","firstChild","window","onload"],"mappings":"AAAA,QAASA,OACP,GAAIC,SAAU,mBACd,IAAIC,MAAOC,SAASC,cAAc,IAClCF,MAAKG,UAAYJ,OACb,IAAIK,MAAOH,SAASI,qBAAqB,QAAQ,EAC/CD,MAAKE,aAAaN,KAAMI,KAAKG,YAGpCC,OAAOC,OAASX"}
\ No newline at end of file
diff --git a/middleman-core/fixtures/asset-hash-prefix/source/layout.erb b/middleman-core/fixtures/asset-hash-prefix/source/layout.erb
new file mode 100644
index 00000000..c8aacecf
--- /dev/null
+++ b/middleman-core/fixtures/asset-hash-prefix/source/layout.erb
@@ -0,0 +1,17 @@
+
+
+
+
+
+ <%= javascript_include_tag "application" %>
+ <%= yield_content :head %>
+
+
+
+
+
+ <%= yield %>
+
+
+
+
diff --git a/middleman-core/fixtures/asset-host-app/source/images/blank12.gif b/middleman-core/fixtures/asset-host-app/source/images/blank12.gif
deleted file mode 100644
index e69de29b..00000000
diff --git a/middleman-core/fixtures/asset-host-app/source/images/blank41.gif b/middleman-core/fixtures/asset-host-app/source/images/blank41.gif
deleted file mode 100644
index e69de29b..00000000
diff --git a/middleman-core/fixtures/asset-host-app/source/images/blank42.gif b/middleman-core/fixtures/asset-host-app/source/images/blank42.gif
deleted file mode 100644
index e69de29b..00000000
diff --git a/middleman-core/fixtures/asset-host-app/source/images/blank5.gif b/middleman-core/fixtures/asset-host-app/source/images/blank5.gif
deleted file mode 100644
index e69de29b..00000000
diff --git a/middleman-core/fixtures/asset-host-app/source/images/blank51.gif b/middleman-core/fixtures/asset-host-app/source/images/blank51.gif
deleted file mode 100644
index e69de29b..00000000
diff --git a/middleman-core/fixtures/asset-host-app/source/images/blank52.gif b/middleman-core/fixtures/asset-host-app/source/images/blank52.gif
deleted file mode 100644
index e69de29b..00000000
diff --git a/middleman-core/fixtures/asset-host-app/source/images/blank6.gif b/middleman-core/fixtures/asset-host-app/source/images/blank6.gif
deleted file mode 100644
index e69de29b..00000000
diff --git a/middleman-core/fixtures/asset-host-app/source/images/blank61.gif b/middleman-core/fixtures/asset-host-app/source/images/blank61.gif
deleted file mode 100644
index e69de29b..00000000
diff --git a/middleman-core/fixtures/asset-host-app/source/images/blank62.gif b/middleman-core/fixtures/asset-host-app/source/images/blank62.gif
deleted file mode 100644
index e69de29b..00000000
diff --git a/middleman-core/fixtures/asset-host-app/source/images/blank7.gif b/middleman-core/fixtures/asset-host-app/source/images/blank7.gif
deleted file mode 100644
index e69de29b..00000000
diff --git a/middleman-core/fixtures/asset-host-app/source/images/blank71.gif b/middleman-core/fixtures/asset-host-app/source/images/blank71.gif
deleted file mode 100644
index e69de29b..00000000
diff --git a/middleman-core/fixtures/asset-host-app/source/images/blank72.gif b/middleman-core/fixtures/asset-host-app/source/images/blank72.gif
deleted file mode 100644
index e69de29b..00000000
diff --git a/middleman-core/fixtures/asset-host-app/source/images/blank8.gif b/middleman-core/fixtures/asset-host-app/source/images/blank8.gif
deleted file mode 100644
index e69de29b..00000000
diff --git a/middleman-core/fixtures/asset-host-app/source/images/blank81.gif b/middleman-core/fixtures/asset-host-app/source/images/blank81.gif
deleted file mode 100644
index e69de29b..00000000
diff --git a/middleman-core/fixtures/asset-host-app/source/images/blank82.gif b/middleman-core/fixtures/asset-host-app/source/images/blank82.gif
deleted file mode 100644
index e69de29b..00000000
diff --git a/middleman-core/fixtures/page-id-app/config-proc.rb b/middleman-core/fixtures/page-id-app/config-proc.rb
new file mode 100644
index 00000000..03070f0e
--- /dev/null
+++ b/middleman-core/fixtures/page-id-app/config-proc.rb
@@ -0,0 +1,7 @@
+%w(1 2 3).each do |n|
+ proxy "/#{n}.html", "/index.html", id: "page#{n}"
+end
+
+page "/overwrites/*", id: :"something-else"
+
+config[:page_id_generator] = ->(path){ path + "-foo" }
diff --git a/middleman-core/fixtures/page-id-app/source/feed.xml.erb b/middleman-core/fixtures/page-id-app/source/feed.xml.erb
new file mode 100644
index 00000000..a27800bd
--- /dev/null
+++ b/middleman-core/fixtures/page-id-app/source/feed.xml.erb
@@ -0,0 +1 @@
+I am: <%= current_resource.page_id %>
diff --git a/middleman-core/fixtures/page-id-app/source/folder/foldern.html.erb b/middleman-core/fixtures/page-id-app/source/folder/foldern.html.erb
new file mode 100644
index 00000000..a27800bd
--- /dev/null
+++ b/middleman-core/fixtures/page-id-app/source/folder/foldern.html.erb
@@ -0,0 +1 @@
+I am: <%= current_resource.page_id %>
diff --git a/middleman-core/fixtures/page-id-app/source/implicit.html.erb b/middleman-core/fixtures/page-id-app/source/implicit.html.erb
new file mode 100644
index 00000000..a27800bd
--- /dev/null
+++ b/middleman-core/fixtures/page-id-app/source/implicit.html.erb
@@ -0,0 +1 @@
+I am: <%= current_resource.page_id %>
diff --git a/middleman-core/fixtures/page-id-app/source/index.html.erb b/middleman-core/fixtures/page-id-app/source/index.html.erb
index 8f2997b6..6060bc3f 100644
--- a/middleman-core/fixtures/page-id-app/source/index.html.erb
+++ b/middleman-core/fixtures/page-id-app/source/index.html.erb
@@ -4,3 +4,11 @@ URL1: <%= url_for "frontmatter" %>
URL2: <%= url_for "page2" %>
URL3: <%= link_to "Hi", "page3" %>
URL4: <%= link_to "Sym", :"something-else" %>
+URL5: <%= link_to "Imp", :implicit %>
+URL6: <%= link_to "Foldern", "folder/foldern" %>
+URL7: <%= link_to "Feed", "feed.xml" %>
+
+<%# If custom proc %>
+URL8: <%= link_to "Imp", "implicit.html-foo" %>
+URL9: <%= link_to "Foldern", "folder/foldern.html-foo" %>
+URL10: <%= link_to "Feed", "feed.xml-foo" %>
diff --git a/middleman-core/fixtures/asset-host-app/source/images/blank11.gif b/middleman-core/fixtures/sass-in-slim-app/config.rb
similarity index 100%
rename from middleman-core/fixtures/asset-host-app/source/images/blank11.gif
rename to middleman-core/fixtures/sass-in-slim-app/config.rb
diff --git a/middleman-core/fixtures/sinatra-app/config.rb b/middleman-core/fixtures/sinatra-app/config.rb
new file mode 100644
index 00000000..0251a715
--- /dev/null
+++ b/middleman-core/fixtures/sinatra-app/config.rb
@@ -0,0 +1,14 @@
+require "sinatra"
+
+class MySinatra < Sinatra::Base
+ get "/" do
+ "Hello World (Sinatra)"
+ end
+ get "/derp.html" do
+ "De doo"
+ end
+end
+
+map "/sinatra" do
+ run MySinatra
+end
diff --git a/middleman-core/fixtures/sinatra-app/source/index.html.erb b/middleman-core/fixtures/sinatra-app/source/index.html.erb
new file mode 100644
index 00000000..8b59c41c
--- /dev/null
+++ b/middleman-core/fixtures/sinatra-app/source/index.html.erb
@@ -0,0 +1,5 @@
+---
+layout: false
+---
+
+Hello World (Middleman)
\ No newline at end of file
diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb
index 4ecd40f8..52b31c92 100644
--- a/middleman-core/lib/middleman-core/application.rb
+++ b/middleman-core/lib/middleman-core/application.rb
@@ -157,12 +157,12 @@ module Middleman
define_setting :layout, :_auto_layout, 'Default layout name'
# Which file extensions have a layout by default.
- # @return [Set.]
- define_setting :extensions_with_layout, %w(.htm .html .xhtml .php), 'Which file extensions have a layout by default.', set: true
+ # @return [Array.]
+ define_setting :extensions_with_layout, %w(.htm .html .xhtml .php), 'Which file extensions have a layout by default.'
# Which file extensions are "assets."
# @return [Array.]
- define_setting :asset_extensions, %w(.css .png .jpg .jpeg .webp .svg .svgz .js .gif .ttf .otf .woff .woff2 .eot .ico .map), 'Which file extensions are treated as assets.', set: true
+ define_setting :asset_extensions, %w(.css .png .jpg .jpeg .webp .svg .svgz .js .gif .ttf .otf .woff .woff2 .eot .ico .map), 'Which file extensions are treated as assets.'
# Default string encoding for templates and output.
# @return [String]
@@ -203,6 +203,7 @@ module Middleman
define_setting :watcher_disable, false, 'If the Listen watcher should not run'
define_setting :watcher_force_polling, false, 'If the Listen watcher should run in polling mode'
define_setting :watcher_latency, nil, 'The Listen watcher latency'
+ define_setting :watcher_wait_for_delay, 0.5, 'The Listen watcher delay between calls when changes exist'
# Delegate convenience methods off to their implementations
def_delegator :"::Middleman::Logger", :singleton, :logger
@@ -266,6 +267,8 @@ module Middleman
# Evaluate a passed block if given
config_context.instance_exec(&block) if block_given?
+ apply_cli_options
+
execute_callbacks(:before_sitemap)
# Initialize the Sitemap
@@ -276,8 +279,6 @@ module Middleman
# Before config is parsed, before extensions get to it.
execute_callbacks(:initialized)
- apply_cli_options
-
# Before config is parsed. Mostly used for extensions.
execute_callbacks(:before_configuration)
@@ -344,11 +345,11 @@ module Middleman
# Clean up missing Tilt exts
def prune_tilt_templates!
- ::Tilt.mappings.each_key do |key|
+ ::Tilt.default_mapping.lazy_map.each_key do |key|
begin
::Tilt[".#{key}"]
rescue LoadError, NameError
- ::Tilt.mappings.delete(key)
+ ::Tilt.default_mapping.lazy_map.delete(key)
end
end
end
diff --git a/middleman-core/lib/middleman-core/builder.rb b/middleman-core/lib/middleman-core/builder.rb
index c84bfa39..1796d4d7 100644
--- a/middleman-core/lib/middleman-core/builder.rb
+++ b/middleman-core/lib/middleman-core/builder.rb
@@ -2,6 +2,7 @@ require 'pathname'
require 'fileutils'
require 'tempfile'
require 'parallel'
+require 'middleman-core/rack'
require 'middleman-core/callback_manager'
require 'middleman-core/contracts'
@@ -38,6 +39,9 @@ module Middleman
@cleaning = opts.fetch(:clean)
@parallel = opts.fetch(:parallel, true)
+ rack_app = ::Middleman::Rack.new(@app).to_app
+ @rack = ::Rack::MockRequest.new(rack_app)
+
@callbacks = ::Middleman::CallbackManager.new
@callbacks.install_methods!(self, [:on_build_event])
end
@@ -223,7 +227,15 @@ module Middleman
if resource.binary?
export_file!(output_file, resource.file_descriptor[:full_path])
else
- export_file!(output_file, binary_encode(resource.render))
+ response = @rack.get(::URI.escape(resource.request_path))
+
+ # If we get a response, save it to a tempfile.
+ if response.status == 200
+ export_file!(output_file, binary_encode(response.body))
+ else
+ trigger(:error, output_file, response.body)
+ return false
+ end
end
rescue => e
trigger(:error, output_file, "#{e}\n#{e.backtrace.join("\n")}")
diff --git a/middleman-core/lib/middleman-core/configuration.rb b/middleman-core/lib/middleman-core/configuration.rb
index 0d6d9be7..c916fc90 100644
--- a/middleman-core/lib/middleman-core/configuration.rb
+++ b/middleman-core/lib/middleman-core/configuration.rb
@@ -1,5 +1,3 @@
-require 'set'
-
module Middleman
module Configuration
# A class that manages a collection of documented settings.
@@ -131,37 +129,23 @@ module Middleman
def initialize(key, default, description, options={})
@value_set = false
- @array_wrapped_value = nil
- @array_wrapped_default = nil
self.key = key
self.default = default
self.description = description
self.options = options
-
- @array_wrapped_default = if self.default && options[:set] && self.default.is_a?(Array)
- Set.new(self.default)
- end
end
# The user-supplied value for this setting, overriding the default
def value=(value)
@value = value
@value_set = true
-
- @array_wrapped_value = if @value && options[:set] && @value.is_a?(Array)
- Set.new(@value)
- end
end
# The effective value of the setting, which may be the default
# if the user has not set a value themselves. Note that even if the
# user sets the value to nil it will override the default.
def value
- if value_set?
- @array_wrapped_value ? @array_wrapped_value : @value
- else
- @array_wrapped_default ? @array_wrapped_default : default
- end
+ value_set? ? @value : default
end
# Whether or not there has been a value set beyond the default
diff --git a/middleman-core/lib/middleman-core/core_extensions.rb b/middleman-core/lib/middleman-core/core_extensions.rb
index ea31f89a..e38be937 100644
--- a/middleman-core/lib/middleman-core/core_extensions.rb
+++ b/middleman-core/lib/middleman-core/core_extensions.rb
@@ -19,6 +19,12 @@ Middleman::Extensions.register :data, auto_activate: :before_sitemap do
Middleman::CoreExtensions::Data
end
+# Rewrite embedded URLs via Rack
+Middleman::Extensions.register :inline_url_rewriter, auto_activate: :before_sitemap do
+ require 'middleman-core/core_extensions/inline_url_rewriter'
+ Middleman::CoreExtensions::InlineURLRewriter
+end
+
# Catch and show exceptions at the Rack level
Middleman::Extensions.register :show_exceptions, auto_activate: :before_configuration, modes: [:server] do
require 'middleman-core/core_extensions/show_exceptions'
diff --git a/middleman-core/lib/middleman-core/core_extensions/file_watcher.rb b/middleman-core/lib/middleman-core/core_extensions/file_watcher.rb
index 82df8f73..6fd16ae9 100644
--- a/middleman-core/lib/middleman-core/core_extensions/file_watcher.rb
+++ b/middleman-core/lib/middleman-core/core_extensions/file_watcher.rb
@@ -28,10 +28,7 @@ module Middleman
super
# Setup source collection.
- @sources = ::Middleman::Sources.new(app,
- disable_watcher: app.config[:watcher_disable],
- force_polling: app.config[:watcher_force_polling],
- latency: app.config[:watcher_latency])
+ @sources = ::Middleman::Sources.new(app)
# Add default ignores.
IGNORES.each do |key, value|
@@ -55,6 +52,13 @@ module Middleman
# @return [void]
Contract Any
def after_configuration
+ @watcher.update_config(
+ disable_watcher: app.config[:watcher_disable],
+ force_polling: app.config[:watcher_force_polling],
+ latency: app.config[:watcher_latency],
+ wait_for_delay: app.config[:watcher_wait_for_delay]
+ )
+
if @original_source_dir != app.config[:source]
@watcher.update_path(app.config[:source])
end
diff --git a/middleman-core/lib/middleman-core/core_extensions/inline_url_rewriter.rb b/middleman-core/lib/middleman-core/core_extensions/inline_url_rewriter.rb
new file mode 100644
index 00000000..43354e97
--- /dev/null
+++ b/middleman-core/lib/middleman-core/core_extensions/inline_url_rewriter.rb
@@ -0,0 +1,135 @@
+require 'rack'
+require 'rack/response'
+require 'memoist'
+require 'middleman-core/util'
+require 'middleman-core/contracts'
+
+module Middleman
+ module CoreExtensions
+ class InlineURLRewriter < ::Middleman::Extension
+ include Contracts
+
+ expose_to_application rewrite_inline_urls: :add
+
+ REWRITER_DESCRIPTOR = {
+ id: Symbol,
+ proc: Or[Proc, Method],
+ url_extensions: ArrayOf[String],
+ source_extensions: ArrayOf[String],
+ ignore: ArrayOf[::Middleman::Util::IGNORE_DESCRIPTOR],
+ after: Maybe[Symbol]
+ }.freeze
+
+ def initialize(app, options_hash={}, &block)
+ super
+
+ @rewriters = {}
+ end
+
+ Contract REWRITER_DESCRIPTOR => Any
+ def add(options)
+ @rewriters[options] = options
+ end
+
+ def after_configuration
+ return if @rewriters.empty?
+
+ rewriters = @rewriters.values.sort do |a, b|
+ if b[:after] && b[:after] == a[:id]
+ 1
+ else
+ 0
+ end
+ end
+
+ app.use Rack, rewriters: rewriters, middleman_app: @app
+ end
+
+ class Rack
+ extend Memoist
+ include Contracts
+
+ Contract RespondTo[:call], {
+ middleman_app: IsA['Middleman::Application'],
+ rewriters: ArrayOf[REWRITER_DESCRIPTOR]
+ } => Any
+ def initialize(app, options={})
+ @rack_app = app
+ @middleman_app = options.fetch(:middleman_app)
+ @rewriters = options.fetch(:rewriters)
+
+ all_source_exts = @rewriters
+ .reduce([]) { |sum, rewriter| sum + rewriter[:source_extensions] }
+ .flatten
+ .uniq
+ @source_exts_regex_text = Regexp.union(all_source_exts).to_s
+
+ @all_asset_exts = @rewriters
+ .reduce([]) { |sum, rewriter| sum + rewriter[:url_extensions] }
+ .flatten
+ .uniq
+ end
+
+ def call(env)
+ status, headers, response = @rack_app.call(env)
+
+ # Allow configuration or upstream request to skip all rewriting
+ return [status, headers, response] if env['bypass_inline_url_rewriter'] == 'true'
+
+ path = ::Middleman::Util.full_path(env['PATH_INFO'], @middleman_app)
+
+ return [status, headers, response] unless path =~ /(^\/$)|(#{@source_exts_regex_text}$)/
+ return [status, headers, response] unless body = ::Middleman::Util.extract_response_text(response)
+
+ dirpath = ::Pathname.new(File.dirname(path))
+
+ rewritten = ::Middleman::Util.instrument 'inline_url_rewriter', path: path do
+ ::Middleman::Util.rewrite_paths(body, path, @all_asset_exts, @middleman_app) do |asset_path|
+ uri = ::Middleman::Util.parse_uri(asset_path)
+
+ relative_path = uri.host.nil?
+
+ full_asset_path = if relative_path
+ dirpath.join(asset_path).to_s
+ else
+ asset_path
+ end
+
+ @rewriters.each do |rewriter|
+ uid = rewriter.fetch(:id)
+
+ # Allow upstream request to skip this specific rewriting
+ next if env["bypass_inline_url_rewriter_#{uid}"] == 'true'
+
+ exts = rewriter.fetch(:url_extensions)
+ next unless exts.include?(::File.extname(asset_path))
+
+ source_exts = rewriter.fetch(:source_extensions)
+ next unless source_exts.include?(::File.extname(path))
+
+ ignore = rewriter.fetch(:ignore)
+ next if ignore.any? { |r| ::Middleman::Util.should_ignore?(r, full_asset_path) }
+
+ rewrite_ignore = Array(rewriter[:rewrite_ignore] || [])
+ next if rewrite_ignore.any? { |i| ::Middleman::Util.path_match(i, path) }
+
+ proc = rewriter.fetch(:proc)
+
+ result = proc.call(asset_path, dirpath, path)
+ asset_path = result if result
+ end
+
+ asset_path
+ end
+ end
+
+ ::Rack::Response.new(
+ rewritten,
+ status,
+ headers
+ ).finish
+ end
+ end
+ end
+ end
+end
diff --git a/middleman-core/lib/middleman-core/extension.rb b/middleman-core/lib/middleman-core/extension.rb
index 0d1f212d..9805455a 100644
--- a/middleman-core/lib/middleman-core/extension.rb
+++ b/middleman-core/lib/middleman-core/extension.rb
@@ -60,7 +60,7 @@ module Middleman
# There are also some less common hooks that can be listened to from within an extension's `initialize` method:
#
# * `app.before_render {|body, path, locs, template_class| ... }` - Manipulate template sources before they are rendered.
- # * `app.after_render {|content, path, locs, template_class| ... }` - Manipulate output text after a template has been rendered.
+ # * `app.after_render {|content, path, locs, template_class| ... }` - Manipulate output text after a template has been rendered. It is also common to install a Rack middleware to do this instead.
# * `app.ready { ... }` - Run code once Middleman is ready to serve or build files (after `after_configuration`).
#
diff --git a/middleman-core/lib/middleman-core/extensions/asset_hash.rb b/middleman-core/lib/middleman-core/extensions/asset_hash.rb
index f78eed5e..3e2a02aa 100644
--- a/middleman-core/lib/middleman-core/extensions/asset_hash.rb
+++ b/middleman-core/lib/middleman-core/extensions/asset_hash.rb
@@ -1,15 +1,19 @@
require 'middleman-core/util'
+require 'middleman-core/rack'
class Middleman::Extensions::AssetHash < ::Middleman::Extension
- option :sources, %w(.css .htm .html .js .php .xhtml), 'List of extensions that are searched for hashable assets.', set: true
- option :exts, nil, 'List of extensions that get asset hashes appended to them.', set: true
+ option :sources, %w(.css .htm .html .js .php .xhtml), 'List of extensions that are searched for hashable assets.'
+ option :exts, nil, 'List of extensions that get asset hashes appended to them.'
option :ignore, [], 'Regexes of filenames to skip adding asset hashes to'
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites'
+ option :prefix, '', 'Prefix for hash'
def initialize(app, options_hash={}, &block)
super
+ require 'addressable/uri'
require 'digest/sha1'
+ require 'rack/mock'
# Allow specifying regexes to ignore, plus always ignore apple touch icons
@ignore = Array(options.ignore) + [/^apple-touch-icon/]
@@ -17,6 +21,14 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
# Exclude .ico from the default list because browsers expect it
# to be named "favicon.ico"
@exts = options.exts || (app.config[:asset_extensions] - %w(.ico))
+
+ app.rewrite_inline_urls id: :asset_hash,
+ url_extensions: @exts.sort.reverse,
+ source_extensions: options.sources,
+ ignore: @ignore,
+ rewrite_ignore: options.rewrite_ignore,
+ proc: method(:rewrite_url),
+ after: :asset_host
end
Contract String, Or[String, Pathname], Any => Maybe[String]
@@ -34,6 +46,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
replacement_path = "/#{asset_page.destination_path}"
replacement_path = Pathname.new(replacement_path).relative_path_from(dirpath).to_s if relative_path
+
replacement_path
end
@@ -41,18 +54,9 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
# @return Array
Contract ResourceList => ResourceList
def manipulate_resource_list(resources)
- resources.each do |r|
- next unless r.destination_path.end_with?('/', *options.sources)
- next if Array(options.rewrite_ignore || []).any? do |i|
- ::Middleman::Util.path_match(i, "/#{r.destination_path}")
- end
-
- r.filters << ::Middleman::InlineURLRewriter.new(:asset_hash,
- app,
- r,
- url_extensions: @exts,
- ignore: options.ignore,
- proc: method(:rewrite_url))
+ @rack_client ||= begin
+ rack_app = ::Middleman::Rack.new(app).to_app
+ ::Rack::MockRequest.new(rack_app)
end
# Process resources in order: binary images and fonts, then SVG, then JS/CSS.
@@ -78,12 +82,18 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
digest = if resource.binary?
::Digest::SHA1.file(resource.source_file).hexdigest[0..7]
else
- # Render without asset hash
- body = resource.render { |f| !f.respond_to?(:filter_name) || f.filter_name != :asset_hash }
- ::Digest::SHA1.hexdigest(body)[0..7]
+ # Render through the Rack interface so middleware and mounted apps get a shot
+ response = @rack_client.get(
+ ::URI.escape(resource.destination_path),
+ 'bypass_inline_url_rewriter_asset_hash' => 'true'
+ )
+
+ raise "#{resource.path} should be in the sitemap!" unless response.status == 200
+
+ ::Digest::SHA1.hexdigest(response.body)[0..7]
end
- resource.destination_path = resource.destination_path.sub(/\.(\w+)$/) { |ext| "-#{digest}#{ext}" }
+ resource.destination_path = resource.destination_path.sub(/\.(\w+)$/) { |ext| "-#{options.prefix}#{digest}#{ext}" }
resource
end
diff --git a/middleman-core/lib/middleman-core/extensions/asset_host.rb b/middleman-core/lib/middleman-core/extensions/asset_host.rb
index b076299d..7cb83d07 100644
--- a/middleman-core/lib/middleman-core/extensions/asset_host.rb
+++ b/middleman-core/lib/middleman-core/extensions/asset_host.rb
@@ -1,3 +1,5 @@
+require 'addressable/uri'
+
class Middleman::Extensions::AssetHost < ::Middleman::Extension
option :host, nil, 'The asset host to use or a Proc to determine asset host', required: true
option :exts, nil, 'List of extensions that get cache busters strings appended to them.'
@@ -5,22 +7,15 @@ class Middleman::Extensions::AssetHost < ::Middleman::Extension
option :ignore, [], 'Regexes of filenames to skip adding query strings to'
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for host rewrites'
- Contract ResourceList => ResourceList
- def manipulate_resource_list(resources)
- resources.each do |r|
- next unless r.destination_path.end_with?('/', *options.sources)
- next if Array(options.rewrite_ignore || []).any? do |i|
- ::Middleman::Util.path_match(i, "/#{r.destination_path}")
- end
+ def initialize(app, options_hash={}, &block)
+ super
- r.filters << ::Middleman::InlineURLRewriter.new(:asset_host,
- app,
- r,
- after_filter: :asset_hash,
- url_extensions: options.exts || app.config[:asset_extensions],
- ignore: options.ignore,
- proc: method(:rewrite_url))
- end
+ app.rewrite_inline_urls id: :asset_host,
+ url_extensions: options.exts || app.config[:asset_extensions],
+ source_extensions: options.sources,
+ ignore: options.ignore,
+ rewrite_ignore: options.rewrite_ignore,
+ proc: method(:rewrite_url)
end
Contract String, Or[String, Pathname], Any => String
diff --git a/middleman-core/lib/middleman-core/extensions/cache_buster.rb b/middleman-core/lib/middleman-core/extensions/cache_buster.rb
index ea723a81..2de11632 100644
--- a/middleman-core/lib/middleman-core/extensions/cache_buster.rb
+++ b/middleman-core/lib/middleman-core/extensions/cache_buster.rb
@@ -1,25 +1,19 @@
# The Cache Buster extension
class Middleman::Extensions::CacheBuster < ::Middleman::Extension
- option :exts, nil, 'List of extensions that get cache busters strings appended to them.', set: true
- option :sources, %w(.css .htm .html .js .php .xhtml), 'List of extensions that are searched for bustable assets.', set: true
+ option :exts, nil, 'List of extensions that get cache busters strings appended to them.'
+ option :sources, %w(.css .htm .html .js .php .xhtml), 'List of extensions that are searched for bustable assets.'
option :ignore, [], 'Regexes of filenames to skip adding query strings to'
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites'
- Contract ResourceList => ResourceList
- def manipulate_resource_list(resources)
- resources.each do |r|
- next unless r.destination_path.end_with?('/', *options.sources)
- next if Array(options.rewrite_ignore || []).any? do |i|
- ::Middleman::Util.path_match(i, "/#{r.destination_path}")
- end
+ def initialize(app, options_hash={}, &block)
+ super
- r.filters << ::Middleman::InlineURLRewriter.new(:cache_buster,
- app,
- r,
- url_extensions: options.exts || app.config[:asset_extensions],
- ignore: options.ignore,
- proc: method(:rewrite_url))
- end
+ app.rewrite_inline_urls id: :cache_buster,
+ url_extensions: options.exts || app.config[:asset_extensions],
+ source_extensions: options.sources,
+ ignore: options.ignore,
+ rewrite_ignore: options.rewrite_ignore,
+ proc: method(:rewrite_url)
end
Contract String, Or[String, Pathname], Any => String
diff --git a/middleman-core/lib/middleman-core/extensions/directory_indexes.rb b/middleman-core/lib/middleman-core/extensions/directory_indexes.rb
index 3bc340ee..cef88868 100644
--- a/middleman-core/lib/middleman-core/extensions/directory_indexes.rb
+++ b/middleman-core/lib/middleman-core/extensions/directory_indexes.rb
@@ -1,5 +1,3 @@
-require 'set'
-
# Directory Indexes extension
class Middleman::Extensions::DirectoryIndexes < ::Middleman::Extension
# This should run after most other sitemap manipulators so that it
@@ -13,7 +11,7 @@ class Middleman::Extensions::DirectoryIndexes < ::Middleman::Extension
index_file = app.config[:index_file]
new_index_path = "/#{index_file}"
- extensions = Set.new(%w(.htm .html .php .xhtml))
+ extensions = %w(.htm .html .php .xhtml)
resources.each do |resource|
# Check if it would be pointless to reroute
diff --git a/middleman-core/lib/middleman-core/extensions/gzip.rb b/middleman-core/lib/middleman-core/extensions/gzip.rb
index a633f78f..0483fe32 100644
--- a/middleman-core/lib/middleman-core/extensions/gzip.rb
+++ b/middleman-core/lib/middleman-core/extensions/gzip.rb
@@ -10,7 +10,7 @@
# to .css, .htm, .html, .js, and .xhtml
#
class Middleman::Extensions::Gzip < ::Middleman::Extension
- option :exts, %w(.css .htm .html .js .svg .xhtml), 'File extensions to Gzip when building.', set: true
+ option :exts, %w(.css .htm .html .js .svg .xhtml), 'File extensions to Gzip when building.'
option :ignore, [], 'Patterns to avoid gzipping'
option :overwrite, false, 'Overwrite original files instead of adding .gz extension.'
diff --git a/middleman-core/lib/middleman-core/extensions/minify_css.rb b/middleman-core/lib/middleman-core/extensions/minify_css.rb
index 9174322f..aca9c60b 100644
--- a/middleman-core/lib/middleman-core/extensions/minify_css.rb
+++ b/middleman-core/lib/middleman-core/extensions/minify_css.rb
@@ -1,5 +1,6 @@
+require 'active_support/core_ext/object/try'
+require 'memoist'
require 'middleman-core/contracts'
-require 'rack/mime'
# Minify CSS Extension
class Middleman::Extensions::MinifyCss < ::Middleman::Extension
@@ -9,10 +10,17 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
require 'sass'
SassCompressor
}, 'Set the CSS compressor to use.'
- option :content_types, %w(text/css), 'Content types of resources that contain CSS', set: true
- option :inline_content_types, %w(text/html text/php), 'Content types of resources that contain inline CSS', set: true
+ option :content_types, %w(text/css), 'Content types of resources that contain CSS'
+ option :inline_content_types, %w(text/html text/php), 'Content types of resources that contain inline CSS'
- INLINE_CSS_REGEX = /(