-
Notifications
You must be signed in to change notification settings - Fork 53
/
middleman_helpers.feature
152 lines (131 loc) · 4.33 KB
/
middleman_helpers.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
Feature: Access to Middleman helpers
Sprockets is given an `asset_path` helper that is able to use the Middleman sitemap. This allows Sprockets methods like `image-url` to work for Middleman assets.
By default helpers other than asset_path that are added to Middleman aren't available in Sprockets' rendering context. They can, however, be added through a configuration option. There is a caveat though that `current_resource` is unavailable so look out for helpers that depend on it.
Scenario: Using asset_path to link to a Middleman asset
Here we're depending on the behavior of `image-url` to call asset_path internally
Given a fixture app "base-app"
And a file named "config.rb" with:
"""
activate :sprockets
set :http_prefix, '/winterfell'
"""
And a file named "source/images/img.svg" with:
"""
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20001102//EN"
"http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd">
<svg width="100%" height="100%">
<g transform="translate(50,50)">
<rect x="0" y="0" width="150" height="50" style="fill:red;" />
</g>
</svg>
"""
And a file named "source/stylesheets/site.css.scss" with:
"""
body {
background: image-url('img.svg');
}
"""
And the Server is running
When I go to "/stylesheets/site.css"
Then I should see:
"""
body {
background: url(/winterfell/images/img.svg); }
"""
Scenario: Sprockets has access to Middleman data
Given a fixture app "base-app"
And a file named "config.rb" with:
"""
activate :sprockets
"""
And a file named "data/test.yml" with:
"""
foo: bar
"""
And a file named "source/javascripts/data_accessor.js.coffee.erb" with:
"""
console.log '<%= data.test.foo %>'
"""
And the Server is running
When I go to "/javascripts/data_accessor.js"
Then I should see "console.log('bar')"
Scenario: Using a helper from a Sprockets asset
Given a fixture app "base-app"
And a file named "config.rb" with:
"""
activate :sprockets do |c|
c.expose_middleman_helpers = true
end
helpers do
def hello
'hello'
end
end
"""
And a file named "source/index.html.erb" with:
"""
<h1><%= hello %></h1>
"""
And a file named "source/javascripts/site.js.erb" with:
"""
console.log('<%= hello %>');
"""
And a file named "vendor/javascripts/imported.js.erb" with:
"""
console.log('<%= hello %>');
"""
And a file named "source/javascripts/importer.js" with:
"""
//= require imported
"""
And the Server is running
When I go to "/index.html"
Then I should see "<h1>hello</h1>"
When I go to "/javascripts/site.js"
Then I should see "console.log('hello');"
When I go to "/javascripts/importer.js"
Then I should see "console.log('hello');"
Scenario: current_resource is available
Given a fixture app "base-app"
And a file named "config.rb" with:
"""
activate :sprockets
"""
And a file named "source/index.html.erb" with:
"""
<pre><%= current_resource.url %></pre>
"""
And a file named "source/javascripts/site.js.erb" with:
"""
console.log('<%= current_resource.url %>');
"""
And the Server is running
When I go to "/index.html"
Then I should see "<pre>/</pre>"
When going to "/javascripts/site.js" should not raise an exception
And I should see "console.log('/javascripts/site.js');"
Scenario: Helpers are not included by default
Given a fixture app "base-app"
And a file named "config.rb" with:
"""
activate :sprockets
helpers do
def hello
'hello'
end
end
"""
And a file named "source/index.html.erb" with:
"""
<h1><%= hello %></h1>
"""
And a file named "source/javascripts/site.js.erb" with:
"""
console.log('<%= hello %>');
"""
And the Server is running
When I go to "/index.html"
Then I should see "<h1>hello</h1>"
When going to "/javascripts/site.js" should not raise an exception
Then I should see "undefined local variable or method `hello'"