locomotivecms_steam 1.5.0.rc0 → 1.5.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/Gemfile +3 -6
- data/Gemfile.lock +39 -39
- data/README.md +2 -2
- data/lib/locomotive/steam/adapters/filesystem/sanitizers/section.rb +62 -16
- data/lib/locomotive/steam/adapters/filesystem/sanitizers/site.rb +15 -1
- data/lib/locomotive/steam/adapters/filesystem/yaml_loader.rb +30 -9
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb +1 -1
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/page.rb +1 -1
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/section.rb +14 -2
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/site.rb +1 -1
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/translation.rb +1 -1
- data/lib/locomotive/steam/adapters/mongodb.rb +1 -1
- data/lib/locomotive/steam/entities/content_entry.rb +0 -1
- data/lib/locomotive/steam/entities/site.rb +4 -0
- data/lib/locomotive/steam/errors.rb +54 -18
- data/lib/locomotive/steam/liquid/drops/content_entry.rb +1 -1
- data/lib/locomotive/steam/liquid/drops/content_entry_collection.rb +1 -1
- data/lib/locomotive/steam/liquid/drops/content_types.rb +1 -1
- data/lib/locomotive/steam/liquid/drops/inherited_block.rb +28 -0
- data/lib/locomotive/steam/liquid/drops/metafields.rb +2 -2
- data/lib/locomotive/steam/liquid/drops/params.rb +1 -1
- data/lib/locomotive/steam/liquid/drops/section.rb +10 -2
- data/lib/locomotive/steam/liquid/drops/section_content_proxy.rb +13 -2
- data/lib/locomotive/steam/liquid/drops/section_editor_setting_data.rb +1 -1
- data/lib/locomotive/steam/liquid/drops/session_proxy.rb +1 -1
- data/lib/locomotive/steam/liquid/file_system.rb +46 -0
- data/lib/locomotive/steam/liquid/filters/array.rb +61 -0
- data/lib/locomotive/steam/liquid/filters/misc.rb +12 -2
- data/lib/locomotive/steam/liquid/filters/number.rb +13 -12
- data/lib/locomotive/steam/liquid/filters/text.rb +4 -0
- data/lib/locomotive/steam/liquid/patches.rb +58 -19
- data/lib/locomotive/steam/liquid/tags/alt_page_links.rb +9 -5
- data/lib/locomotive/steam/liquid/tags/concerns/attributes.rb +47 -0
- data/lib/locomotive/steam/liquid/tags/concerns/path.rb +18 -31
- data/lib/locomotive/steam/liquid/tags/concerns/section.rb +22 -11
- data/lib/locomotive/steam/liquid/tags/consume.rb +26 -33
- data/lib/locomotive/steam/liquid/tags/csrf.rb +2 -2
- data/lib/locomotive/steam/liquid/tags/editable/base.rb +30 -20
- data/lib/locomotive/steam/liquid/tags/editable/control.rb +2 -2
- data/lib/locomotive/steam/liquid/tags/editable/file.rb +11 -11
- data/lib/locomotive/steam/liquid/tags/editable/text.rb +5 -5
- data/lib/locomotive/steam/liquid/tags/extends.rb +56 -8
- data/lib/locomotive/steam/liquid/tags/global_section.rb +6 -6
- data/lib/locomotive/steam/liquid/tags/google_analytics.rb +16 -6
- data/lib/locomotive/steam/liquid/tags/hybrid.rb +8 -4
- data/lib/locomotive/steam/liquid/tags/inherited_block.rb +90 -13
- data/lib/locomotive/steam/liquid/tags/inline_editor.rb +4 -4
- data/lib/locomotive/steam/liquid/tags/link_to.rb +2 -1
- data/lib/locomotive/steam/liquid/tags/locale_switcher.rb +25 -21
- data/lib/locomotive/steam/liquid/tags/model_form.rb +38 -17
- data/lib/locomotive/steam/liquid/tags/nav.rb +4 -4
- data/lib/locomotive/steam/liquid/tags/page_not_found.rb +19 -0
- data/lib/locomotive/steam/liquid/tags/paginate.rb +13 -7
- data/lib/locomotive/steam/liquid/tags/path_to.rb +1 -0
- data/lib/locomotive/steam/liquid/tags/redirect_to.rb +34 -0
- data/lib/locomotive/steam/liquid/tags/section.rb +34 -33
- data/lib/locomotive/steam/liquid/tags/sections_dropzone.rb +1 -1
- data/lib/locomotive/steam/liquid/tags/seo.rb +2 -4
- data/lib/locomotive/steam/liquid/tags/session_assign.rb +1 -0
- data/lib/locomotive/steam/liquid/tags/snippet.rb +21 -29
- data/lib/locomotive/steam/liquid/tags/with_scope.rb +61 -27
- data/lib/locomotive/steam/liquid.rb +3 -1
- data/lib/locomotive/steam/middlewares/cache.rb +117 -0
- data/lib/locomotive/steam/middlewares/concerns/helpers.rb +22 -8
- data/lib/locomotive/steam/middlewares/concerns/liquid_context.rb +5 -1
- data/lib/locomotive/steam/middlewares/concerns/rendering.rb +53 -0
- data/lib/locomotive/steam/middlewares/impersonated_entry.rb +4 -0
- data/lib/locomotive/steam/middlewares/locale.rb +2 -2
- data/lib/locomotive/steam/middlewares/locale_redirection.rb +1 -1
- data/lib/locomotive/steam/middlewares/logging.rb +1 -0
- data/lib/locomotive/steam/middlewares/page_not_found.rb +37 -0
- data/lib/locomotive/steam/middlewares/redirection.rb +1 -1
- data/lib/locomotive/steam/middlewares/renderer.rb +4 -26
- data/lib/locomotive/steam/middlewares/thread_safe.rb +0 -4
- data/lib/locomotive/steam/models/pager.rb +1 -0
- data/lib/locomotive/steam/server.rb +3 -1
- data/lib/locomotive/steam/services/action_service.rb +5 -0
- data/lib/locomotive/steam/services/auth_service.rb +9 -9
- data/lib/locomotive/steam/services/cookie_service.rb +1 -0
- data/lib/locomotive/steam/services/external_api_service.rb +5 -0
- data/lib/locomotive/steam/services/liquid_parser_service.rb +4 -2
- data/lib/locomotive/steam/services/page_finder_service.rb +1 -1
- data/lib/locomotive/steam/services/recaptcha_service.rb +4 -2
- data/lib/locomotive/steam/version.rb +1 -1
- data/lib/locomotive/steam.rb +5 -1
- data/locomotivecms_steam.gemspec +4 -4
- data/spec/fixtures/default/app/views/pages/basic.liquid.haml +1 -0
- data/spec/fixtures/default/app/views/pages/music.liquid.haml +6 -0
- data/spec/fixtures/default/app/views/sections/carousel.liquid +15 -16
- data/spec/fixtures/default/app/views/sections/footer.liquid +37 -3
- data/spec/fixtures/default/app/views/sections/header.liquid +47 -10
- data/spec/fixtures/default/app/views/sections/misc/hero.liquid +28 -0
- data/spec/fixtures/default/config/metafields_schema.yml +3 -0
- data/spec/integration/liquid/tags/section_spec.rb +82 -0
- data/spec/integration/repositories/content_entry_repository_spec.rb +9 -0
- data/spec/integration/server/basic_spec.rb +2 -2
- data/spec/integration/server/metafields_spec.rb +1 -0
- data/spec/integration/services/content_entry_service_spec.rb +12 -0
- data/spec/support/helpers.rb +1 -0
- data/spec/support/liquid.rb +32 -2
- data/spec/support/mongo.rb +1 -0
- data/spec/unit/adapters/filesystem/sanitizers/section_spec.rb +66 -40
- data/spec/unit/adapters/filesystem/yaml_loaders/section_spec.rb +25 -0
- data/spec/unit/errors_spec.rb +1 -1
- data/spec/unit/liquid/drops/content_entry_collection_spec.rb +3 -3
- data/spec/unit/liquid/drops/content_entry_spec.rb +4 -4
- data/spec/unit/liquid/drops/content_types_spec.rb +2 -2
- data/spec/unit/liquid/drops/metafields_spec.rb +8 -8
- data/spec/unit/liquid/drops/params_spec.rb +5 -5
- data/spec/unit/liquid/drops/section_content_proxy_spec.rb +69 -18
- data/spec/unit/liquid/drops/section_spec.rb +1 -1
- data/spec/unit/liquid/file_system_spec.rb +25 -0
- data/spec/unit/liquid/filters/array_spec.rb +140 -0
- data/spec/unit/liquid/filters/misc_spec.rb +21 -3
- data/spec/unit/liquid/filters/number_spec.rb +4 -4
- data/spec/unit/liquid/filters/text_spec.rb +4 -0
- data/spec/unit/liquid/tags/alt_page_links_spec.rb +19 -2
- data/spec/unit/liquid/tags/authorize_spec.rb +1 -1
- data/spec/unit/liquid/tags/editable/text_spec.rb +32 -4
- data/spec/unit/liquid/tags/extends_spec.rb +115 -28
- data/spec/unit/liquid/tags/global_section_spec.rb +4 -3
- data/spec/unit/liquid/tags/google_analytics_spec.rb +21 -2
- data/spec/unit/liquid/tags/inherited_block_spec.rb +18 -4
- data/spec/unit/liquid/tags/inline_editor_spec.rb +11 -0
- data/spec/unit/liquid/tags/link_to_spec.rb +1 -1
- data/spec/unit/liquid/tags/model_form_spec.rb +7 -0
- data/spec/unit/liquid/tags/page_not_found_spec.rb +14 -0
- data/spec/unit/liquid/tags/redirect_to_spec.rb +171 -0
- data/spec/unit/liquid/tags/section_spec.rb +43 -3
- data/spec/unit/liquid/tags/sections_dropzone_spec.rb +0 -1
- data/spec/unit/liquid/tags/snippet_spec.rb +9 -8
- data/spec/unit/liquid/tags/with_scope_spec.rb +80 -60
- data/spec/unit/middlewares/cache_spec.rb +186 -0
- data/spec/unit/middlewares/impersonated_entry_spec.rb +7 -0
- data/spec/unit/middlewares/locale_redirection_spec.rb +7 -0
- data/spec/unit/middlewares/locale_spec.rb +8 -1
- data/spec/unit/middlewares/page_not_found_spec.rb +46 -0
- data/spec/unit/middlewares/redirection_spec.rb +8 -0
- data/spec/unit/middlewares/renderer_spec.rb +64 -6
- data/spec/unit/middlewares/section_spec.rb +1 -0
- data/spec/unit/models/pager_spec.rb +11 -1
- data/spec/unit/repositories/section_repository_spec.rb +1 -1
- data/spec/unit/services/action_service_spec.rb +23 -3
- data/spec/unit/services/page_redirection_service_spec.rb +2 -2
- data/spec/unit/services/recaptcha_service_spec.rb +1 -1
- metadata +50 -24
@@ -21,6 +21,24 @@ describe Locomotive::Steam::Liquid::Filters::Misc do
|
|
21
21
|
expect(default(nil, 42)).to eq 42
|
22
22
|
end
|
23
23
|
|
24
|
+
describe 'blank?' do
|
25
|
+
|
26
|
+
let(:array) { [0, "foobar", Object.new, nil, "", " ", "\n"] }
|
27
|
+
subject { array.map { |x| blank?(x) } }
|
28
|
+
|
29
|
+
it { is_expected.to eq [false, false, false, true, true, true, true] }
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'present?' do
|
34
|
+
|
35
|
+
let(:array) { [0, "foobar", Object.new, nil, "", " ", "\n"] }
|
36
|
+
subject { array.map { |x| present?(x) } }
|
37
|
+
|
38
|
+
it { is_expected.to eq [true, true, true, false, false, false, false] }
|
39
|
+
|
40
|
+
end
|
41
|
+
|
24
42
|
describe 'index' do
|
25
43
|
|
26
44
|
let(:array) { [1, 2, 3, 4] }
|
@@ -123,11 +141,11 @@ describe Locomotive::Steam::Liquid::Filters::Misc do
|
|
123
141
|
|
124
142
|
let(:array) { [1, 2, 3, 4] }
|
125
143
|
|
126
|
-
subject { shuffle(array) }
|
144
|
+
subject { 5.times.map { shuffle(array) } }
|
127
145
|
|
128
146
|
it 'returns an array in a random order' do
|
129
|
-
expect(subject.
|
130
|
-
expect(subject
|
147
|
+
expect(subject.all? { |x| x == array }).to eq(false)
|
148
|
+
expect(subject.all? { |x| x.sort == array }).to eq(true)
|
131
149
|
end
|
132
150
|
|
133
151
|
end
|
@@ -39,7 +39,7 @@ describe Locomotive::Steam::Liquid::Filters::Number do
|
|
39
39
|
context 'with options' do
|
40
40
|
|
41
41
|
let(:input) { 42.01 }
|
42
|
-
let(:options) {
|
42
|
+
let(:options) { { 'unit' => "€", 'format' => "%n %u", 'precision' => 1 } }
|
43
43
|
|
44
44
|
it { expect(subject).to eq '42.0 €' }
|
45
45
|
|
@@ -50,7 +50,7 @@ describe Locomotive::Steam::Liquid::Filters::Number do
|
|
50
50
|
let(:environments) { { 'my_unit' => 'Franc' } }
|
51
51
|
|
52
52
|
let(:input) { 42.01 }
|
53
|
-
let(:options) {
|
53
|
+
let(:options) { { 'unit' => 'my_unit', 'format' => "%n %u" } }
|
54
54
|
|
55
55
|
it { expect(subject).to eq '42.01 Franc' }
|
56
56
|
|
@@ -79,7 +79,7 @@ describe Locomotive::Steam::Liquid::Filters::Number do
|
|
79
79
|
context 'with options' do
|
80
80
|
|
81
81
|
let(:input) { '42.01' }
|
82
|
-
let(:options) {
|
82
|
+
let(:options) { { 'precision' => 0 } }
|
83
83
|
|
84
84
|
it { expect(subject).to eq '42%' }
|
85
85
|
|
@@ -108,7 +108,7 @@ describe Locomotive::Steam::Liquid::Filters::Number do
|
|
108
108
|
context 'with options' do
|
109
109
|
|
110
110
|
let(:input) { '1234567' }
|
111
|
-
let(:options) {
|
111
|
+
let(:options) { { 'precision' => 2 } }
|
112
112
|
|
113
113
|
it { expect(subject).to eq '1.2 MB' }
|
114
114
|
|
@@ -41,6 +41,10 @@ describe Locomotive::Steam::Liquid::Filters::Text do
|
|
41
41
|
expect(encode('http:://www.example.com?key=hello world')).to eq 'http%3A%3A%2F%2Fwww.example.com%3Fkey%3Dhello+world'
|
42
42
|
end
|
43
43
|
|
44
|
+
it 'parameterizes an input' do
|
45
|
+
expect(parameterize('séjourner & dormir')).to eq 'sejourner-dormir'
|
46
|
+
end
|
47
|
+
|
44
48
|
it 'replaces \n by <br/>' do
|
45
49
|
expect(multi_line("hello\nworld")).to eq 'hello<br/>world'
|
46
50
|
end
|
@@ -30,7 +30,7 @@ describe Locomotive::Steam::Liquid::Tags::AltPageLinks do
|
|
30
30
|
|
31
31
|
it { is_expected.to eq((<<-HTML
|
32
32
|
<link rel="alternate" hreflang="x-default" href="https://www.example.com/" />
|
33
|
-
<link rel="alternate" hreflang="en" href="https://www.example.com/
|
33
|
+
<link rel="alternate" hreflang="en" href="https://www.example.com/" />
|
34
34
|
<link rel="alternate" hreflang="fr" href="https://www.example.com/fr" />
|
35
35
|
HTML
|
36
36
|
).strip)
|
@@ -43,7 +43,7 @@ describe Locomotive::Steam::Liquid::Tags::AltPageLinks do
|
|
43
43
|
it 'has to be the same links' do
|
44
44
|
is_expected.to eq((<<-HTML
|
45
45
|
<link rel="alternate" hreflang="x-default" href="https://www.example.com/" />
|
46
|
-
<link rel="alternate" hreflang="en" href="https://www.example.com/
|
46
|
+
<link rel="alternate" hreflang="en" href="https://www.example.com/" />
|
47
47
|
<link rel="alternate" hreflang="fr" href="https://www.example.com/fr" />
|
48
48
|
HTML
|
49
49
|
).strip)
|
@@ -51,6 +51,23 @@ describe Locomotive::Steam::Liquid::Tags::AltPageLinks do
|
|
51
51
|
|
52
52
|
end
|
53
53
|
|
54
|
+
context 'the developer wants to pass an ending path (dynamic routing)' do
|
55
|
+
|
56
|
+
let(:locale) { 'fr' }
|
57
|
+
let(:page) { liquid_instance_double('News', index?: false, localized_attributes: { title: true, fullpath: true }, title: { en: 'News', fr: 'Actualités' }, fullpath: { en: 'news', fr: 'actualites' }, templatized?: false) }
|
58
|
+
let(:assigns) { { 'page' => drop, 'base_url' => 'https://www.example.com', 'alt_page_links_ending_path' => '/2019/06' } }
|
59
|
+
|
60
|
+
it 'has to be the same links' do
|
61
|
+
is_expected.to eq((<<-HTML
|
62
|
+
<link rel="alternate" hreflang="x-default" href="https://www.example.com/news/2019/06" />
|
63
|
+
<link rel="alternate" hreflang="en" href="https://www.example.com/news/2019/06" />
|
64
|
+
<link rel="alternate" hreflang="fr" href="https://www.example.com/fr/actualites/2019/06" />
|
65
|
+
HTML
|
66
|
+
).strip)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
54
71
|
end
|
55
72
|
|
56
73
|
end
|
@@ -31,7 +31,7 @@ describe Locomotive::Steam::Liquid::Tags::Authorize do
|
|
31
31
|
context 'unauthenticated account' do
|
32
32
|
|
33
33
|
it 'redirects to the sign in page' do
|
34
|
-
expect { subject }.to raise_error(Locomotive::Steam::RedirectionException, 'Redirect to /me/sign_in')
|
34
|
+
expect { subject }.to raise_error(Locomotive::Steam::RedirectionException, 'Redirect to /me/sign_in (302)')
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
@@ -93,11 +93,13 @@ describe Locomotive::Steam::Liquid::Tags::Editable::Text do
|
|
93
93
|
|
94
94
|
let(:live_editing) { false }
|
95
95
|
let(:element_editing) { true }
|
96
|
+
let(:wagon) { false }
|
96
97
|
|
97
|
-
let(:child_page)
|
98
|
-
let(:element)
|
99
|
-
let(:services)
|
100
|
-
let(:
|
98
|
+
let(:child_page) { instance_double('Page', fullpath: 'child-page') }
|
99
|
+
let(:element) { instance_double('EditableText', _id: 42, id: 42, content: nil, inline_editing?: element_editing, inline_editing: element_editing, format: 'html') }
|
100
|
+
let(:services) { Locomotive::Steam::Services.build_instance(nil) }
|
101
|
+
let(:repositories) { instance_double('Repositories') }
|
102
|
+
let(:context) { ::Liquid::Context.new({ 'wagon' => wagon }, {}, { page: child_page, services: services, repositories: repositories, live_editing: live_editing }) }
|
101
103
|
|
102
104
|
before { allow(services.editable_element).to receive(:find).and_return(element) }
|
103
105
|
|
@@ -193,6 +195,32 @@ describe Locomotive::Steam::Liquid::Tags::Editable::Text do
|
|
193
195
|
|
194
196
|
end
|
195
197
|
|
198
|
+
context 'site with sections' do
|
199
|
+
|
200
|
+
let(:repositories) { instance_double('Repositories', section: instance_double('SectionRepository', count: 1)) }
|
201
|
+
|
202
|
+
context 'in production' do
|
203
|
+
|
204
|
+
it "doesn't display the warning message" do
|
205
|
+
expect(Locomotive::Common::Logger).not_to receive(:error).with("[child-page] You can't use editable elements whereas you declared section(s)".colorize(:red))
|
206
|
+
subject
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
context 'in Wagon' do
|
212
|
+
|
213
|
+
let(:wagon) { true }
|
214
|
+
|
215
|
+
it "displays a warning message (because we don't allow editable elements and sections to be used together in the same site)" do
|
216
|
+
expect(Locomotive::Common::Logger).to receive(:error).with("[child-page] You can't use editable elements whereas you declared section(s)".colorize(:red))
|
217
|
+
subject
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
223
|
+
|
196
224
|
end
|
197
225
|
|
198
226
|
end
|
@@ -2,50 +2,137 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Locomotive::Steam::Liquid::Tags::Extends do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
describe 'unit bevahiors' do
|
6
|
+
|
7
|
+
before { Liquid::Template.file_system = ::Liquid::LayoutFileSystem.new }
|
8
|
+
|
9
|
+
before do
|
10
|
+
allow_any_instance_of(described_class).to receive(:parse_parent_template) do |instance|
|
11
|
+
::Liquid::Template.parse(
|
12
|
+
::Liquid::Template.file_system.read_template_file(
|
13
|
+
instance.instance_variable_get(:@template_name), {}
|
14
|
+
),
|
15
|
+
instance.parse_context
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:assigns) { {} }
|
21
|
+
subject { render_template(source, ::Liquid::Context.new(assigns)) }
|
22
|
+
|
23
|
+
context 'the template uses a wrong syntax of extends' do
|
24
|
+
let(:source) { '{% extends %}' }
|
25
|
+
it { expect { subject }.to raise_exception("Liquid syntax error (line 1): Syntax Error in 'extends' - Valid syntax: extends <page_handle_or_parent_keyword>") }
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'the template uses a endtag' do
|
29
|
+
let(:source) { '{% extends base %}{% endextends %}' }
|
30
|
+
it { is_expected.to eq '<body>base</body>' }
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'the template has a block' do
|
34
|
+
let(:source) { Liquid::Template.file_system.read_template_file('page_with_title', nil) }
|
35
|
+
it { is_expected.to eq '<body><h1>Hello</h1><p>Lorem ipsum</p></body>' }
|
36
|
+
end
|
16
37
|
|
17
|
-
|
38
|
+
context 'the template extends another template' do
|
39
|
+
let(:source) { '{% extends base %}' }
|
40
|
+
it { is_expected.to eq '<body>base</body>' }
|
41
|
+
end
|
18
42
|
|
19
|
-
|
20
|
-
|
43
|
+
context 'the template extends an inherited template' do
|
44
|
+
let(:source) { '{% extends inherited %}' }
|
45
|
+
it { is_expected.to eq '<body>base</body>' }
|
46
|
+
end
|
21
47
|
|
22
|
-
|
48
|
+
context 'the template can pass variables to the parent template' do
|
49
|
+
let(:assigns) { { 'name' => 'Macbook' } }
|
50
|
+
let(:source) { '{% extends product %}' }
|
51
|
+
it { is_expected.to eq '<body><h1>Our product: Macbook</h1></body>' }
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'the template can pass variables to the inherited parent template' do
|
55
|
+
let(:assigns) { { 'name' => 'PC' } }
|
56
|
+
let(:source) { '{% extends product_with_warranty %}' }
|
57
|
+
it { is_expected.to eq '<body><h1>Our product: PC</h1><p>mandatory warranty</p></body>' }
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'the template does not render statements outside blocks' do
|
61
|
+
let(:source) { '{% extends base %} Hello world' }
|
62
|
+
it { is_expected.to eq '<body>base</body>' }
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'the template extends another template with a single block' do
|
66
|
+
let(:source) { '{% extends page_with_title %}' }
|
67
|
+
it { is_expected.to eq '<body><h1>Hello</h1><p>Lorem ipsum</p></body>' }
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'the template overrides a block' do
|
71
|
+
let(:source) { '{% extends page_with_title %}{% block title %}Sweet{% endblock %}' }
|
72
|
+
it { is_expected.to eq '<body><h1>Sweet</h1><p>Lorem ipsum</p></body>' }
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'the template has access to the content of the overriden_block' do
|
76
|
+
let(:source) { '{% extends page_with_title %}{% block title %}{{ block.super }} world{% endblock %}' }
|
77
|
+
it { is_expected.to eq '<body><h1>Hello world</h1><p>Lorem ipsum</p></body>' }
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'the template accepts nested blocks' do
|
81
|
+
let(:assigns) { { 'name' => 'iPhone' } }
|
82
|
+
let(:source) { '{% extends product_with_static_price %}{% block info/price %}{{ block.super }}<p>(not on sale)</p>{% endblock %}' }
|
83
|
+
it { is_expected.to eq '<body><h1>Our product: iPhone</h1><h2>Some info</h2><p>$42.00</p><p>(not on sale)</p></body>' }
|
84
|
+
end
|
23
85
|
|
24
86
|
end
|
25
87
|
|
26
|
-
describe '
|
88
|
+
describe 'in Steam' do
|
89
|
+
|
90
|
+
let(:source) { '{% extends parent %} ' }
|
91
|
+
let(:page) { instance_double('Page', title: 'About us') }
|
92
|
+
let(:site) { instance_double('Site', default_locale: :en) }
|
93
|
+
let!(:listener) { Liquid::SimpleEventsListener.new }
|
94
|
+
let(:finder) { Locomotive::Steam::ParentFinderService.new(instance_double('PageRepository', site: site, locale: :en)) }
|
95
|
+
let(:parser) { Locomotive::Steam::LiquidParserService.new(nil, nil) }
|
96
|
+
let(:options) { { parent_finder: finder, page: page, parser: parser } }
|
97
|
+
|
98
|
+
before do
|
99
|
+
expect(finder.repository).to receive(:parent_of).with(page).and_return(parent)
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'no parent page found' do
|
103
|
+
|
104
|
+
let(:parent) { nil }
|
105
|
+
let(:template) { parse_template(source, options) }
|
106
|
+
|
107
|
+
it { expect { template }.to raise_exception Locomotive::Steam::Liquid::PageNotFound }
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
describe 'parent page exists' do
|
112
|
+
|
113
|
+
let!(:template) { parse_template(source, options) }
|
27
114
|
|
28
|
-
|
115
|
+
let(:parent) { instance_double('Index', handle: nil, slug: nil, localized_attributes: { source: true, template: true }, source: { en: 'Hello world!' }, template: { en: nil }) }
|
29
116
|
|
30
|
-
|
117
|
+
it { expect(listener.event_names.first).to eq 'steam.parse.extends' }
|
118
|
+
it { expect(template.render).to eq 'Hello world!' }
|
119
|
+
it { expect(options[:page]).to eq page }
|
31
120
|
|
32
|
-
|
33
|
-
it { expect(template.render).to eq 'Hello world!' }
|
34
|
-
it { expect(options[:page]).to eq page }
|
121
|
+
describe 'set the layout name' do
|
35
122
|
|
36
|
-
|
123
|
+
let(:source) { '{% extends parent %}{% block message %}My layout: {{ layout_name }}{% endblock %}' }
|
37
124
|
|
38
|
-
|
125
|
+
let(:parent) { instance_double('Index', handle: nil, slug: 'index', localized_attributes: { source: true, template: true }, source: { en: 'Hello world! {% block message %}{% endblock %}' }, template: { en: nil }) }
|
39
126
|
|
40
|
-
|
127
|
+
it { expect(template.render).to eq 'Hello world! My layout: index' }
|
41
128
|
|
42
|
-
|
129
|
+
context 'the handle of the parent page exists' do
|
43
130
|
|
44
|
-
|
131
|
+
let(:parent) { instance_double('Index', handle: 'home', slug: 'index', localized_attributes: { source: true, template: true }, source: { en: 'Hello world! {% block message %}{% endblock %}' }, template: { en: nil }) }
|
45
132
|
|
46
|
-
|
133
|
+
it { expect(template.render).to eq 'Hello world! My layout: home' }
|
47
134
|
|
48
|
-
|
135
|
+
end
|
49
136
|
|
50
137
|
end
|
51
138
|
|
@@ -8,9 +8,10 @@ describe Locomotive::Steam::Liquid::Tags::GlobalSection do
|
|
8
8
|
let(:source) { 'Locomotive {% global_section header %}' }
|
9
9
|
let(:live_editing) { true }
|
10
10
|
let(:content) { {} }
|
11
|
+
let(:file_system) { Locomotive::Steam::Liquid::FileSystem.new(section_finder: finder) }
|
11
12
|
let(:site) { liquid_instance_double('Site', sections_content: content) }
|
12
13
|
let(:assigns) { { 'site' => site } }
|
13
|
-
let(:context) { ::Liquid::Context.new(assigns, {}, { services: services, live_editing: live_editing }) }
|
14
|
+
let(:context) { ::Liquid::Context.new(assigns, {}, { services: services, live_editing: live_editing, file_system: file_system }) }
|
14
15
|
|
15
16
|
before do
|
16
17
|
allow(finder).to receive(:find).and_return(section)
|
@@ -121,8 +122,8 @@ describe Locomotive::Steam::Liquid::Tags::GlobalSection do
|
|
121
122
|
definition: { settings: [], blocks: [] }
|
122
123
|
)}
|
123
124
|
|
124
|
-
it 'raises
|
125
|
-
expect { subject }.to raise_exception(Locomotive::Steam::
|
125
|
+
it 'raises an TemplateError' do
|
126
|
+
expect { subject }.to raise_exception(Locomotive::Steam::TemplateError)
|
126
127
|
end
|
127
128
|
end
|
128
129
|
|
@@ -2,13 +2,32 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Locomotive::Steam::Liquid::Tags::GoogleAnalytics do
|
4
4
|
|
5
|
-
let(:
|
5
|
+
let(:context) { ::Liquid::Context.new({ 'ga_id' => '42' })}
|
6
|
+
let(:source) { "{% google_analytics 42 %}" }
|
6
7
|
|
7
|
-
subject { render_template(source) }
|
8
|
+
subject { render_template(source, context) }
|
8
9
|
|
9
10
|
it { is_expected.to include %{<script async src="https://www.googletagmanager.com/gtag/js?id=42"></script>} }
|
10
11
|
it { is_expected.to include "gtag('config', '42');" }
|
11
12
|
|
13
|
+
describe 'passing a string' do
|
14
|
+
|
15
|
+
let(:source) { "{% google_analytics 'ga-42' %}" }
|
16
|
+
|
17
|
+
it { is_expected.to include %{<script async src="https://www.googletagmanager.com/gtag/js?id=ga-42"></script>} }
|
18
|
+
it { is_expected.to include "gtag('config', 'ga-42');" }
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'passing a variable' do
|
23
|
+
|
24
|
+
let(:source) { "{% google_analytics ga_id %}" }
|
25
|
+
|
26
|
+
it { is_expected.to include %{<script async src="https://www.googletagmanager.com/gtag/js?id=42"></script>} }
|
27
|
+
it { is_expected.to include "gtag('config', '42');" }
|
28
|
+
|
29
|
+
end
|
30
|
+
|
12
31
|
describe 'raises an error if the syntax is incorrect' do
|
13
32
|
let(:source) { '{% google_analytics %}' }
|
14
33
|
it { expect { subject }.to raise_exception(::Liquid::SyntaxError) }
|
@@ -11,27 +11,39 @@ describe Locomotive::Steam::Liquid::Tags::InheritedBlock do
|
|
11
11
|
let(:finder) { instance_double('Finder', find: parent) }
|
12
12
|
let(:options) { { page: page, parent_finder: finder, parser: Locomotive::Steam::LiquidParserService.new(nil, nil) } }
|
13
13
|
|
14
|
-
|
14
|
+
subject { parse_template(source, options) }
|
15
|
+
|
16
|
+
describe 'wrong syntax' do
|
17
|
+
|
18
|
+
let(:source) { '{% extends parent %}{% block %}Hello world{% endblock %}' }
|
19
|
+
it { expect { subject }.to raise_exception(Liquid::SyntaxError) }
|
20
|
+
end
|
15
21
|
|
16
22
|
describe 'without a super block' do
|
17
23
|
|
24
|
+
before { subject }
|
25
|
+
|
18
26
|
it { expect(listener.events.size).to eq 3 }
|
19
27
|
it { expect(listener.events.first.last[:found_super]).to eq false }
|
20
|
-
it { expect(
|
28
|
+
it { expect(subject.render).to eq 'My product: Skis' }
|
21
29
|
|
22
30
|
end
|
23
31
|
|
24
32
|
describe 'with a super block' do
|
25
33
|
|
34
|
+
before { subject }
|
35
|
+
|
26
36
|
let(:source) { '{% extends parent %}{% block product %}Skis (previous: {{ block.super }}){% endblock %}' }
|
27
37
|
|
28
38
|
it { expect(listener.events.first.last[:found_super]).to eq true }
|
29
|
-
it { expect(
|
39
|
+
it { expect(subject.render).to eq 'My product: Skis (previous: Random)' }
|
30
40
|
|
31
41
|
end
|
32
42
|
|
33
43
|
describe 'passing options' do
|
34
44
|
|
45
|
+
before { subject }
|
46
|
+
|
35
47
|
let(:source) { '{% extends parent %}{% block product, short_name: true, priority: 10 %}Skis{% endblock %}' }
|
36
48
|
|
37
49
|
it { expect(listener.events.size).to eq 3 }
|
@@ -45,9 +57,11 @@ describe Locomotive::Steam::Liquid::Tags::InheritedBlock do
|
|
45
57
|
|
46
58
|
describe 'live editing on' do
|
47
59
|
|
60
|
+
before { subject }
|
61
|
+
|
48
62
|
let(:context) { ::Liquid::Context.new({}, {}, { live_editing: true }) }
|
49
63
|
|
50
|
-
it { expect(
|
64
|
+
it { expect(subject.render(context)).to eq 'My product: <span class="locomotive-block-anchor" data-element-id="product" style="visibility: hidden"></span>Skis' }
|
51
65
|
|
52
66
|
end
|
53
67
|
|
@@ -20,7 +20,7 @@ describe Locomotive::Steam::Liquid::Tags::PathTo do
|
|
20
20
|
context 'unknown tag' do
|
21
21
|
|
22
22
|
let(:source) { '{% link_to index %}{% endbar %}{% endlink_to %}' }
|
23
|
-
it { expect { subject }.to raise_error("Liquid syntax error (line 1):
|
23
|
+
it { expect { subject }.to raise_error("Liquid syntax error (line 1): 'endbar' is not a valid delimiter for link_to tags. use endlink_to") }
|
24
24
|
|
25
25
|
end
|
26
26
|
|
@@ -19,6 +19,13 @@ describe Locomotive::Steam::Liquid::Tags::ModelForm do
|
|
19
19
|
|
20
20
|
it { is_expected.to eq %(<form method="POST" enctype="multipart/form-data"><input type="hidden" name="content_type_slug" value="newsletter_addresses" /><input type="hidden" name="token" value="42" />Newsletter Form</form>) }
|
21
21
|
|
22
|
+
describe 'invalid syntax' do
|
23
|
+
|
24
|
+
let(:source) { "{% model_form %}Hello world{% endmodel_form %}" }
|
25
|
+
it { expect { subject }.to raise_error("Liquid syntax error (line 1): Syntax Error in 'model_form' - Valid syntax: model_form <content_type_slug>(, <attributes>)") }
|
26
|
+
|
27
|
+
end
|
28
|
+
|
22
29
|
describe 'with a different dom id and css class' do
|
23
30
|
|
24
31
|
let(:source) { "{% model_form 'newsletter_addresses', id: 'my-form', class: 'col-md-12' %}Newsletter Form{% endmodel_form %}" }
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Locomotive::Steam::Liquid::Tags::PageNotFound do
|
4
|
+
|
5
|
+
let(:template) { '{% render_page_not_found %}' }
|
6
|
+
let(:context) { ::Liquid::Context.new({}, {}, {}) }
|
7
|
+
|
8
|
+
subject { render_template(template, context) }
|
9
|
+
|
10
|
+
it 'raises an exception' do
|
11
|
+
expect { subject }.to raise_error(Locomotive::Steam::PageNotFoundException)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|