diff --git a/middleman-core/features/i18n_link_to.feature b/middleman-core/features/i18n_link_to.feature index 1befe171..200188ef 100644 --- a/middleman-core/features/i18n_link_to.feature +++ b/middleman-core/features/i18n_link_to.feature @@ -1,6 +1,6 @@ -Feature: i18n Links +Feature: i18n Paths - Scenario: A template changes i18n during preview + Scenario: link_to is i18n aware Given a fixture app "empty-app" And a file named "data/pages.yml" with: """ @@ -46,4 +46,46 @@ Feature: i18n Links Then I should see 'Current hello.html' Then I should see 'Other hello.html' Then I should see 'Current Block' - Then I should see 'Other Block' \ No newline at end of file + Then I should see 'Other Block' + + Scenario: url_for is i18n aware + Given a fixture app "empty-app" + And a file named "data/pages.yml" with: + """ + - hello.html + """ + And a file named "locales/en.yml" with: + """ + --- + en: + msg: Hello + """ + And a file named "locales/es.yml" with: + """ + --- + es: + paths: + hello: "hola" + msg: Hola + """ + And a file named "source/localizable/hello.html.erb" with: + """ + Page: <%= t(:msg) %> + <% data.pages.each_with_index do |p, i| %> + Current: <%= url_for "/#{p}" %> + Other: <%= url_for "/#{p}", locale: ::I18n.locale == :en ? :es : :en %> + <% end %> + """ + And a file named "config.rb" with: + """ + activate :i18n + """ + Given the Server is running at "empty-app" + When I go to "/hello.html" + Then I should see "Page: Hello" + Then I should see 'Current: /hello.html' + Then I should see 'Other: /es/hola.html' + When I go to "/es/hola.html" + Then I should see "Page: Hola" + Then I should see 'Current: /es/hola.html' + Then I should see 'Other: /hello.html' diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index 28496679..7c0ddcfc 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -73,7 +73,7 @@ module Middleman # Which server name should be used # @return [NilClass, String] - config.define_setting :host, nil , 'The preview host name' + config.define_setting :host, nil, 'The preview host name' # Whether to serve the preview server over HTTPS. # @return [Boolean] diff --git a/middleman-core/lib/middleman-core/cli/bundler.rb b/middleman-core/lib/middleman-core/cli/bundler.rb index 27e461ce..12003454 100644 --- a/middleman-core/lib/middleman-core/cli/bundler.rb +++ b/middleman-core/lib/middleman-core/cli/bundler.rb @@ -34,6 +34,6 @@ module Middleman::Cli # Map "u" to "upgrade" Base.map( - 'u' => 'upgrade' + 'u' => 'upgrade' ) end diff --git a/middleman-core/lib/middleman-core/cli/init.rb b/middleman-core/lib/middleman-core/cli/init.rb index 08b6c4e6..76eb5ed3 100644 --- a/middleman-core/lib/middleman-core/cli/init.rb +++ b/middleman-core/lib/middleman-core/cli/init.rb @@ -64,8 +64,8 @@ module Middleman::Cli # Map "i", "new" and "n" to "init" Base.map( - 'i' => 'init', - 'new' => 'init', - 'n' => 'init' + 'i' => 'init', + 'new' => 'init', + 'n' => 'init' ) end diff --git a/middleman-core/lib/middleman-core/core_extensions/front_matter.rb b/middleman-core/lib/middleman-core/core_extensions/front_matter.rb index c10daa64..3e1ca08b 100644 --- a/middleman-core/lib/middleman-core/core_extensions/front_matter.rb +++ b/middleman-core/lib/middleman-core/core_extensions/front_matter.rb @@ -101,7 +101,7 @@ module Middleman::CoreExtensions data, content = frontmatter_and_content(p) if app.files.exists?("#{path}.frontmatter") - external_data, _ = frontmatter_and_content("#{p}.frontmatter") + external_data, = frontmatter_and_content("#{p}.frontmatter") data = external_data.deep_merge(data) end diff --git a/middleman-core/lib/middleman-core/core_extensions/rendering.rb b/middleman-core/lib/middleman-core/core_extensions/rendering.rb index a5ce0d9a..205e1063 100644 --- a/middleman-core/lib/middleman-core/core_extensions/rendering.rb +++ b/middleman-core/lib/middleman-core/core_extensions/rendering.rb @@ -422,7 +422,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 begin content = if block_given? diff --git a/middleman-core/lib/middleman-core/core_extensions/request.rb b/middleman-core/lib/middleman-core/core_extensions/request.rb index 3a0292e7..b1476e35 100644 --- a/middleman-core/lib/middleman-core/core_extensions/request.rb +++ b/middleman-core/lib/middleman-core/core_extensions/request.rb @@ -173,8 +173,8 @@ module Middleman def current_path=(path) Thread.current[:current_path] = path Thread.current[:legacy_request] = ::Thor::CoreExt::HashWithIndifferentAccess.new( - path: path, - params: req ? ::Thor::CoreExt::HashWithIndifferentAccess.new(req.params) : {} + path: path, + params: req ? ::Thor::CoreExt::HashWithIndifferentAccess.new(req.params) : {} ) end diff --git a/middleman-core/lib/middleman-core/preview_server.rb b/middleman-core/lib/middleman-core/preview_server.rb index 27152706..7ab5fff6 100644 --- a/middleman-core/lib/middleman-core/preview_server.rb +++ b/middleman-core/lib/middleman-core/preview_server.rb @@ -198,12 +198,12 @@ module Middleman http_opts[:SSLEnable] = true if ssl_certificate || ssl_private_key - raise "You must provide both :ssl_certificate and :ssl_private_key" unless ssl_private_key && ssl_certificate + raise 'You must provide both :ssl_certificate and :ssl_private_key' unless ssl_private_key && ssl_certificate http_opts[:SSLCertificate] = OpenSSL::X509::Certificate.new File.read ssl_certificate http_opts[:SSLPrivateKey] = OpenSSL::PKey::RSA.new File.read ssl_private_key else # use a generated self-signed cert - cert, key = create_self_signed_cert(1024, [["CN", host]], "Middleman Preview Server") + cert, key = create_self_signed_cert(1024, [['CN', host]], 'Middleman Preview Server') http_opts[:SSLCertificate] = cert http_opts[:SSLPrivateKey] = key end @@ -251,24 +251,24 @@ module Middleman cert.subject = name cert.issuer = name cert.not_before = Time.now - cert.not_after = Time.now + (365*24*60*60) + cert.not_after = Time.now + (365 * 24 * 60 * 60) cert.public_key = rsa.public_key - ef = OpenSSL::X509::ExtensionFactory.new(nil,cert) + ef = OpenSSL::X509::ExtensionFactory.new(nil, cert) ef.issuer_certificate = cert cert.extensions = [ - ef.create_extension("basicConstraints","CA:FALSE"), - ef.create_extension("keyUsage", "keyEncipherment"), - ef.create_extension("subjectKeyIdentifier", "hash"), - ef.create_extension("extendedKeyUsage", "serverAuth"), - ef.create_extension("nsComment", comment), - ] - aki = ef.create_extension("authorityKeyIdentifier", - "keyid:always,issuer:always") + ef.create_extension('basicConstraints', 'CA:FALSE'), + ef.create_extension('keyUsage', 'keyEncipherment'), + ef.create_extension('subjectKeyIdentifier', 'hash'), + ef.create_extension('extendedKeyUsage', 'serverAuth'), + ef.create_extension('nsComment', comment) + ] + aki = ef.create_extension('authorityKeyIdentifier', + 'keyid:always,issuer:always') cert.add_extension(aki) cert.sign(rsa, OpenSSL::Digest::SHA1.new) - return [ cert, rsa ] + [cert, rsa] end # Attach a new Middleman::Application instance diff --git a/middleman-core/lib/middleman-core/sitemap.rb b/middleman-core/lib/middleman-core/sitemap.rb index 10754990..4abb1d37 100644 --- a/middleman-core/lib/middleman-core/sitemap.rb +++ b/middleman-core/lib/middleman-core/sitemap.rb @@ -28,16 +28,16 @@ module Middleman root_dotfiles: proc { |file| file.start_with?('.') }, # Files starting with an dot, but not .htaccess - source_dotfiles: proc { |file| + source_dotfiles: proc do |file| file =~ %r{/\.} && file !~ %r{/\.(htaccess|htpasswd|nojekyll)} - }, + end, # Files starting with an underscore, but not a double-underscore partials: proc { |file| file =~ %r{/_[^_]} }, - layout: proc { |file, sitemap_app| + layout: proc do |file, sitemap_app| file.start_with?(File.join(sitemap_app.config[:source], 'layout.')) || file.start_with?(File.join(sitemap_app.config[:source], 'layouts/')) - } + end }, 'Callbacks that can exclude paths from the sitemap' # Include instance methods diff --git a/middleman-core/lib/middleman-core/sitemap/extensions/redirects.rb b/middleman-core/lib/middleman-core/sitemap/extensions/redirects.rb index 980dbe96..a5c59b01 100644 --- a/middleman-core/lib/middleman-core/sitemap/extensions/redirects.rb +++ b/middleman-core/lib/middleman-core/sitemap/extensions/redirects.rb @@ -80,7 +80,7 @@ module Middleman url = ::Middleman::Util.url_for(store.app, @request_path, relative: false, find_resource: true - ) + ) if output output.call(path, url) diff --git a/middleman-core/lib/middleman-core/sitemap/queryable.rb b/middleman-core/lib/middleman-core/sitemap/queryable.rb index af225e5d..e3d1347d 100644 --- a/middleman-core/lib/middleman-core/sitemap/queryable.rb +++ b/middleman-core/lib/middleman-core/sitemap/queryable.rb @@ -125,7 +125,8 @@ module Middleman unless VALID_OPERATORS.include? opts[:operator] raise OperatorNotSupportedError end - @attribute, @operator = opts[:attribute], opts[:operator] + @attribute = opts[:attribute] + @operator = opts[:operator] end end end diff --git a/middleman-core/lib/middleman-core/sitemap/store.rb b/middleman-core/lib/middleman-core/sitemap/store.rb index 18333788..589a8ab6 100644 --- a/middleman-core/lib/middleman-core/sitemap/store.rb +++ b/middleman-core/lib/middleman-core/sitemap/store.rb @@ -231,10 +231,10 @@ module Middleman private def reset_lookup_cache! - @lock.synchronize { + @lock.synchronize do @_lookup_by_path = {} @_lookup_by_destination_path = {} - } + end end # Removes the templating extensions, while keeping the others 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 5d6bee6f..0ac4c147 100644 --- a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb +++ b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb @@ -8,7 +8,8 @@ class Padrino::Helpers::OutputHelpers::ErbHandler # Force Erb capture not to use safebuffer # rubocop:disable UnderscorePrefixedVariableName 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 @@ -255,12 +256,12 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension url = url_for(url, options) super end - + # Modified Padrino image_tag so that it finds the paths for srcset # using asset_path for the images listed in the srcset param def image_tag(path, params={}) params.symbolize_keys! - + if params.key?(:srcset) images_sources = params[:srcset].split(',').map do |src_def| if src_def.include?('//') diff --git a/middleman-core/lib/middleman-more/core_extensions/i18n.rb b/middleman-core/lib/middleman-more/core_extensions/i18n.rb index 7ae83a7a..c679c52e 100644 --- a/middleman-core/lib/middleman-more/core_extensions/i18n.rb +++ b/middleman-core/lib/middleman-more/core_extensions/i18n.rb @@ -58,20 +58,11 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension ::I18n.t(*args) end - def link_to(*args, &block) - options = args.extract_options! - name = block_given? ? '' : args.shift - href = args.first - + def url_for(path_or_resource, options={}) locale = options.delete(:locale) || ::I18n.locale - - url = extensions[:i18n].localized_path(href, locale) - new_args = [] - new_args << name unless block_given? - new_args << url || href - new_args << options - super(*new_args, &block) + href = super(path_or_resource, options) + extensions[:i18n].localized_path(href, locale) || href end end @@ -177,9 +168,9 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension p.to_s.match(@locales_regex) && (p.to_s.split(File::SEPARATOR).length == 2) end - known_langs.map { |p| + known_langs.map do |p| File.basename(p.to_s).sub(/\.ya?ml$/, '').sub(/\.rb$/, '') - }.sort.map(&:to_sym) + end.sort.map(&:to_sym) end end diff --git a/middleman-core/lib/middleman-more/extensions/automatic_image_sizes.rb b/middleman-core/lib/middleman-more/extensions/automatic_image_sizes.rb index 45d89c8a..b36d3733 100644 --- a/middleman-core/lib/middleman-more/extensions/automatic_image_sizes.rb +++ b/middleman-core/lib/middleman-more/extensions/automatic_image_sizes.rb @@ -27,8 +27,8 @@ class Middleman::Extensions::AutomaticImageSizes < ::Middleman::Extension retina = full_path.match(/@(\d)x\.[a-zA-Z]{3,4}$/) if retina factor = retina[1].to_i - width = width / factor - height = height / factor + width /= factor + height /= factor end params[:width] = width params[:height] = height diff --git a/middleman-core/lib/middleman-more/extensions/minify_javascript.rb b/middleman-core/lib/middleman-more/extensions/minify_javascript.rb index df020765..ea605f04 100644 --- a/middleman-core/lib/middleman-more/extensions/minify_javascript.rb +++ b/middleman-core/lib/middleman-more/extensions/minify_javascript.rb @@ -103,7 +103,9 @@ class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension # @return [String] def minify_inline(content) content.gsub(INLINE_JS_REGEX) do |match| - first, inline_content, last = $1, $2, $3 + first = $1 + inline_content = $2 + last = $3 # Only compress script tags that contain JavaScript (as opposed to # something like jQuery templates, identified with a "text/html" type).