locomotivecms_steam 1.4.1 → 1.5.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +31 -25
  4. data/Rakefile +2 -2
  5. data/config/locales/pt-BR.yml +43 -13
  6. data/lib/locomotive/steam.rb +9 -4
  7. data/lib/locomotive/steam/adapters/filesystem.rb +2 -7
  8. data/lib/locomotive/steam/adapters/filesystem/sanitizer.rb +0 -2
  9. data/lib/locomotive/steam/adapters/filesystem/sanitizers/page.rb +11 -0
  10. data/lib/locomotive/steam/adapters/filesystem/sanitizers/section.rb +37 -0
  11. data/lib/locomotive/steam/adapters/filesystem/sanitizers/site.rb +18 -0
  12. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb +4 -3
  13. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_type.rb +4 -3
  14. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/section.rb +40 -0
  15. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/snippet.rb +0 -1
  16. data/lib/locomotive/steam/adapters/memory.rb +1 -1
  17. data/lib/locomotive/steam/entities/content_entry.rb +15 -3
  18. data/lib/locomotive/steam/entities/content_type.rb +2 -1
  19. data/lib/locomotive/steam/entities/page.rb +21 -19
  20. data/lib/locomotive/steam/entities/section.rb +24 -0
  21. data/lib/locomotive/steam/entities/site.rb +3 -1
  22. data/lib/locomotive/steam/liquid.rb +2 -0
  23. data/lib/locomotive/steam/liquid/drops/page.rb +4 -2
  24. data/lib/locomotive/steam/liquid/drops/params.rb +51 -0
  25. data/lib/locomotive/steam/liquid/drops/section.rb +56 -0
  26. data/lib/locomotive/steam/liquid/drops/section_block.rb +47 -0
  27. data/lib/locomotive/steam/liquid/drops/section_content_proxy.rb +97 -0
  28. data/lib/locomotive/steam/liquid/drops/section_editor_setting_data.rb +65 -0
  29. data/lib/locomotive/steam/liquid/drops/site.rb +2 -1
  30. data/lib/locomotive/steam/liquid/errors.rb +2 -0
  31. data/lib/locomotive/steam/liquid/filters/base.rb +3 -3
  32. data/lib/locomotive/steam/liquid/filters/date.rb +1 -1
  33. data/lib/locomotive/steam/liquid/filters/html.rb +7 -2
  34. data/lib/locomotive/steam/liquid/filters/json.rb +3 -1
  35. data/lib/locomotive/steam/liquid/tags/action.rb +2 -2
  36. data/lib/locomotive/steam/liquid/tags/alt_page_links.rb +63 -0
  37. data/lib/locomotive/steam/liquid/tags/concerns/i18n_page.rb +1 -1
  38. data/lib/locomotive/steam/liquid/tags/concerns/section.rb +117 -0
  39. data/lib/locomotive/steam/liquid/tags/global_section.rb +32 -0
  40. data/lib/locomotive/steam/liquid/tags/model_form.rb +1 -1
  41. data/lib/locomotive/steam/liquid/tags/section.rb +87 -0
  42. data/lib/locomotive/steam/liquid/tags/sections_dropzone.rb +56 -0
  43. data/lib/locomotive/steam/liquid/tags/snippet.rb +3 -2
  44. data/lib/locomotive/steam/liquid/template.rb +0 -5
  45. data/lib/locomotive/steam/middlewares.rb +1 -1
  46. data/lib/locomotive/steam/middlewares/auth.rb +29 -13
  47. data/lib/locomotive/steam/middlewares/concerns/helpers.rb +59 -0
  48. data/lib/locomotive/steam/middlewares/concerns/liquid_context.rb +94 -0
  49. data/lib/locomotive/steam/middlewares/encoded_link_redirection.rb +45 -0
  50. data/lib/locomotive/steam/middlewares/entry_submission.rb +1 -1
  51. data/lib/locomotive/steam/middlewares/favicon.rb +1 -1
  52. data/lib/locomotive/steam/middlewares/locale.rb +63 -15
  53. data/lib/locomotive/steam/middlewares/locale_redirection.rb +18 -6
  54. data/lib/locomotive/steam/middlewares/logging.rb +1 -1
  55. data/lib/locomotive/steam/middlewares/page.rb +35 -6
  56. data/lib/locomotive/steam/middlewares/path.rb +1 -1
  57. data/lib/locomotive/steam/middlewares/private_access.rb +1 -1
  58. data/lib/locomotive/steam/middlewares/redirection.rb +1 -1
  59. data/lib/locomotive/steam/middlewares/renderer.rb +2 -82
  60. data/lib/locomotive/steam/middlewares/robots.rb +1 -1
  61. data/lib/locomotive/steam/middlewares/section.rb +56 -0
  62. data/lib/locomotive/steam/middlewares/site.rb +1 -1
  63. data/lib/locomotive/steam/middlewares/sitemap.rb +58 -45
  64. data/lib/locomotive/steam/middlewares/templatized_page.rb +1 -1
  65. data/lib/locomotive/steam/middlewares/thread_safe.rb +85 -2
  66. data/lib/locomotive/steam/middlewares/timezone.rb +1 -1
  67. data/lib/locomotive/steam/middlewares/url_redirection.rb +1 -1
  68. data/lib/locomotive/steam/models/entity.rb +0 -2
  69. data/lib/locomotive/steam/models/mapper.rb +5 -3
  70. data/lib/locomotive/steam/models/scope.rb +8 -0
  71. data/lib/locomotive/steam/repositories.rb +4 -0
  72. data/lib/locomotive/steam/repositories/content_entry_repository.rb +6 -2
  73. data/lib/locomotive/steam/repositories/page_repository.rb +4 -1
  74. data/lib/locomotive/steam/repositories/section_repository.rb +14 -0
  75. data/lib/locomotive/steam/repositories/site_repository.rb +1 -1
  76. data/lib/locomotive/steam/repositories/snippet_repository.rb +0 -3
  77. data/lib/locomotive/steam/server.rb +3 -1
  78. data/lib/locomotive/steam/services.rb +17 -1
  79. data/lib/locomotive/steam/services/action_service.rb +10 -0
  80. data/lib/locomotive/steam/services/concerns/decorator.rb +0 -2
  81. data/lib/locomotive/steam/services/image_resizer_service.rb +1 -1
  82. data/lib/locomotive/steam/services/page_finder_service.rb +6 -0
  83. data/lib/locomotive/steam/services/section_finder_service.rb +17 -0
  84. data/lib/locomotive/steam/services/url_builder_service.rb +31 -17
  85. data/lib/locomotive/steam/services/url_finder_service.rb +87 -0
  86. data/lib/locomotive/steam/version.rb +2 -2
  87. data/locomotivecms_steam.gemspec +1 -1
  88. data/spec/fixtures/default/app/views/pages/tags/section.liquid.haml +11 -0
  89. data/spec/fixtures/default/app/views/sections/carousel.liquid +20 -0
  90. data/spec/fixtures/default/app/views/sections/footer.liquid +48 -0
  91. data/spec/fixtures/default/app/views/sections/header.liquid +54 -0
  92. data/spec/fixtures/default/config/deploy.yml +1 -1
  93. data/spec/fixtures/errors/section_bad_json_content.liquid +9 -0
  94. data/spec/fixtures/errors/section_bad_json_header.liquid +8 -0
  95. data/spec/fixtures/mongodb/locomotive_accounts.bson +0 -0
  96. data/spec/fixtures/mongodb/locomotive_accounts.metadata.json +1 -1
  97. data/spec/fixtures/mongodb/locomotive_activities.bson +0 -0
  98. data/spec/fixtures/mongodb/locomotive_activities.metadata.json +1 -1
  99. data/spec/fixtures/mongodb/locomotive_content_assets.bson +0 -0
  100. data/spec/fixtures/mongodb/locomotive_content_assets.metadata.json +1 -1
  101. data/spec/fixtures/mongodb/locomotive_content_entries.bson +0 -0
  102. data/spec/fixtures/mongodb/locomotive_content_entries.metadata.json +1 -1
  103. data/spec/fixtures/mongodb/locomotive_content_types.bson +0 -0
  104. data/spec/fixtures/mongodb/locomotive_content_types.metadata.json +1 -1
  105. data/spec/fixtures/mongodb/locomotive_pages.bson +0 -0
  106. data/spec/fixtures/mongodb/locomotive_pages.metadata.json +1 -1
  107. data/spec/fixtures/mongodb/locomotive_sections.bson +0 -0
  108. data/spec/fixtures/mongodb/{sessions.metadata.json → locomotive_sections.metadata.json} +1 -1
  109. data/spec/fixtures/mongodb/locomotive_sites.bson +0 -0
  110. data/spec/fixtures/mongodb/locomotive_sites.metadata.json +1 -1
  111. data/spec/fixtures/mongodb/locomotive_snippets.bson +0 -0
  112. data/spec/fixtures/mongodb/locomotive_snippets.metadata.json +1 -1
  113. data/spec/fixtures/mongodb/locomotive_theme_assets.bson +0 -0
  114. data/spec/fixtures/mongodb/locomotive_theme_assets.metadata.json +1 -1
  115. data/spec/fixtures/mongodb/locomotive_translations.bson +0 -0
  116. data/spec/fixtures/mongodb/locomotive_translations.metadata.json +1 -1
  117. data/spec/integration/repositories/content_entry_repository_spec.rb +1 -1
  118. data/spec/integration/repositories/page_repository_spec.rb +1 -1
  119. data/spec/integration/repositories/theme_asset_repository_spec.rb +1 -1
  120. data/spec/integration/server/auth_spec.rb +0 -4
  121. data/spec/integration/server/basic_spec.rb +8 -0
  122. data/spec/integration/server/contact_form_spec.rb +15 -2
  123. data/spec/integration/server/sitemap_spec.rb +5 -3
  124. data/spec/integration/services/content_entry_service_spec.rb +1 -1
  125. data/spec/support/helpers.rb +3 -3
  126. data/spec/unit/adapters/filesystem/sanitizers/section_spec.rb +65 -0
  127. data/spec/unit/adapters/filesystem/sanitizers/site_spec.rb +28 -2
  128. data/spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb +8 -4
  129. data/spec/unit/adapters/filesystem/yaml_loaders/content_type_spec.rb +2 -2
  130. data/spec/unit/adapters/filesystem/yaml_loaders/page_spec.rb +1 -1
  131. data/spec/unit/adapters/filesystem/yaml_loaders/section_spec.rb +27 -0
  132. data/spec/unit/entities/section_spec.rb +29 -0
  133. data/spec/unit/liquid/drops/params_spec.rb +38 -0
  134. data/spec/unit/liquid/drops/section_content_proxy_spec.rb +88 -0
  135. data/spec/unit/liquid/drops/section_spec.rb +26 -0
  136. data/spec/unit/liquid/filters/html_spec.rb +198 -170
  137. data/spec/unit/liquid/filters/json_spec.rb +7 -0
  138. data/spec/unit/liquid/tags/action_spec.rb +12 -2
  139. data/spec/unit/liquid/tags/alt_page_links_spec.rb +58 -0
  140. data/spec/unit/liquid/tags/global_section_spec.rb +130 -0
  141. data/spec/unit/liquid/tags/link_to_spec.rb +1 -1
  142. data/spec/unit/liquid/tags/locale_switcher_spec.rb +1 -1
  143. data/spec/unit/liquid/tags/model_form_spec.rb +8 -0
  144. data/spec/unit/liquid/tags/path_to_spec.rb +26 -3
  145. data/spec/unit/liquid/tags/section_spec.rb +231 -0
  146. data/spec/unit/liquid/tags/sections_dropzone_spec.rb +107 -0
  147. data/spec/unit/middlewares/auth_spec.rb +9 -2
  148. data/spec/unit/middlewares/encoded_link_redirection_spec.rb +73 -0
  149. data/spec/unit/middlewares/entry_submission_spec.rb +1 -1
  150. data/spec/unit/middlewares/helpers_spec.rb +3 -64
  151. data/spec/unit/middlewares/locale_redirection_spec.rb +13 -2
  152. data/spec/unit/middlewares/locale_spec.rb +52 -10
  153. data/spec/unit/middlewares/page_spec.rb +57 -16
  154. data/spec/unit/middlewares/private_access_spec.rb +1 -1
  155. data/spec/unit/middlewares/redirection_spec.rb +1 -1
  156. data/spec/unit/middlewares/renderer_spec.rb +2 -1
  157. data/spec/unit/middlewares/section_spec.rb +70 -0
  158. data/spec/unit/middlewares/site_spec.rb +1 -1
  159. data/spec/unit/middlewares/sitemap_spec.rb +4 -42
  160. data/spec/unit/middlewares/url_redirection_spec.rb +1 -1
  161. data/spec/unit/repositories/content_entry_repository_spec.rb +13 -13
  162. data/spec/unit/repositories/section_repository_spec.rb +38 -0
  163. data/spec/unit/repositories/snippet_repository_spec.rb +0 -3
  164. data/spec/unit/services/action_service_spec.rb +19 -1
  165. data/spec/unit/services/asset_host_service_spec.rb +8 -0
  166. data/spec/unit/services/parent_finder_service_spec.rb +1 -2
  167. data/spec/unit/services/section_finder_service_spec.rb +28 -0
  168. data/spec/unit/services/url_builder_service_spec.rb +14 -4
  169. data/spec/unit/services/url_finder_service_spec.rb +100 -0
  170. data/spec/unit/services_spec.rb +34 -20
  171. metadata +72 -11
  172. data/lib/locomotive/steam/middlewares/helpers.rb +0 -140
  173. data/spec/fixtures/mongodb/sessions.bson +0 -0
@@ -54,6 +54,13 @@ describe Locomotive::Steam::Liquid::Filters::Json do
54
54
 
55
55
  end
56
56
 
57
+ describe '#Render Hash' do
58
+
59
+ let(:input) { [{'foo': 'bar'}] }
60
+ it { expect(subject).to eq %({"foo":"bar"}) }
61
+
62
+ end
63
+
57
64
  describe '#open_json' do
58
65
 
59
66
  let(:input) { '' }
@@ -5,8 +5,9 @@ describe Locomotive::Steam::Liquid::Tags::Action do
5
5
  let(:site) { instance_double('Site', default_locale: 'en') }
6
6
  let(:source) { '{% action "random Javascript action" %}var foo = 42; setProp("foo", foo);{% endaction %}' }
7
7
  let(:assigns) { {} }
8
+ let(:registers) { { services: services } }
8
9
  let(:services) { Locomotive::Steam::Services.build_instance }
9
- let(:context) { ::Liquid::Context.new(assigns, {}, { services: services }) }
10
+ let(:context) { ::Liquid::Context.new(assigns, {}, registers) }
10
11
 
11
12
  before { allow(services).to receive(:current_site).and_return(site) }
12
13
 
@@ -27,9 +28,18 @@ describe Locomotive::Steam::Liquid::Tags::Action do
27
28
 
28
29
  it { subject; expect(context['foo']).to eq 42.0 }
29
30
 
31
+ describe 'accessing params through props' do
32
+
33
+ let(:assigns) { { 'params' => Locomotive::Steam::Liquid::Drops::Params.new({ foo: 'bar' }) } }
34
+ let(:source) { '{% action "getProps" %}var params = getProp("params");setProp("result", params.foo);{% endaction %}' }
35
+
36
+ it { subject; expect(context['result']).to eq('bar') }
37
+
38
+ end
39
+
30
40
  describe 'uploaded file' do
31
41
 
32
- let(:assigns) { { 'params' => { 'my_file' => { 'tempfile' => Tempfile.new('my_file') } } } }
42
+ let(:registers) { { services: services, params: { 'my_file' => { 'tempfile' => Tempfile.new('my_file') } } } }
33
43
  let(:source) { '{% action "uploaded file" %}setProp("path", params.my_file.tempfile);{% endaction %}' }
34
44
 
35
45
  it { subject; expect(context['path']).to match /\/my_file/ }
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Steam::Liquid::Tags::AltPageLinks do
4
+
5
+ let(:locale) { 'en' }
6
+ let(:assigns) { { 'page' => drop, 'base_url' => 'https://www.example.com' } }
7
+ let(:prefix_default) { false }
8
+ let(:services) { Locomotive::Steam::Services.build_instance }
9
+ let(:locales) { %w(en) }
10
+ let(:site) { instance_double('Site', locales: locales, default_locale: 'en', prefix_default_locale: prefix_default) }
11
+ let(:drop) { Locomotive::Steam::Liquid::Drops::Page.new(page) }
12
+ let(:page) { liquid_instance_double('Index', index?: true, localized_attributes: { title: true, fullpath: true }, title: { en: 'Home', fr: 'Accueil' }, fullpath: { en: 'index', fr: 'index' }, templatized?: false) }
13
+ let(:context) { ::Liquid::Context.new(assigns, {}, { services: services, site: site, locale: locale }) }
14
+
15
+ subject { render_template(source, context) }
16
+
17
+ before { allow(services).to receive(:current_site).and_return(site) }
18
+
19
+ describe 'default rendering' do
20
+
21
+ let(:source) { '{% alt_page_links %}' }
22
+
23
+ it 'renders an empty string if one single locale' do
24
+ is_expected.to eq('')
25
+ end
26
+
27
+ context 'multilingual site' do
28
+
29
+ let(:locales) { %w(en fr) }
30
+
31
+ it { is_expected.to eq((<<-HTML
32
+ <link rel="alternate" hreflang="x-default" href="https://www.example.com/" />
33
+ <link rel="alternate" hreflang="en" href="https://www.example.com/en" />
34
+ <link rel="alternate" hreflang="fr" href="https://www.example.com/fr" />
35
+ HTML
36
+ ).strip)
37
+ }
38
+
39
+ context 'the current locale is different from the default one' do
40
+
41
+ let(:locale) { 'fr' }
42
+
43
+ it 'has to be the same links' do
44
+ is_expected.to eq((<<-HTML
45
+ <link rel="alternate" hreflang="x-default" href="https://www.example.com/" />
46
+ <link rel="alternate" hreflang="en" href="https://www.example.com/en" />
47
+ <link rel="alternate" hreflang="fr" href="https://www.example.com/fr" />
48
+ HTML
49
+ ).strip)
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+
58
+ end
@@ -0,0 +1,130 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Steam::Liquid::Tags::GlobalSection do
4
+
5
+ let(:services) { Locomotive::Steam::Services.build_instance(nil) }
6
+ let(:finder) { services.section_finder }
7
+ let(:source) { 'Locomotive {% global_section header %}' }
8
+ let(:live_editing) { true }
9
+ let(:content) { {} }
10
+ let(:site) { liquid_instance_double('Site', sections_content: content) }
11
+ let(:assigns) { { 'site' => site } }
12
+ let(:context) { ::Liquid::Context.new(assigns, {}, { services: services, live_editing: live_editing }) }
13
+
14
+ before do
15
+ allow(finder).to receive(:find).and_return(section)
16
+ end
17
+
18
+ describe 'rendering' do
19
+
20
+ let(:definition) { {
21
+ type: 'header',
22
+ class: 'my-awesome-header',
23
+ settings: [
24
+ { id: 'brand', type: 'text', label: 'Brand' },
25
+ { id: 'image', type: 'image_picker' }
26
+ ],
27
+ blocks: [
28
+ { type: 'menu_item', settings: [
29
+ { id: 'title', type: 'text' },
30
+ { id: 'image', type: 'image_picker' }
31
+ ]}
32
+ ],
33
+ default: {
34
+ settings: { brand: 'NoCoffee', image: 'foo.png' },
35
+ blocks: [{ id: 42, type: 'menu_item', settings: { title: 'Home', image: 'foo.png' } }] }
36
+ }.deep_stringify_keys }
37
+
38
+ let(:section) { instance_double(
39
+ 'Header',
40
+ slug: 'header',
41
+ type: 'header',
42
+ liquid_source: liquid_source,
43
+ definition: definition,
44
+ )}
45
+
46
+ subject { render_template(source, context) }
47
+
48
+ context 'no block' do
49
+
50
+ let(:liquid_source) { %(built by <a>\n\t<strong>{{ section.settings.brand }}</strong></a>) }
51
+
52
+ it { is_expected.to eq %(Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header">built by <a>\n\t<strong data-locomotive-editor-setting="section-site-header.brand">NoCoffee</strong></a></div>) }
53
+
54
+ context 'capturing the setting in a liquid variable' do
55
+
56
+ let(:liquid_source) { %({% capture brand %}<strong class="bold">{{ section.settings.brand }}</strong>{% endcapture %}built by <a>\n\t{{ brand }}</a>) }
57
+
58
+ it { is_expected.to eq %(Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header">built by <a>\n\t<strong class="bold" data-locomotive-editor-setting="section-site-header.brand">NoCoffee</strong></a></div>) }
59
+
60
+ end
61
+
62
+
63
+ context 'with a non string type input' do
64
+
65
+ let(:liquid_source) { 'built by <strong>{{ section.settings.image }}</strong>' }
66
+
67
+ it { is_expected.to eq 'Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header">built by <strong>foo.png</strong></div>' }
68
+
69
+ end
70
+
71
+ context 'without the live editing feature enabled' do
72
+
73
+ let(:live_editing) { false }
74
+
75
+ it { is_expected.to eq %(Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header">built by <a>\n\t<strong>NoCoffee</strong></a></div>) }
76
+
77
+ end
78
+
79
+ end
80
+
81
+ context 'with blocks' do
82
+
83
+ let(:liquid_source) { '{% for foo in section.blocks %}<a href="/">{{ foo.settings.title }}</a>{% endfor %}' }
84
+
85
+ it { is_expected.to eq 'Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header"><a href="/" data-locomotive-editor-setting="section-site-header-block.42.title">Home</a></div>' }
86
+
87
+ context 'with a non text type input' do
88
+
89
+ let(:liquid_source) { '{% for foo in section.blocks %}<a>{{ foo.settings.image }}</a>{% endfor %}' }
90
+
91
+ it { is_expected.to eq 'Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header"><a>foo.png</a></div>' }
92
+
93
+ end
94
+
95
+ end
96
+
97
+ context 'with site value' do
98
+ let(:content) {
99
+ {
100
+ header: {
101
+ settings: { brand: 'Locomotive' },
102
+ blocks: []
103
+ }
104
+ }.deep_stringify_keys
105
+ }
106
+
107
+ let(:liquid_source) { 'built by <strong>{{ section.settings.brand }}</strong>' }
108
+
109
+ it { is_expected.to eq 'Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header">built by <strong data-locomotive-editor-setting="section-site-header.brand">Locomotive</strong></div>' }
110
+
111
+ end
112
+
113
+ context 'rendering error (action) found in the section' do
114
+
115
+ let(:live_editing) { false }
116
+ let(:liquid_source) { '{% action "Hello world" %}a.b(+}{% endaction %}' }
117
+ let(:section) { instance_double('section',
118
+ name: 'Hero',
119
+ liquid_source: liquid_source,
120
+ definition: { settings: [], blocks: [] }
121
+ )}
122
+
123
+ it 'raises ParsingRenderingError' do
124
+ expect { subject }.to raise_exception(Locomotive::Steam::ParsingRenderingError)
125
+ end
126
+ end
127
+
128
+ end
129
+
130
+ end
@@ -71,7 +71,7 @@ describe Locomotive::Steam::Liquid::Tags::PathTo do
71
71
  context 'prefix_default_locale is true' do
72
72
 
73
73
  let(:prefix_default) { true }
74
- it { is_expected.to eq 'My link: <a href="/en/">Home</a>!' }
74
+ it { is_expected.to eq 'My link: <a href="/en">Home</a>!' }
75
75
 
76
76
  end
77
77
 
@@ -30,7 +30,7 @@ describe Locomotive::Steam::Liquid::Tags::LocaleSwitcher do
30
30
  context 'prefix_default_locale is true' do
31
31
 
32
32
  let(:prefix_default) { true }
33
- it { is_expected.to eq '<div id="locale-switcher"><a href="/en/" class="en current">en</a> | <a href="/fr" class="fr">fr</a></div>' }
33
+ it { is_expected.to eq '<div id="locale-switcher"><a href="/en" class="en current">en</a> | <a href="/fr" class="fr">fr</a></div>' }
34
34
 
35
35
  end
36
36
 
@@ -47,6 +47,14 @@ describe Locomotive::Steam::Liquid::Tags::ModelForm do
47
47
 
48
48
  end
49
49
 
50
+ context 'rendered at /_app/foo/preview/contact' do
51
+
52
+ let(:path) { '/_app/foo/preview/contact' }
53
+ let(:env) { { 'steam.mounted_on' => '/_app/foo/preview/' } }
54
+ it { is_expected.to eq %(<form method="POST" enctype="multipart/form-data" action="/_app/foo/preview/contact.json"><input type="hidden" name="content_type_slug" value="newsletter_addresses" /><input type="hidden" name="token" value="42" />Newsletter Form</form>) }
55
+
56
+ end
57
+
50
58
  end
51
59
 
52
60
  describe 'specifying an action' do
@@ -4,9 +4,11 @@ describe Locomotive::Steam::Liquid::Tags::PathTo do
4
4
 
5
5
  let(:prefix_default) { false }
6
6
  let(:assigns) { {} }
7
+ let(:current_locale) { 'en' }
8
+ let(:locales) { ['en'] }
7
9
  let(:services) { Locomotive::Steam::Services.build_instance }
8
- let(:site) { instance_double('Site', locales: ['en'], default_locale: 'en', prefix_default_locale: prefix_default) }
9
- let(:context) { ::Liquid::Context.new(assigns, {}, { services: services, site: site, locale: 'en' }) }
10
+ let(:site) { instance_double('Site', locales: locales, default_locale: 'en', prefix_default_locale: prefix_default) }
11
+ let(:context) { ::Liquid::Context.new(assigns, {}, { services: services, site: site, locale: current_locale }) }
10
12
 
11
13
  subject { render_template(source, context) }
12
14
 
@@ -52,10 +54,31 @@ describe Locomotive::Steam::Liquid::Tags::PathTo do
52
54
 
53
55
  end
54
56
 
57
+ context 'the current locale in session is different from the requested locale' do
58
+
59
+ let(:current_locale) { 'fr' }
60
+ let(:locales) { ['en', 'fr'] }
61
+ let(:source) { "{% path_to index, locale: 'en' %}" }
62
+
63
+ before do
64
+ services.url_builder.current_locale = current_locale
65
+ end
66
+
67
+ it { is_expected.to eq '/en' }
68
+
69
+ context 'prefix_default_locale is true' do
70
+
71
+ let(:prefix_default) { true }
72
+ it { is_expected.to eq '/en' }
73
+
74
+ end
75
+
76
+ end
77
+
55
78
  context 'prefix_default_locale is true' do
56
79
 
57
80
  let(:prefix_default) { true }
58
- it { is_expected.to eq '/en/' }
81
+ it { is_expected.to eq '/en' }
59
82
 
60
83
  end
61
84
 
@@ -0,0 +1,231 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Steam::Liquid::Tags::Section do
4
+
5
+ let(:services) { Locomotive::Steam::Services.build_instance(nil) }
6
+ let(:finder) { services.section_finder }
7
+ let(:source) { 'Locomotive {% section header %}' }
8
+ let(:live_editing) { true }
9
+ let(:content) { {} }
10
+ let(:alt_content) { nil }
11
+ let(:page) { liquid_instance_double('Page', sections_content: content)}
12
+ let(:assigns) { { 'page' => page } }
13
+ let(:context) { ::Liquid::Context.new(assigns, {}, { services: services, live_editing: live_editing, _section_content: alt_content }) }
14
+
15
+ describe 'parsing' do
16
+
17
+ subject { parse_template(source) }
18
+
19
+ describe 'raises an error if the syntax is incorrect' do
20
+ let(:source) { 'Locomotive {% section %}' }
21
+ it { expect { subject }.to raise_exception(Liquid::SyntaxError) }
22
+ end
23
+
24
+ end
25
+
26
+ describe 'rendering' do
27
+
28
+ before do
29
+ allow(finder).to receive(:find).and_return(section)
30
+ end
31
+
32
+ subject { render_template(source, context) }
33
+
34
+ let(:definition) { {
35
+ type: 'header',
36
+ class: 'my-awesome-header',
37
+ settings: [
38
+ { id: 'brand', type: 'text', label: 'Brand' },
39
+ { id: 'image', type: 'image_picker' }
40
+ ],
41
+ blocks: [
42
+ { type: 'menu_item', settings: [
43
+ { id: 'title', type: 'text' },
44
+ { id: 'image', type: 'image_picker' }
45
+ ]}
46
+ ],
47
+ default: {
48
+ settings: { brand: 'NoCoffee', image: 'foo.png' },
49
+ blocks: [{ id: 42, type: 'menu_item', settings: { title: 'Home', image: 'foo.png' } }] }
50
+ }.deep_stringify_keys }
51
+
52
+ let(:section) { instance_double(
53
+ 'Header',
54
+ slug: 'header',
55
+ type: 'header',
56
+ liquid_source: liquid_source,
57
+ definition: definition,
58
+ )}
59
+
60
+ context 'no block' do
61
+
62
+ let(:liquid_source) { %(built by <a>\n\t<strong>{{ section.settings.brand }}</strong></a>) }
63
+
64
+ it { is_expected.to eq 'Locomotive'\
65
+ ' <div id="locomotive-section-page-header"'\
66
+ ' class="locomotive-section my-awesome-header"'\
67
+ ' data-locomotive-section-type="header">'\
68
+ 'built by <a>' + %(\n\t) + '<strong data-locomotive-editor-setting="section-page-header.brand">NoCoffee</strong></a>'\
69
+ '</div>' }
70
+
71
+ context 'capturing the setting in a liquid variable' do
72
+
73
+ let(:liquid_source) { %({% capture brand %}<strong class="bold">{{ section.settings.brand }}</strong>{% endcapture %}built by <a>\n\t{{ brand }}</a>) }
74
+
75
+ it { is_expected.to eq 'Locomotive'\
76
+ ' <div id="locomotive-section-page-header"'\
77
+ ' class="locomotive-section my-awesome-header"'\
78
+ ' data-locomotive-section-type="header">'\
79
+ 'built by <a>' + %(\n\t) + '<strong class="bold" data-locomotive-editor-setting="section-page-header.brand">NoCoffee</strong></a>'\
80
+ '</div>' }
81
+
82
+ end
83
+
84
+ context 'with a non string type input' do
85
+
86
+ let(:liquid_source) { 'built by <strong>{{ section.settings.image }}</strong>' }
87
+
88
+ it { is_expected.to eq 'Locomotive'\
89
+ ' <div id="locomotive-section-page-header"'\
90
+ ' class="locomotive-section my-awesome-header"'\
91
+ ' data-locomotive-section-type="header">'\
92
+ 'built by <strong>foo.png</strong>'\
93
+ '</div>' }
94
+
95
+ end
96
+
97
+ context 'without the live editing feature enabled' do
98
+
99
+ let(:live_editing) { false }
100
+
101
+ it { is_expected.to eq 'Locomotive '\
102
+ '<div id="locomotive-section-page-header"'\
103
+ ' class="locomotive-section my-awesome-header"'\
104
+ ' data-locomotive-section-type="header">'\
105
+ 'built by <a>' + %(\n\t) + '<strong>NoCoffee</strong></a>'\
106
+ '</div>' }
107
+
108
+ end
109
+
110
+ end
111
+
112
+ context 'with blocks' do
113
+
114
+ let(:liquid_source) { '{% for foo in section.blocks %}<a href="/">{{ foo.settings.title }}</a>{% endfor %}' }
115
+
116
+ it { is_expected.to eq 'Locomotive'\
117
+ ' <div id="locomotive-section-page-header"'\
118
+ ' class="locomotive-section my-awesome-header"'\
119
+ ' data-locomotive-section-type="header">'\
120
+ '<a href="/" data-locomotive-editor-setting="section-page-header-block.42.title">Home</a>'\
121
+ '</div>' }
122
+
123
+ context 'with a non text type input' do
124
+
125
+ let(:liquid_source) { '{% for foo in section.blocks %}<a>{{ foo.settings.image }}</a>{% endfor %}' }
126
+
127
+ it { is_expected.to eq 'Locomotive'\
128
+ ' <div id="locomotive-section-page-header"'\
129
+ ' class="locomotive-section my-awesome-header"'\
130
+ ' data-locomotive-section-type="header">'\
131
+ '<a>foo.png</a>'\
132
+ '</div>' }
133
+
134
+ end
135
+
136
+ end
137
+
138
+ context 'with page content' do
139
+ let(:liquid_source) { 'built by <strong>{{ section.settings.brand }}</strong>' }
140
+
141
+ context 'with on section' do
142
+
143
+ context 'with simple type' do
144
+ let(:content) {
145
+ {
146
+ header: {
147
+ settings: { brand: 'Locomotive' },
148
+ blocks: []
149
+ }
150
+ }.deep_stringify_keys
151
+ }
152
+
153
+ it { is_expected.to eq 'Locomotive '\
154
+ '<div id="locomotive-section-page-header"'\
155
+ ' class="locomotive-section my-awesome-header"'\
156
+ ' data-locomotive-section-type="header">'\
157
+ 'built by '\
158
+ '<strong data-locomotive-editor-setting="section-page-header.brand">'\
159
+ 'Locomotive'\
160
+ '</strong>'\
161
+ '</div>' }
162
+ end
163
+
164
+ context 'with an id passed as an option' do
165
+
166
+ let(:source) { 'Locomotive {% section header, id: "my_header" %}'}
167
+ let(:content) {
168
+ {
169
+ 'my_header': {
170
+ settings: { brand: 'Locomotive' },
171
+ blocks: []
172
+ }
173
+ }.deep_stringify_keys
174
+ }
175
+
176
+ it { is_expected.to eq 'Locomotive '\
177
+ '<div id="locomotive-section-page-my_header" '\
178
+ 'class="locomotive-section my-awesome-header" '\
179
+ 'data-locomotive-section-type="header">'\
180
+ 'built by '\
181
+ '<strong data-locomotive-editor-setting="section-page-my_header.brand">'\
182
+ 'Locomotive'\
183
+ '</strong>'\
184
+ '</div>' }
185
+ end
186
+
187
+ context 'with an id within the content' do
188
+ let(:source) { 'Locomotive {% section header %}'}
189
+ let(:alt_content) {
190
+ {
191
+ id: 'site-header',
192
+ settings: { brand: 'Locomotive' },
193
+ blocks: []
194
+ }.deep_stringify_keys
195
+ }
196
+
197
+ it { is_expected.to eq 'Locomotive '\
198
+ '<div id="locomotive-section-site-header" '\
199
+ 'class="locomotive-section my-awesome-header" '\
200
+ 'data-locomotive-section-type="header">'\
201
+ 'built by '\
202
+ '<strong data-locomotive-editor-setting="section-site-header.brand">'\
203
+ 'Locomotive'\
204
+ '</strong>'\
205
+ '</div>' }
206
+
207
+ end
208
+
209
+ end
210
+ end
211
+
212
+
213
+ context 'rendering error (action) found in the section' do
214
+
215
+ let(:live_editing) { false }
216
+ let(:liquid_source) { '{% action "Hello world" %}a.b(+}{% endaction %}' }
217
+ let(:section) { instance_double('section',
218
+ name: 'Hero',
219
+ liquid_source: liquid_source,
220
+ definition: { settings: [], blocks: [] }
221
+ )}
222
+
223
+ it 'raises ParsingRenderingError' do
224
+ expect { subject }.to raise_exception(Locomotive::Steam::ParsingRenderingError)
225
+ end
226
+ end
227
+
228
+ end
229
+
230
+ end
231
+