From 8b4e2d043ca70fa882827e6f6679148043614a7e Mon Sep 17 00:00:00 2001 From: Rene Klacan Date: Thu, 27 Oct 2016 15:10:28 +0200 Subject: [PATCH 01/13] Fix source watcher configuration --- .../lib/middleman-core/application.rb | 1 + .../core_extensions/file_watcher.rb | 12 ++++-- middleman-core/lib/middleman-core/sources.rb | 9 ++-- .../middleman-core/sources/source_watcher.rb | 43 ++++++++++++++----- 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index fb1ab93f..52b31c92 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -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 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/sources.rb b/middleman-core/lib/middleman-core/sources.rb index d2f64a40..67992fe5 100644 --- a/middleman-core/lib/middleman-core/sources.rb +++ b/middleman-core/lib/middleman-core/sources.rb @@ -53,18 +53,15 @@ module Middleman # Create a new collection of sources. # # @param [Middleman::Application] app The parent app. - # @param [Hash] options Global options. # @param [Array] watchers Default watchers. - Contract IsA['Middleman::Application'], Maybe[Hash], Maybe[Array] => Any - def initialize(app, options={}, watchers=[]) + Contract IsA['Middleman::Application'], Maybe[Array] => Any + def initialize(app, watchers=[]) @app = app @watchers = watchers @sorted_watchers = @watchers.dup.freeze ::Middleman::Sources.file_cache = {} - @options = options - # Set of procs wanting to be notified of changes @on_change_callbacks = ::Hamster::Vector.empty @@ -172,7 +169,7 @@ module Middleman # @return [Middleman::Sources] Contract Symbol => ::Middleman::Sources def by_type(type) - self.class.new @app, @options, watchers.select { |d| d.type == type } + self.class.new @app, watchers.select { |d| d.type == type } end # Get all files for this collection of watchers. diff --git a/middleman-core/lib/middleman-core/sources/source_watcher.rb b/middleman-core/lib/middleman-core/sources/source_watcher.rb index 88d75f3f..b6d8b28a 100644 --- a/middleman-core/lib/middleman-core/sources/source_watcher.rb +++ b/middleman-core/lib/middleman-core/sources/source_watcher.rb @@ -75,9 +75,10 @@ module Middleman @ignored = options.fetch(:ignored, proc { false }) @only = Array(options.fetch(:only, [])) - @disable_watcher = app.build? || @parent.options.fetch(:disable_watcher, false) - @force_polling = @parent.options.fetch(:force_polling, false) - @latency = @parent.options.fetch(:latency, nil) + @disable_watcher = app.build? + @force_polling = false + @latency = nil + @wait_for_delay = nil @listener = nil @@ -95,13 +96,18 @@ module Middleman def update_path(directory) @directory = Pathname(File.expand_path(directory, app.root)) - stop_listener! if @listener + without_listener_running do + update([], @files.values.map { |source_file| source_file[:full_path] }) + end + end - update([], @files.values.map { |source_file| source_file[:full_path] }) - - poll_once! - - listen! unless @disable_watcher + def update_config(options={}) + without_listener_running do + @disable_watcher = options.fetch(:disable_watcher, false) + @force_polling = options.fetch(:force_polling, false) + @latency = options.fetch(:latency, nil) + @wait_for_delay = options.fetch(:wait_for_delay, nil) + end end # Stop watching. @@ -160,10 +166,10 @@ module Middleman config = { force_polling: @force_polling, - wait_for_delay: 0.5 } - config[:latency] = @latency.to_i if @latency + config[:wait_for_delay] = @wait_for_delay.try(:to_f) || 0.5 + config[:latency] = @latency.to_f if @latency @listener = ::Listen.to(@directory.to_s, config, &method(:on_listener_change)) @@ -343,5 +349,20 @@ module Middleman @only.any? { |reg| file[:relative_path].to_s =~ reg } end end + + private + + def without_listener_running + listener_running = @listener && @listener.processing? + + stop_listener! if listener_running + + yield + + if listener_running + poll_once! + listen! + end + end end end From d7792f788c7f666114477d539eb9f7aaac5beee4 Mon Sep 17 00:00:00 2001 From: Rene Klacan Date: Sat, 29 Oct 2016 02:48:18 +0200 Subject: [PATCH 02/13] Keep old Sources#initialize signature --- middleman-core/lib/middleman-core/sources.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/middleman-core/lib/middleman-core/sources.rb b/middleman-core/lib/middleman-core/sources.rb index 67992fe5..ced46227 100644 --- a/middleman-core/lib/middleman-core/sources.rb +++ b/middleman-core/lib/middleman-core/sources.rb @@ -53,9 +53,10 @@ module Middleman # Create a new collection of sources. # # @param [Middleman::Application] app The parent app. + # @param [Hash] options Global options. # @param [Array] watchers Default watchers. - Contract IsA['Middleman::Application'], Maybe[Array] => Any - def initialize(app, watchers=[]) + Contract IsA['Middleman::Application'], Maybe[Hash], Maybe[Array] => Any + def initialize(app, _options={}, watchers=[]) @app = app @watchers = watchers @sorted_watchers = @watchers.dup.freeze @@ -169,7 +170,7 @@ module Middleman # @return [Middleman::Sources] Contract Symbol => ::Middleman::Sources def by_type(type) - self.class.new @app, watchers.select { |d| d.type == type } + self.class.new @app, nil, watchers.select { |d| d.type == type } end # Get all files for this collection of watchers. From b4699cd741f22425b45cb7751f2c358f68ae6bb0 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Mon, 31 Oct 2016 09:30:46 -0700 Subject: [PATCH 03/13] Poll source on path change --- middleman-core/lib/middleman-core/sources/source_watcher.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/middleman-core/lib/middleman-core/sources/source_watcher.rb b/middleman-core/lib/middleman-core/sources/source_watcher.rb index b6d8b28a..8e3a3550 100644 --- a/middleman-core/lib/middleman-core/sources/source_watcher.rb +++ b/middleman-core/lib/middleman-core/sources/source_watcher.rb @@ -99,6 +99,8 @@ module Middleman without_listener_running do update([], @files.values.map { |source_file| source_file[:full_path] }) end + + poll_once! end def update_config(options={}) From 604c0e2b5d2c17a4fee85f8fd80d62cacd1f1652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kla=C4=8Dan?= Date: Mon, 31 Oct 2016 18:50:03 +0100 Subject: [PATCH 04/13] Fix source watcher configuration (#1999) * Fix source watcher configuration * Keep old Sources#initialize signature * Poll source on path change --- .../lib/middleman-core/application.rb | 1 + .../core_extensions/file_watcher.rb | 12 ++++-- middleman-core/lib/middleman-core/sources.rb | 6 +-- .../middleman-core/sources/source_watcher.rb | 41 +++++++++++++++---- 4 files changed, 43 insertions(+), 17 deletions(-) diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index fb1ab93f..52b31c92 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -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 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/sources.rb b/middleman-core/lib/middleman-core/sources.rb index d2f64a40..ced46227 100644 --- a/middleman-core/lib/middleman-core/sources.rb +++ b/middleman-core/lib/middleman-core/sources.rb @@ -56,15 +56,13 @@ module Middleman # @param [Hash] options Global options. # @param [Array] watchers Default watchers. Contract IsA['Middleman::Application'], Maybe[Hash], Maybe[Array] => Any - def initialize(app, options={}, watchers=[]) + def initialize(app, _options={}, watchers=[]) @app = app @watchers = watchers @sorted_watchers = @watchers.dup.freeze ::Middleman::Sources.file_cache = {} - @options = options - # Set of procs wanting to be notified of changes @on_change_callbacks = ::Hamster::Vector.empty @@ -172,7 +170,7 @@ module Middleman # @return [Middleman::Sources] Contract Symbol => ::Middleman::Sources def by_type(type) - self.class.new @app, @options, watchers.select { |d| d.type == type } + self.class.new @app, nil, watchers.select { |d| d.type == type } end # Get all files for this collection of watchers. diff --git a/middleman-core/lib/middleman-core/sources/source_watcher.rb b/middleman-core/lib/middleman-core/sources/source_watcher.rb index 88d75f3f..8e3a3550 100644 --- a/middleman-core/lib/middleman-core/sources/source_watcher.rb +++ b/middleman-core/lib/middleman-core/sources/source_watcher.rb @@ -75,9 +75,10 @@ module Middleman @ignored = options.fetch(:ignored, proc { false }) @only = Array(options.fetch(:only, [])) - @disable_watcher = app.build? || @parent.options.fetch(:disable_watcher, false) - @force_polling = @parent.options.fetch(:force_polling, false) - @latency = @parent.options.fetch(:latency, nil) + @disable_watcher = app.build? + @force_polling = false + @latency = nil + @wait_for_delay = nil @listener = nil @@ -95,13 +96,20 @@ module Middleman def update_path(directory) @directory = Pathname(File.expand_path(directory, app.root)) - stop_listener! if @listener - - update([], @files.values.map { |source_file| source_file[:full_path] }) + without_listener_running do + update([], @files.values.map { |source_file| source_file[:full_path] }) + end poll_once! + end - listen! unless @disable_watcher + def update_config(options={}) + without_listener_running do + @disable_watcher = options.fetch(:disable_watcher, false) + @force_polling = options.fetch(:force_polling, false) + @latency = options.fetch(:latency, nil) + @wait_for_delay = options.fetch(:wait_for_delay, nil) + end end # Stop watching. @@ -160,10 +168,10 @@ module Middleman config = { force_polling: @force_polling, - wait_for_delay: 0.5 } - config[:latency] = @latency.to_i if @latency + config[:wait_for_delay] = @wait_for_delay.try(:to_f) || 0.5 + config[:latency] = @latency.to_f if @latency @listener = ::Listen.to(@directory.to_s, config, &method(:on_listener_change)) @@ -343,5 +351,20 @@ module Middleman @only.any? { |reg| file[:relative_path].to_s =~ reg } end end + + private + + def without_listener_running + listener_running = @listener && @listener.processing? + + stop_listener! if listener_running + + yield + + if listener_running + poll_once! + listen! + end + end end end From 97082d5fc47513c78ed69d8319bb3002c57c732d Mon Sep 17 00:00:00 2001 From: James Pearson Date: Fri, 4 Nov 2016 14:56:30 +0000 Subject: [PATCH 05/13] Added addressable to the gemfile (#2001) addressable is required for middleman init, but was not installed as part of a fresh install of Middleman --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index a4415ab8..491a940d 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ 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 # Optional middleman dependencies, included for tests gem 'haml', '>= 4.0.5', require: false From 5adea781c9087689e9e11a57aaff6bbf3921e9f0 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Fri, 4 Nov 2016 08:23:33 -0700 Subject: [PATCH 06/13] Fix up tests --- .rubocop.yml | 2 ++ Gemfile | 2 +- middleman-core/lib/middleman-core/version.rb | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) 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/Gemfile b/Gemfile index 491a940d..54dc7b36 100644 --- a/Gemfile +++ b/Gemfile @@ -27,7 +27,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/middleman-core/lib/middleman-core/version.rb b/middleman-core/lib/middleman-core/version.rb index 6f3f1228..cd959488 100644 --- a/middleman-core/lib/middleman-core/version.rb +++ b/middleman-core/lib/middleman-core/version.rb @@ -1,5 +1,5 @@ module Middleman # Current Version # @return [String] - VERSION = '4.1.10'.freeze unless const_defined?(:VERSION) + VERSION = '4.1.11'.freeze unless const_defined?(:VERSION) end From 046d15cfa5f91cf29b8bfa8f041930db152fe3e2 Mon Sep 17 00:00:00 2001 From: sandstrom Date: Thu, 17 Nov 2016 05:59:25 +0100 Subject: [PATCH 07/13] Fix addressable require (#2009) --- middleman-core/lib/middleman-core/util/paths.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middleman-core/lib/middleman-core/util/paths.rb b/middleman-core/lib/middleman-core/util/paths.rb index 2814cfc9..dfa60f15 100644 --- a/middleman-core/lib/middleman-core/util/paths.rb +++ b/middleman-core/lib/middleman-core/util/paths.rb @@ -1,7 +1,7 @@ # Core Pathname library used for traversal require 'pathname' require 'uri' -require 'addressable' +require 'addressable/uri' require 'memoist' require 'tilt' From 42e31c8c5ebc4580d391353fe69f391f8d0a708c Mon Sep 17 00:00:00 2001 From: Jonathan Allard Date: Thu, 17 Nov 2016 00:00:16 -0500 Subject: [PATCH 08/13] Make .html implicit for page IDs (#1996) * Make .html implicit for page IDs * Add Pry gem * Add setting :page_id_generator to override page ID derivation --- Gemfile | 5 ++ middleman-core/features/page-id.feature | 48 ++++++++++++++++++- .../fixtures/page-id-app/config-proc.rb | 7 +++ .../fixtures/page-id-app/source/feed.xml.erb | 1 + .../source/folder/foldern.html.erb | 1 + .../page-id-app/source/implicit.html.erb | 1 + .../page-id-app/source/index.html.erb | 8 ++++ .../lib/middleman-core/sitemap/resource.rb | 26 +++++++++- .../lib/middleman-core/util/paths.rb | 3 +- 9 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 middleman-core/fixtures/page-id-app/config-proc.rb create mode 100644 middleman-core/fixtures/page-id-app/source/feed.xml.erb create mode 100644 middleman-core/fixtures/page-id-app/source/folder/foldern.html.erb create mode 100644 middleman-core/fixtures/page-id-app/source/implicit.html.erb diff --git a/Gemfile b/Gemfile index 54dc7b36..db4043a0 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,11 @@ 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 gem 'sassc', '~> 1.8', require: false 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/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/lib/middleman-core/sitemap/resource.rb b/middleman-core/lib/middleman-core/sitemap/resource.rb index 9ff97478..f3619873 100644 --- a/middleman-core/lib/middleman-core/sitemap/resource.rb +++ b/middleman-core/lib/middleman-core/sitemap/resource.rb @@ -87,7 +87,7 @@ module Middleman Contract Or[Symbol, String, Fixnum] def page_id - metadata[:page][:id] || destination_path + metadata[:page][:id] || make_implicit_page_id(destination_path) end # Merge in new metadata specific to this resource. @@ -208,6 +208,30 @@ module Middleman "#<#{self.class} path=#{@path}>" end alias inspect to_s # Ruby 2.0 calls inspect for NoMethodError instead of to_s + + protected + + # Makes a page id based on path (when not otherwise given) + # + # Removes .html extension and potential leading slashes or dots + # eg. "foo/bar/baz.foo.html" => "foo/bar/baz.foo" + Contract String => String + def make_implicit_page_id(path) + @id ||= begin + if prok = @app.config[:page_id_generator] + return prok.call(path) + end + + basename = if ext == ".html" + File.basename(path, ext) + else + File.basename(path) + end + + # Remove leading dot or slash if present + File.join(File.dirname(path), basename).gsub(/^\.?\//, '') + end + end end class StringResource < Resource diff --git a/middleman-core/lib/middleman-core/util/paths.rb b/middleman-core/lib/middleman-core/util/paths.rb index dfa60f15..2e229392 100644 --- a/middleman-core/lib/middleman-core/util/paths.rb +++ b/middleman-core/lib/middleman-core/util/paths.rb @@ -152,7 +152,8 @@ module Middleman def url_for(app, path_or_resource, options={}) if path_or_resource.is_a?(String) || path_or_resource.is_a?(Symbol) r = app.sitemap.find_resource_by_page_id(path_or_resource) - path_or_resource = r if r + + path_or_resource = r ? r : path_or_resource.to_s end # Handle Resources and other things which define their own url method From a680fb30c54886a6b427ea9b11121b938281e106 Mon Sep 17 00:00:00 2001 From: Stanislav Date: Wed, 23 Nov 2016 20:34:53 +0300 Subject: [PATCH 09/13] Add bower_components ignore (#2010) --- middleman-core/lib/middleman-core/preview_server.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/middleman-core/lib/middleman-core/preview_server.rb b/middleman-core/lib/middleman-core/preview_server.rb index b70e9c99..4b2b713b 100644 --- a/middleman-core/lib/middleman-core/preview_server.rb +++ b/middleman-core/lib/middleman-core/preview_server.rb @@ -160,6 +160,9 @@ module Middleman path: root, only: match_against + # Hack around bower_components in root. + watcher.listener.ignore(/^bower_components/) + # Hack around node_modules in root. watcher.listener.ignore(/^node_modules/) From e30f413376840967157977f56b6298758c222745 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Fri, 25 Nov 2016 13:58:35 -0800 Subject: [PATCH 10/13] Fix broken block ignore form. --- CHANGELOG.md | 8 ++++++++ .../lib/middleman-core/sitemap/extensions/ignores.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6494a17..ccfc2272 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ master === +# 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. diff --git a/middleman-core/lib/middleman-core/sitemap/extensions/ignores.rb b/middleman-core/lib/middleman-core/sitemap/extensions/ignores.rb index ad2d95c0..0367c64a 100644 --- a/middleman-core/lib/middleman-core/sitemap/extensions/ignores.rb +++ b/middleman-core/lib/middleman-core/sitemap/extensions/ignores.rb @@ -74,7 +74,7 @@ module Middleman end end - class BlockIgnoreDescriptor + class BlockIgnoreDescriptor < IgnoreDescriptor def ignored?(match_path) block.call(match_path) end From 073f273fe4465fdfb642adb567153d806c67dfcc Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Fri, 25 Nov 2016 14:03:56 -0800 Subject: [PATCH 11/13] Prep --- middleman-core/lib/middleman-core/version.rb | 2 +- middleman-core/spec/middleman-core/util_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/middleman-core/lib/middleman-core/version.rb b/middleman-core/lib/middleman-core/version.rb index cd959488..2519db9e 100644 --- a/middleman-core/lib/middleman-core/version.rb +++ b/middleman-core/lib/middleman-core/version.rb @@ -1,5 +1,5 @@ module Middleman # Current Version # @return [String] - VERSION = '4.1.11'.freeze unless const_defined?(:VERSION) + VERSION = '4.1.12'.freeze unless const_defined?(:VERSION) end diff --git a/middleman-core/spec/middleman-core/util_spec.rb b/middleman-core/spec/middleman-core/util_spec.rb index a852521d..9c429145 100644 --- a/middleman-core/spec/middleman-core/util_spec.rb +++ b/middleman-core/spec/middleman-core/util_spec.rb @@ -220,7 +220,7 @@ describe Middleman::Util do it "does not loop infinitely when file name is a possible templating engine" do expect do - Timeout::timeout(0.5) do + Timeout::timeout(3.0) do result = Middleman::Util.step_through_extensions("markdown.scss") expect(result).to eq "markdown" end From 30217d2c04d52179aca6d0dc1dd07fdee7d56ed2 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Tue, 29 Nov 2016 20:14:19 -0800 Subject: [PATCH 12/13] Change how config options are passed to Thor. Removes new Thor warnings from #2017 --- CHANGELOG.md | 4 ++++ middleman-cli/bin/middleman | 2 -- middleman-cli/lib/middleman-cli/build.rb | 4 ++-- middleman-cli/lib/middleman-cli/server.rb | 2 +- middleman-core/lib/middleman-core/application.rb | 1 + middleman-core/lib/middleman-core/preview_server.rb | 6 +++--- middleman-core/lib/middleman-core/version.rb | 2 +- 7 files changed, 12 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccfc2272..148aa2e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ master === +# 4.1.13 + +* Change how config options are passed to Thor. Removes new Thor warnings from #2017 + # 4.1.12 * Fix broken `ignore { |p| true }` form. diff --git a/middleman-cli/bin/middleman b/middleman-cli/bin/middleman index 46fa5889..8b381a08 100755 --- a/middleman-cli/bin/middleman +++ b/middleman-cli/bin/middleman @@ -25,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 diff --git a/middleman-cli/lib/middleman-cli/build.rb b/middleman-cli/lib/middleman-cli/build.rb index df871ce2..9e521dde 100644 --- a/middleman-cli/lib/middleman-cli/build.rb +++ b/middleman-cli/lib/middleman-cli/build.rb @@ -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/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-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index 52b31c92..eb819433 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -306,6 +306,7 @@ module Middleman execute_callbacks(:after_configuration) # Everything is stable + $stderr.puts config[:exit_before_ready].inspect execute_callbacks(:ready) unless config[:exit_before_ready] end diff --git a/middleman-core/lib/middleman-core/preview_server.rb b/middleman-core/lib/middleman-core/preview_server.rb index 4b2b713b..1a3d220e 100644 --- a/middleman-core/lib/middleman-core/preview_server.rb +++ b/middleman-core/lib/middleman-core/preview_server.rb @@ -143,7 +143,7 @@ module Middleman app = ::Middleman::Application.new do config[:cli_options] = cli_options.each_with_object({}) do |(k, v), sum| - sum[k] = v unless v == :undefined + sum[k] = v end ready do @@ -162,7 +162,7 @@ module Middleman # Hack around bower_components in root. watcher.listener.ignore(/^bower_components/) - + # Hack around node_modules in root. watcher.listener.ignore(/^node_modules/) @@ -207,7 +207,7 @@ module Middleman end def possible_from_cli(key, config) - if @cli_options[key] && @cli_options[key] != :undefined + if @cli_options[key] @cli_options[key] else config[key] diff --git a/middleman-core/lib/middleman-core/version.rb b/middleman-core/lib/middleman-core/version.rb index 2519db9e..94753eef 100644 --- a/middleman-core/lib/middleman-core/version.rb +++ b/middleman-core/lib/middleman-core/version.rb @@ -1,5 +1,5 @@ module Middleman # Current Version # @return [String] - VERSION = '4.1.12'.freeze unless const_defined?(:VERSION) + VERSION = '4.1.13'.freeze unless const_defined?(:VERSION) end From b6167b1369827d871421eb0ee88cb7bf15fbdc5c Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Sat, 3 Dec 2016 11:32:09 -0800 Subject: [PATCH 13/13] Fix #2019 --- middleman-core/lib/middleman-core/application.rb | 1 - middleman-core/lib/middleman-core/version.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index eb819433..52b31c92 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -306,7 +306,6 @@ module Middleman execute_callbacks(:after_configuration) # Everything is stable - $stderr.puts config[:exit_before_ready].inspect execute_callbacks(:ready) unless config[:exit_before_ready] end diff --git a/middleman-core/lib/middleman-core/version.rb b/middleman-core/lib/middleman-core/version.rb index 94753eef..7b1bf403 100644 --- a/middleman-core/lib/middleman-core/version.rb +++ b/middleman-core/lib/middleman-core/version.rb @@ -1,5 +1,5 @@ module Middleman # Current Version # @return [String] - VERSION = '4.1.13'.freeze unless const_defined?(:VERSION) + VERSION = '4.1.14'.freeze unless const_defined?(:VERSION) end