Tweak locale links
This commit is contained in:
parent
6502b37934
commit
d3c7436647
|
@ -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:
|
||||
"""
|
||||
|
@ -47,3 +47,45 @@ Feature: i18n Links
|
|||
Then I should see '<a title="Other hello.html" href="/hello.html">Other hello.html</a>'
|
||||
Then I should see '<a class="current" href="/es/hola.html"><span>Current Block</span></a>'
|
||||
Then I should see '<a title="Other hello.html" href="/hello.html"><span>Other Block</span></a>'
|
||||
|
||||
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'
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
@ -257,18 +257,18 @@ module Middleman
|
|||
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),
|
||||
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")
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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).
|
||||
|
|
Loading…
Reference in a new issue