middleman-more 3.0.11 → 3.0.12.pre.1
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.
- data/features/cache_buster.feature +15 -0
- data/features/helpers_form_tag.feature +26 -0
- data/features/helpers_url_for.feature +152 -0
- data/features/i18n_preview.feature +45 -0
- data/features/minify_css.feature +9 -13
- data/features/minify_javascript.feature +20 -31
- data/fixtures/coffeescript-app/config.rb +0 -1
- data/fixtures/minify-js-app/config.rb +0 -1
- data/fixtures/passthrough-app/source/inline-css.html.haml +4 -5
- data/lib/middleman-more/core_extensions/default_helpers.rb +96 -73
- data/lib/middleman-more/core_extensions/i18n.rb +21 -13
- data/lib/middleman-more/extensions/automatic_image_sizes.rb +1 -1
- data/lib/middleman-more/extensions/relative_assets.rb +2 -2
- data/middleman-more.gemspec +0 -1
- data/spec/middleman-more/future_spec.rb +0 -0
- data/spec/spec_helper.rb +0 -0
- metadata +15 -12
@@ -25,3 +25,18 @@ Feature: Generate mtime-based query string for busting browser caches
|
|
25
25
|
When I go to "/cache-buster.html"
|
26
26
|
Then I should see "site.css?"
|
27
27
|
Then I should see "blank.gif?"
|
28
|
+
|
29
|
+
Scenario: Rendering css with the feature and relative_assets enabled
|
30
|
+
Given "relative_assets" feature is "enabled"
|
31
|
+
Given "cache_buster" feature is "enabled"
|
32
|
+
And the Server is running at "cache-buster-app"
|
33
|
+
When I go to "/stylesheets/relative_assets.css"
|
34
|
+
Then I should see "blank.gif?"
|
35
|
+
|
36
|
+
Scenario: Rendering html with the feature and relative_assets enabled
|
37
|
+
Given "relative_assets" feature is "enabled"
|
38
|
+
Given "cache_buster" feature is "enabled"
|
39
|
+
And the Server is running at "cache-buster-app"
|
40
|
+
When I go to "/cache-buster.html"
|
41
|
+
Then I should see "site.css?"
|
42
|
+
Then I should see "blank.gif?"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Feature: form_tag helper
|
2
|
+
|
3
|
+
Scenario: form_tag produces relative links
|
4
|
+
Given a fixture app "indexable-app"
|
5
|
+
And an empty file named "config.rb"
|
6
|
+
And a file named "source/form_tag.html.erb" with:
|
7
|
+
"""
|
8
|
+
absolute: <% form_tag "/needs_index.html#absolute", :relative => true do %>
|
9
|
+
<% end %>
|
10
|
+
relative: <% form_tag "needs_index.html#relative", :relative => true do %>
|
11
|
+
<% end %>
|
12
|
+
"""
|
13
|
+
And a file named "source/form_tag/sub.html.erb" with:
|
14
|
+
"""
|
15
|
+
absolute: <% form_tag "/needs_index.html#absolute", :relative => true do %>
|
16
|
+
<% end %>
|
17
|
+
relative: <% form_tag "../needs_index.html#relative", :relative => true do %>
|
18
|
+
<% end %>
|
19
|
+
"""
|
20
|
+
And the Server is running at "indexable-app"
|
21
|
+
When I go to "/form_tag.html"
|
22
|
+
Then I should see 'action="needs_index.html#absolute"'
|
23
|
+
Then I should see 'action="needs_index.html#relative"'
|
24
|
+
When I go to "/form_tag/sub.html"
|
25
|
+
Then I should see 'action="../needs_index.html#absolute"'
|
26
|
+
Then I should see 'action="../needs_index.html#relative"'
|
@@ -0,0 +1,152 @@
|
|
1
|
+
Feature: url_for helper
|
2
|
+
|
3
|
+
Scenario: url_for produces relative links
|
4
|
+
Given a fixture app "indexable-app"
|
5
|
+
And an empty file named "config.rb"
|
6
|
+
And a file named "source/url_for.html.erb" with:
|
7
|
+
"""
|
8
|
+
absolute: <%= url_for "/needs_index.html", :relative => true %>
|
9
|
+
relative: <%= url_for "needs_index.html", :relative => true %>
|
10
|
+
"""
|
11
|
+
And a file named "source/url_for/sub.html.erb" with:
|
12
|
+
"""
|
13
|
+
absolute: <%= url_for "/needs_index.html", :relative => true %>
|
14
|
+
relative: <%= url_for "../needs_index.html", :relative => true %>
|
15
|
+
"""
|
16
|
+
And the Server is running at "indexable-app"
|
17
|
+
When I go to "/url_for.html"
|
18
|
+
Then I should see 'absolute: needs_index.html'
|
19
|
+
Then I should see 'relative: needs_index.html'
|
20
|
+
When I go to "/url_for/sub.html"
|
21
|
+
Then I should see 'absolute: ../needs_index.html'
|
22
|
+
Then I should see 'relative: ../needs_index.html'
|
23
|
+
|
24
|
+
Scenario: url_for relative works with strip_index_file
|
25
|
+
Given a fixture app "indexable-app"
|
26
|
+
And a file named "config.rb" with:
|
27
|
+
"""
|
28
|
+
set :relative_links, true
|
29
|
+
set :strip_index_file, true
|
30
|
+
helpers do
|
31
|
+
def menu_items(path='url_for.html')
|
32
|
+
sitemap.find_resource_by_destination_path(path).children
|
33
|
+
end
|
34
|
+
end
|
35
|
+
"""
|
36
|
+
And a file named "source/url_for.html.erb" with:
|
37
|
+
"""
|
38
|
+
<% menu_items.each do |item| %>
|
39
|
+
"<%= url_for(item.url) %>"
|
40
|
+
"<%= url_for(item) %>"
|
41
|
+
<% end %>
|
42
|
+
"""
|
43
|
+
And a file named "source/url_for/sub.html.erb" with:
|
44
|
+
"""
|
45
|
+
<% menu_items.each do |item| %>
|
46
|
+
"<%= url_for(item.url) %>"
|
47
|
+
"<%= url_for(item) %>"
|
48
|
+
<% end %>
|
49
|
+
"""
|
50
|
+
And the Server is running at "indexable-app"
|
51
|
+
When I go to "/url_for.html"
|
52
|
+
Then I should see '"url_for/sub.html"'
|
53
|
+
Then I should not see "/url_for/sub.html"
|
54
|
+
When I go to "/url_for/sub.html"
|
55
|
+
Then I should see '"sub.html"'
|
56
|
+
Then I should not see "/url_for/sub.html"
|
57
|
+
|
58
|
+
Scenario: url_for produces relative links when :relative_links is set to true
|
59
|
+
Given a fixture app "indexable-app"
|
60
|
+
And a file named "config.rb" with:
|
61
|
+
"""
|
62
|
+
set :relative_links, true
|
63
|
+
"""
|
64
|
+
And a file named "source/url_for.html.erb" with:
|
65
|
+
"""
|
66
|
+
absolute: <%= url_for "/needs_index.html" %>
|
67
|
+
relative: <%= url_for "needs_index.html", :relative => false %>
|
68
|
+
unknown: <%= url_for "foo.html" %>
|
69
|
+
"""
|
70
|
+
And a file named "source/url_for/sub.html.erb" with:
|
71
|
+
"""
|
72
|
+
absolute: <%= url_for "/needs_index.html" %>
|
73
|
+
relative: <%= url_for "../needs_index.html" %>
|
74
|
+
"""
|
75
|
+
And the Server is running at "indexable-app"
|
76
|
+
When I go to "/url_for.html"
|
77
|
+
Then I should see 'absolute: needs_index.html'
|
78
|
+
Then I should see 'relative: /needs_index.html'
|
79
|
+
Then I should see 'unknown: foo.html'
|
80
|
+
When I go to "/url_for/sub.html"
|
81
|
+
Then I should see 'absolute: ../needs_index.html'
|
82
|
+
Then I should see 'relative: ../needs_index.html'
|
83
|
+
|
84
|
+
Scenario: url_for knows about directory indexes
|
85
|
+
Given a fixture app "indexable-app"
|
86
|
+
And a file named "source/url_for.html.erb" with:
|
87
|
+
"""
|
88
|
+
absolute: <%= url_for "/needs_index.html", :relative => true %>
|
89
|
+
relative: <%= url_for "needs_index.html", :relative => true %>
|
90
|
+
"""
|
91
|
+
And a file named "source/url_for/sub.html.erb" with:
|
92
|
+
"""
|
93
|
+
absolute: <%= url_for "/needs_index.html", :relative => true %>
|
94
|
+
relative: <%= url_for "../needs_index.html", :relative => true %>
|
95
|
+
"""
|
96
|
+
And the Server is running at "indexable-app"
|
97
|
+
When I go to "/url_for/"
|
98
|
+
Then I should see 'absolute: ../needs_index/'
|
99
|
+
Then I should see 'relative: ../needs_index/'
|
100
|
+
When I go to "/url_for/sub/"
|
101
|
+
Then I should see 'absolute: ../../needs_index/'
|
102
|
+
Then I should see 'relative: ../../needs_index/'
|
103
|
+
|
104
|
+
Scenario: url_for can take a Resource
|
105
|
+
Given a fixture app "indexable-app"
|
106
|
+
And a file named "source/url_for.html.erb" with:
|
107
|
+
"""
|
108
|
+
"<%= url_for sitemap.find_resource_by_path("/needs_index.html") %>"
|
109
|
+
"""
|
110
|
+
And the Server is running at "indexable-app"
|
111
|
+
When I go to "/url_for/"
|
112
|
+
Then I should see '"/needs_index/"'
|
113
|
+
|
114
|
+
Scenario: Setting http_prefix
|
115
|
+
Given a fixture app "indexable-app"
|
116
|
+
And a file named "config.rb" with:
|
117
|
+
"""
|
118
|
+
set :http_prefix, "/foo"
|
119
|
+
"""
|
120
|
+
And a file named "source/url_for.html.erb" with:
|
121
|
+
"""
|
122
|
+
<%= url_for "/needs_index.html" %>
|
123
|
+
"""
|
124
|
+
And the Server is running at "indexable-app"
|
125
|
+
When I go to "/url_for.html"
|
126
|
+
Then I should see '/foo/needs_index.html'
|
127
|
+
|
128
|
+
Scenario: url_for preserves query string and anchor and isn't messed up by them
|
129
|
+
Given a fixture app "indexable-app"
|
130
|
+
And a file named "source/url_for.html.erb" with:
|
131
|
+
"""
|
132
|
+
Needs Index Anchor <%= url_for "/needs_index.html#foo" %>
|
133
|
+
Needs Index Query <%= url_for "/needs_index.html?foo" %>
|
134
|
+
Needs Index Query and Anchor <%= url_for "/needs_index.html?foo#foo" %>
|
135
|
+
"""
|
136
|
+
And the Server is running at "indexable-app"
|
137
|
+
When I go to "/url_for/"
|
138
|
+
Then I should see 'Needs Index Anchor /needs_index/#foo'
|
139
|
+
Then I should see 'Needs Index Query /needs_index/?foo'
|
140
|
+
Then I should see 'Needs Index Query and Anchor /needs_index/?foo#foo'
|
141
|
+
|
142
|
+
Scenario: url_for accepts a :query option that appends a query string
|
143
|
+
Given a fixture app "indexable-app"
|
144
|
+
And a file named "source/url_for.html.erb" with:
|
145
|
+
"""
|
146
|
+
Needs Index String <%= url_for "/needs_index.html", :query => "foo" %>
|
147
|
+
Needs Index Hash <%= url_for "/needs_index.html", :query => { :foo => :bar } %>
|
148
|
+
"""
|
149
|
+
And the Server is running at "indexable-app"
|
150
|
+
When I go to "/url_for/"
|
151
|
+
Then I should see 'Needs Index String /needs_index/?foo'
|
152
|
+
Then I should see 'Needs Index Hash /needs_index/?foo=bar'
|
@@ -103,6 +103,51 @@ Feature: i18n Preview
|
|
103
103
|
Then I should see "Como Esta?"
|
104
104
|
When I go to "/spanish/hola.html"
|
105
105
|
Then I should see "Hola World"
|
106
|
+
|
107
|
+
Scenario: Running localize with a non-English mount config
|
108
|
+
Given a fixture app "i18n-test-app"
|
109
|
+
And a file named "config.rb" with:
|
110
|
+
"""
|
111
|
+
activate :i18n, :mount_at_root => :es
|
112
|
+
"""
|
113
|
+
Given the Server is running at "i18n-test-app"
|
114
|
+
When I go to "/en/index.html"
|
115
|
+
Then I should see "Howdy"
|
116
|
+
When I go to "/en/hello.html"
|
117
|
+
Then I should see "Hello World"
|
118
|
+
When I go to "/"
|
119
|
+
Then I should see "Como Esta?"
|
120
|
+
When I go to "/hola.html"
|
121
|
+
Then I should see "Hola World"
|
122
|
+
When I go to "/hello.html"
|
123
|
+
Then I should see "File Not Found"
|
124
|
+
When I go to "/es/index.html"
|
125
|
+
Then I should see "File Not Found"
|
126
|
+
When I go to "/es/hola.html"
|
127
|
+
Then I should see "File Not Found"
|
128
|
+
|
129
|
+
Scenario: Running localize with a non-English lang subset
|
130
|
+
Given a fixture app "i18n-test-app"
|
131
|
+
And a file named "config.rb" with:
|
132
|
+
"""
|
133
|
+
activate :i18n, :langs => :es
|
134
|
+
"""
|
135
|
+
Given the Server is running at "i18n-test-app"
|
136
|
+
When I go to "/en/index.html"
|
137
|
+
Then I should see "File Not Found"
|
138
|
+
When I go to "/en/hello.html"
|
139
|
+
Then I should see "File Not Found"
|
140
|
+
When I go to "/"
|
141
|
+
Then I should see "Como Esta?"
|
142
|
+
When I go to "/hola.html"
|
143
|
+
Then I should see "Hola World"
|
144
|
+
When I go to "/hello.html"
|
145
|
+
Then I should see "File Not Found"
|
146
|
+
When I go to "/es/index.html"
|
147
|
+
Then I should see "File Not Found"
|
148
|
+
When I go to "/es/hola.html"
|
149
|
+
Then I should see "File Not Found"
|
150
|
+
|
106
151
|
|
107
152
|
Scenario: Running localize with the no mount config
|
108
153
|
Given a fixture app "i18n-test-app"
|
data/features/minify_css.feature
CHANGED
@@ -53,13 +53,11 @@ Feature: Minify CSS
|
|
53
53
|
When I go to "/inline-css.html"
|
54
54
|
Then I should see:
|
55
55
|
"""
|
56
|
-
<style
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
}
|
62
|
-
/*]]>*/
|
56
|
+
<style>
|
57
|
+
body {
|
58
|
+
test: style;
|
59
|
+
good: deal;
|
60
|
+
}
|
63
61
|
</style>
|
64
62
|
"""
|
65
63
|
|
@@ -83,7 +81,7 @@ Feature: Minify CSS
|
|
83
81
|
When I go to "/inline-css.html"
|
84
82
|
Then I should see:
|
85
83
|
"""
|
86
|
-
<style
|
84
|
+
<style>
|
87
85
|
body {
|
88
86
|
test: style;
|
89
87
|
good: deal; }
|
@@ -108,7 +106,7 @@ Feature: Minify CSS
|
|
108
106
|
When I go to "/inline-css.html"
|
109
107
|
Then I should see:
|
110
108
|
"""
|
111
|
-
<style
|
109
|
+
<style>
|
112
110
|
Hello
|
113
111
|
</style>
|
114
112
|
"""
|
@@ -123,9 +121,7 @@ Feature: Minify CSS
|
|
123
121
|
When I go to "/inline-css.html"
|
124
122
|
Then I should see:
|
125
123
|
"""
|
126
|
-
<style
|
127
|
-
|
128
|
-
body{test:style;good:deal}
|
129
|
-
/*]]>*/
|
124
|
+
<style>
|
125
|
+
body{test:style;good:deal}
|
130
126
|
</style>
|
131
127
|
"""
|
@@ -10,15 +10,13 @@ Feature: Minify Javascript
|
|
10
10
|
When I go to "/inline-js.html"
|
11
11
|
Then I should see:
|
12
12
|
"""
|
13
|
-
<script
|
14
|
-
|
15
|
-
;
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
})();
|
21
|
-
//]]>
|
13
|
+
<script>
|
14
|
+
;(function() {
|
15
|
+
this;
|
16
|
+
should();
|
17
|
+
all.be();
|
18
|
+
on = { one: line };
|
19
|
+
})();
|
22
20
|
</script>
|
23
21
|
<script>
|
24
22
|
;(function() {
|
@@ -61,15 +59,13 @@ Feature: Minify Javascript
|
|
61
59
|
When I go to "/inline-js.html"
|
62
60
|
Then I should see:
|
63
61
|
"""
|
64
|
-
<script
|
65
|
-
|
66
|
-
;
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
})();
|
72
|
-
//]]>
|
62
|
+
<script>
|
63
|
+
;(function() {
|
64
|
+
this;
|
65
|
+
should();
|
66
|
+
all.be();
|
67
|
+
on = { one: line };
|
68
|
+
})();
|
73
69
|
</script>
|
74
70
|
<script>
|
75
71
|
;(function() {
|
@@ -110,10 +106,8 @@ Feature: Minify Javascript
|
|
110
106
|
When I go to "/inline-js.html"
|
111
107
|
Then I should see:
|
112
108
|
"""
|
113
|
-
<script
|
114
|
-
|
115
|
-
Hello
|
116
|
-
//]]>
|
109
|
+
<script>
|
110
|
+
Hello
|
117
111
|
</script>
|
118
112
|
<script>
|
119
113
|
Hello
|
@@ -138,10 +132,8 @@ Feature: Minify Javascript
|
|
138
132
|
When I go to "/inline-js.html"
|
139
133
|
Then I should see:
|
140
134
|
"""
|
141
|
-
<script
|
142
|
-
|
143
|
-
(function(){this,should(),all.be(),on={one:line}})();
|
144
|
-
//]]>
|
135
|
+
<script>
|
136
|
+
(function(){this,should(),all.be(),on={one:line}})();
|
145
137
|
</script>
|
146
138
|
<script>
|
147
139
|
(function(){this,should(),too()})();
|
@@ -177,12 +169,11 @@ Feature: Minify Javascript
|
|
177
169
|
Given a fixture app "minify-js-app"
|
178
170
|
And a file named "config.rb" with:
|
179
171
|
"""
|
180
|
-
require "coffee-filter"
|
181
172
|
activate :minify_javascript, :inline => true
|
182
173
|
"""
|
183
174
|
And the Server is running at "minify-js-app"
|
184
175
|
When I go to "/inline-coffeescript.html"
|
185
|
-
Then I should see "
|
176
|
+
Then I should see "3" lines
|
186
177
|
|
187
178
|
Scenario: Rendering external js (coffeescript) with the feature enabled
|
188
179
|
Given a fixture app "minify-js-app"
|
@@ -198,8 +189,6 @@ Feature: Minify Javascript
|
|
198
189
|
Given a fixture app "passthrough-app"
|
199
190
|
And a file named "config.rb" with:
|
200
191
|
"""
|
201
|
-
require "coffee-filter"
|
202
|
-
|
203
192
|
module ::PassThrough
|
204
193
|
def self.compress(data)
|
205
194
|
data
|
@@ -214,7 +203,7 @@ Feature: Minify Javascript
|
|
214
203
|
"""
|
215
204
|
And the Server is running at "passthrough-app"
|
216
205
|
When I go to "/inline-coffeescript.html"
|
217
|
-
Then I should see "
|
206
|
+
Then I should see "13" lines
|
218
207
|
|
219
208
|
Scenario: Rendering external js (coffeescript) with a passthrough minifier
|
220
209
|
Given a fixture app "passthrough-app"
|
@@ -1 +0,0 @@
|
|
1
|
-
require "coffee-filter"
|
@@ -1 +0,0 @@
|
|
1
|
-
require "coffee-filter"
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
good: deal
|
1
|
+
:sass
|
2
|
+
body
|
3
|
+
test: style
|
4
|
+
good: deal
|
@@ -64,7 +64,7 @@ module Middleman
|
|
64
64
|
# If the basename of the request as no extension, assume we are serving a
|
65
65
|
# directory and join index_file to the path.
|
66
66
|
path = File.join(asset_dir, current_path)
|
67
|
-
path = path.
|
67
|
+
path = path.sub(/#{File.extname(path)}$/, ".#{asset_ext}")
|
68
68
|
|
69
69
|
yield path if sitemap.find_resource_by_path(path)
|
70
70
|
end
|
@@ -74,11 +74,11 @@ module Middleman
|
|
74
74
|
# @return [String]
|
75
75
|
def page_classes
|
76
76
|
path = current_path.dup
|
77
|
-
path << index_file if path.
|
78
|
-
path =
|
77
|
+
path << index_file if path.end_with?('/')
|
78
|
+
path = Util.strip_leading_slash(path)
|
79
79
|
|
80
80
|
classes = []
|
81
|
-
parts = path.split('.')
|
81
|
+
parts = path.split('.').first.split('/')
|
82
82
|
parts.each_with_index { |path, i| classes << parts.first(i+1).join('_') }
|
83
83
|
|
84
84
|
classes.join(' ')
|
@@ -90,22 +90,93 @@ module Middleman
|
|
90
90
|
# @param [String] source The path to the file
|
91
91
|
# @return [String]
|
92
92
|
def asset_path(kind, source)
|
93
|
-
return source if source
|
93
|
+
return source if source.to_s.include?('//')
|
94
94
|
asset_folder = case kind
|
95
95
|
when :css then css_dir
|
96
96
|
when :js then js_dir
|
97
97
|
when :images then images_dir
|
98
98
|
else kind.to_s
|
99
99
|
end
|
100
|
-
source = source.to_s.
|
100
|
+
source = source.to_s.tr(' ', '')
|
101
101
|
ignore_extension = (kind == :images) # don't append extension
|
102
|
-
source << ".#{kind}" unless ignore_extension
|
103
|
-
if source
|
104
|
-
|
105
|
-
end
|
102
|
+
source << ".#{kind}" unless ignore_extension || source.end_with?(".#{kind}")
|
103
|
+
asset_folder = "" if source.start_with?('/') # absolute path
|
104
|
+
|
106
105
|
asset_url(source, asset_folder)
|
107
106
|
end
|
108
107
|
|
108
|
+
# Given a source path (referenced either absolutely or relatively)
|
109
|
+
# or a Resource, this will produce the nice URL configured for that
|
110
|
+
# path, respecting :relative_links, directory indexes, etc.
|
111
|
+
def url_for(path_or_resource, options={})
|
112
|
+
# Handle Resources and other things which define their own url method
|
113
|
+
url = path_or_resource.respond_to?(:url) ? path_or_resource.url : path_or_resource
|
114
|
+
|
115
|
+
begin
|
116
|
+
uri = URI(url)
|
117
|
+
rescue URI::InvalidURIError
|
118
|
+
# Nothing we can do with it, it's not really a URI
|
119
|
+
return url
|
120
|
+
end
|
121
|
+
|
122
|
+
relative = options.delete(:relative)
|
123
|
+
raise "Can't use the relative option with an external URL" if relative && uri.host
|
124
|
+
|
125
|
+
# Allow people to turn on relative paths for all links with
|
126
|
+
# set :relative_links, true
|
127
|
+
# but still override on a case by case basis with the :relative parameter.
|
128
|
+
effective_relative = relative || false
|
129
|
+
effective_relative = true if relative.nil? && relative_links
|
130
|
+
|
131
|
+
# Try to find a sitemap resource corresponding to the desired path
|
132
|
+
this_resource = current_resource # store in a local var to save work
|
133
|
+
if path_or_resource.is_a?(Sitemap::Resource)
|
134
|
+
resource = path_or_resource
|
135
|
+
resource_url = url
|
136
|
+
elsif this_resource && uri.path
|
137
|
+
# Handle relative urls
|
138
|
+
url_path = Pathname(uri.path)
|
139
|
+
current_source_dir = Pathname('/' + this_resource.path).dirname
|
140
|
+
url_path = current_source_dir.join(url_path) if url_path.relative?
|
141
|
+
resource = sitemap.find_resource_by_path(url_path.to_s)
|
142
|
+
resource_url = resource.url if resource
|
143
|
+
end
|
144
|
+
|
145
|
+
if resource
|
146
|
+
# Switch to the relative path between this_resource and the given resource
|
147
|
+
# if we've been asked to.
|
148
|
+
if effective_relative
|
149
|
+
# Output urls relative to the destination path, not the source path
|
150
|
+
current_dir = Pathname('/' + this_resource.destination_path).dirname
|
151
|
+
relative_path = Pathname(resource_url).relative_path_from(current_dir).to_s
|
152
|
+
|
153
|
+
# Put back the trailing slash to avoid unnecessary Apache redirects
|
154
|
+
if resource_url.end_with?('/') && !relative_path.end_with?('/')
|
155
|
+
relative_path << '/'
|
156
|
+
end
|
157
|
+
|
158
|
+
uri.path = relative_path
|
159
|
+
else
|
160
|
+
uri.path = resource_url
|
161
|
+
end
|
162
|
+
else
|
163
|
+
# If they explicitly asked for relative links but we can't find a resource...
|
164
|
+
raise "No resource exists at #{url}" if relative
|
165
|
+
end
|
166
|
+
|
167
|
+
# Support a :query option that can be a string or hash
|
168
|
+
if query = options.delete(:query)
|
169
|
+
uri.query = query.respond_to?(:to_param) ? query.to_param : query.to_s
|
170
|
+
end
|
171
|
+
|
172
|
+
# Support a :fragment or :anchor option just like Padrino
|
173
|
+
fragment = options.delete(:anchor) || options.delete(:fragment)
|
174
|
+
uri.fragment = fragment.to_s if fragment
|
175
|
+
|
176
|
+
# Finally make the URL back into a string
|
177
|
+
uri.to_s
|
178
|
+
end
|
179
|
+
|
109
180
|
# Overload the regular link_to to be sitemap-aware - if you
|
110
181
|
# reference a source path, either absolutely or relatively,
|
111
182
|
# you'll get that resource's nice URL. Also, there is a
|
@@ -123,75 +194,27 @@ module Middleman
|
|
123
194
|
url_arg_index = block_given? ? 0 : 1
|
124
195
|
options_index = block_given? ? 1 : 2
|
125
196
|
|
197
|
+
if block_given? && args.size > 2
|
198
|
+
raise ArgumentError.new("Too many arguments to link_to(url, options={}, &block)")
|
199
|
+
end
|
200
|
+
|
126
201
|
if url = args[url_arg_index]
|
127
202
|
options = args[options_index] || {}
|
128
|
-
|
129
|
-
|
130
|
-
#
|
131
|
-
|
132
|
-
url = args[url_arg_index] = url.url
|
133
|
-
end
|
134
|
-
|
135
|
-
if url.include? '://'
|
136
|
-
raise "Can't use the relative option with an external URL" if relative
|
137
|
-
elsif current_resource
|
138
|
-
# Handle relative urls
|
139
|
-
current_source_dir = Pathname('/' + current_resource.path).dirname
|
140
|
-
|
141
|
-
begin
|
142
|
-
uri = URI(url)
|
143
|
-
url_path = uri.path
|
144
|
-
rescue
|
145
|
-
end
|
146
|
-
|
147
|
-
if url_path
|
148
|
-
path = Pathname(url_path)
|
149
|
-
url_path = current_source_dir.join(path).to_s if path.relative?
|
150
|
-
|
151
|
-
resource = sitemap.find_resource_by_path(url_path)
|
152
|
-
|
153
|
-
# Allow people to turn on relative paths for all links with config[:relative_links] = true
|
154
|
-
# but still override on a case by case basis with the :relative parameter.
|
155
|
-
effective_relative = relative || false
|
156
|
-
if relative.nil? && relative_links
|
157
|
-
effective_relative = true
|
158
|
-
end
|
159
|
-
|
160
|
-
if resource
|
161
|
-
if effective_relative
|
162
|
-
resource_url = resource.url
|
163
|
-
|
164
|
-
# Output urls relative to the destination path, not the source path
|
165
|
-
current_dir = Pathname('/' + current_resource.destination_path).dirname
|
166
|
-
new_url = Pathname(resource_url).relative_path_from(current_dir).to_s
|
167
|
-
|
168
|
-
# Put back the trailing slash to avoid unnecessary Apache redirects
|
169
|
-
if resource_url.end_with?('/') && !new_url.end_with?('/')
|
170
|
-
new_url << '/'
|
171
|
-
end
|
172
|
-
else
|
173
|
-
new_url = resource.url
|
174
|
-
end
|
175
|
-
|
176
|
-
uri.path = new_url
|
177
|
-
|
178
|
-
args[url_arg_index] = uri.to_s
|
179
|
-
else
|
180
|
-
raise "No resource exists at #{url}" if relative
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
# Support a :query option that can be a string or hash
|
186
|
-
if query = options.delete(:query)
|
187
|
-
uri = URI(args[url_arg_index])
|
188
|
-
uri.query = query.respond_to?(:to_param) ? query.to_param : query.to_s
|
189
|
-
args[url_arg_index] = uri.to_s
|
190
|
-
end
|
203
|
+
raise ArgumentError.new("Options must be a hash") unless options.is_a?(Hash)
|
204
|
+
|
205
|
+
# Transform the url through our magic url_for method
|
206
|
+
args[url_arg_index] = url_for(url, options)
|
191
207
|
end
|
192
208
|
|
193
209
|
super(*args, &block)
|
194
210
|
end
|
211
|
+
|
212
|
+
# Modified Padrino form_for that uses Middleman's url_for
|
213
|
+
# to transform the URL.
|
214
|
+
def form_tag(url, options={}, &block)
|
215
|
+
url = url_for(url, options)
|
216
|
+
super
|
217
|
+
end
|
195
218
|
end
|
196
219
|
end
|
197
220
|
end
|
@@ -26,9 +26,10 @@ module Middleman
|
|
26
26
|
|
27
27
|
def initialize(app, options={})
|
28
28
|
@app = app
|
29
|
-
@locales_glob = File.join(app.locales_dir, "**", "*.{rb,yml}")
|
29
|
+
@locales_glob = File.join(app.locales_dir, "**", "*.{rb,yml,yaml}")
|
30
30
|
|
31
|
-
|
31
|
+
# File.fnmatch doesn't support brackets: {rb,yml}
|
32
|
+
regex = @locales_glob.sub(/\./, '\.').sub(File.join("**", "*"), ".*").sub(/\//, '\/').sub("{rb,yml,yaml}", "rb|ya?ml")
|
32
33
|
@locales_regex = %r{^#{regex}}
|
33
34
|
|
34
35
|
@maps = {}
|
@@ -43,7 +44,7 @@ module Middleman
|
|
43
44
|
@mount_at_root = @options.has_key?(:mount_at_root) ? @options[:mount_at_root] : langs.first
|
44
45
|
|
45
46
|
if !@app.build?
|
46
|
-
logger.info "== Locales: #{langs.join(", ")}"
|
47
|
+
logger.info "== Locales: #{langs.join(", ")} (Default #{@mount_at_root})"
|
47
48
|
end
|
48
49
|
|
49
50
|
# Don't output localizable files
|
@@ -52,15 +53,20 @@ module Middleman
|
|
52
53
|
@app.sitemap.provides_metadata_for_path do |url|
|
53
54
|
if d = get_localization_data(url)
|
54
55
|
lang, page_id = d
|
55
|
-
instance_vars = Proc.new {
|
56
|
-
::I18n.locale = lang
|
57
|
-
@lang = lang
|
58
|
-
@page_id = page_id
|
59
|
-
}
|
60
|
-
{ :blocks => [instance_vars] }
|
61
56
|
else
|
62
|
-
|
57
|
+
# Default to the @mount_at_root lang
|
58
|
+
page_id = nil
|
59
|
+
lang = @mount_at_root
|
63
60
|
end
|
61
|
+
|
62
|
+
instance_vars = Proc.new do
|
63
|
+
::I18n.locale = lang
|
64
|
+
@lang = lang
|
65
|
+
@page_id = page_id
|
66
|
+
end
|
67
|
+
|
68
|
+
locals = { :lang => lang, :page_id => page_id }
|
69
|
+
{ :blocks => [instance_vars], :locals => locals }
|
64
70
|
end
|
65
71
|
|
66
72
|
@app.sitemap.register_resource_list_manipulator(
|
@@ -73,15 +79,17 @@ module Middleman
|
|
73
79
|
end
|
74
80
|
|
75
81
|
def on_file_changed(file)
|
76
|
-
if @locales_regex
|
82
|
+
if @locales_regex =~ file
|
77
83
|
::I18n.reload!
|
78
84
|
end
|
79
85
|
end
|
80
86
|
|
81
87
|
def langs
|
82
|
-
@options[:langs]
|
88
|
+
if @options[:langs]
|
89
|
+
Array(@options[:langs]).map(&:to_sym)
|
90
|
+
else
|
83
91
|
Dir[File.join(@app.root, @locales_glob)].map { |file|
|
84
|
-
File.basename(file).sub(/\.
|
92
|
+
File.basename(file).sub(/\.ya?ml$/, "").sub(/\.rb$/, "")
|
85
93
|
}.sort.map(&:to_sym)
|
86
94
|
end
|
87
95
|
end
|
@@ -38,7 +38,7 @@ module Middleman
|
|
38
38
|
params[:alt] ||= ""
|
39
39
|
|
40
40
|
real_path = path
|
41
|
-
real_path = File.join(images_dir, real_path) unless real_path
|
41
|
+
real_path = File.join(images_dir, real_path) unless real_path.start_with?('/')
|
42
42
|
full_path = File.join(source_dir, real_path)
|
43
43
|
|
44
44
|
if File.exists? full_path
|
@@ -32,11 +32,11 @@ module Middleman
|
|
32
32
|
def asset_url(path, prefix="")
|
33
33
|
path = super(path, prefix)
|
34
34
|
|
35
|
-
if path.include?("//")
|
35
|
+
if path.include?("//") || !current_resource
|
36
36
|
path
|
37
37
|
else
|
38
38
|
current_dir = Pathname('/' + current_resource.destination_path)
|
39
|
-
Pathname(path).relative_path_from(current_dir.dirname)
|
39
|
+
Pathname(path).relative_path_from(current_dir.dirname).to_s
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
data/middleman-more.gemspec
CHANGED
File without changes
|
data/spec/spec_helper.rb
ADDED
File without changes
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-more
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
5
|
-
prerelease:
|
4
|
+
version: 3.0.12.pre.1
|
5
|
+
prerelease: 7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Thomas Reynolds
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: middleman-core
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - '='
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 3.0.
|
22
|
+
version: 3.0.12.pre.1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - '='
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version: 3.0.
|
30
|
+
version: 3.0.12.pre.1
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
32
|
name: uglifier
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
@@ -219,9 +219,11 @@ files:
|
|
219
219
|
- features/gzip.feature
|
220
220
|
- features/helpers_auto_javascript_include_tag.feature
|
221
221
|
- features/helpers_auto_stylesheet_link_tag.feature
|
222
|
+
- features/helpers_form_tag.feature
|
222
223
|
- features/helpers_link_to.feature
|
223
224
|
- features/helpers_lorem.feature
|
224
225
|
- features/helpers_page_classes.feature
|
226
|
+
- features/helpers_url_for.feature
|
225
227
|
- features/i18n_builder.feature
|
226
228
|
- features/i18n_preview.feature
|
227
229
|
- features/ignore.feature
|
@@ -627,6 +629,8 @@ files:
|
|
627
629
|
- lib/middleman-more/templates/smacss/source/stylesheets/style.css.scss
|
628
630
|
- lib/middleman_extension.rb
|
629
631
|
- middleman-more.gemspec
|
632
|
+
- spec/middleman-more/future_spec.rb
|
633
|
+
- spec/spec_helper.rb
|
630
634
|
homepage: http://middlemanapp.com
|
631
635
|
licenses:
|
632
636
|
- MIT
|
@@ -642,19 +646,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
642
646
|
version: '0'
|
643
647
|
segments:
|
644
648
|
- 0
|
645
|
-
hash:
|
649
|
+
hash: -2224394918226240711
|
646
650
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
647
651
|
none: false
|
648
652
|
requirements:
|
649
|
-
- - ! '
|
653
|
+
- - ! '>'
|
650
654
|
- !ruby/object:Gem::Version
|
651
|
-
version:
|
652
|
-
segments:
|
653
|
-
- 0
|
654
|
-
hash: 1634045275272907332
|
655
|
+
version: 1.3.1
|
655
656
|
requirements: []
|
656
657
|
rubyforge_project:
|
657
|
-
rubygems_version: 1.8.
|
658
|
+
rubygems_version: 1.8.23
|
658
659
|
signing_key:
|
659
660
|
specification_version: 3
|
660
661
|
summary: Hand-crafted frontend development
|
@@ -676,9 +677,11 @@ test_files:
|
|
676
677
|
- features/gzip.feature
|
677
678
|
- features/helpers_auto_javascript_include_tag.feature
|
678
679
|
- features/helpers_auto_stylesheet_link_tag.feature
|
680
|
+
- features/helpers_form_tag.feature
|
679
681
|
- features/helpers_link_to.feature
|
680
682
|
- features/helpers_lorem.feature
|
681
683
|
- features/helpers_page_classes.feature
|
684
|
+
- features/helpers_url_for.feature
|
682
685
|
- features/i18n_builder.feature
|
683
686
|
- features/i18n_preview.feature
|
684
687
|
- features/ignore.feature
|