middleman-core 3.0.0.beta.3 → 3.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/middleman +32 -30
- data/features/clean_build.feature +0 -13
- data/features/extensionless_text_files.feature +2 -34
- data/features/front-matter.feature +27 -6
- data/features/frontmatter_page_settings.feature +6 -15
- data/features/ignore.feature +1 -78
- data/features/sitemap_traversal.feature +5 -5
- data/features/support/env.rb +3 -0
- data/features/wildcard_page_helper.feature +0 -9
- data/fixtures/frontmatter-app/source/front-matter-encoding.html.erb +7 -0
- data/fixtures/frontmatter-app/source/{front-matter.html.erb → front-matter-line-2.html.erb} +0 -1
- data/fixtures/frontmatter-app/source/json-front-matter-2.php.erb +2 -2
- data/fixtures/frontmatter-app/source/json-front-matter-auto.erb +2 -2
- data/fixtures/frontmatter-app/source/json-front-matter-encoding.html.erb +7 -0
- data/fixtures/frontmatter-app/source/json-front-matter-line-2.html.erb +7 -0
- data/fixtures/frontmatter-app/source/json-front-matter.html.erb +2 -2
- data/fixtures/frontmatter-settings-app/config.rb +1 -3
- data/fixtures/indexable-app/config.rb +0 -4
- data/fixtures/traversal-app/config.rb +0 -2
- data/lib/middleman-core/application.rb +7 -48
- data/lib/middleman-core/cli.rb +49 -46
- data/lib/middleman-core/cli/build.rb +62 -30
- data/lib/middleman-core/cli/extension.rb +1 -1
- data/lib/middleman-core/cli/server.rb +4 -3
- data/lib/middleman-core/core_extensions.rb +1 -10
- data/lib/middleman-core/core_extensions/extensions.rb +14 -9
- data/lib/middleman-core/core_extensions/file_watcher.rb +44 -46
- data/lib/middleman-core/core_extensions/front_matter.rb +27 -11
- data/lib/middleman-core/core_extensions/rendering.rb +74 -7
- data/lib/middleman-core/core_extensions/request.rb +32 -33
- data/lib/middleman-core/core_extensions/routing.rb +5 -3
- data/lib/middleman-core/extensions.rb +11 -21
- data/lib/middleman-core/preview_server.rb +3 -3
- data/lib/middleman-core/renderers/coffee_script.rb +41 -0
- data/lib/middleman-core/renderers/haml.rb +30 -0
- data/lib/middleman-core/renderers/less.rb +46 -0
- data/lib/middleman-core/renderers/liquid.rb +35 -0
- data/lib/middleman-core/renderers/markdown.rb +57 -0
- data/lib/middleman-core/renderers/redcarpet.rb +38 -0
- data/lib/middleman-core/renderers/sass.rb +85 -0
- data/lib/middleman-core/renderers/slim.rb +30 -0
- data/lib/middleman-core/sitemap/resource.rb +6 -2
- data/lib/middleman-core/step_definitions/middleman_steps.rb +2 -2
- data/lib/middleman-core/templates/extension/gemspec +1 -1
- data/lib/middleman-core/templates/extension/lib/lib.rb +1 -1
- data/lib/middleman-core/util.rb +4 -0
- data/lib/middleman-core/version.rb +1 -9
- data/middleman-core.gemspec +3 -7
- metadata +146 -312
- data/features/asset_host.feature +0 -7
- data/features/automatic_image_sizes.feature +0 -16
- data/features/content_for.feature +0 -6
- data/features/directory_index.feature +0 -66
- data/features/former_padrino_helpers.feature +0 -12
- data/features/helpers_auto_javascript_include_tag.feature +0 -27
- data/features/helpers_auto_stylesheet_link_tag.feature +0 -27
- data/features/helpers_lorem.feature +0 -6
- data/features/helpers_page_classes.feature +0 -17
- data/features/helpers_relative_link_to.feature +0 -68
- data/features/i18n_builder.feature +0 -121
- data/features/i18n_preview.feature +0 -113
- data/features/instance_vars.feature +0 -18
- data/features/nested_layouts.feature +0 -24
- data/features/partials.feature +0 -46
- data/fixtures/asset-host-app/config.rb +0 -6
- data/fixtures/asset-host-app/source/.htaccess +0 -1
- data/fixtures/asset-host-app/source/asset_host.html.erb +0 -1
- data/fixtures/asset-host-app/source/images/blank.gif +0 -0
- data/fixtures/auto-css-app/config.rb +0 -11
- data/fixtures/auto-css-app/source/auto-css.html.erb +0 -1
- data/fixtures/auto-css-app/source/auto-css/auto-css.html.erb +0 -1
- data/fixtures/auto-css-app/source/auto-css/index.html.erb +0 -1
- data/fixtures/auto-css-app/source/auto-css/sub/auto-css.html.erb +0 -1
- data/fixtures/auto-css-app/source/stylesheets/auto-css.css +0 -3
- data/fixtures/auto-css-app/source/stylesheets/auto-css/auto-css.css +0 -3
- data/fixtures/auto-css-app/source/stylesheets/auto-css/index.css +0 -0
- data/fixtures/auto-css-app/source/stylesheets/auto-css/sub/auto-css.css +0 -3
- data/fixtures/auto-js-app/config.rb +0 -11
- data/fixtures/auto-js-app/source/auto-js.html.erb +0 -1
- data/fixtures/auto-js-app/source/auto-js/auto-js.html.erb +0 -1
- data/fixtures/auto-js-app/source/auto-js/index.html.erb +0 -1
- data/fixtures/auto-js-app/source/auto-js/sub/auto-js.html.erb +0 -1
- data/fixtures/auto-js-app/source/javascripts/auto-js.js +0 -1
- data/fixtures/auto-js-app/source/javascripts/auto-js/auto-js.js +0 -1
- data/fixtures/auto-js-app/source/javascripts/auto-js/index.js +0 -1
- data/fixtures/auto-js-app/source/javascripts/auto-js/sub/auto-js.js +0 -1
- data/fixtures/automatic-image-size-app/config.rb +0 -0
- data/fixtures/automatic-image-size-app/source/auto-image-sizes.html.erb +0 -1
- data/fixtures/automatic-image-size-app/source/images/blank.gif +0 -0
- data/fixtures/clean-dir-app/config.rb +0 -2
- data/fixtures/clean-dir-app/source/about.html +0 -1
- data/fixtures/content-for-app/config.rb +0 -3
- data/fixtures/content-for-app/source/content_for_erb.html.erb +0 -5
- data/fixtures/content-for-app/source/layouts/content_for.erb +0 -4
- data/fixtures/different-engine-partial/config.rb +0 -0
- data/fixtures/different-engine-partial/source/index.html.erb +0 -1
- data/fixtures/different-engine-partial/source/layouts/layout.erb +0 -7
- data/fixtures/different-engine-partial/source/shared/_footer.str +0 -1
- data/fixtures/different-engine-partial/source/shared/_header.erb +0 -1
- data/fixtures/frontmatter-settings-app/source/no_index.html.erb +0 -5
- data/fixtures/i18n-alt-root-app/locales/en.yml +0 -4
- data/fixtures/i18n-alt-root-app/locales/es.yml +0 -7
- data/fixtures/i18n-alt-root-app/source/lang_data/hello.html.erb +0 -1
- data/fixtures/i18n-alt-root-app/source/lang_data/index.html.erb +0 -1
- data/fixtures/i18n-alt-root-app/source/layout.erb +0 -1
- data/fixtures/i18n-test-app/locales/en.yml +0 -4
- data/fixtures/i18n-test-app/locales/es.yml +0 -7
- data/fixtures/i18n-test-app/source/layout.erb +0 -1
- data/fixtures/i18n-test-app/source/localizable/hello.html.erb +0 -1
- data/fixtures/i18n-test-app/source/localizable/index.html.erb +0 -1
- data/fixtures/instance-vars-app/config.rb +0 -0
- data/fixtures/instance-vars-app/source/_vartial.erb +0 -5
- data/fixtures/instance-vars-app/source/instance-var-set.html.erb +0 -2
- data/fixtures/instance-vars-app/source/layout.erb +0 -3
- data/fixtures/instance-vars-app/source/no-instance-var.html.erb +0 -1
- data/fixtures/lorem-app/config.rb +0 -1
- data/fixtures/lorem-app/source/lorem.html.erb +0 -13
- data/fixtures/nested-layout-app/config.rb +0 -1
- data/fixtures/nested-layout-app/source/data-one.html.erb +0 -5
- data/fixtures/nested-layout-app/source/data-two.html.erb +0 -5
- data/fixtures/nested-layout-app/source/index.html.erb +0 -1
- data/fixtures/nested-layout-app/source/layouts/inner.erb +0 -4
- data/fixtures/nested-layout-app/source/layouts/master.erb +0 -3
- data/fixtures/nested-layout-app/source/layouts/outer.erb +0 -4
- data/fixtures/padrino-helpers-app/config.rb +0 -0
- data/fixtures/padrino-helpers-app/source/former_padrino_test.html.erb +0 -5
- data/fixtures/page-classes-app/config.rb +0 -4
- data/fixtures/page-classes-app/source/page-classes.html.erb +0 -1
- data/fixtures/page-classes-app/source/sub1/page-classes.html.erb +0 -1
- data/fixtures/page-classes-app/source/sub1/sub2/page-classes.html.erb +0 -1
- data/fixtures/partials-app/config.rb +0 -0
- data/fixtures/partials-app/source/_locals.erb +0 -1
- data/fixtures/partials-app/source/_main.erb +0 -1
- data/fixtures/partials-app/source/_main.str +0 -1
- data/fixtures/partials-app/source/index.html.erb +0 -3
- data/fixtures/partials-app/source/locals.html.erb +0 -1
- data/fixtures/partials-app/source/second.html.str +0 -3
- data/fixtures/partials-app/source/shared/_footer.erb +0 -1
- data/fixtures/partials-app/source/shared/_header.erb +0 -1
- data/fixtures/partials-app/source/shared/snippet.erb +0 -1
- data/fixtures/partials-app/source/sub/_local.erb +0 -1
- data/fixtures/partials-app/source/sub/index.html.erb +0 -3
- data/fixtures/partials-app/source/using_snippet.html.erb +0 -1
- data/fixtures/wildcard-directory-index-app/config.rb +0 -2
- data/fixtures/wildcard-directory-index-app/source/admin/index.html.erb +0 -1
- data/fixtures/wildcard-directory-index-app/source/admin/page.html.erb +0 -1
- data/fixtures/wildcard-directory-index-app/source/index.html.erb +0 -1
- data/fixtures/wildcard-directory-index-app/source/layouts/admin.erb +0 -2
- data/fixtures/wildcard-directory-index-app/source/layouts/layout.erb +0 -2
- data/lib/middleman-core/core_extensions/assets.rb +0 -43
- data/lib/middleman-core/core_extensions/default_helpers.rb +0 -172
- data/lib/middleman-core/core_extensions/i18n.rb +0 -146
- data/lib/middleman-core/extensions/asset_host.rb +0 -47
- data/lib/middleman-core/extensions/automatic_image_sizes.rb +0 -57
- data/lib/middleman-core/extensions/automatic_image_sizes/fastimage.rb +0 -287
- data/lib/middleman-core/extensions/directory_indexes.rb +0 -54
- data/lib/middleman-core/extensions/lorem.rb +0 -195
@@ -1 +0,0 @@
|
|
1
|
-
<footer>Footer</header>
|
@@ -1 +0,0 @@
|
|
1
|
-
<header>Header</header>
|
@@ -1 +0,0 @@
|
|
1
|
-
Snippet
|
@@ -1 +0,0 @@
|
|
1
|
-
<h2>Local Partial</h2>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= partial "shared/snippet" %>
|
@@ -1 +0,0 @@
|
|
1
|
-
Index
|
@@ -1 +0,0 @@
|
|
1
|
-
Page
|
@@ -1 +0,0 @@
|
|
1
|
-
Index
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module Middleman
|
2
|
-
module CoreExtensions
|
3
|
-
|
4
|
-
# Base helper to manipulate asset paths
|
5
|
-
module Assets
|
6
|
-
|
7
|
-
# Extension registered
|
8
|
-
class << self
|
9
|
-
def registered(app)
|
10
|
-
# Disable Padrino cache buster
|
11
|
-
app.set :asset_stamp, false
|
12
|
-
|
13
|
-
# Include helpers
|
14
|
-
app.send :include, InstanceMethod
|
15
|
-
end
|
16
|
-
alias :included :registered
|
17
|
-
end
|
18
|
-
|
19
|
-
# Methods to be mixed-in to Middleman::Application
|
20
|
-
module InstanceMethod
|
21
|
-
|
22
|
-
# Get the URL of an asset given a type/prefix
|
23
|
-
#
|
24
|
-
# @param [String] path The path (such as "photo.jpg")
|
25
|
-
# @param [String] prefix The type prefix (such as "images")
|
26
|
-
# @return [String] The fully qualified asset url
|
27
|
-
def asset_url(path, prefix="")
|
28
|
-
# Don't touch assets which already have a full path
|
29
|
-
if path.include?("//")
|
30
|
-
path
|
31
|
-
else # rewrite paths to use their destination path
|
32
|
-
path = File.join(prefix, path)
|
33
|
-
if resource = sitemap.find_resource_by_path(path)
|
34
|
-
path = resource.destination_path
|
35
|
-
end
|
36
|
-
|
37
|
-
File.join(http_prefix, path)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,172 +0,0 @@
|
|
1
|
-
module Middleman
|
2
|
-
module CoreExtensions
|
3
|
-
# Built-in helpers
|
4
|
-
module DefaultHelpers
|
5
|
-
|
6
|
-
# Extension registered
|
7
|
-
class << self
|
8
|
-
# @private
|
9
|
-
def registered(app)
|
10
|
-
require "active_support/core_ext/integer/inflections"
|
11
|
-
require 'padrino-helpers'
|
12
|
-
|
13
|
-
app.helpers ::Padrino::Helpers::OutputHelpers
|
14
|
-
app.helpers ::Padrino::Helpers::TagHelpers
|
15
|
-
app.helpers ::Padrino::Helpers::AssetTagHelpers
|
16
|
-
app.helpers ::Padrino::Helpers::FormHelpers
|
17
|
-
app.helpers ::Padrino::Helpers::FormatHelpers
|
18
|
-
app.helpers ::Padrino::Helpers::RenderHelpers
|
19
|
-
app.helpers ::Padrino::Helpers::NumberHelpers
|
20
|
-
# app.helpers ::Padrino::Helpers::TranslationHelpers
|
21
|
-
|
22
|
-
app.helpers Helpers
|
23
|
-
|
24
|
-
app.set :relative_links, false
|
25
|
-
end
|
26
|
-
alias :included :registered
|
27
|
-
end
|
28
|
-
|
29
|
-
# The helpers
|
30
|
-
module Helpers
|
31
|
-
# Output a stylesheet link tag based on the current path
|
32
|
-
#
|
33
|
-
# @param [String] separator How to break up path in parts
|
34
|
-
# @return [String]
|
35
|
-
def auto_stylesheet_link_tag(separator="/")
|
36
|
-
auto_tag(:css, separator) do |path|
|
37
|
-
stylesheet_link_tag path
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# Output a javascript tag based on the current path
|
42
|
-
#
|
43
|
-
# @param [String] separator How to break up path in parts
|
44
|
-
# @return [String]
|
45
|
-
def auto_javascript_include_tag(separator="/")
|
46
|
-
auto_tag(:js, separator) do |path|
|
47
|
-
javascript_include_tag path
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# Output a stylesheet link tag based on the current path
|
52
|
-
#
|
53
|
-
# @param [Symbol] asset_ext The type of asset
|
54
|
-
# @param [String] separator How to break up path in parts
|
55
|
-
# @param [String] asset_dir Where to look for assets
|
56
|
-
# @return [void]
|
57
|
-
def auto_tag(asset_ext, separator="/", asset_dir=nil)
|
58
|
-
if asset_dir.nil?
|
59
|
-
asset_dir = case asset_ext
|
60
|
-
when :js then js_dir
|
61
|
-
when :css then css_dir
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# If the basename of the request as no extension, assume we are serving a
|
66
|
-
# directory and join index_file to the path.
|
67
|
-
path = full_path(current_path.dup)
|
68
|
-
path = path.sub(%r{^/}, '')
|
69
|
-
path = path.gsub(File.extname(path), ".#{asset_ext}")
|
70
|
-
path = path.gsub("/", separator)
|
71
|
-
|
72
|
-
yield path if sitemap.find_resource_by_path(File.join(asset_dir, path))
|
73
|
-
end
|
74
|
-
|
75
|
-
# Generate body css classes based on the current path
|
76
|
-
#
|
77
|
-
# @return [String]
|
78
|
-
def page_classes
|
79
|
-
path = current_path.dup
|
80
|
-
path << index_file if path.match(%r{/$})
|
81
|
-
path = path.gsub(%r{^/}, '')
|
82
|
-
|
83
|
-
classes = []
|
84
|
-
parts = path.split('.')[0].split('/')
|
85
|
-
parts.each_with_index { |path, i| classes << parts.first(i+1).join('_') }
|
86
|
-
|
87
|
-
classes.join(' ')
|
88
|
-
end
|
89
|
-
|
90
|
-
# Get the path of a file of a given type
|
91
|
-
#
|
92
|
-
# @param [Symbol] kind The type of file
|
93
|
-
# @param [String] source The path to the file
|
94
|
-
# @return [String]
|
95
|
-
def asset_path(kind, source)
|
96
|
-
return source if source =~ /^http/
|
97
|
-
asset_folder = case kind
|
98
|
-
when :css then css_dir
|
99
|
-
when :js then js_dir
|
100
|
-
when :images then images_dir
|
101
|
-
else kind.to_s
|
102
|
-
end
|
103
|
-
source = source.to_s.gsub(/\s/, '')
|
104
|
-
ignore_extension = (kind == :images) # don't append extension
|
105
|
-
source << ".#{kind}" unless ignore_extension or source =~ /\.#{kind}/
|
106
|
-
result_path = source if source =~ %r{^/} # absolute path
|
107
|
-
result_path ||= asset_url(source, asset_folder)
|
108
|
-
"#{result_path}"
|
109
|
-
end
|
110
|
-
|
111
|
-
# Overload the regular link_to to be sitemap-aware - if you
|
112
|
-
# reference a source path, either absolutely or relatively,
|
113
|
-
# you'll get that resource's nice URL. Also, there is a
|
114
|
-
# :relative option which, if set to true, will produce
|
115
|
-
# relative URLs instead of absolute URLs. You can also add
|
116
|
-
#
|
117
|
-
# set :relative_links, true
|
118
|
-
#
|
119
|
-
# to config.rb to have all links default to relative.
|
120
|
-
def link_to(*args, &block)
|
121
|
-
url_arg_index = block_given? ? 0 : 1
|
122
|
-
options_index = block_given? ? 1 : 2
|
123
|
-
|
124
|
-
if url = args[url_arg_index]
|
125
|
-
options = args[options_index] || {}
|
126
|
-
relative = options.delete(:relative)
|
127
|
-
|
128
|
-
|
129
|
-
if url.include? '://'
|
130
|
-
raise "Can't use the relative option with an external URL" if relative
|
131
|
-
else
|
132
|
-
# Handle relative urls
|
133
|
-
current_dir = Pathname('/' + current_resource.path).dirname
|
134
|
-
path = Pathname(url)
|
135
|
-
|
136
|
-
url = current_dir.join(path).to_s if path.relative?
|
137
|
-
|
138
|
-
resource = sitemap.find_resource_by_path(url)
|
139
|
-
|
140
|
-
# Allow people to turn on relative paths for all links with set :relative_links, true
|
141
|
-
# but still override on a case by case basis with the :relative parameter.
|
142
|
-
effective_relative = relative || false
|
143
|
-
if relative.nil? && relative_links
|
144
|
-
effective_relative = true
|
145
|
-
end
|
146
|
-
|
147
|
-
if resource
|
148
|
-
if effective_relative
|
149
|
-
resource_url = resource.url
|
150
|
-
new_url = Pathname(resource_url).relative_path_from(current_dir).to_s
|
151
|
-
|
152
|
-
# Put back the trailing slash to avoid unnecessary Apache redirects
|
153
|
-
if resource_url.end_with?('/') && !new_url.end_with?('/')
|
154
|
-
new_url << '/'
|
155
|
-
end
|
156
|
-
else
|
157
|
-
new_url = resource.url
|
158
|
-
end
|
159
|
-
|
160
|
-
args[url_arg_index] = new_url
|
161
|
-
else
|
162
|
-
raise "No resource exists at #{url}" if relative
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
super(*args, &block)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
@@ -1,146 +0,0 @@
|
|
1
|
-
# i18n Namespace
|
2
|
-
module Middleman
|
3
|
-
module CoreExtensions
|
4
|
-
module I18n
|
5
|
-
|
6
|
-
# Setup extension
|
7
|
-
class << self
|
8
|
-
|
9
|
-
# Once registerd
|
10
|
-
def registered(app)
|
11
|
-
app.set :locales_dir, "locales"
|
12
|
-
|
13
|
-
app.send :include, InstanceMethods
|
14
|
-
|
15
|
-
# Needed for helpers as well
|
16
|
-
app.after_configuration do
|
17
|
-
# This is for making the tests work - since the tests
|
18
|
-
# don't completely reload middleman, I18n.load_path can get
|
19
|
-
# polluted with paths from other test app directories that don't
|
20
|
-
# exist anymore.
|
21
|
-
::I18n.load_path.delete_if {|path| path =~ %r{tmp/aruba}}
|
22
|
-
::I18n.load_path += Dir[File.join(root, locales_dir, "*.yml")]
|
23
|
-
::I18n.reload!
|
24
|
-
end
|
25
|
-
end
|
26
|
-
alias :included :registered
|
27
|
-
end
|
28
|
-
|
29
|
-
class Localizer
|
30
|
-
def initialize(app)
|
31
|
-
@app = app
|
32
|
-
@maps = {}
|
33
|
-
end
|
34
|
-
|
35
|
-
def setup(options)
|
36
|
-
@options = options
|
37
|
-
|
38
|
-
@lang_map = @options[:lang_map] || {}
|
39
|
-
@path = @options[:path] || "/:locale/"
|
40
|
-
@templates_dir = @options[:templates_dir] || "localizable"
|
41
|
-
@mount_at_root = @options.has_key?(:mount_at_root) ? @options[:mount_at_root] : langs.first
|
42
|
-
|
43
|
-
if !@app.build?
|
44
|
-
puts "== Locales: #{langs.join(", ")}"
|
45
|
-
end
|
46
|
-
|
47
|
-
# Don't output localizable files
|
48
|
-
@app.ignore File.join(@templates_dir, "**")
|
49
|
-
|
50
|
-
@app.sitemap.provides_metadata_for_path do |url|
|
51
|
-
if d = get_localization_data(url)
|
52
|
-
lang, page_id = d
|
53
|
-
instance_vars = Proc.new {
|
54
|
-
::I18n.locale = lang
|
55
|
-
@lang = lang
|
56
|
-
@page_id = page_id
|
57
|
-
}
|
58
|
-
{ :blocks => [instance_vars] }
|
59
|
-
else
|
60
|
-
{}
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
@app.sitemap.register_resource_list_manipulator(
|
65
|
-
:i18n,
|
66
|
-
@app.i18n
|
67
|
-
)
|
68
|
-
end
|
69
|
-
|
70
|
-
def langs
|
71
|
-
@options[:langs] || begin
|
72
|
-
Dir[File.join(@app.root, @app.locales_dir, "*.yml")].map { |file|
|
73
|
-
File.basename(file).gsub(".yml", "")
|
74
|
-
}.sort.map(&:to_sym)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def get_localization_data(path)
|
79
|
-
@_localization_data ||= {}
|
80
|
-
@_localization_data[path]
|
81
|
-
end
|
82
|
-
|
83
|
-
# Update the main sitemap resource list
|
84
|
-
# @return [void]
|
85
|
-
def manipulate_resource_list(resources)
|
86
|
-
@_localization_data = {}
|
87
|
-
|
88
|
-
new_resources = []
|
89
|
-
|
90
|
-
resources.each do |resource|
|
91
|
-
next unless File.fnmatch(File.join(@templates_dir, "**"), resource.path)
|
92
|
-
|
93
|
-
page_id = File.basename(resource.path, File.extname(resource.path))
|
94
|
-
|
95
|
-
langs.map do |lang|
|
96
|
-
::I18n.locale = lang
|
97
|
-
|
98
|
-
localized_page_id = ::I18n.t("paths.#{page_id}", :default => page_id)
|
99
|
-
path = resource.path.sub(@templates_dir, "")
|
100
|
-
|
101
|
-
# Build lang path
|
102
|
-
if @mount_at_root == lang
|
103
|
-
prefix = "/"
|
104
|
-
else
|
105
|
-
replacement = @lang_map.has_key?(lang) ? @lang_map[lang] : lang
|
106
|
-
prefix = @path.sub(":locale", replacement.to_s)
|
107
|
-
end
|
108
|
-
|
109
|
-
path = ::Middleman::Util.normalize_path(
|
110
|
-
File.join(prefix, path.sub(page_id, localized_page_id))
|
111
|
-
)
|
112
|
-
|
113
|
-
@_localization_data[path] = [lang, path, localized_page_id]
|
114
|
-
|
115
|
-
p = ::Middleman::Sitemap::Resource.new(
|
116
|
-
@app.sitemap,
|
117
|
-
path
|
118
|
-
)
|
119
|
-
p.proxy_to(resource.path)
|
120
|
-
|
121
|
-
new_resources << p
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
resources + new_resources
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
# Frontmatter class methods
|
130
|
-
module InstanceMethods
|
131
|
-
|
132
|
-
# Initialize the i18n
|
133
|
-
def i18n
|
134
|
-
@_i18n ||= Localizer.new(self)
|
135
|
-
end
|
136
|
-
|
137
|
-
# Main i18n API
|
138
|
-
def localize(options={})
|
139
|
-
settings.after_configuration do
|
140
|
-
i18n.setup(options)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# Extensions namespace
|
2
|
-
module Middleman::Extensions
|
3
|
-
|
4
|
-
# Asset Host module
|
5
|
-
module AssetHost
|
6
|
-
|
7
|
-
# Setup extension
|
8
|
-
class << self
|
9
|
-
|
10
|
-
# Once registered
|
11
|
-
def registered(app)
|
12
|
-
# Default to no host
|
13
|
-
app.set :asset_host, false
|
14
|
-
|
15
|
-
# Include methods
|
16
|
-
app.send :include, InstanceMethods
|
17
|
-
end
|
18
|
-
|
19
|
-
alias :included :registered
|
20
|
-
end
|
21
|
-
|
22
|
-
# Asset Host Instance Methods
|
23
|
-
module InstanceMethods
|
24
|
-
|
25
|
-
# Override default asset url helper to include asset hosts
|
26
|
-
#
|
27
|
-
# @param [String] path
|
28
|
-
# @param [String] prefix
|
29
|
-
# @return [String]
|
30
|
-
def asset_url(path, prefix="")
|
31
|
-
original_output = super
|
32
|
-
return original_output unless asset_host
|
33
|
-
|
34
|
-
asset_prefix = if asset_host.is_a?(Proc)
|
35
|
-
asset_host.call(original_output)
|
36
|
-
elsif asset_host.is_a?(String)
|
37
|
-
asset_host
|
38
|
-
end
|
39
|
-
|
40
|
-
File.join(asset_prefix, original_output)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Register the extension
|
46
|
-
register :asset_host, AssetHost
|
47
|
-
end
|