From 2b449bc3989ad99111a990699bfd956ead601644 Mon Sep 17 00:00:00 2001 From: Artem Vorotnikov Date: Sun, 5 Jul 2015 09:19:10 +0300 Subject: [PATCH 01/30] Remove showtitle attribute from asciidoc renderer --- .../fixtures/asciidoc-app/source/hello-with-title.adoc | 1 + middleman-core/lib/middleman-core/renderers/asciidoc.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/middleman-core/fixtures/asciidoc-app/source/hello-with-title.adoc b/middleman-core/fixtures/asciidoc-app/source/hello-with-title.adoc index e2c7673b..d687c940 100644 --- a/middleman-core/fixtures/asciidoc-app/source/hello-with-title.adoc +++ b/middleman-core/fixtures/asciidoc-app/source/hello-with-title.adoc @@ -1,4 +1,5 @@ = Page Title +:showtitle: :page-layout: default Hello, AsciiDoc! diff --git a/middleman-core/lib/middleman-core/renderers/asciidoc.rb b/middleman-core/lib/middleman-core/renderers/asciidoc.rb index 9ad14a53..c8fa1d78 100644 --- a/middleman-core/lib/middleman-core/renderers/asciidoc.rb +++ b/middleman-core/lib/middleman-core/renderers/asciidoc.rb @@ -8,7 +8,7 @@ module Middleman app.config.define_setting :asciidoc, { safe: :safe, backend: :html5, - attributes: %W(showtitle env=middleman env-middleman middleman-version=#{::Middleman::VERSION}) + attributes: %W(env=middleman env-middleman middleman-version=#{::Middleman::VERSION}) }, 'AsciiDoc engine options (Hash)' app.config.define_setting :asciidoc_attributes, [], 'AsciiDoc custom attributes (Array)' app.before_configuration do From fa3a95fa2337a916266f9ae4119cc962a7c89afb Mon Sep 17 00:00:00 2001 From: Ash Furrow Date: Sat, 1 Aug 2015 18:09:14 -0400 Subject: [PATCH 02/30] Fixes problem with after_render hooks returning nil. --- .../lib/middleman-core/core_extensions/rendering.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/middleman-core/lib/middleman-core/core_extensions/rendering.rb b/middleman-core/lib/middleman-core/core_extensions/rendering.rb index 11e1cbb0..c1aab213 100644 --- a/middleman-core/lib/middleman-core/core_extensions/rendering.rb +++ b/middleman-core/lib/middleman-core/core_extensions/rendering.rb @@ -316,9 +316,9 @@ module Middleman self.class.callbacks_for_hook(:after_render).each do |callback| # Uber::Options::Value doesn't respond to call newcontent = if callback.respond_to?(:call) - content = callback.call(content, path, locs, template_class) + callback.call(content, path, locs, template_class) elsif callback.respond_to?(:evaluate) - content = callback.evaluate(self, content, path, locs, template_class) + callback.evaluate(self, content, path, locs, template_class) end content = newcontent if newcontent # Allow the callback to return nil to skip it end From 10feaad451fcb58b7c8da3eef73321fb87adb9c5 Mon Sep 17 00:00:00 2001 From: nslocum Date: Fri, 11 Sep 2015 08:42:52 -0400 Subject: [PATCH 03/30] Ignore gems installed in local dir. --- middleman-core/lib/middleman-core/templates/shared/gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/middleman-core/lib/middleman-core/templates/shared/gitignore b/middleman-core/lib/middleman-core/templates/shared/gitignore index a320f7b6..33061e33 100644 --- a/middleman-core/lib/middleman-core/templates/shared/gitignore +++ b/middleman-core/lib/middleman-core/templates/shared/gitignore @@ -16,3 +16,6 @@ # Ignore .DS_store file .DS_Store + +# Ignore gems installed in local directory +vendor/bundle/ From c09b15a8957aa80d0dea333138450727ba6800f7 Mon Sep 17 00:00:00 2001 From: Nick Slocum Date: Sun, 13 Sep 2015 11:05:11 -0400 Subject: [PATCH 04/30] specify the root directory. --- middleman-core/lib/middleman-core/templates/shared/gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middleman-core/lib/middleman-core/templates/shared/gitignore b/middleman-core/lib/middleman-core/templates/shared/gitignore index 33061e33..67e76f65 100644 --- a/middleman-core/lib/middleman-core/templates/shared/gitignore +++ b/middleman-core/lib/middleman-core/templates/shared/gitignore @@ -18,4 +18,4 @@ .DS_Store # Ignore gems installed in local directory -vendor/bundle/ +/vendor/bundle/ From 2aac804e925880defd737bcd26fde5ad76eb11b9 Mon Sep 17 00:00:00 2001 From: inoue_sachiro Date: Wed, 30 Sep 2015 21:23:27 +0900 Subject: [PATCH 05/30] Fix: Can't clean files when the project is under a hidden directory. --- middleman-core/features/clean_build.feature | 18 ++++++++++++++++++ .../clean-app/config-hidden-dir-after.rb | 5 +++++ .../clean-app/config-hidden-dir-before.rb | 1 + middleman-core/lib/middleman-core/cli/build.rb | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 middleman-core/fixtures/clean-app/config-hidden-dir-after.rb create mode 100644 middleman-core/fixtures/clean-app/config-hidden-dir-before.rb diff --git a/middleman-core/features/clean_build.feature b/middleman-core/features/clean_build.feature index e5254df4..eaa9942e 100644 --- a/middleman-core/features/clean_build.feature +++ b/middleman-core/features/clean_build.feature @@ -42,3 +42,21 @@ Feature: Build Clean Then the following files should not exist: | sub/dir/about.html | | sub/dir/nested/nested.html | + + Scenario: Build and clean an app under a hidden directory + Given a fixture app "clean-app" + And app "clean-app" is using config "hidden-dir-before" + And a built app at "clean-app" + Then the following files should exist: + | .build/index.html | + | .build/should_be_ignored.html | + | .build/should_be_ignored2.html | + | .build/should_be_ignored3.html | + Given app "clean-app" is using config "hidden-dir-after" + And a built app at "clean-app" + Then the following files should exist: + | .build/index.html | + And the following files should not exist: + | .build/should_be_ignored.html | + | .build/should_be_ignored2.html | + | .build/should_be_ignored3.html | diff --git a/middleman-core/fixtures/clean-app/config-hidden-dir-after.rb b/middleman-core/fixtures/clean-app/config-hidden-dir-after.rb new file mode 100644 index 00000000..454d5cf8 --- /dev/null +++ b/middleman-core/fixtures/clean-app/config-hidden-dir-after.rb @@ -0,0 +1,5 @@ +set :build_dir, ".build" + +ignore "/should_be_ignored.html" +page "/should_be_ignored2.html", :ignore => true +page "/target_ignore.html", :proxy => "/should_be_ignored3.html", :ignore => true diff --git a/middleman-core/fixtures/clean-app/config-hidden-dir-before.rb b/middleman-core/fixtures/clean-app/config-hidden-dir-before.rb new file mode 100644 index 00000000..69609a81 --- /dev/null +++ b/middleman-core/fixtures/clean-app/config-hidden-dir-before.rb @@ -0,0 +1 @@ +set :build_dir, ".build" diff --git a/middleman-core/lib/middleman-core/cli/build.rb b/middleman-core/lib/middleman-core/cli/build.rb index e32a5252..541dc23a 100644 --- a/middleman-core/lib/middleman-core/cli/build.rb +++ b/middleman-core/lib/middleman-core/cli/build.rb @@ -167,7 +167,7 @@ module Middleman::Cli paths = ::Middleman::Util.all_files_under(@build_dir).map(&:realpath).select(&:file?) @to_clean += paths.select do |path| - path.to_s !~ /\/\./ || path.to_s =~ /\.(htaccess|htpasswd)/ + path.relative_path_from(@build_dir.realpath).to_s !~ /\/\./ || path.to_s =~ /\.(htaccess|htpasswd)/ end return unless RUBY_PLATFORM =~ /darwin/ From 65a65b9677a12d7e6a03f9f93565719ef0f72599 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 3 Oct 2015 10:06:52 +0900 Subject: [PATCH 06/30] remove unnecessary require `require 'rubygems'` is already required in Ruby 1.9 or later. --- Rakefile | 1 - gem_rake_helper.rb | 1 - middleman-core/Rakefile | 1 - middleman-core/lib/middleman-core/extensions.rb | 2 -- middleman-core/lib/middleman-core/templates/shared/config.ru | 1 - 5 files changed, 6 deletions(-) diff --git a/Rakefile b/Rakefile index d1fe239e..78c26691 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,3 @@ -require 'rubygems' unless defined?(Gem) require 'rake' require File.expand_path('../middleman-core/lib/middleman-core/version.rb', __FILE__) diff --git a/gem_rake_helper.rb b/gem_rake_helper.rb index ff7a592d..0fdd80bb 100644 --- a/gem_rake_helper.rb +++ b/gem_rake_helper.rb @@ -1,4 +1,3 @@ -require 'rubygems' unless defined?(Gem) require 'rake' require 'yard' diff --git a/middleman-core/Rakefile b/middleman-core/Rakefile index 6e3c4ee8..5cbeb120 100644 --- a/middleman-core/Rakefile +++ b/middleman-core/Rakefile @@ -3,5 +3,4 @@ RAKE_ROOT = __FILE__ GEM_NAME = ENV['NAME'] || 'middleman-core' -require 'rubygems' require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper') diff --git a/middleman-core/lib/middleman-core/extensions.rb b/middleman-core/lib/middleman-core/extensions.rb index bef3d44d..7334a89b 100644 --- a/middleman-core/lib/middleman-core/extensions.rb +++ b/middleman-core/lib/middleman-core/extensions.rb @@ -56,8 +56,6 @@ module Middleman # # @private def load_extensions_in_path - require 'rubygems' - extensions = rubygems_latest_specs.select do |spec| spec_has_file?(spec, EXTENSION_FILE) end diff --git a/middleman-core/lib/middleman-core/templates/shared/config.ru b/middleman-core/lib/middleman-core/templates/shared/config.ru index 9bff44ef..f7fc24a0 100644 --- a/middleman-core/lib/middleman-core/templates/shared/config.ru +++ b/middleman-core/lib/middleman-core/templates/shared/config.ru @@ -1,4 +1,3 @@ -require 'rubygems' require 'middleman/rack' run Middleman.server From 5a4d7352f14e05ca7af2510544bf01db651b7e55 Mon Sep 17 00:00:00 2001 From: Mike Boone Date: Sun, 4 Oct 2015 20:59:53 -0400 Subject: [PATCH 07/30] Fixed typos. --- middleman-core/lib/middleman-core/cli.rb | 2 +- middleman-core/lib/middleman-core/configuration.rb | 2 +- .../lib/middleman-core/core_extensions/rendering.rb | 4 ++-- .../lib/middleman-core/core_extensions/show_exceptions.rb | 2 +- middleman-core/lib/middleman-core/meta_pages/sitemap_tree.rb | 2 +- middleman-core/lib/middleman-core/preview_server.rb | 2 +- .../lib/middleman-core/preview_server/server_information.rb | 2 +- middleman-core/lib/middleman-core/renderers/liquid.rb | 2 +- .../lib/middleman-core/sitemap/extensions/content_type.rb | 2 +- middleman-core/lib/middleman-core/sitemap/store.rb | 4 ++-- middleman-core/lib/middleman-core/util.rb | 2 +- middleman-core/lib/middleman-more/extensions/cache_buster.rb | 2 +- 12 files changed, 14 insertions(+), 14 deletions(-) diff --git a/middleman-core/lib/middleman-core/cli.rb b/middleman-core/lib/middleman-core/cli.rb index 5090351f..8cf5976f 100644 --- a/middleman-core/lib/middleman-core/cli.rb +++ b/middleman-core/lib/middleman-core/cli.rb @@ -5,7 +5,7 @@ require 'thor/group' # CLI Module module Middleman module Cli - # The base task from which everything else etends + # The base task from which everything else extends class Base < Thor class << self def start(*args) diff --git a/middleman-core/lib/middleman-core/configuration.rb b/middleman-core/lib/middleman-core/configuration.rb index e1cff713..a95c1933 100644 --- a/middleman-core/lib/middleman-core/configuration.rb +++ b/middleman-core/lib/middleman-core/configuration.rb @@ -48,7 +48,7 @@ module Middleman self.class.config end - # Backwards compatibilty with old Sinatra template interface + # Backwards compatibility with old Sinatra template interface # # @deprecated Prefer accessing settings through "config". # diff --git a/middleman-core/lib/middleman-core/core_extensions/rendering.rb b/middleman-core/lib/middleman-core/core_extensions/rendering.rb index c1aab213..aa3e4430 100644 --- a/middleman-core/lib/middleman-core/core_extensions/rendering.rb +++ b/middleman-core/lib/middleman-core/core_extensions/rendering.rb @@ -214,7 +214,7 @@ module Middleman locals = options[:locals] if ::Tilt[found_partial] - # Render the partial if found, otherwide throw exception + # Render the partial if found, otherwise throw exception _render_with_all_renderers(found_partial, locals, self, options, &block) else read_template_file(found_partial) @@ -265,7 +265,7 @@ module Middleman # Try to work around: https://github.com/middleman/middleman/issues/501 locs = locs.dup - # Detect the remdering engine from the extension + # Detect the rendering engine from the extension extension = File.extname(path) engine = extension[1..-1].to_sym diff --git a/middleman-core/lib/middleman-core/core_extensions/show_exceptions.rb b/middleman-core/lib/middleman-core/core_extensions/show_exceptions.rb index 5eba1c0a..380b76b9 100644 --- a/middleman-core/lib/middleman-core/core_extensions/show_exceptions.rb +++ b/middleman-core/lib/middleman-core/core_extensions/show_exceptions.rb @@ -15,7 +15,7 @@ module Middleman # When in dev app.configure :development do - # Include middlemare + # Include middleware use ::Rack::ShowExceptions if config[:show_exceptions] end end diff --git a/middleman-core/lib/middleman-core/meta_pages/sitemap_tree.rb b/middleman-core/lib/middleman-core/meta_pages/sitemap_tree.rb index 4ba89350..66c9b4ca 100644 --- a/middleman-core/lib/middleman-core/meta_pages/sitemap_tree.rb +++ b/middleman-core/lib/middleman-core/meta_pages/sitemap_tree.rb @@ -59,7 +59,7 @@ module Middleman if path_parts.size == 1 sitemap_class = SitemapResource - # Allow special sitemap resources to use custom metadata view calsses + # Allow special sitemap resources to use custom metadata view classes sitemap_class = resource.meta_pages_class if resource.respond_to? :meta_pages_class @children[first_part] = sitemap_class.new(resource) diff --git a/middleman-core/lib/middleman-core/preview_server.rb b/middleman-core/lib/middleman-core/preview_server.rb index 9076b2fa..78a2ac7a 100644 --- a/middleman-core/lib/middleman-core/preview_server.rb +++ b/middleman-core/lib/middleman-core/preview_server.rb @@ -199,7 +199,7 @@ module Middleman @listener.start end - # Trap some interupt signals and shut down smoothly + # Trap some interrupt signals and shut down smoothly # @return [void] def register_signal_handlers %w(INT HUP TERM QUIT).each do |sig| diff --git a/middleman-core/lib/middleman-core/preview_server/server_information.rb b/middleman-core/lib/middleman-core/preview_server/server_information.rb index 937efdd5..186d3423 100644 --- a/middleman-core/lib/middleman-core/preview_server/server_information.rb +++ b/middleman-core/lib/middleman-core/preview_server/server_information.rb @@ -70,7 +70,7 @@ module Middleman config[:server_name] = server_name end - # Make information of internal server class avaible to make debugging + # Make information of internal server class available to make debugging # easier. This can be used to log the class which was used to determine # the preview server settings # diff --git a/middleman-core/lib/middleman-core/renderers/liquid.rb b/middleman-core/lib/middleman-core/renderers/liquid.rb index 376a8709..faffd370 100644 --- a/middleman-core/lib/middleman-core/renderers/liquid.rb +++ b/middleman-core/lib/middleman-core/renderers/liquid.rb @@ -7,7 +7,7 @@ module Middleman module Liquid # Setup extension class << self - # Once registerd + # Once registered def registered(app) app.before_configuration do template_extensions liquid: :html diff --git a/middleman-core/lib/middleman-core/sitemap/extensions/content_type.rb b/middleman-core/lib/middleman-core/sitemap/extensions/content_type.rb index 619ec225..8f6498dd 100644 --- a/middleman-core/lib/middleman-core/sitemap/extensions/content_type.rb +++ b/middleman-core/lib/middleman-core/sitemap/extensions/content_type.rb @@ -5,7 +5,7 @@ module Middleman::Sitemap::Extensions module ContentType # The preferred MIME content type for this resource def content_type - # Allow explcitly setting content type from page/proxy options + # Allow explicitly setting content type from page/proxy options meta_type = metadata[:options][:content_type] return meta_type if meta_type diff --git a/middleman-core/lib/middleman-core/sitemap/store.rb b/middleman-core/lib/middleman-core/sitemap/store.rb index aa46497b..14625743 100644 --- a/middleman-core/lib/middleman-core/sitemap/store.rb +++ b/middleman-core/lib/middleman-core/sitemap/store.rb @@ -54,7 +54,7 @@ module Middleman rebuild_resource_list!(:registered_new) end - # Rebuild the list of resources from scratch, using registed manipulators + # Rebuild the list of resources from scratch, using registered manipulators # rubocop:disable UnusedMethodArgument # @return [void] def rebuild_resource_list!(reason=nil) @@ -99,7 +99,7 @@ module Middleman end end - # Invalidate our cached view of resource that are not ingnored. If your extension + # Invalidate our cached view of resource that are not ignored. If your extension # adds ways to ignore files, you should call this to make sure #resources works right. def invalidate_resources_not_ignored_cache! @resources_not_ignored = nil diff --git a/middleman-core/lib/middleman-core/util.rb b/middleman-core/lib/middleman-core/util.rb index d559a442..7e695abc 100644 --- a/middleman-core/lib/middleman-core/util.rb +++ b/middleman-core/lib/middleman-core/util.rb @@ -112,7 +112,7 @@ module Middleman end end - # Get a recusive list of files inside a path. + # Get a recursive list of files inside a path. # Works with symlinks. # # @param path Some path string or Pathname diff --git a/middleman-core/lib/middleman-more/extensions/cache_buster.rb b/middleman-core/lib/middleman-more/extensions/cache_buster.rb index 1028cb84..24b6e240 100644 --- a/middleman-core/lib/middleman-more/extensions/cache_buster.rb +++ b/middleman-core/lib/middleman-more/extensions/cache_buster.rb @@ -43,7 +43,7 @@ class Middleman::Extensions::CacheBuster < ::Middleman::Extension else # It's a template, possible with partials. We can't really # know when it's updated, so generate fresh cache buster every - # time during developement + # time during development http_path << '?' + Time.now.strftime('%s') end end From 9a529cd29403ae0ef74653243e6c07ce668c0cb6 Mon Sep 17 00:00:00 2001 From: Alex Sharp Date: Mon, 5 Oct 2015 11:08:52 -0700 Subject: [PATCH 08/30] Add Errno::ENETUNREACH to exception list in BasicNetworkResolver Fixes #1621 --- .../lib/middleman-core/dns_resolver/basic_network_resolver.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/middleman-core/lib/middleman-core/dns_resolver/basic_network_resolver.rb b/middleman-core/lib/middleman-core/dns_resolver/basic_network_resolver.rb index 11dc3096..f4b90deb 100644 --- a/middleman-core/lib/middleman-core/dns_resolver/basic_network_resolver.rb +++ b/middleman-core/lib/middleman-core/dns_resolver/basic_network_resolver.rb @@ -21,7 +21,7 @@ module Middleman # Array of Names def getnames(ip) resolver.getnames(ip.to_s).map(&:to_s) - rescue Resolv::ResolvError, Errno::EADDRNOTAVAIL + rescue Resolv::ResolvError, Errno::EADDRNOTAVAIL, Errno::ENETUNREACH [] end @@ -34,7 +34,7 @@ module Middleman # Array of ipaddresses def getaddresses(name) resolver.getaddresses(name.to_s).map(&:to_s) - rescue Resolv::ResolvError, Errno::EADDRNOTAVAIL + rescue Resolv::ResolvError, Errno::EADDRNOTAVAIL, Errno::ENETUNREACH [] end From 3a7848da9e9ce9acfd59b36fe47e1bce841a3161 Mon Sep 17 00:00:00 2001 From: Alexey Pokhozhaev Date: Fri, 2 Oct 2015 15:12:13 +0300 Subject: [PATCH 09/30] Little bit cleaned up. Dry in rake tasks. Fix $LOAD_PATH --- Gemfile | 2 +- Rakefile | 31 +++++++++---------------- middleman-core/.gemtest | 0 middleman-core/.rspec | 1 - middleman-core/Rakefile | 7 +----- middleman-core/lib/middleman-core.rb | 4 ---- middleman-core/middleman-core.gemspec | 6 +++-- middleman/.gemtest | 0 middleman/Rakefile | 6 +---- middleman/features/.gitkeep | 0 middleman/fixtures/.gitkeep | 0 middleman/middleman.gemspec | 8 +++---- middleman/spec/middleman/future_spec.rb | 0 middleman/spec/spec_helper.rb | 0 14 files changed, 22 insertions(+), 43 deletions(-) delete mode 100644 middleman-core/.gemtest delete mode 100644 middleman-core/.rspec delete mode 100644 middleman/.gemtest delete mode 100644 middleman/features/.gitkeep delete mode 100644 middleman/fixtures/.gitkeep delete mode 100644 middleman/spec/middleman/future_spec.rb delete mode 100644 middleman/spec/spec_helper.rb diff --git a/Gemfile b/Gemfile index 08de2a54..2c8a8e9e 100644 --- a/Gemfile +++ b/Gemfile @@ -35,6 +35,6 @@ gem 'simplecov', '~> 0.10', require: false gem 'coveralls', '~> 0.8', require: false # Middleman itself -gem 'middleman', path: 'middleman' gem 'middleman-core', path: 'middleman-core' +gem 'middleman', path: 'middleman' gem 'middleman-sprockets', github: 'middleman/middleman-sprockets', branch: 'v3-stable-real' diff --git a/Rakefile b/Rakefile index 78c26691..89546ff3 100644 --- a/Rakefile +++ b/Rakefile @@ -1,17 +1,17 @@ require 'rake' -require File.expand_path('../middleman-core/lib/middleman-core/version.rb', __FILE__) - -ROOT = File.expand_path(File.dirname(__FILE__)) -GEM_NAME = 'middleman' - -middleman_gems = %w(middleman-core middleman) -GEM_PATHS = middleman_gems.freeze +require 'middleman-core/version' def sh_rake(command) sh "#{Gem.ruby} -S rake #{command}", verbose: true end +def within_each_gem(&block) + %w(middleman-core middleman).each do |dir| + Dir.chdir(dir) { block.call } + end +end + desc 'Displays the current version' task :version do puts "Current version: #{Middleman::VERSION}" @@ -28,32 +28,23 @@ end desc 'Release all middleman gems' task publish: :push do puts 'Pushing to rubygems...' - GEM_PATHS.each do |dir| - Dir.chdir(dir) { sh_rake('release') } - end + within_each_gem { sh_rake('release') } end desc 'Generate documentation for all middleman gems' task :doc do - GEM_PATHS.each do |g| - Dir.chdir("#{File.join(ROOT, g)}") { sh "#{Gem.ruby} -S rake yard" } - end + within_each_gem { sh_rake('yard') } end desc 'Run tests for all middleman gems' task :test do Rake::Task['rubocop'].invoke - - GEM_PATHS.each do |g| - Dir.chdir("#{File.join(ROOT, g)}") { sh "#{Gem.ruby} -S rake test" } - end + within_each_gem { sh_rake('test') } end desc 'Run specs for all middleman gems' task :spec do - GEM_PATHS.each do |g| - Dir.chdir("#{File.join(ROOT, g)}") { sh "#{Gem.ruby} -S rake spec" } - end + within_each_gem { sh_rake('spec') } end require 'rubocop/rake_task' diff --git a/middleman-core/.gemtest b/middleman-core/.gemtest deleted file mode 100644 index e69de29b..00000000 diff --git a/middleman-core/.rspec b/middleman-core/.rspec deleted file mode 100644 index 4e1e0d2f..00000000 --- a/middleman-core/.rspec +++ /dev/null @@ -1 +0,0 @@ ---color diff --git a/middleman-core/Rakefile b/middleman-core/Rakefile index 5cbeb120..a093ee44 100644 --- a/middleman-core/Rakefile +++ b/middleman-core/Rakefile @@ -1,6 +1 @@ -# coding:utf-8 -RAKE_ROOT = __FILE__ - -GEM_NAME = ENV['NAME'] || 'middleman-core' - -require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper') +require_relative '../gem_rake_helper' diff --git a/middleman-core/lib/middleman-core.rb b/middleman-core/lib/middleman-core.rb index 8170fefb..5a1e7294 100644 --- a/middleman-core/lib/middleman-core.rb +++ b/middleman-core/lib/middleman-core.rb @@ -1,9 +1,5 @@ # rubocop:disable FileName -# Setup our load paths -libdir = File.expand_path(File.dirname(__FILE__)) -$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir) - # Top-level Middleman namespace module Middleman # Backwards compatibility namespace diff --git a/middleman-core/middleman-core.gemspec b/middleman-core/middleman-core.gemspec index 844e6de9..7c5d6d0b 100644 --- a/middleman-core/middleman-core.gemspec +++ b/middleman-core/middleman-core.gemspec @@ -1,5 +1,7 @@ -# -*- encoding: utf-8 -*- -require File.expand_path("../lib/middleman-core/version", __FILE__) +lib = File.expand_path("../lib", __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) + +require "middleman-core/version" Gem::Specification.new do |s| s.name = "middleman-core" diff --git a/middleman/.gemtest b/middleman/.gemtest deleted file mode 100644 index e69de29b..00000000 diff --git a/middleman/Rakefile b/middleman/Rakefile index 120b9c7c..a093ee44 100644 --- a/middleman/Rakefile +++ b/middleman/Rakefile @@ -1,5 +1 @@ -# coding:utf-8 -RAKE_ROOT = __FILE__ - -GEM_NAME = 'middleman' -require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper') +require_relative '../gem_rake_helper' diff --git a/middleman/features/.gitkeep b/middleman/features/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/middleman/fixtures/.gitkeep b/middleman/fixtures/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/middleman/middleman.gemspec b/middleman/middleman.gemspec index 11e4e871..b34ebfbb 100644 --- a/middleman/middleman.gemspec +++ b/middleman/middleman.gemspec @@ -1,6 +1,7 @@ -# -*- encoding: utf-8 -*- -$:.push File.expand_path("../lib", __FILE__) -require File.expand_path("../../middleman-core/lib/middleman-core/version.rb", __FILE__) +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) + +require "middleman-core/version" Gem::Specification.new do |s| s.name = "middleman" @@ -14,7 +15,6 @@ Gem::Specification.new do |s| s.description = "A static site generator. Provides dozens of templating languages (Haml, Sass, Compass, Slim, CoffeeScript, and more). Makes minification, compression, cache busting, Yaml data (and more) an easy part of your development cycle." s.files = `git ls-files -z`.split("\0") - s.test_files = `git ls-files -z -- {fixtures,features}/*`.split("\0") s.require_paths = ["lib"] s.required_ruby_version = '>= 1.9.3' diff --git a/middleman/spec/middleman/future_spec.rb b/middleman/spec/middleman/future_spec.rb deleted file mode 100644 index e69de29b..00000000 diff --git a/middleman/spec/spec_helper.rb b/middleman/spec/spec_helper.rb deleted file mode 100644 index e69de29b..00000000 From b9cdc2bba41f978cbfa9e9dcdc59d74cf8c0b1c0 Mon Sep 17 00:00:00 2001 From: Alexey Pokhozhaev Date: Wed, 7 Oct 2015 15:29:34 +0300 Subject: [PATCH 10/30] Run cucumber if features directory exists + removed unused task --- gem_rake_helper.rb | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/gem_rake_helper.rb b/gem_rake_helper.rb index 0fdd80bb..ab9037fd 100644 --- a/gem_rake_helper.rb +++ b/gem_rake_helper.rb @@ -21,15 +21,7 @@ Cucumber::Rake::Task.new do |t| exempt_tags << '--tags ~@nowindows' if Gem.win_platform? exempt_tags << '--tags ~@travishatesme' if ENV['TRAVIS'] == 'true' t.cucumber_opts = "--require features --color #{exempt_tags.join(' ')} --strict"# --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}" -end - -Cucumber::Rake::Task.new(:cucumber_wip) do |t| - exempt_tags = ['--tags @wip'] - exempt_tags << '--tags ~@nojava' if RUBY_PLATFORM == 'java' - exempt_tags << '--tags ~@encoding' unless Object.const_defined?(:Encoding) - exempt_tags << '--tags ~@nowindows' if Gem.win_platform? - t.cucumber_opts = "--color #{exempt_tags.join(' ')} --strict"# --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}" -end +end if Dir.exists? 'features' require 'rspec/core/rake_task' desc 'Run RSpec' From 4d46b84aaeabbb1095030c97612a419ab7af84a3 Mon Sep 17 00:00:00 2001 From: Alexey Pokhozhaev Date: Wed, 7 Oct 2015 15:59:12 +0300 Subject: [PATCH 11/30] Do not run specs if there is no spec directory --- gem_rake_helper.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gem_rake_helper.rb b/gem_rake_helper.rb index ab9037fd..4e5bd75b 100644 --- a/gem_rake_helper.rb +++ b/gem_rake_helper.rb @@ -21,7 +21,7 @@ Cucumber::Rake::Task.new do |t| exempt_tags << '--tags ~@nowindows' if Gem.win_platform? exempt_tags << '--tags ~@travishatesme' if ENV['TRAVIS'] == 'true' t.cucumber_opts = "--require features --color #{exempt_tags.join(' ')} --strict"# --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}" -end if Dir.exists? 'features' +end require 'rspec/core/rake_task' desc 'Run RSpec' @@ -30,8 +30,12 @@ RSpec::Core::RakeTask.new do |spec| spec.rspec_opts = ['--color', '--format documentation'] end +test_tasks = [] +test_tasks << :spec if Dir.exists? 'spec' +test_tasks << :cucumber if Dir.exists? 'features' + desc 'Run tests, both RSpec and Cucumber' -task test: [:spec, :cucumber] +task test: test_tasks YARD::Rake::YardocTask.new From 492281f9e8d2957f34d7a53b7f5445a8be1803e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Fri, 9 Oct 2015 11:06:41 +0200 Subject: [PATCH 12/30] Refator Data Loader to prevent middleman from crashing due to invalid data file --- middleman-core/features/data.feature | 28 ++++++++ .../middleman-core/core_extensions/data.rb | 12 ++-- .../core_extensions/data/file_loader.rb | 71 +++++++++++++++++++ 3 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 middleman-core/lib/middleman-core/core_extensions/data/file_loader.rb diff --git a/middleman-core/features/data.feature b/middleman-core/features/data.feature index fcce8445..2487b188 100644 --- a/middleman-core/features/data.feature +++ b/middleman-core/features/data.feature @@ -51,3 +51,31 @@ Feature: Local Data API Then I should see "title1:Hello" Then I should see "title2:More" Then I should see "title3:Stuff" + + Scenario: Invalid YAML + Given a fixture app "basic-data-app" + And the default aruba timeout is 30 seconds + And a file named "data/test.yml" with: + """ + 'ASDSFDa: + -asdf asdf + """ + When I run `middleman build` + Then the output should contain: + """ + failed due to an error: + """ + + Scenario: Invalid JSON + Given a fixture app "basic-data-app" + And the default aruba timeout is 30 seconds + And a file named "data/test.json" with: + """ + 'ASDSFDa: + -asdf asdf + """ + When I run `middleman build` + Then the output should contain: + """ + failed due to an error: + """ diff --git a/middleman-core/lib/middleman-core/core_extensions/data.rb b/middleman-core/lib/middleman-core/core_extensions/data.rb index 0f25c223..680ea173 100644 --- a/middleman-core/lib/middleman-core/core_extensions/data.rb +++ b/middleman-core/lib/middleman-core/core_extensions/data.rb @@ -7,9 +7,7 @@ module Middleman class << self # @private def registered(app) - # Data formats - require 'yaml' - require 'json' + require 'middleman-core/core_extensions/data/file_loader' app.config.define_setting :data_dir, 'data', 'The directory data files are stored in' app.send :include, InstanceMethods @@ -95,11 +93,9 @@ module Middleman data_path = full_path.relative_path_from(root + @app.config[:data_dir]) - if %w(.yaml .yml).include?(extension) - data = YAML.load_file(full_path) - elsif extension == '.json' - data = JSON.parse(full_path.read) - else + begin + data = FileLoader.new.load(full_path) + rescue FileLoader::NoFileLoaderFoundError return end diff --git a/middleman-core/lib/middleman-core/core_extensions/data/file_loader.rb b/middleman-core/lib/middleman-core/core_extensions/data/file_loader.rb new file mode 100644 index 00000000..7f27dbab --- /dev/null +++ b/middleman-core/lib/middleman-core/core_extensions/data/file_loader.rb @@ -0,0 +1,71 @@ +require 'yaml' +require 'json' + +module Middleman + module CoreExtensions + module Data + # Load data files + class FileLoader + # No parser available + class NoFileLoaderFoundError < StandardError; end + + # Load yaml files + class YamlFileLoader + def match?(file) + %w(.yaml .yml).include? File.extname(file) + end + + # @param [Pathname] file + def load(file) + YAML.load_file(file) + rescue Psych::SyntaxError, StandardError => e + $stderr.puts %(Loading data file "#{file}" failed due to an error: #{e.message}) + {} + end + end + + # Load json files + class JsonFileLoader + def match?(file) + '.json' == File.extname(file) + end + + # @param [Pathname] file + def load(file) + JSON.parse(file.read) + rescue => e + $stderr.puts %(Loading data file "#{file}" failed due to an error: #{e.message}) + {} + end + end + + # Default loader + # + # Always fails + class NilFileLoader + def match?(file) + raise NoFileLoaderFoundError + end + end + + private + + attr_reader :loaders + + public + + def initialize + @loaders = [] + @loaders << YamlFileLoader.new + @loaders << JsonFileLoader.new + @loaders << NilFileLoader.new + end + + # Load file using loader + def load(file) + loaders.find { |l| l.match? file }.load(file) + end + end + end + end +end From db1e8b8611efae6d81b0ec8ea27c3e4fd56db5c4 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Sat, 17 Oct 2015 14:06:50 -0700 Subject: [PATCH 13/30] add a specific require. hopefully helping #1601 --- .../lib/middleman-more/core_extensions/default_helpers.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb index 3fe8d680..830e93eb 100644 --- a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb +++ b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb @@ -1,10 +1,11 @@ require 'padrino-helpers' +require 'padrino-helpers/output_helpers' # Don't fail on invalid locale, that's not what our current # users expect. ::I18n.enforce_available_locales = false -class Padrino::Helpers::OutputHelpers::ErbHandler +class ::Padrino::Helpers::OutputHelpers::ErbHandler # Force Erb capture not to use safebuffer # rubocop:disable UnderscorePrefixedVariableName def capture_from_template(*args, &block) From 546cadf4fd367ee2a6ec6bb7c641f14aaf46da5c Mon Sep 17 00:00:00 2001 From: Tommy Santerre Date: Sat, 17 Oct 2015 21:53:47 -0400 Subject: [PATCH 14/30] Add some requires to help #1601 --- .../lib/middleman-core/meta_pages/sitemap_resource.rb | 2 ++ .../lib/middleman-more/core_extensions/default_helpers.rb | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/middleman-core/lib/middleman-core/meta_pages/sitemap_resource.rb b/middleman-core/lib/middleman-core/meta_pages/sitemap_resource.rb index 9d1d1ec0..78c77ec9 100644 --- a/middleman-core/lib/middleman-core/meta_pages/sitemap_resource.rb +++ b/middleman-core/lib/middleman-core/meta_pages/sitemap_resource.rb @@ -1,4 +1,6 @@ require 'padrino-helpers' +require 'padrino-helpers/output_helpers' +require 'padrino-helpers/tag_helpers' module Middleman module MetaPages diff --git a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb index 830e93eb..74d384ee 100644 --- a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb +++ b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb @@ -1,5 +1,10 @@ require 'padrino-helpers' +require 'padrino-helpers/asset_tag_helpers' +require 'padrino-helpers/form_helpers' +require 'padrino-helpers/format_helpers' +require 'padrino-helpers/number_helpers' require 'padrino-helpers/output_helpers' +require 'padrino-helpers/render_helpers' # Don't fail on invalid locale, that's not what our current # users expect. From 3d8853092541398332d7137ce04359c72c371d6c Mon Sep 17 00:00:00 2001 From: Jenn Date: Fri, 23 Oct 2015 23:33:39 -0400 Subject: [PATCH 15/30] Update LICENSE.md updated copyright year from 2014 to 2015 --- LICENSE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 41ba676e..9b818889 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2010-2014 Thomas Reynolds +Copyright (c) 2010-2015 Thomas Reynolds Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. From 601653b766df244361078df788f20084d86a454a Mon Sep 17 00:00:00 2001 From: glamouracademy Date: Tue, 27 Oct 2015 12:38:16 -0400 Subject: [PATCH 16/30] Add link for RubyGem package manager download --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 540ca969..468196b9 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ These days, many websites are built with an API in mind. Rather than package the ## Installation -Middleman is built on Ruby and uses the RubyGems package manager for installation. These are usually pre-installed on Mac OS X and Linux. Windows users can install both using [RubyInstaller]. +Middleman is built on Ruby and uses the [RubyGems package manager] (https://rubygems.org/pages/download) for installation. These are usually pre-installed on Mac OS X and Linux. Windows users can install both using [RubyInstaller]. ``` gem install middleman From 807bb3264ccd7d01c8ebeee7284c705fb08196ce Mon Sep 17 00:00:00 2001 From: Tyson Gach Date: Wed, 28 Oct 2015 09:50:02 -0400 Subject: [PATCH 17/30] Update donation link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 468196b9..dd2bd0c7 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ The best way to get quick responses to your issues and swift fixes to your bugs ## Donate -[Click here to lend your support to Middleman](https://spacebox.io/s/4dXbHBorC3) +Help support the Middleman team [with a donation](https://plasso.co/s/4dXbHBorC3). ## Versioning From 1c94fe989ceaa2d263b52539bbb14b1350730449 Mon Sep 17 00:00:00 2001 From: Dave Powers Date: Wed, 28 Oct 2015 20:50:10 -0400 Subject: [PATCH 18/30] Update link to getting started guide [ci skip] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dd2bd0c7..1e179096 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/middleman/middleman?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -**Middleman** is a static site generator using all the shortcuts and tools in modern web development. Check out [middlemanapp.com](http://middlemanapp.com/) for detailed tutorials, including a [getting started guide](http://middlemanapp.com/basics/getting-started/). You can also follow [@middlemanapp](https://twitter.com/middlemanapp) for updates. +**Middleman** is a static site generator using all the shortcuts and tools in modern web development. Check out [middlemanapp.com](http://middlemanapp.com/) for detailed tutorials, including a [getting started guide](https://middlemanapp.com/basics/install/). You can also follow [@middlemanapp](https://twitter.com/middlemanapp) for updates. ## Why Middleman? From 575423628d6cc80fea98275e06eb7ba6f8d8e43e Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Sun, 1 Nov 2015 09:23:33 -0800 Subject: [PATCH 19/30] Add back full version path, fixes #1671 --- middleman/middleman.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middleman/middleman.gemspec b/middleman/middleman.gemspec index b34ebfbb..fb50b8db 100644 --- a/middleman/middleman.gemspec +++ b/middleman/middleman.gemspec @@ -1,7 +1,7 @@ lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require "middleman-core/version" +require File.expand_path("../../middleman-core/lib/middleman-core/version.rb", __FILE__) Gem::Specification.new do |s| s.name = "middleman" From d67e5f512b60009cae5d0e59bf9e07f55e8ce0f8 Mon Sep 17 00:00:00 2001 From: Landon Schropp Date: Mon, 2 Nov 2015 20:56:39 -0800 Subject: [PATCH 20/30] Add missing require to default_helpers.rb Helps resolve #1673 --- .../lib/middleman-more/core_extensions/default_helpers.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb index 74d384ee..1fe2777e 100644 --- a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb +++ b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb @@ -5,6 +5,7 @@ require 'padrino-helpers/format_helpers' require 'padrino-helpers/number_helpers' require 'padrino-helpers/output_helpers' require 'padrino-helpers/render_helpers' +require 'padrino-helpers/tag_helpers' # Don't fail on invalid locale, that's not what our current # users expect. From 90d386079dc189af419f1b5d62384b44264ea5bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Mon, 9 Nov 2015 14:46:28 +0100 Subject: [PATCH 21/30] Make it easier for users behind http proxies to install gems from github with bundler 1.x --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 2c8a8e9e..28cc1bb2 100644 --- a/Gemfile +++ b/Gemfile @@ -37,4 +37,4 @@ gem 'coveralls', '~> 0.8', require: false # Middleman itself gem 'middleman-core', path: 'middleman-core' gem 'middleman', path: 'middleman' -gem 'middleman-sprockets', github: 'middleman/middleman-sprockets', branch: 'v3-stable-real' +gem 'middleman-sprockets', git: 'https://github.com/middleman/middleman-sprockets', branch: 'v3-stable-real' From 741caab5468dac39ade14116b0033361e54d3a1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Mon, 9 Nov 2015 14:46:48 +0100 Subject: [PATCH 22/30] Make middleman compatible with aruba 0.10.x --- Gemfile | 2 +- .../features/cli/preview_server.feature | 2 +- middleman-core/features/data.feature | 4 +- .../step_definitions/queryable_steps.rb | 167 +++++++++++++----- .../lib/middleman-core/step_definitions.rb | 2 +- .../step_definitions/builder_steps.rb | 22 ++- .../step_definitions/commandline_steps.rb | 18 +- .../step_definitions/middleman_steps.rb | 12 +- .../step_definitions/server_steps.rb | 80 +++++---- 9 files changed, 206 insertions(+), 103 deletions(-) diff --git a/Gemfile b/Gemfile index 28cc1bb2..67063cfe 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ gem 'yard', '~> 0.8', require: false # Test tools gem 'pry', '~> 0.10', group: :development -gem 'aruba', '~> 0.7.4' +gem 'aruba', '~> 0.10.0' gem 'rspec', '~> 3.0' gem 'cucumber', '~> 2.0' diff --git a/middleman-core/features/cli/preview_server.feature b/middleman-core/features/cli/preview_server.feature index f82a0a1f..9481bc04 100644 --- a/middleman-core/features/cli/preview_server.feature +++ b/middleman-core/features/cli/preview_server.feature @@ -6,7 +6,7 @@ Feature: Run the preview server Background: Given a fixture app "preview-server-app" - And the default aruba timeout is 30 seconds + And the default aruba exit timeout is 30 seconds Scenario: Start the server with defaults When I run `middleman server` interactively diff --git a/middleman-core/features/data.feature b/middleman-core/features/data.feature index 2487b188..35601eb7 100644 --- a/middleman-core/features/data.feature +++ b/middleman-core/features/data.feature @@ -54,7 +54,7 @@ Feature: Local Data API Scenario: Invalid YAML Given a fixture app "basic-data-app" - And the default aruba timeout is 30 seconds + And the default aruba exit timeout is 30 seconds And a file named "data/test.yml" with: """ 'ASDSFDa: @@ -68,7 +68,7 @@ Feature: Local Data API Scenario: Invalid JSON Given a fixture app "basic-data-app" - And the default aruba timeout is 30 seconds + And the default aruba exit timeout is 30 seconds And a file named "data/test.json" with: """ 'ASDSFDa: diff --git a/middleman-core/features/step_definitions/queryable_steps.rb b/middleman-core/features/step_definitions/queryable_steps.rb index 995c3d33..8b8a12d0 100644 --- a/middleman-core/features/step_definitions/queryable_steps.rb +++ b/middleman-core/features/step_definitions/queryable_steps.rb @@ -18,118 +18,195 @@ end Then /^should raise an exception if the operator is not supported$/ do expect { - selector = ::Middleman::Sitemap::Queryable::Selector.new :attribute => :author, :operator => 'zomg' + ::Middleman::Sitemap::Queryable::Selector.new :attribute => :author, :operator => 'zomg' }.to raise_error(::Middleman::Sitemap::Queryable::OperatorNotSupportedError) end Then /^should limit the documents to the number specified$/ do - @server_inst.sitemap.order_by(:id).limit(2).all.map { |r| r.raw_data[:id] }.sort.should == [1,2].sort + cd '.' do + with_environment do + @server_inst.sitemap.order_by(:id).limit(2).all.map { |r| r.raw_data[:id] }.sort.should == [1,2].sort + end + end end Then /^should offset the documents by the number specified$/ do - @server_inst.sitemap.order_by(:id).offset(2).all.map { |r| r.raw_data[:id] }.sort.should == [3,4,5].sort + cd '.' do + with_environment do + @server_inst.sitemap.order_by(:id).offset(2).all.map { |r| r.raw_data[:id] }.sort.should == [3,4,5].sort + end + end end Then /^should support offset and limit at the same time$/ do - @server_inst.sitemap.order_by(:id).offset(1).limit(2).all.map { |r| r.raw_data[:id] }.sort.should == [2,3].sort + cd '.' do + with_environment do + @server_inst.sitemap.order_by(:id).offset(1).limit(2).all.map { |r| r.raw_data[:id] }.sort.should == [2,3].sort + end + end end Then /^should not freak out about an offset higher than the document count$/ do - @server_inst.sitemap.order_by(:id).offset(5).all.should == [] + cd '.' do + with_environment do + @server_inst.sitemap.order_by(:id).offset(5).all.should == [] + end + end end Then /^should return the right documents$/ do - documents = @server_inst.sitemap.resources.select { |r| !r.raw_data.empty? } - document_1 = documents[0] - document_2 = documents[1] + cd '.' do + with_environment do + documents = @server_inst.sitemap.resources.select { |r| !r.raw_data.empty? } + document_1 = documents[0] + document_2 = documents[1] - found_document = @server_inst.sitemap.where(:title => document_1.raw_data[:title]).first - document_1.should == found_document - - found_document = @server_inst.sitemap.where(:title => document_2.raw_data[:title]).first - document_2.should == found_document + found_document = @server_inst.sitemap.where(:title => document_1.raw_data[:title]).first + document_1.should == found_document + + found_document = @server_inst.sitemap.where(:title => document_2.raw_data[:title]).first + document_2.should == found_document + end + end end Then /^should be chainable$/ do - documents = @server_inst.sitemap.resources.select { |r| !r.raw_data.empty? } - document_1 = documents[0] + cd '.' do + with_environment do + documents = @server_inst.sitemap.resources.select { |r| !r.raw_data.empty? } + document_1 = documents[0] - document_proxy = @server_inst.sitemap.where(:title => document_1.raw_data[:title]) - document_proxy.where(:id => document_1.raw_data[:id]) - document_1.should == document_proxy.first + document_proxy = @server_inst.sitemap.where(:title => document_1.raw_data[:title]) + document_proxy.where(:id => document_1.raw_data[:id]) + document_1.should == document_proxy.first + end + end end Then /^should not be confused by attributes not present in all documents$/ do - result = @server_inst.sitemap.where(:seldom_attribute => 'is seldom').all - result.map { |r| r.raw_data[:id] }.should == [4] + cd '.' do + with_environment do + result = @server_inst.sitemap.where(:seldom_attribute => 'is seldom').all + result.map { |r| r.raw_data[:id] }.should == [4] + end + end end Then /^with a gt operator should return the right documents$/ do selector = ::Middleman::Sitemap::Queryable::Selector.new :attribute => :id, :operator => 'gt' - found_documents = @server_inst.sitemap.where(selector => 2).all - found_documents.map { |r| r.raw_data[:id] }.sort.should == [5,3,4].sort + cd '.' do + with_environment do + found_documents = @server_inst.sitemap.where(selector => 2).all + found_documents.map { |r| r.raw_data[:id] }.sort.should == [5,3,4].sort + end + end end Then /^with a gte operator should return the right documents$/ do selector = ::Middleman::Sitemap::Queryable::Selector.new :attribute => :id, :operator => 'gte' - found_documents = @server_inst.sitemap.where(selector => 2).all - found_documents.map { |r| r.raw_data[:id] }.sort.should == [2,5,3,4].sort + + cd '.' do + with_environment do + found_documents = @server_inst.sitemap.where(selector => 2).all + found_documents.map { |r| r.raw_data[:id] }.sort.should == [2,5,3,4].sort + end + end end Then /^with an in operator should return the right documents$/ do selector = ::Middleman::Sitemap::Queryable::Selector.new :attribute => :id, :operator => 'in' - found_documents = @server_inst.sitemap.where(selector => [2,3]).all - found_documents.map { |r| r.raw_data[:id] }.sort.should == [2,3].sort + cd '.' do + with_environment do + found_documents = @server_inst.sitemap.where(selector => [2,3]).all + found_documents.map { |r| r.raw_data[:id] }.sort.should == [2,3].sort + end + end end Then /^with an lt operator should return the right documents$/ do selector = ::Middleman::Sitemap::Queryable::Selector.new :attribute => :id, :operator => 'lt' - found_documents = @server_inst.sitemap.where(selector => 2).all - found_documents.map { |r| r.raw_data[:id] }.should == [1] + cd '.' do + with_environment do + found_documents = @server_inst.sitemap.where(selector => 2).all + found_documents.map { |r| r.raw_data[:id] }.should == [1] + end + end end Then /^with an lte operator should return the right documents$/ do selector = ::Middleman::Sitemap::Queryable::Selector.new :attribute => :id, :operator => 'lte' - found_documents = @server_inst.sitemap.where(selector => 2).all - found_documents.map { |r| r.raw_data[:id] }.sort.should == [1,2].sort + cd '.' do + with_environment do + found_documents = @server_inst.sitemap.where(selector => 2).all + found_documents.map { |r| r.raw_data[:id] }.sort.should == [1,2].sort + end + end end Then /^with an include operator include should return the right documents$/ do selector = ::Middleman::Sitemap::Queryable::Selector.new :attribute => :tags, :operator => 'include' - found_documents = @server_inst.sitemap.where(selector => 'ruby').all - found_documents.map { |r| r.raw_data[:id] }.sort.should == [1,2].sort + cd '.' do + with_environment do + found_documents = @server_inst.sitemap.where(selector => 'ruby').all + found_documents.map { |r| r.raw_data[:id] }.sort.should == [1,2].sort + end + end end Then /^with mixed operators should return the right documents$/ do in_selector = ::Middleman::Sitemap::Queryable::Selector.new :attribute => :id, :operator => 'in' gt_selector = ::Middleman::Sitemap::Queryable::Selector.new :attribute => :id, :operator => 'gt' - documents_proxy = @server_inst.sitemap.where(in_selector => [2,3]) - found_documents = documents_proxy.where(gt_selector => 2).all - found_documents.map { |r| r.raw_data[:id] }.should == [3] + cd '.' do + with_environment do + documents_proxy = @server_inst.sitemap.where(in_selector => [2,3]) + found_documents = documents_proxy.where(gt_selector => 2).all + found_documents.map { |r| r.raw_data[:id] }.should == [3] + end + end end Then /^using multiple constrains in one where should return the right documents$/ do selector = ::Middleman::Sitemap::Queryable::Selector.new :attribute => :id, :operator => 'lte' - found_documents = @server_inst.sitemap.where(selector => 2, :status => :published).all - found_documents.map { |r| r.raw_data[:id] }.sort.should == [1,2].sort + cd '.' do + with_environment do + found_documents = @server_inst.sitemap.where(selector => 2, :status => :published).all + found_documents.map { |r| r.raw_data[:id] }.sort.should == [1,2].sort + end + end end Then /^should support ordering by attribute ascending$/ do - found_documents = @server_inst.sitemap.order_by(:title => :asc).all - found_documents.map { |r| r.raw_data[:id] }.should == [2,3,1,5,4] + cd '.' do + with_environment do + found_documents = @server_inst.sitemap.order_by(:title => :asc).all + found_documents.map { |r| r.raw_data[:id] }.should == [2,3,1,5,4] + end + end end Then /^should support ordering by attribute descending$/ do - found_documents = @server_inst.sitemap.order_by(:title => :desc).all - found_documents.map { |r| r.raw_data[:id] }.should == [4,5,1,3,2] + cd '.' do + with_environment do + found_documents = @server_inst.sitemap.order_by(:title => :desc).all + found_documents.map { |r| r.raw_data[:id] }.should == [4,5,1,3,2] + end + end end Then /^should order by attribute ascending by default$/ do - found_documents = @server_inst.sitemap.order_by(:title).all - found_documents.map { |r| r.raw_data[:id] }.should == [2,3,1,5,4] + cd '.' do + with_environment do + found_documents = @server_inst.sitemap.order_by(:title).all + found_documents.map { |r| r.raw_data[:id] }.should == [2,3,1,5,4] + end + end end Then /^should exclude documents that do not own the attribute$/ do - found_documents = @server_inst.sitemap.order_by(:status).all - found_documents.map { |r| r.raw_data[:id] }.to_set.should == [1,2].to_set + cd '.' do + with_environment do + found_documents = @server_inst.sitemap.order_by(:status).all + found_documents.map { |r| r.raw_data[:id] }.to_set.should == [1,2].to_set + end + end end diff --git a/middleman-core/lib/middleman-core/step_definitions.rb b/middleman-core/lib/middleman-core/step_definitions.rb index 25c4790a..169af910 100644 --- a/middleman-core/lib/middleman-core/step_definitions.rb +++ b/middleman-core/lib/middleman-core/step_definitions.rb @@ -1,5 +1,5 @@ require 'aruba/cucumber' -require 'aruba/jruby' +require 'aruba/config/jruby' require 'middleman-core/step_definitions/middleman_steps' require 'middleman-core/step_definitions/builder_steps' require 'middleman-core/step_definitions/server_steps' diff --git a/middleman-core/lib/middleman-core/step_definitions/builder_steps.rb b/middleman-core/lib/middleman-core/step_definitions/builder_steps.rb index e57bb51b..12890595 100644 --- a/middleman-core/lib/middleman-core/step_definitions/builder_steps.rb +++ b/middleman-core/lib/middleman-core/step_definitions/builder_steps.rb @@ -5,29 +5,27 @@ Before do end Given /^app "([^\"]*)" is using config "([^\"]*)"$/ do |path, config_name| - target = File.join(PROJECT_ROOT_PATH, 'fixtures', path) - config_path = File.join(current_directory, "config-#{config_name}.rb") - config_dest = File.join(current_directory, 'config.rb') - FileUtils.cp(config_path, config_dest) + copy("config-#{config_name}.rb", 'config.rb') end Given /^an empty app$/ do step %Q{a directory named "empty_app"} step %Q{I cd to "empty_app"} - ENV['MM_ROOT'] = nil + + delete_environment_variable 'MM_ROOT' end Given /^a fixture app "([^\"]*)"$/ do |path| - ENV['MM_ROOT'] = nil + delete_environment_variable 'MM_ROOT' # This step can be reentered from several places but we don't want # to keep re-copying and re-cd-ing into ever-deeper directories - next if File.basename(current_directory) == path + next if File.basename(expand_path('.')) == path step %Q{a directory named "#{path}"} target_path = File.join(PROJECT_ROOT_PATH, 'fixtures', path) - FileUtils.cp_r(target_path, current_directory) + FileUtils.cp_r(target_path, expand_path('.')) step %Q{I cd to "#{path}"} end @@ -58,20 +56,20 @@ Given /^a successfully built app at "([^\"]*)" with flags "([^\"]*)"$/ do |path, end Given /^a modification time for a file named "([^\"]*)"$/ do |file| - target = File.join(current_directory, file) + target = expand_path(file) @modification_times[target] = File.mtime(target) end Then /^the file "([^\"]*)" should not have been updated$/ do |file| - target = File.join(current_directory, file) + target = expand_path(file) File.mtime(target).should == @modification_times[target] end # Provide this Aruba overload in case we're matching something with quotes in it Then /^the file "([^"]*)" should contain '([^']*)'$/ do |file, partial_content| - check_file_content(file, Regexp.new(Regexp.escape(partial_content)), true) + expect(file).to have_file_content Regexp.new(Regexp.escape(partial_content)) end And /the file "(.*)" should be gzipped/ do |file| - expect(File.binread(File.join(current_directory, file), 2)).to eq(['1F8B'].pack('H*')) + expect(File.binread(expand_path(file), 2)).to eq(['1F8B'].pack('H*')) end diff --git a/middleman-core/lib/middleman-core/step_definitions/commandline_steps.rb b/middleman-core/lib/middleman-core/step_definitions/commandline_steps.rb index 5a663c32..3a203b1d 100644 --- a/middleman-core/lib/middleman-core/step_definitions/commandline_steps.rb +++ b/middleman-core/lib/middleman-core/step_definitions/commandline_steps.rb @@ -1,11 +1,11 @@ When /^I stop (?:middleman|all commands) if the output( of the last command)? contains:$/ do |last_command, expected| begin - Timeout.timeout(exit_timeout) do + Timeout.timeout(aruba.config.exit_timeout) do loop do - fail "You need to start middleman interactively first." unless @interactive + fail "You need to start middleman interactively first." if last_command_started.nil? - if unescape(@interactive.output) =~ Regexp.new(unescape(expected)) - only_processes.each { |p| p.terminate } + if sanitize_text(last_command_started.output) =~ Regexp.new(sanitize_text(expected)) + terminate_all_commands break end @@ -13,10 +13,10 @@ When /^I stop (?:middleman|all commands) if the output( of the last command)? co end end rescue ChildProcess::TimeoutError, TimeoutError - @interactive.terminate + terminate_all_commands ensure - announcer.stdout @interactive.stdout - announcer.stderr @interactive.stderr + announcer.announce :stdout, last_command_started.stdout + announcer.announce :stderr, last_command_started.stderr end end @@ -68,7 +68,7 @@ Given /I start a mdns server with:/ do |string| ) ) - set_env 'PATH', File.expand_path(File.join(current_dir, 'bin')) + ':' + ENV['PATH'] + set_environment_variable 'PATH', File.expand_path(File.join(current_dir, 'bin')) + ':' + ENV['PATH'] write_file db_file, string @mdns_server = run("dns_server.rb #{db_file} #{port}", 120) @@ -80,7 +80,7 @@ end # Make sure each and every process is really dead After do - only_processes.each { |p| p.terminate } + terminate_all_commands end Before '@ruby-2.1' do diff --git a/middleman-core/lib/middleman-core/step_definitions/middleman_steps.rb b/middleman-core/lib/middleman-core/step_definitions/middleman_steps.rb index 70dbcf44..3fa17474 100644 --- a/middleman-core/lib/middleman-core/step_definitions/middleman_steps.rb +++ b/middleman-core/lib/middleman-core/step_definitions/middleman_steps.rb @@ -9,9 +9,17 @@ Then /^the file "([^\"]*)" is removed$/ do |path| end Then /^the file "([^\"]*)" did change$/ do |path| - @server_inst.files.did_change(path) + cd '.' do + with_environment do + @server_inst.files.did_change(path) + end + end end Then /^the file "([^\"]*)" did delete$/ do |path| - @server_inst.files.did_delete(path) + cd '.' do + with_environment do + @server_inst.files.did_delete(path) + end + end end diff --git a/middleman-core/lib/middleman-core/step_definitions/server_steps.rb b/middleman-core/lib/middleman-core/step_definitions/server_steps.rb index 0d2d7a92..4844760c 100644 --- a/middleman-core/lib/middleman-core/step_definitions/server_steps.rb +++ b/middleman-core/lib/middleman-core/step_definitions/server_steps.rb @@ -31,15 +31,13 @@ Given /^current environment is "([^\"]*)"$/ do |env| end Given /^the Server is running$/ do - root_dir = File.expand_path(current_directory) - - if File.exists?(File.join(root_dir, 'source')) - ENV['MM_SOURCE'] = 'source' + if exist? 'source' + set_environment_variable 'MM_SOURCE', 'source' else - ENV['MM_SOURCE'] = '' + set_environment_variable 'MM_SOURCE', '' end - ENV['MM_ROOT'] = root_dir + set_environment_variable 'MM_ROOT', expand_path('.') initialize_commands = @initialize_commands || [] initialize_commands.unshift lambda { @@ -47,10 +45,12 @@ Given /^the Server is running$/ do set :show_exceptions, false } - in_current_directory do - @server_inst = Middleman::Application.server.inst do - initialize_commands.each do |p| - instance_exec(&p) + cd '.' do + with_environment do + @server_inst = Middleman::Application.server.inst do + initialize_commands.each do |p| + instance_exec(&p) + end end end end @@ -68,61 +68,81 @@ Given /^a template named "([^\"]*)" with:$/ do |name, string| end When /^I go to "([^\"]*)"$/ do |url| - in_current_directory do - visit(URI.encode(url).to_s) + cd '.' do + with_environment do + visit(URI.encode(url).to_s) + end end end Then /^going to "([^\"]*)" should not raise an exception$/ do |url| - in_current_directory do - expect{ visit(URI.encode(url).to_s) }.to_not raise_exception + cd '.' do + with_environment do + expect{ visit(URI.encode(url).to_s) }.to_not raise_exception + end end end Then /^the content type should be "([^\"]*)"$/ do |expected| - in_current_directory do - expect(page.response_headers['Content-Type']).to start_with expected + cd '.' do + with_environment do + expect(page.response_headers['Content-Type']).to start_with expected + end end end Then /^I should see "([^\"]*)"$/ do |expected| - in_current_directory do - expect(page.body).to include expected + cd '.' do + with_environment do + expect(page.body).to include expected + end end end Then /^I should see '([^\']*)'$/ do |expected| - in_current_directory do - expect(page.body).to include expected + cd '.' do + with_environment do + expect(page.body).to include expected + end end end Then /^I should see:$/ do |expected| - in_current_directory do - expect(page.body).to include expected + cd '.' do + with_environment do + expect(page.body).to include expected + end end end Then /^I should not see "([^\"]*)"$/ do |expected| - in_current_directory do - expect(page.body).not_to include expected + cd '.' do + with_environment do + expect(page.body).not_to include expected + end end end Then /^I should not see:$/ do |expected| - in_current_directory do - expect(page.body).not_to include expected + cd '.' do + with_environment do + expect(page.body).not_to include expected + end end end Then /^the status code should be "([^\"]*)"$/ do |expected| - in_current_directory do - expect(page.status_code).to eq expected.to_i + cd '.' do + with_environment do + expect(page.status_code).to eq expected.to_i + end end end Then /^I should see "([^\"]*)" lines$/ do |lines| - in_current_directory do - expect(page.body.chomp.split($/).length).to eq lines.to_i + cd '.' do + with_environment do + expect(page.body.chomp.split($/).length).to eq lines.to_i + end end end From 1d2126b9f760a9b27465c65aeca03a1d58253ee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Wed, 11 Nov 2015 21:39:54 +0100 Subject: [PATCH 23/30] Move HTTPS to server information --- .../lib/middleman-core/preview_server.rb | 14 +++++--------- .../preview_server/server_information.rb | 13 +++++++++++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/middleman-core/lib/middleman-core/preview_server.rb b/middleman-core/lib/middleman-core/preview_server.rb index 78a2ac7a..a20a7d63 100644 --- a/middleman-core/lib/middleman-core/preview_server.rb +++ b/middleman-core/lib/middleman-core/preview_server.rb @@ -13,10 +13,6 @@ module Middleman attr_reader :app, :ssl_certificate, :ssl_private_key, :environment, :server_information delegate :logger, to: :app - def https? - @https - end - # Start an instance of Middleman::Application # @return [void] def start(opts={}) @@ -26,6 +22,7 @@ module Middleman @options = opts @server_information = ServerInformation.new + @server_information.https = (@options[:https] == true) # New app evaluates the middleman configuration. Since this can be # invalid as well, we need to evaluate the configuration BEFORE @@ -42,9 +39,9 @@ module Middleman logger.debug %(== Server information is provided by #{server_information.handler}) logger.debug %(== The Middleman is running in "#{environment}" environment) - logger.debug format('== The Middleman preview server is bind to %s', ServerUrl.new(hosts: server_information.listeners, port: server_information.port, https: https?).to_bind_addresses.join(', ')) - logger.info format('== View your site at %s', ServerUrl.new(hosts: server_information.site_addresses, port: server_information.port, https: https?).to_urls.join(', ')) - logger.info format('== Inspect your site configuration at %s', ServerUrl.new(hosts: server_information.site_addresses, port: server_information.port, https: https?).to_config_urls.join(', ')) + logger.debug format('== The Middleman preview server is bound to %s', ServerUrl.new(hosts: server_information.listeners, port: server_information.port, https: server_information.https?).to_bind_addresses.join(', ')) + logger.info format('== View your site at %s', ServerUrl.new(hosts: server_information.site_addresses, port: server_information.port, https: server_information.https?).to_urls.join(', ')) + logger.info format('== Inspect your site configuration at %s', ServerUrl.new(hosts: server_information.site_addresses, port: server_information.port, https: server_information.https?).to_config_urls.join(', ')) @initialized ||= false return if @initialized @@ -153,7 +150,6 @@ module Middleman logger.warn format('== The Middleman uses a different port "%s" then the configured one "%s" because some other server is listening on that port.', server_information.port, configured_port) unless @app.config[:port] == configured_port - @https = @app.config[:https] @environment = @app.config[:environment] @ssl_certificate = @app.config[:ssl_certificate] @@ -224,7 +220,7 @@ module Middleman DoNotReverseLookup: true } - if https? + if server_information.https? http_opts[:SSLEnable] = true if ssl_certificate || ssl_private_key diff --git a/middleman-core/lib/middleman-core/preview_server/server_information.rb b/middleman-core/lib/middleman-core/preview_server/server_information.rb index 186d3423..0fe70092 100644 --- a/middleman-core/lib/middleman-core/preview_server/server_information.rb +++ b/middleman-core/lib/middleman-core/preview_server/server_information.rb @@ -20,6 +20,8 @@ module Middleman public + attr_writer :https + def initialize(opts={}) @resolver = opts.fetch(:resolver, DnsResolver.new) @validator = opts.fetch(:validator, ServerInformationValidator.new) @@ -64,10 +66,12 @@ module Middleman @bind_address = config[:bind_address] @port = config[:port] @server_name = config[:server_name] + @https = config[:https] config[:bind_address] = bind_address - config[:port] = port - config[:server_name] = server_name + config[:port] = port + config[:server_name] = server_name + config[:https] = https? end # Make information of internal server class available to make debugging @@ -139,6 +143,11 @@ module Middleman def listeners information.listeners end + + # Is https enabled? + def https? + @https == true + end end end end From 4e9ae8cc4213bdceac78cca88a5d220bb1fdf937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Wed, 11 Nov 2015 21:49:37 +0100 Subject: [PATCH 24/30] Before server hook --- .../features/cli/preview_server-hook.feature | 17 +++++++++ .../features/cli/preview_server.feature | 38 +++++++++---------- .../preview-server-hook-app/config.rb | 19 ++++++++++ .../source/index.html.erb | 9 +++++ .../lib/middleman-core/application.rb | 3 ++ .../lib/middleman-core/preview_server.rb | 3 ++ .../server_information_callback_proxy.rb | 35 +++++++++++++++++ .../preview_server/server_url.rb | 21 ++++++++-- 8 files changed, 122 insertions(+), 23 deletions(-) create mode 100644 middleman-core/features/cli/preview_server-hook.feature create mode 100644 middleman-core/fixtures/preview-server-hook-app/config.rb create mode 100644 middleman-core/fixtures/preview-server-hook-app/source/index.html.erb create mode 100644 middleman-core/lib/middleman-core/preview_server/server_information_callback_proxy.rb diff --git a/middleman-core/features/cli/preview_server-hook.feature b/middleman-core/features/cli/preview_server-hook.feature new file mode 100644 index 00000000..15f6cba0 --- /dev/null +++ b/middleman-core/features/cli/preview_server-hook.feature @@ -0,0 +1,17 @@ +Feature: Run preview server before hook + + Scenario: When run + Given a fixture app "preview-server-hook-app" + And the default aruba timeout is 30 seconds + When I run `middleman server --server-name localhost --bind-address 127.0.0.1` interactively + And I stop middleman if the output contains: + """ + ### END ### + """ + Then the output should contain: + """ + /// 127.0.0.1:4567 /// + /// 4567 /// + /// localhost /// + /// http://localhost:4567 /// + """ diff --git a/middleman-core/features/cli/preview_server.feature b/middleman-core/features/cli/preview_server.feature index f82a0a1f..200cda6f 100644 --- a/middleman-core/features/cli/preview_server.feature +++ b/middleman-core/features/cli/preview_server.feature @@ -31,7 +31,7 @@ Feature: Run the preview server """ Then the output should contain: """ - The Middleman preview server is bind to ":::4567", "0.0.0.0:4567" + The Middleman preview server is bound to ":::4567", "0.0.0.0:4567" """ And the output should contain: """ @@ -52,7 +52,7 @@ Feature: Run the preview server """ Then the output should contain: """ - The Middleman preview server is bind to ":::4567", "0.0.0.0:4567" + The Middleman preview server is bound to ":::4567", "0.0.0.0:4567" """ And the output should contain: """ @@ -76,7 +76,7 @@ Feature: Run the preview server """ Then the output should contain: """ - The Middleman preview server is bind to "127.0.0.1:4567" + The Middleman preview server is bound to "127.0.0.1:4567" """ And the output should contain: """ @@ -104,7 +104,7 @@ Feature: Run the preview server """ Then the output should contain: """ - The Middleman preview server is bind to "127.0.0.1:4567" + The Middleman preview server is bound to "127.0.0.1:4567" """ And the output should contain: """ @@ -127,7 +127,7 @@ Feature: Run the preview server """ Then the output should contain: """ - The Middleman preview server is bind to "127.0.0.5:4567" + The Middleman preview server is bound to "127.0.0.5:4567" """ And the output should contain: """ @@ -151,7 +151,7 @@ Feature: Run the preview server """ Then the output should contain: """ - The Middleman preview server is bind to "::1:4567" + The Middleman preview server is bound to "::1:4567" """ And the output should contain: """ @@ -170,7 +170,7 @@ Feature: Run the preview server """ Then the output should contain: """ - The Middleman preview server is bind to "0.0.0.0:4567" + The Middleman preview server is bound to "0.0.0.0:4567" """ And the output should contain: """ @@ -189,7 +189,7 @@ Feature: Run the preview server """ Then the output should contain: """ - The Middleman preview server is bind to ":::4567" + The Middleman preview server is bound to ":::4567" """ And the output should contain: """ @@ -213,7 +213,7 @@ Feature: Run the preview server """ Then the output should contain: """ - The Middleman preview server is bind to "127.0.0.1:4567" + The Middleman preview server is bound to "127.0.0.1:4567" """ And the output should contain: """ @@ -241,7 +241,7 @@ Feature: Run the preview server """ Then the output should contain: """ - The Middleman preview server is bind to "127.0.0.1:4567" + The Middleman preview server is bound to "127.0.0.1:4567" """ And the output should contain: """ @@ -265,7 +265,7 @@ Feature: Run the preview server """ Then the output should contain: """ - The Middleman preview server is bind to "127.0.0.1:4567" + The Middleman preview server is bound to "127.0.0.1:4567" """ And the output should contain: """ @@ -284,7 +284,7 @@ Feature: Run the preview server """ Then the output should contain: """ - The Middleman preview server is bind to "127.0.0.1:4567" + The Middleman preview server is bound to "127.0.0.1:4567" """ And the output should contain: """ @@ -303,7 +303,7 @@ Feature: Run the preview server """ Then the output should contain: """ - The Middleman preview server is bind to "::1:4567" + The Middleman preview server is bound to "::1:4567" """ And the output should contain: """ @@ -322,7 +322,7 @@ Feature: Run the preview server """ Then the output should contain: """ - The Middleman preview server is bind to ":::4567", "0.0.0.0:4567" + The Middleman preview server is bound to ":::4567", "0.0.0.0:4567" """ And the output should contain: """ @@ -341,7 +341,7 @@ Feature: Run the preview server """ Then the output should contain: """ - The Middleman preview server is bind to ":::65432", "0.0.0.0:65432" + The Middleman preview server is bound to ":::65432", "0.0.0.0:65432" """ Scenario: Start the server with port 65432 configured via config.rb @@ -356,7 +356,7 @@ Feature: Run the preview server """ Then the output should contain: """ - The Middleman preview server is bind to ":::65432", "0.0.0.0:65432" + The Middleman preview server is bound to ":::65432", "0.0.0.0:65432" """ Scenario: Start the server when port is blocked by other middleman instance @@ -456,7 +456,7 @@ Feature: Run the preview server """ Then the output should contain: """ - The Middleman preview server is bind to "127.0.0.1:4567" + The Middleman preview server is bound to "127.0.0.1:4567" """ And the output should contain: """ @@ -488,7 +488,7 @@ Feature: Run the preview server """ Then the output should contain: """ - The Middleman preview server is bind to "127.0.0.1:4567" + The Middleman preview server is bound to "127.0.0.1:4567" """ And the output should contain: """ @@ -520,7 +520,7 @@ Feature: Run the preview server """ Then the output should contain: """ - The Middleman preview server is bind to "127.0.0.1:4567" + The Middleman preview server is bound to "127.0.0.1:4567" """ And the output should contain: """ diff --git a/middleman-core/fixtures/preview-server-hook-app/config.rb b/middleman-core/fixtures/preview-server-hook-app/config.rb new file mode 100644 index 00000000..9892009e --- /dev/null +++ b/middleman-core/fixtures/preview-server-hook-app/config.rb @@ -0,0 +1,19 @@ +set :layout, false + +class MyFeature < Middleman::Extension + def initialize(app, options_hash = {}, &block) + super + + app.before_server do |server_information| + puts "/// #{server_information.listeners.first} ///" + puts "/// #{server_information.port} ///" + puts "/// #{server_information.server_name} ///" + puts "/// #{server_information.site_addresses.first} ///" + puts "/// ### END ### ///" + end + end +end + +::Middleman::Extensions.register(:my_feature, MyFeature) + +activate :my_feature diff --git a/middleman-core/fixtures/preview-server-hook-app/source/index.html.erb b/middleman-core/fixtures/preview-server-hook-app/source/index.html.erb new file mode 100644 index 00000000..ca390d46 --- /dev/null +++ b/middleman-core/fixtures/preview-server-hook-app/source/index.html.erb @@ -0,0 +1,9 @@ + + + + preview-server-hook-app + + +

preview-server-hook-app

+ + diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index 0bf11717..58b69d0c 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -41,6 +41,9 @@ module Middleman # Runs after the build is finished define_hook :after_build + # Runs before the preview server is started + define_hook :before_server + # Mix-in helper methods. Accepts either a list of Modules # and/or a block to be evaluated # @return [void] diff --git a/middleman-core/lib/middleman-core/preview_server.rb b/middleman-core/lib/middleman-core/preview_server.rb index a20a7d63..9e7ebd47 100644 --- a/middleman-core/lib/middleman-core/preview_server.rb +++ b/middleman-core/lib/middleman-core/preview_server.rb @@ -5,6 +5,7 @@ require 'middleman-core/meta_pages' require 'middleman-core/logger' require 'middleman-core/preview_server/server_information' require 'middleman-core/preview_server/server_url' +require 'middleman-core/preview_server/server_information_callback_proxy' # rubocop:disable GlobalVars module Middleman @@ -53,6 +54,8 @@ module Middleman # reloading later on. ::Middleman::Profiling.report('server_start') + app.run_hook(:before_server, ServerInformationCallbackProxy.new(server_information)) + loop do @webrick.start diff --git a/middleman-core/lib/middleman-core/preview_server/server_information_callback_proxy.rb b/middleman-core/lib/middleman-core/preview_server/server_information_callback_proxy.rb new file mode 100644 index 00000000..106abba0 --- /dev/null +++ b/middleman-core/lib/middleman-core/preview_server/server_information_callback_proxy.rb @@ -0,0 +1,35 @@ +module Middleman + class PreviewServer + # This class wraps server information to be used in call back + # + # * listeners + # * port + # * server name + # * site_addresses + # + # All information is "dupped" and the callback is not meant to be used to + # modify these information. + class ServerInformationCallbackProxy + attr_reader :server_name, :port, :site_addresses, :listeners + + def initialize(server_information) + @listeners = ServerUrl.new( + hosts: server_information.listeners, + port: server_information.port, + https: server_information.https?, + format_output: false + ).to_bind_addresses + + @port = server_information.port + @server_name = server_information.server_name.dup unless server_information.server_name == nil + + @site_addresses = ServerUrl.new( + hosts: server_information.site_addresses, + port: server_information.port, + https: server_information.https?, + format_output: false + ).to_urls + end + end + end +end diff --git a/middleman-core/lib/middleman-core/preview_server/server_url.rb b/middleman-core/lib/middleman-core/preview_server/server_url.rb index 9b7a5b29..bc18da55 100644 --- a/middleman-core/lib/middleman-core/preview_server/server_url.rb +++ b/middleman-core/lib/middleman-core/preview_server/server_url.rb @@ -6,7 +6,7 @@ module Middleman class ServerUrl private - attr_reader :hosts, :port, :https + attr_reader :hosts, :port, :https, :format_output public @@ -14,6 +14,7 @@ module Middleman @hosts = opts.fetch(:hosts) @port = opts.fetch(:port) @https = opts.fetch(:https, false) + @format_output = opts.fetch(:format_output, true) end # Return bind addresses @@ -21,7 +22,11 @@ module Middleman # @return [Array] # List of bind addresses of format host:port def to_bind_addresses - hosts.map { |l| format('"%s:%s"', l.to_s, port) } + if format_output + hosts.map { |l| format('"%s:%s"', l.to_s, port) } + else + hosts.map { |l| format('%s:%s', l.to_s, port) } + end end # Return server urls @@ -29,7 +34,11 @@ module Middleman # @return [Array] # List of urls of format http://host:port def to_urls - hosts.map { |l| format('"%s://%s:%s"', https? ? 'https' : 'http', l.to_browser, port) } + if format_output + hosts.map { |l| format('"%s://%s:%s"', https? ? 'https' : 'http', l.to_browser, port) } + else + hosts.map { |l| format('%s://%s:%s', https? ? 'https' : 'http', l.to_browser, port) } + end end # Return server config urls @@ -37,7 +46,11 @@ module Middleman # @return [Array] # List of urls of format http://host:port/__middleman def to_config_urls - hosts.map { |l| format('"%s://%s:%s/__middleman"', https? ? 'https' : 'http', l.to_browser, port) } + if format_output + hosts.map { |l| format('"%s://%s:%s/__middleman"', https? ? 'https' : 'http', l.to_browser, port) } + else + hosts.map { |l| format('%s://%s:%s/__middleman', https? ? 'https' : 'http', l.to_browser, port) } + end end private From 02d25ee883a4b8aeabe2464bcb25f04ddd8b8c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Wed, 11 Nov 2015 21:51:35 +0100 Subject: [PATCH 25/30] Add warning to contributing.md --- CONTRIBUTING.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b1b005ec..54d23421 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,6 +29,9 @@ Ideally, a bug report should include a pull request with failing specs. [gist]: https://gist.github.com/ ## Submitting a Pull Request + +** WE DO NOT ACCEPT NEW FEATURES FOR THE V3 BRANCH ANYMORE ** + 1. [Fork the repository.][fork] 2. Create a topic [branch]. `git checkout -b local_topic_branch` 3. Add specs for your unimplemented feature or bug fix. From 2ee07bdcb6af8efd30d7ec0b63e86f5a4864ffd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Wed, 11 Nov 2015 21:52:28 +0100 Subject: [PATCH 26/30] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 54d23421..2cb5a0ac 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -30,7 +30,7 @@ Ideally, a bug report should include a pull request with failing specs. ## Submitting a Pull Request -** WE DO NOT ACCEPT NEW FEATURES FOR THE V3 BRANCH ANYMORE ** +**WE DO NOT ACCEPT NEW FEATURES FOR THE V3 BRANCH ANYMORE** 1. [Fork the repository.][fork] 2. Create a topic [branch]. `git checkout -b local_topic_branch` From 78fb92d497b365a3d5a9d79ce5b1881dfc3f15bc Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Wed, 11 Nov 2015 13:14:31 -0800 Subject: [PATCH 27/30] Adapt to upstream hooks API change. Fixes #1658 --- CHANGELOG.md | 7 +++++++ .../lib/middleman-core/core_extensions/rendering.rb | 12 ++++++------ middleman-core/lib/middleman-core/version.rb | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a461146..53bc0858 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ master === +3.4.1 +=== + +* Adapt to upstream hooks API change, fixing `after_render` hook bugs. (#1658) +* Add a bunch of requires to help Windows users. +* Refator Data Loader to prevent middleman from crashing due to invalid data file. (#1633) + 3.4.0 === diff --git a/middleman-core/lib/middleman-core/core_extensions/rendering.rb b/middleman-core/lib/middleman-core/core_extensions/rendering.rb index aa3e4430..7dab1814 100644 --- a/middleman-core/lib/middleman-core/core_extensions/rendering.rb +++ b/middleman-core/lib/middleman-core/core_extensions/rendering.rb @@ -296,10 +296,10 @@ module Middleman # Allow hooks to manipulate the template before render self.class.callbacks_for_hook(:before_render).each do |callback| # Uber::Options::Value doesn't respond to call - newbody = if callback.respond_to?(:call) - callback.call(body, path, locs, template_class) + newbody = if callback.is_a? ::Uber::Options::Value + callback.call(self, body, path, locs, template_class) elsif callback.respond_to?(:evaluate) - callback.evaluate(self, body, path, locs, template_class) + callback.call(body, path, locs, template_class) end body = newbody if newbody # Allow the callback to return nil to skip it end @@ -315,10 +315,10 @@ module Middleman # Allow hooks to manipulate the result after render self.class.callbacks_for_hook(:after_render).each do |callback| # Uber::Options::Value doesn't respond to call - newcontent = if callback.respond_to?(:call) - callback.call(content, path, locs, template_class) + newcontent = if callback.is_a? ::Uber::Options::Value + callback.call(self, content, path, locs, template_class) elsif callback.respond_to?(:evaluate) - callback.evaluate(self, content, path, locs, template_class) + callback.call(content, path, locs, template_class) end content = newcontent if newcontent # Allow the callback to return nil to skip it end diff --git a/middleman-core/lib/middleman-core/version.rb b/middleman-core/lib/middleman-core/version.rb index 01894a8e..d8a3037f 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 = '3.4.0' unless const_defined?(:VERSION) + VERSION = '3.4.1' unless const_defined?(:VERSION) end From 30335091c8b167063cf015264bc4fe1dc267e088 Mon Sep 17 00:00:00 2001 From: Steven Sloan Date: Thu, 12 Nov 2015 15:27:26 -0500 Subject: [PATCH 28/30] fix(default_helpers): allow asset_url to work outside of a resource context This way calls from extensions/etc can call app.asset_url() and get the correct path back. Additionally, an exception will be raised if also using relative assets as the current resource will be needed in that case. --- .../lib/middleman-more/core_extensions/default_helpers.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb index 1fe2777e..c7ceac45 100644 --- a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb +++ b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb @@ -223,7 +223,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension # @return [String] The fully qualified asset url def asset_url(path, prefix='', options={}) # Don't touch assets which already have a full path - if path.include?('//') || path.start_with?('data:') || !current_resource + if path.include?('//') || path.start_with?('data:') path else # rewrite paths to use their destination path result = if resource = sitemap.find_resource_by_destination_path(url_for(path)) @@ -241,6 +241,10 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension if options[:relative] != true result else + unless current_resource + raise ArgumentError, "#asset_url must be run in a context with current_resource if relative: true" + end + current_dir = Pathname('/' + current_resource.destination_path) Pathname(result).relative_path_from(current_dir.dirname).to_s end From 9dc144e9f7abb587f34f0a1c15eab4a503834879 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Thu, 10 Dec 2015 13:22:46 -0800 Subject: [PATCH 29/30] Disable stylus test --- middleman-core/features/stylus.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middleman-core/features/stylus.feature b/middleman-core/features/stylus.feature index df17962b..027a8438 100644 --- a/middleman-core/features/stylus.feature +++ b/middleman-core/features/stylus.feature @@ -1,4 +1,4 @@ -@nojava +@wip @nojava Feature: Stylus Updates and Partials Scenario: The preview server should update stylesheets when Stylus changes Given the Server is running at "stylus-preview-app" From 37845e89c0c4e84bbab9b202cf21e0c02c84d398 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Thu, 10 Dec 2015 13:24:35 -0800 Subject: [PATCH 30/30] Changelog [ci skip] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53bc0858..9db919f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ master * Adapt to upstream hooks API change, fixing `after_render` hook bugs. (#1658) * Add a bunch of requires to help Windows users. * Refator Data Loader to prevent middleman from crashing due to invalid data file. (#1633) +* Add `before_server` hook. 3.4.0 ===