diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..5d126348 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.rubocop.yml b/.rubocop.yml index 652f08fb..337be055 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -25,8 +25,6 @@ ClassLength: Enabled: false Documentation: Enabled: false -Encoding: - Enabled: false HashSyntax: EnforcedStyle: ruby19 SpaceAroundEqualsInParameterDefault: diff --git a/middleman-cli/lib/middleman-cli/templates/extension/Rakefile b/middleman-cli/lib/middleman-cli/templates/extension/Rakefile index 529dfacf..4c62996f 100644 --- a/middleman-cli/lib/middleman-cli/templates/extension/Rakefile +++ b/middleman-cli/lib/middleman-cli/templates/extension/Rakefile @@ -4,7 +4,7 @@ Bundler::GemHelper.install_tasks require 'cucumber/rake/task' Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t| - t.cucumber_opts = "--color --tags ~@wip --strict" + t.cucumber_opts = '--color --tags ~@wip --strict' end require 'rake/clean' diff --git a/middleman-core/.rspec b/middleman-core/.rspec new file mode 100644 index 00000000..5052887a --- /dev/null +++ b/middleman-core/.rspec @@ -0,0 +1 @@ +--color \ No newline at end of file diff --git a/middleman-core/cucumber.yml b/middleman-core/cucumber.yml new file mode 100644 index 00000000..922a378c --- /dev/null +++ b/middleman-core/cucumber.yml @@ -0,0 +1,2 @@ +default: --require features --tags ~@wip +wip: --require features --tags @wip \ No newline at end of file diff --git a/middleman-core/features/chained_templates.feature b/middleman-core/features/chained_templates.feature index 4647e7eb..27135bf6 100644 --- a/middleman-core/features/chained_templates.feature +++ b/middleman-core/features/chained_templates.feature @@ -7,19 +7,19 @@ Feature: Templates should be chainable Then I should see "Title" And I should see "Subtitle" And I should see "Sup" - + Scenario: Build chained template Given a successfully built app at "chained-app" When I cd to "build" Then the following files should exist: | index.html | - | test.html.combobreaker | + | test.erb.combobreaker | And the file "index.html" should contain "Title" And the file "index.html" should contain "Subtitle" And the file "index.html" should contain "Sup" - And the file "test.html.combobreaker.html" should contain "Title" - And the file "test.html.combobreaker.html" should contain "Subtitle" - And the file "test.html.combobreaker.html" should contain "Sup" + And the file "test.erb.combobreaker" should contain "Title" + And the file "test.erb.combobreaker" should contain "Subtitle" + And the file "test.erb.combobreaker" should contain "Sup" Scenario: Partials are parsed by multiple template engines: Outer template has .erb and inner .md.erb Given a fixture app "partial-chained_templates-app" @@ -32,7 +32,7 @@ Feature: Templates should be chainable And a template named "my_partial.html.md.erb" with: """ ## My Partial - + <%= 'hello world' %> """ And the Server is running @@ -61,7 +61,7 @@ Feature: Templates should be chainable And a template named "my_partial.html.md.erb" with: """ ## My Partial - + <%= 'hello world' %> """ And the Server is running @@ -90,7 +90,7 @@ Feature: Templates should be chainable And a template named "my_partial.html.erb" with: """

My Partial

- + <%= 'hello world' %> """ And the Server is running diff --git a/middleman-core/fixtures/chained-app/source/test.html.combobreaker.str.erb b/middleman-core/fixtures/chained-app/source/test.erb.combobreaker.str.erb similarity index 100% rename from middleman-core/fixtures/chained-app/source/test.html.combobreaker.str.erb rename to middleman-core/fixtures/chained-app/source/test.erb.combobreaker.str.erb diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index 9ee3f4b9..6c39af54 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -1,5 +1,3 @@ -# Use ActiveSupport JSON -require 'active_support/json' require 'active_support/core_ext/integer/inflections' require 'middleman-core/contracts' diff --git a/middleman-core/lib/middleman-core/core_extensions/default_helpers.rb b/middleman-core/lib/middleman-core/core_extensions/default_helpers.rb index 71666bab..ba508c4d 100644 --- a/middleman-core/lib/middleman-core/core_extensions/default_helpers.rb +++ b/middleman-core/lib/middleman-core/core_extensions/default_helpers.rb @@ -7,7 +7,8 @@ require 'padrino-helpers' class Padrino::Helpers::OutputHelpers::ErbHandler # Force Erb capture not to use safebuffer def capture_from_template(*args, &block) - self.output_buffer, buf_was = '', output_buffer + self.output_buffer = '' + buf_was = output_buffer raw = block.call(*args) captured = template.instance_variable_get(:@_out_buf) self.output_buffer = buf_was diff --git a/middleman-core/lib/middleman-core/extensions/asset_hash.rb b/middleman-core/lib/middleman-core/extensions/asset_hash.rb index e3248bd5..bb1389e9 100644 --- a/middleman-core/lib/middleman-core/extensions/asset_hash.rb +++ b/middleman-core/lib/middleman-core/extensions/asset_hash.rb @@ -17,7 +17,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension def after_configuration # Allow specifying regexes to ignore, plus always ignore apple touch icons @ignore = Array(options.ignore) + [/^apple-touch-icon/] - + app.use ::Middleman::Middleware::InlineURLRewriter, id: :asset_hash, url_extensions: options.exts, diff --git a/middleman-core/lib/middleman-core/preview_server.rb b/middleman-core/lib/middleman-core/preview_server.rb index 4d727bd1..d9f5c172 100644 --- a/middleman-core/lib/middleman-core/preview_server.rb +++ b/middleman-core/lib/middleman-core/preview_server.rb @@ -125,8 +125,8 @@ module Middleman # config.rb watcher = files.watch :reload, - path: root, - only: match_against + path: root, + only: match_against # Hack around node_modules in root. watcher.listener.ignore(/^node_modules/) diff --git a/middleman-core/lib/middleman-core/rack.rb b/middleman-core/lib/middleman-core/rack.rb index a6743c59..3e2a6f25 100644 --- a/middleman-core/lib/middleman-core/rack.rb +++ b/middleman-core/lib/middleman-core/rack.rb @@ -102,7 +102,7 @@ module Middleman begin # Write out the contents of the page - res.write resource.render({}, { rack: { request: req } }) + res.write resource.render({}, rack: { request: req }) # Valid content is a 200 status res.status = 200 diff --git a/middleman-core/lib/middleman-core/renderers/haml.rb b/middleman-core/lib/middleman-core/renderers/haml.rb index 7e2b6fbb..24cdced4 100644 --- a/middleman-core/lib/middleman-core/renderers/haml.rb +++ b/middleman-core/lib/middleman-core/renderers/haml.rb @@ -40,7 +40,6 @@ module Middleman # Haml Renderer class Haml < ::Middleman::Extension - def initialize(app, options={}, &block) super @@ -53,7 +52,7 @@ module Middleman modified_options = options.dup modified_options[:context] = compiler_options[:context] - text = template_class.new(nil, 1, modified_options) {text}.render + text = template_class.new(nil, 1, modified_options) { text }.render super(text, compiler_options) end end diff --git a/middleman-core/lib/middleman-core/sitemap/extensions/proxies.rb b/middleman-core/lib/middleman-core/sitemap/extensions/proxies.rb index 0285726f..110d9890 100644 --- a/middleman-core/lib/middleman-core/sitemap/extensions/proxies.rb +++ b/middleman-core/lib/middleman-core/sitemap/extensions/proxies.rb @@ -86,8 +86,8 @@ module Middleman end class Resource - def proxy_to(path) - throw "Resource#proxy_to has been removed. Use ProxyResource class instead." + def proxy_to(_path) + throw 'Resource#proxy_to has been removed. Use ProxyResource class instead.' end end diff --git a/middleman-core/lib/middleman-core/sitemap/resource.rb b/middleman-core/lib/middleman-core/sitemap/resource.rb index 14b43fd7..4a247cb8 100644 --- a/middleman-core/lib/middleman-core/sitemap/resource.rb +++ b/middleman-core/lib/middleman-core/sitemap/resource.rb @@ -48,9 +48,7 @@ module Middleman @app = @store.app @path = path - if source && source.is_a?(String) - source = Pathname(source) - end + source = Pathname(source) if source && source.is_a?(String) if source && source.is_a?(Pathname) @file_descriptor = ::Middleman::SourceFile.new(source.relative_path_from(@app.source_dir), source, @app.source_dir, Set.new([:source])) diff --git a/middleman-core/lib/middleman-core/sitemap/store.rb b/middleman-core/lib/middleman-core/sitemap/store.rb index f7af3bd2..54e6b1ce 100644 --- a/middleman-core/lib/middleman-core/sitemap/store.rb +++ b/middleman-core/lib/middleman-core/sitemap/store.rb @@ -187,23 +187,24 @@ module Middleman @app.logger.debug '== Rebuilding resource list' - @resources = @resource_list_manipulators.reduce([]) do |result, m| + @resources = [] + + @resource_list_manipulators.each do |m| @app.logger.debug "== Running manipulator: #{m[:name]}" - newres = m[:manipulator].send(m[:custom_name] || :manipulate_resource_list, result) + @resources = m[:manipulator].send(m[:custom_name] || :manipulate_resource_list, @resources) # Reset lookup cache reset_lookup_cache! # Rebuild cache - newres.each do |resource| + @resources.each do |resource| @_lookup_by_path[resource.path] = resource @_lookup_by_destination_path[resource.destination_path] = resource end - newres + invalidate_resources_not_ignored_cache! end - invalidate_resources_not_ignored_cache! @update_count += 1 end end @@ -223,7 +224,7 @@ module Middleman Contract String => String def remove_templating_extensions(path) # Strip templating extensions as long as Tilt knows them - path = path.sub(File.extname(path), '') while ::Tilt[path] + path = path.sub(/#{::Regexp.escape(File.extname(path))}$/, '') while ::Tilt[path] path end diff --git a/middleman-core/lib/middleman-core/sources/source_watcher.rb b/middleman-core/lib/middleman-core/sources/source_watcher.rb index 82dc8f74..38ac639a 100644 --- a/middleman-core/lib/middleman-core/sources/source_watcher.rb +++ b/middleman-core/lib/middleman-core/sources/source_watcher.rb @@ -8,16 +8,14 @@ require 'backports/2.0.0/enumerable/lazy' module Listen class Silencer # TODO: switch type and path places - and verify - def silenced?(relative_path, type) + def silenced?(relative_path, _type) path = relative_path.to_s # if only_patterns && type == :file # return true unless only_patterns.any? { |pattern| path =~ pattern } # end - if only_patterns - return !only_patterns.any? { |pattern| path =~ pattern } - end + return !only_patterns.any? { |pattern| path =~ pattern } if only_patterns ignore_patterns.any? { |pattern| path =~ pattern } end diff --git a/middleman-core/lib/middleman-core/template_context.rb b/middleman-core/lib/middleman-core/template_context.rb index 48498d85..6771ddbe 100644 --- a/middleman-core/lib/middleman-core/template_context.rb +++ b/middleman-core/lib/middleman-core/template_context.rb @@ -71,7 +71,8 @@ module Middleman engine = extension[1..-1].to_sym # Store last engine for later (could be inside nested renders) - self.current_engine, engine_was = engine, current_engine + self.current_engine = engine + engine_was = current_engine # By default, no content is captured content = '' diff --git a/middleman-core/lib/middleman-core/util/data.rb b/middleman-core/lib/middleman-core/util/data.rb index a02d64e2..781ed5c0 100644 --- a/middleman-core/lib/middleman-core/util/data.rb +++ b/middleman-core/lib/middleman-core/util/data.rb @@ -11,11 +11,11 @@ require 'middleman-core/util' require 'yaml' # Parsing JSON data -require 'active_support/json' +require 'json' module Middleman module Util - module Data + module Data include Contracts module_function @@ -121,7 +121,7 @@ module Middleman Contract String, Pathname => Maybe[[Hash, String]] def parse_json(content, full_path) begin - data = map_value(::ActiveSupport::JSON.decode(content)) + data = map_value(::JSON.parse(content)) rescue => e $stderr.puts "JSON Exception parsing #{full_path}: #{e.message}" return nil