middleman-core 3.1.1 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/features/i18n_builder.feature +2 -0
- data/features/i18n_preview.feature +4 -0
- data/features/more-implied_extensions.feature +9 -1
- data/features/redirects.feature +60 -0
- data/fixtures/i18n-test-app/data/defaults_en.yml +0 -0
- data/fixtures/i18n-test-app/data/defaults_es.yml +0 -0
- data/fixtures/i18n-test-app/data/en_defaults.yml +0 -0
- data/fixtures/more-implied-extensions-app/source/layouts/layout.erb +3 -0
- data/lib/middleman-core/core_extensions/file_watcher.rb +5 -1
- data/lib/middleman-core/core_extensions/rendering.rb +1 -4
- data/lib/middleman-core/sitemap.rb +2 -0
- data/lib/middleman-core/sitemap/extensions/redirects.rb +124 -0
- data/lib/middleman-core/sitemap/extensions/request_endpoints.rb +0 -61
- data/lib/middleman-core/sitemap/resource.rb +6 -0
- data/lib/middleman-core/sitemap/store.rb +3 -0
- data/lib/middleman-core/templates/shared/gitignore +3 -0
- data/lib/middleman-core/util.rb +76 -0
- data/lib/middleman-core/version.rb +1 -1
- data/lib/middleman-more/core_extensions/default_helpers.rb +1 -66
- data/lib/middleman-more/core_extensions/i18n.rb +1 -1
- data/middleman-core.gemspec +1 -1
- metadata +15 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41014115c7f4bc10a1ec3505cc1f0f2ed07489b9
|
4
|
+
data.tar.gz: 8d5141b21cc59bf1b41a0d16408b913ddb7e15a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b95f67885b1aa847fdbfd4813d8f8ccd3c40e0bb02adb3206efc2d7df3d5d1f9305c2b018bff97d692b8ef1be96587df038f154124a4d1ac1376d2fbfd058ab
|
7
|
+
data.tar.gz: baf1f6c0c2b2679e920c89eea23898bab033187aaf0699f2411b7eb43c779bd45aa949012e6f7ff60f9216d94c2be54fabfd251ebeb919ece1ce4864290f693c
|
@@ -22,6 +22,8 @@ Feature: i18n Builder
|
|
22
22
|
| password.txt |
|
23
23
|
Then the following files should not exist:
|
24
24
|
| en/index.html |
|
25
|
+
| defaults_en/index.html |
|
26
|
+
| en_defaults/index.html |
|
25
27
|
And the file "index.html" should contain "Howdy"
|
26
28
|
And the file "hello.html" should contain "Hello World"
|
27
29
|
And the file "morning.html" should contain "Good morning"
|
@@ -16,10 +16,14 @@ Feature: i18n Preview
|
|
16
16
|
Then I should see "Good morning"
|
17
17
|
When I go to "/one.html"
|
18
18
|
Then I should see "Only one"
|
19
|
+
When I go to "/defaults_en/index.html"
|
20
|
+
Then I should see "File Not Found"
|
19
21
|
When I go to "/en/index.html"
|
20
22
|
Then I should see "File Not Found"
|
21
23
|
When I go to "/en/morning.html"
|
22
24
|
Then I should see "File Not Found"
|
25
|
+
When I go to "/defaults_es/index.html"
|
26
|
+
Then I should see "File Not Found"
|
23
27
|
When I go to "/es/index.html"
|
24
28
|
Then I should see "Como Esta?"
|
25
29
|
When I go to "/es/hola.html"
|
@@ -12,12 +12,16 @@ Feature: More default extensions
|
|
12
12
|
Then I should see "HELLO"
|
13
13
|
When I go to "/javascripts/app.js"
|
14
14
|
Then I should see "derp"
|
15
|
+
Then I should not see "I am in the layout"
|
15
16
|
When I go to "/stylesheets/style.css"
|
16
17
|
Then I should see "section"
|
18
|
+
Then I should not see "I am in the layout"
|
17
19
|
When I go to "/stylesheets/style2.css"
|
18
20
|
Then I should see "section"
|
21
|
+
Then I should not see "I am in the layout"
|
19
22
|
When I go to "/stylesheets/style3.css"
|
20
23
|
Then I should see "color"
|
24
|
+
Then I should not see "I am in the layout"
|
21
25
|
|
22
26
|
Scenario: Default extensions build
|
23
27
|
Given a fixture app "more-implied-extensions-app"
|
@@ -37,6 +41,10 @@ Feature: More default extensions
|
|
37
41
|
And the file "test3.html" should contain "Howdy"
|
38
42
|
And the file "test4.html" should contain "HELLO"
|
39
43
|
And the file "javascripts/app.js" should contain "derp"
|
44
|
+
And the file "javascripts/app.js" should not contain "I am in the layout"
|
40
45
|
And the file "stylesheets/style.css" should contain "section"
|
46
|
+
And the file "stylesheets/style.css" should not contain "I am in the layout"
|
41
47
|
And the file "stylesheets/style2.css" should contain "section"
|
42
|
-
And the file "stylesheets/
|
48
|
+
And the file "stylesheets/style2.css" should not contain "I am in the layout"
|
49
|
+
And the file "stylesheets/style3.css" should contain "color"
|
50
|
+
And the file "stylesheets/style3.css" should not contain "I am in the layout"
|
@@ -0,0 +1,60 @@
|
|
1
|
+
Feature: Meta redirects
|
2
|
+
|
3
|
+
Scenario: Redirect to unknown file
|
4
|
+
Given a fixture app "large-build-app"
|
5
|
+
And a file named "config.rb" with:
|
6
|
+
"""
|
7
|
+
redirect "hello.html", :to => "world.html"
|
8
|
+
"""
|
9
|
+
And the Server is running at "large-build-app"
|
10
|
+
When I go to "/hello.html"
|
11
|
+
Then I should see '<meta http-equiv=refresh content="0; url=world.html"'
|
12
|
+
|
13
|
+
Scenario: Redirect to external site
|
14
|
+
Given a fixture app "large-build-app"
|
15
|
+
And a file named "config.rb" with:
|
16
|
+
"""
|
17
|
+
redirect "hello.html", :to => "http://example.com"
|
18
|
+
"""
|
19
|
+
And the Server is running at "large-build-app"
|
20
|
+
When I go to "/hello.html"
|
21
|
+
Then I should see '<meta http-equiv=refresh content="0; url=http://example.com"'
|
22
|
+
|
23
|
+
Scenario: Redirect to a resource
|
24
|
+
Given a fixture app "large-build-app"
|
25
|
+
And a file named "config.rb" with:
|
26
|
+
"""
|
27
|
+
ready do
|
28
|
+
r = sitemap.find_resource_by_path("static.html")
|
29
|
+
redirect "hello.html", :to => r
|
30
|
+
end
|
31
|
+
"""
|
32
|
+
And the Server is running at "large-build-app"
|
33
|
+
When I go to "/hello.html"
|
34
|
+
Then I should see '<meta http-equiv=refresh content="0; url=/static.html"'
|
35
|
+
|
36
|
+
Scenario: Redirect to a path with directory index
|
37
|
+
Given a fixture app "large-build-app"
|
38
|
+
And a file named "config.rb" with:
|
39
|
+
"""
|
40
|
+
activate :directory_indexes
|
41
|
+
redirect "hello.html", :to => "link_test.html"
|
42
|
+
redirect "hello2.html", :to => "services/index.html"
|
43
|
+
"""
|
44
|
+
And the Server is running at "large-build-app"
|
45
|
+
When I go to "/hello/index.html"
|
46
|
+
Then I should see '<meta http-equiv=refresh content="0; url=/link_test/"'
|
47
|
+
When I go to "/hello2/index.html"
|
48
|
+
Then I should see '<meta http-equiv=refresh content="0; url=/services/"'
|
49
|
+
|
50
|
+
Scenario: Redirect with custom html
|
51
|
+
Given a fixture app "large-build-app"
|
52
|
+
And a file named "config.rb" with:
|
53
|
+
"""
|
54
|
+
redirect "hello.html", :to => "world.html" do |from, to|
|
55
|
+
"#{from} to #{to}"
|
56
|
+
end
|
57
|
+
"""
|
58
|
+
And the Server is running at "large-build-app"
|
59
|
+
When I go to "/hello.html"
|
60
|
+
Then I should see 'hello.html to world.html'
|
File without changes
|
File without changes
|
File without changes
|
@@ -7,13 +7,13 @@ module Middleman
|
|
7
7
|
module FileWatcher
|
8
8
|
|
9
9
|
IGNORE_LIST = [
|
10
|
+
/^bin\//,
|
10
11
|
/^\.bundle\//,
|
11
12
|
/^vendor\//,
|
12
13
|
/^\.sass-cache\//,
|
13
14
|
/^\.git\//,
|
14
15
|
/^\.gitignore$/,
|
15
16
|
/\.DS_Store/,
|
16
|
-
/^build\//,
|
17
17
|
/^\.rbenv-.*$/,
|
18
18
|
/^Gemfile$/,
|
19
19
|
/^Gemfile\.lock$/,
|
@@ -36,6 +36,10 @@ module Middleman
|
|
36
36
|
files.reload_path(config[:data_dir])
|
37
37
|
end
|
38
38
|
|
39
|
+
app.after_configuration do
|
40
|
+
config[:file_watcher_ignore] << %r{^#{config[:build_dir]}\/}
|
41
|
+
end
|
42
|
+
|
39
43
|
# After config, load everything else
|
40
44
|
app.ready do
|
41
45
|
files.reload_path('.')
|
@@ -154,11 +154,8 @@ module Middleman
|
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
|
-
# Certain output file types don't use layouts
|
158
|
-
needs_layout = !%w(.js .json .css .txt).include?(File.extname(path))
|
159
|
-
|
160
157
|
# If we need a layout and have a layout, use it
|
161
|
-
if
|
158
|
+
if layout_path = fetch_layout(engine, opts)
|
162
159
|
content = render_individual_file(layout_path, locs, opts, context) { content }
|
163
160
|
end
|
164
161
|
|
@@ -2,6 +2,7 @@ require "middleman-core/sitemap/store"
|
|
2
2
|
require "middleman-core/sitemap/resource"
|
3
3
|
|
4
4
|
require "middleman-core/sitemap/extensions/on_disk"
|
5
|
+
require "middleman-core/sitemap/extensions/redirects"
|
5
6
|
require "middleman-core/sitemap/extensions/request_endpoints"
|
6
7
|
require "middleman-core/sitemap/extensions/proxies"
|
7
8
|
require "middleman-core/sitemap/extensions/ignores"
|
@@ -20,6 +21,7 @@ module Middleman
|
|
20
21
|
app.register Middleman::Sitemap::Extensions::RequestEndpoints
|
21
22
|
app.register Middleman::Sitemap::Extensions::Proxies
|
22
23
|
app.register Middleman::Sitemap::Extensions::Ignores
|
24
|
+
app.register Middleman::Sitemap::Extensions::Redirects
|
23
25
|
|
24
26
|
# Set to automatically convert some characters into a directory
|
25
27
|
app.config.define_setting :automatic_directory_matcher, nil, 'Set to automatically convert some characters into a directory'
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module Middleman
|
2
|
+
|
3
|
+
module Sitemap
|
4
|
+
|
5
|
+
module Extensions
|
6
|
+
|
7
|
+
module Redirects
|
8
|
+
|
9
|
+
# Setup extension
|
10
|
+
class << self
|
11
|
+
|
12
|
+
# Once registered
|
13
|
+
def registered(app)
|
14
|
+
# Include methods
|
15
|
+
app.send :include, InstanceMethods
|
16
|
+
end
|
17
|
+
|
18
|
+
alias :included :registered
|
19
|
+
end
|
20
|
+
|
21
|
+
module InstanceMethods
|
22
|
+
def redirect_manager
|
23
|
+
@_redirect_manager ||= RedirectManager.new(self)
|
24
|
+
end
|
25
|
+
|
26
|
+
def redirect(*args, &block)
|
27
|
+
redirect_manager.create_redirect(*args, &block)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Manages the list of proxy configurations and manipulates the sitemap
|
32
|
+
# to include new resources based on those configurations
|
33
|
+
class RedirectManager
|
34
|
+
def initialize(app)
|
35
|
+
@app = app
|
36
|
+
@redirects = {}
|
37
|
+
end
|
38
|
+
|
39
|
+
# Setup a redirect from a path to a target
|
40
|
+
# @param [String] path
|
41
|
+
# @param [Hash] The :to value gives a target path
|
42
|
+
# @return [void]
|
43
|
+
def create_redirect(path, opts={}, &block)
|
44
|
+
if block_given?
|
45
|
+
opts[:template] = block
|
46
|
+
end
|
47
|
+
|
48
|
+
@redirects[path] = opts
|
49
|
+
|
50
|
+
@app.sitemap.rebuild_resource_list!(:added_redirect)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Update the main sitemap resource list
|
54
|
+
# @return [void]
|
55
|
+
def manipulate_resource_list(resources)
|
56
|
+
resources + @redirects.map do |path, opts|
|
57
|
+
r = RedirectResource.new(
|
58
|
+
@app.sitemap,
|
59
|
+
path,
|
60
|
+
opts[:to]
|
61
|
+
)
|
62
|
+
r.output = opts[:template] if opts[:template]
|
63
|
+
r
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class RedirectResource < ::Middleman::Sitemap::Resource
|
69
|
+
attr_accessor :output
|
70
|
+
|
71
|
+
def initialize(store, path, target)
|
72
|
+
@request_path = target
|
73
|
+
|
74
|
+
super(store, path)
|
75
|
+
end
|
76
|
+
|
77
|
+
def template?
|
78
|
+
true
|
79
|
+
end
|
80
|
+
|
81
|
+
def render(*args, &block)
|
82
|
+
url = ::Middleman::Util.url_for(store.app, @request_path, :relative => false, :find_resource => true)
|
83
|
+
|
84
|
+
if output
|
85
|
+
output.call(path, url)
|
86
|
+
else
|
87
|
+
<<-END
|
88
|
+
<html>
|
89
|
+
<head>
|
90
|
+
<meta http-equiv=refresh content="0; url=#{url}" />
|
91
|
+
<meta name="robots" content="noindex,follow" />
|
92
|
+
</head>
|
93
|
+
<body>
|
94
|
+
</body>
|
95
|
+
</html>
|
96
|
+
END
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# def request_path
|
101
|
+
# @request_path
|
102
|
+
# end
|
103
|
+
|
104
|
+
def binary?
|
105
|
+
false
|
106
|
+
end
|
107
|
+
|
108
|
+
def raw_data
|
109
|
+
{}
|
110
|
+
end
|
111
|
+
|
112
|
+
def ignored?
|
113
|
+
false
|
114
|
+
end
|
115
|
+
|
116
|
+
def metadata
|
117
|
+
@local_metadata.dup
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -11,8 +11,6 @@ module Middleman
|
|
11
11
|
|
12
12
|
# Once registered
|
13
13
|
def registered(app)
|
14
|
-
# ::Middleman::Sitemap::Resource.send :include, ResourceInstanceMethods
|
15
|
-
|
16
14
|
# Include methods
|
17
15
|
app.send :include, InstanceMethods
|
18
16
|
end
|
@@ -20,65 +18,6 @@ module Middleman
|
|
20
18
|
alias :included :registered
|
21
19
|
end
|
22
20
|
|
23
|
-
# module ResourceInstanceMethods
|
24
|
-
# # Whether this page is a proxy
|
25
|
-
# # @return [Boolean]
|
26
|
-
# def proxy?
|
27
|
-
# !!@proxied_to
|
28
|
-
# end
|
29
|
-
|
30
|
-
# # Set this page to proxy to a target path
|
31
|
-
# # @param [String] target
|
32
|
-
# # @return [void]
|
33
|
-
# def proxy_to(target)
|
34
|
-
# target = ::Middleman::Util.normalize_path(target)
|
35
|
-
# raise "You can't proxy #{path} to itself!" if target == path
|
36
|
-
# @proxied_to = target
|
37
|
-
# end
|
38
|
-
|
39
|
-
# # The path of the page this page is proxied to, or nil if it's not proxied.
|
40
|
-
# # @return [String]
|
41
|
-
# def proxied_to
|
42
|
-
# @proxied_to
|
43
|
-
# end
|
44
|
-
|
45
|
-
# # The resource for the page this page is proxied to. Throws an exception
|
46
|
-
# # if there is no resource.
|
47
|
-
# # @return [Sitemap::Resource]
|
48
|
-
# def proxied_to_resource
|
49
|
-
# proxy_resource = store.find_resource_by_path(proxied_to)
|
50
|
-
|
51
|
-
# unless proxy_resource
|
52
|
-
# raise "Path #{path} proxies to unknown file #{proxied_to}:#{store.resources.map(&:path)}"
|
53
|
-
# end
|
54
|
-
|
55
|
-
# if proxy_resource.proxy?
|
56
|
-
# raise "You can't proxy #{path} to #{proxied_to} which is itself a proxy."
|
57
|
-
# end
|
58
|
-
|
59
|
-
# proxy_resource
|
60
|
-
# end
|
61
|
-
|
62
|
-
# def get_source_file
|
63
|
-
# if proxy?
|
64
|
-
# proxied_to_resource.source_file
|
65
|
-
# else
|
66
|
-
# super
|
67
|
-
# end
|
68
|
-
# end
|
69
|
-
|
70
|
-
# def content_type
|
71
|
-
# mime_type = super
|
72
|
-
# return mime_type if mime_type
|
73
|
-
|
74
|
-
# if proxy?
|
75
|
-
# proxied_to_resource.content_type
|
76
|
-
# else
|
77
|
-
# nil
|
78
|
-
# end
|
79
|
-
# end
|
80
|
-
# end
|
81
|
-
|
82
21
|
module InstanceMethods
|
83
22
|
def endpoint_manager
|
84
23
|
@_endpoint_manager ||= EndpointManager.new(self)
|
@@ -141,6 +141,12 @@ module Middleman
|
|
141
141
|
blocks << block if block_given?
|
142
142
|
|
143
143
|
app.current_path ||= self.destination_path
|
144
|
+
|
145
|
+
# Certain output file types don't use layouts
|
146
|
+
if !opts.has_key?(:layout)
|
147
|
+
opts[:layout] = false if %w(.js .json .css .txt).include?(self.ext)
|
148
|
+
end
|
149
|
+
|
144
150
|
app.render_template(source_file, locs, opts, blocks)
|
145
151
|
end
|
146
152
|
end
|
@@ -41,6 +41,9 @@ module Middleman
|
|
41
41
|
|
42
42
|
# Proxies
|
43
43
|
register_resource_list_manipulator(:proxies, @app.proxy_manager)
|
44
|
+
|
45
|
+
# Redirects
|
46
|
+
register_resource_list_manipulator(:redirects, @app.redirect_manager)
|
44
47
|
end
|
45
48
|
|
46
49
|
# Register a klass which can manipulate the main site map list. Best to register
|
data/lib/middleman-core/util.rb
CHANGED
@@ -146,5 +146,81 @@ module Middleman
|
|
146
146
|
end
|
147
147
|
end.flatten.compact
|
148
148
|
end
|
149
|
+
|
150
|
+
# Given a source path (referenced either absolutely or relatively)
|
151
|
+
# or a Resource, this will produce the nice URL configured for that
|
152
|
+
# path, respecting :relative_links, directory indexes, etc.
|
153
|
+
def self.url_for(app, path_or_resource, options={})
|
154
|
+
# Handle Resources and other things which define their own url method
|
155
|
+
url = path_or_resource.respond_to?(:url) ? path_or_resource.url : path_or_resource
|
156
|
+
|
157
|
+
begin
|
158
|
+
uri = URI(url)
|
159
|
+
rescue URI::InvalidURIError
|
160
|
+
# Nothing we can do with it, it's not really a URI
|
161
|
+
return url
|
162
|
+
end
|
163
|
+
|
164
|
+
relative = options.delete(:relative)
|
165
|
+
raise "Can't use the relative option with an external URL" if relative && uri.host
|
166
|
+
|
167
|
+
# Allow people to turn on relative paths for all links with
|
168
|
+
# set :relative_links, true
|
169
|
+
# but still override on a case by case basis with the :relative parameter.
|
170
|
+
effective_relative = relative || false
|
171
|
+
effective_relative = true if relative.nil? && app.config[:relative_links]
|
172
|
+
|
173
|
+
# Try to find a sitemap resource corresponding to the desired path
|
174
|
+
this_resource = app.current_resource # store in a local var to save work
|
175
|
+
|
176
|
+
if path_or_resource.is_a?(::Middleman::Sitemap::Resource)
|
177
|
+
resource = path_or_resource
|
178
|
+
resource_url = url
|
179
|
+
elsif this_resource && uri.path
|
180
|
+
# Handle relative urls
|
181
|
+
url_path = Pathname(uri.path)
|
182
|
+
current_source_dir = Pathname('/' + this_resource.path).dirname
|
183
|
+
url_path = current_source_dir.join(url_path) if url_path.relative?
|
184
|
+
resource = app.sitemap.find_resource_by_path(url_path.to_s)
|
185
|
+
resource_url = resource.url if resource
|
186
|
+
elsif options[:find_resource] && uri.path
|
187
|
+
resource = app.sitemap.find_resource_by_path(uri.path)
|
188
|
+
resource_url = resource.url if resource
|
189
|
+
end
|
190
|
+
|
191
|
+
if resource
|
192
|
+
# Switch to the relative path between this_resource and the given resource
|
193
|
+
# if we've been asked to.
|
194
|
+
if effective_relative
|
195
|
+
# Output urls relative to the destination path, not the source path
|
196
|
+
current_dir = Pathname('/' + this_resource.destination_path).dirname
|
197
|
+
relative_path = Pathname(resource_url).relative_path_from(current_dir).to_s
|
198
|
+
|
199
|
+
# Put back the trailing slash to avoid unnecessary Apache redirects
|
200
|
+
if resource_url.end_with?('/') && !relative_path.end_with?('/')
|
201
|
+
relative_path << '/'
|
202
|
+
end
|
203
|
+
|
204
|
+
uri.path = relative_path
|
205
|
+
else
|
206
|
+
uri.path = resource_url
|
207
|
+
end
|
208
|
+
else
|
209
|
+
# If they explicitly asked for relative links but we can't find a resource...
|
210
|
+
raise "No resource exists at #{url}" if relative
|
211
|
+
end
|
212
|
+
|
213
|
+
# Support a :query option that can be a string or hash
|
214
|
+
if query = options.delete(:query)
|
215
|
+
uri.query = query.respond_to?(:to_param) ? query.to_param : query.to_s
|
216
|
+
end
|
217
|
+
|
218
|
+
# Support a :fragment or :anchor option just like Padrino
|
219
|
+
fragment = options.delete(:anchor) || options.delete(:fragment)
|
220
|
+
uri.fragment = fragment.to_s if fragment
|
221
|
+
|
222
|
+
# Finally make the URL back into a string
|
223
|
+
uri.to_s
|
224
|
+
end
|
149
225
|
end
|
150
226
|
end
|
@@ -189,72 +189,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
|
189
189
|
# or a Resource, this will produce the nice URL configured for that
|
190
190
|
# path, respecting :relative_links, directory indexes, etc.
|
191
191
|
def url_for(path_or_resource, options={})
|
192
|
-
|
193
|
-
url = path_or_resource.respond_to?(:url) ? path_or_resource.url : path_or_resource
|
194
|
-
|
195
|
-
begin
|
196
|
-
uri = URI(url)
|
197
|
-
rescue URI::InvalidURIError
|
198
|
-
# Nothing we can do with it, it's not really a URI
|
199
|
-
return url
|
200
|
-
end
|
201
|
-
|
202
|
-
relative = options.delete(:relative)
|
203
|
-
raise "Can't use the relative option with an external URL" if relative && uri.host
|
204
|
-
|
205
|
-
# Allow people to turn on relative paths for all links with
|
206
|
-
# set :relative_links, true
|
207
|
-
# but still override on a case by case basis with the :relative parameter.
|
208
|
-
effective_relative = relative || false
|
209
|
-
effective_relative = true if relative.nil? && config[:relative_links]
|
210
|
-
|
211
|
-
# Try to find a sitemap resource corresponding to the desired path
|
212
|
-
this_resource = current_resource # store in a local var to save work
|
213
|
-
if path_or_resource.is_a?(::Middleman::Sitemap::Resource)
|
214
|
-
resource = path_or_resource
|
215
|
-
resource_url = url
|
216
|
-
elsif this_resource && uri.path
|
217
|
-
# Handle relative urls
|
218
|
-
url_path = Pathname(uri.path)
|
219
|
-
current_source_dir = Pathname('/' + this_resource.path).dirname
|
220
|
-
url_path = current_source_dir.join(url_path) if url_path.relative?
|
221
|
-
resource = sitemap.find_resource_by_path(url_path.to_s)
|
222
|
-
resource_url = resource.url if resource
|
223
|
-
end
|
224
|
-
|
225
|
-
if resource
|
226
|
-
# Switch to the relative path between this_resource and the given resource
|
227
|
-
# if we've been asked to.
|
228
|
-
if effective_relative
|
229
|
-
# Output urls relative to the destination path, not the source path
|
230
|
-
current_dir = Pathname('/' + this_resource.destination_path).dirname
|
231
|
-
relative_path = Pathname(resource_url).relative_path_from(current_dir).to_s
|
232
|
-
|
233
|
-
# Put back the trailing slash to avoid unnecessary Apache redirects
|
234
|
-
if resource_url.end_with?('/') && !relative_path.end_with?('/')
|
235
|
-
relative_path << '/'
|
236
|
-
end
|
237
|
-
|
238
|
-
uri.path = relative_path
|
239
|
-
else
|
240
|
-
uri.path = resource_url
|
241
|
-
end
|
242
|
-
else
|
243
|
-
# If they explicitly asked for relative links but we can't find a resource...
|
244
|
-
raise "No resource exists at #{url}" if relative
|
245
|
-
end
|
246
|
-
|
247
|
-
# Support a :query option that can be a string or hash
|
248
|
-
if query = options.delete(:query)
|
249
|
-
uri.query = query.respond_to?(:to_param) ? query.to_param : query.to_s
|
250
|
-
end
|
251
|
-
|
252
|
-
# Support a :fragment or :anchor option just like Padrino
|
253
|
-
fragment = options.delete(:anchor) || options.delete(:fragment)
|
254
|
-
uri.fragment = fragment.to_s if fragment
|
255
|
-
|
256
|
-
# Finally make the URL back into a string
|
257
|
-
uri.to_s
|
192
|
+
::Middleman::Util.url_for(self, path_or_resource, options)
|
258
193
|
end
|
259
194
|
|
260
195
|
# Overload the regular link_to to be sitemap-aware - if you
|
@@ -93,7 +93,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|
93
93
|
|
94
94
|
def convert_glob_to_regex(glob)
|
95
95
|
# File.fnmatch doesn't support brackets: {rb,yml,yaml}
|
96
|
-
regex = @locales_glob.sub(/\./, '\.').sub(File.join("**", "*"), ".*").sub(/\//, '\/').sub("{rb,yml,yaml}", "rb|ya?ml")
|
96
|
+
regex = @locales_glob.sub(/\./, '\.').sub(File.join("**", "*"), ".*").sub(/\//, '\/').sub("{rb,yml,yaml}", "(rb|ya?ml)")
|
97
97
|
%r{^#{regex}}
|
98
98
|
end
|
99
99
|
|
data/middleman-core.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Reynolds
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -107,14 +107,14 @@ dependencies:
|
|
107
107
|
requirements:
|
108
108
|
- - ~>
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 1.
|
110
|
+
version: 1.2.2
|
111
111
|
type: :runtime
|
112
112
|
prerelease: false
|
113
113
|
version_requirements: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ~>
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 1.
|
117
|
+
version: 1.2.2
|
118
118
|
- !ruby/object:Gem::Dependency
|
119
119
|
name: i18n
|
120
120
|
requirement: !ruby/object:Gem::Requirement
|
@@ -215,6 +215,7 @@ files:
|
|
215
215
|
- features/preview_changes.feature
|
216
216
|
- features/proxy_pages.feature
|
217
217
|
- features/queryable.feature
|
218
|
+
- features/redirects.feature
|
218
219
|
- features/relative_assets.feature
|
219
220
|
- features/request_params.feature
|
220
221
|
- features/sass-assets-paths.feature
|
@@ -494,6 +495,9 @@ files:
|
|
494
495
|
- fixtures/i18n-nested-app/locales/es.yml
|
495
496
|
- fixtures/i18n-nested-app/locales/es/mucho.yml
|
496
497
|
- fixtures/i18n-nested-app/source/localizable/index.html.erb
|
498
|
+
- fixtures/i18n-test-app/data/defaults_en.yml
|
499
|
+
- fixtures/i18n-test-app/data/defaults_es.yml
|
500
|
+
- fixtures/i18n-test-app/data/en_defaults.yml
|
497
501
|
- fixtures/i18n-test-app/locales/en.yml
|
498
502
|
- fixtures/i18n-test-app/locales/es.yml
|
499
503
|
- fixtures/i18n-test-app/source/CNAME
|
@@ -628,6 +632,7 @@ files:
|
|
628
632
|
- fixtures/more-ignore-app/source/reports/index.html
|
629
633
|
- fixtures/more-implied-extensions-app/config.rb
|
630
634
|
- fixtures/more-implied-extensions-app/source/javascripts/app.coffee
|
635
|
+
- fixtures/more-implied-extensions-app/source/layouts/layout.erb
|
631
636
|
- fixtures/more-implied-extensions-app/source/stylesheets/style.scss
|
632
637
|
- fixtures/more-implied-extensions-app/source/stylesheets/style2.sass
|
633
638
|
- fixtures/more-implied-extensions-app/source/stylesheets/style3.less
|
@@ -950,6 +955,7 @@ files:
|
|
950
955
|
- lib/middleman-core/sitemap/extensions/ignores.rb
|
951
956
|
- lib/middleman-core/sitemap/extensions/on_disk.rb
|
952
957
|
- lib/middleman-core/sitemap/extensions/proxies.rb
|
958
|
+
- lib/middleman-core/sitemap/extensions/redirects.rb
|
953
959
|
- lib/middleman-core/sitemap/extensions/request_endpoints.rb
|
954
960
|
- lib/middleman-core/sitemap/extensions/traversal.rb
|
955
961
|
- lib/middleman-core/sitemap/queryable.rb
|
@@ -1416,6 +1422,7 @@ test_files:
|
|
1416
1422
|
- features/preview_changes.feature
|
1417
1423
|
- features/proxy_pages.feature
|
1418
1424
|
- features/queryable.feature
|
1425
|
+
- features/redirects.feature
|
1419
1426
|
- features/relative_assets.feature
|
1420
1427
|
- features/request_params.feature
|
1421
1428
|
- features/sass-assets-paths.feature
|
@@ -1695,6 +1702,9 @@ test_files:
|
|
1695
1702
|
- fixtures/i18n-nested-app/locales/es.yml
|
1696
1703
|
- fixtures/i18n-nested-app/locales/es/mucho.yml
|
1697
1704
|
- fixtures/i18n-nested-app/source/localizable/index.html.erb
|
1705
|
+
- fixtures/i18n-test-app/data/defaults_en.yml
|
1706
|
+
- fixtures/i18n-test-app/data/defaults_es.yml
|
1707
|
+
- fixtures/i18n-test-app/data/en_defaults.yml
|
1698
1708
|
- fixtures/i18n-test-app/locales/en.yml
|
1699
1709
|
- fixtures/i18n-test-app/locales/es.yml
|
1700
1710
|
- fixtures/i18n-test-app/source/CNAME
|
@@ -1829,6 +1839,7 @@ test_files:
|
|
1829
1839
|
- fixtures/more-ignore-app/source/reports/index.html
|
1830
1840
|
- fixtures/more-implied-extensions-app/config.rb
|
1831
1841
|
- fixtures/more-implied-extensions-app/source/javascripts/app.coffee
|
1842
|
+
- fixtures/more-implied-extensions-app/source/layouts/layout.erb
|
1832
1843
|
- fixtures/more-implied-extensions-app/source/stylesheets/style.scss
|
1833
1844
|
- fixtures/more-implied-extensions-app/source/stylesheets/style2.sass
|
1834
1845
|
- fixtures/more-implied-extensions-app/source/stylesheets/style3.less
|