diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a461146..9db919f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ 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) +* Add `before_server` hook. + 3.4.0 === diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b1b005ec..2cb5a0ac 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. diff --git a/Gemfile b/Gemfile index 08de2a54..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' @@ -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-sprockets', github: 'middleman/middleman-sprockets', branch: 'v3-stable-real' +gem 'middleman', path: 'middleman' +gem 'middleman-sprockets', git: 'https://github.com/middleman/middleman-sprockets', branch: 'v3-stable-real' 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. diff --git a/README.md b/README.md index 540ca969..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? @@ -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 @@ -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 diff --git a/Rakefile b/Rakefile index d1fe239e..89546ff3 100644 --- a/Rakefile +++ b/Rakefile @@ -1,18 +1,17 @@ -require 'rubygems' unless defined?(Gem) 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}" @@ -29,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/gem_rake_helper.rb b/gem_rake_helper.rb index ff7a592d..4e5bd75b 100644 --- a/gem_rake_helper.rb +++ b/gem_rake_helper.rb @@ -1,4 +1,3 @@ -require 'rubygems' unless defined?(Gem) require 'rake' require 'yard' @@ -24,14 +23,6 @@ Cucumber::Rake::Task.new do |t| 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 - require 'rspec/core/rake_task' desc 'Run RSpec' RSpec::Core::RakeTask.new do |spec| @@ -39,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 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 6e3c4ee8..a093ee44 100644 --- a/middleman-core/Rakefile +++ b/middleman-core/Rakefile @@ -1,7 +1 @@ -# coding:utf-8 -RAKE_ROOT = __FILE__ - -GEM_NAME = ENV['NAME'] || 'middleman-core' - -require 'rubygems' -require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper') +require_relative '../gem_rake_helper' 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/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..885a75b8 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 @@ -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/features/data.feature b/middleman-core/features/data.feature index fcce8445..35601eb7 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 exit 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 exit 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/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/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" 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/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/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.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/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/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/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/ 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/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 diff --git a/middleman-core/lib/middleman-core/core_extensions/rendering.rb b/middleman-core/lib/middleman-core/core_extensions/rendering.rb index 11e1cbb0..7dab1814 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 @@ -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) - content = 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) - content = 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/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/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 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/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-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..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 @@ -13,10 +14,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 +23,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 +40,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 @@ -56,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 @@ -153,7 +153,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] @@ -199,7 +198,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| @@ -224,7 +223,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 937efdd5..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,13 +66,15 @@ 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 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 # @@ -139,6 +143,11 @@ module Middleman def listeners information.listeners end + + # Is https enabled? + def https? + @https == true + end end end end 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 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 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/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 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 diff --git a/middleman-core/lib/middleman-core/templates/shared/gitignore b/middleman-core/lib/middleman-core/templates/shared/gitignore index a320f7b6..67e76f65 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/ 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-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 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..c7ceac45 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,17 @@ 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' +require 'padrino-helpers/tag_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) @@ -216,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)) @@ -234,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 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 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..fb50b8db 100644 --- a/middleman/middleman.gemspec +++ b/middleman/middleman.gemspec @@ -1,5 +1,6 @@ -# -*- encoding: utf-8 -*- -$:.push File.expand_path("../lib", __FILE__) +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) + require File.expand_path("../../middleman-core/lib/middleman-core/version.rb", __FILE__) Gem::Specification.new do |s| @@ -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