locomotivecms_steam 1.5.3 → 1.6.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +1 -3
  4. data/Gemfile +2 -3
  5. data/Gemfile.lock +57 -54
  6. data/README.md +17 -8
  7. data/bin/steam.rb +3 -13
  8. data/lib/locomotive/steam/adapters/filesystem/sanitizers/content_entry.rb +1 -1
  9. data/lib/locomotive/steam/adapters/mongodb.rb +3 -2
  10. data/lib/locomotive/steam/entities/theme_asset.rb +0 -1
  11. data/lib/locomotive/steam/liquid/drops/section.rb +31 -2
  12. data/lib/locomotive/steam/liquid/drops/section_block.rb +13 -0
  13. data/lib/locomotive/steam/liquid/drops/section_content_proxy.rb +44 -5
  14. data/lib/locomotive/steam/liquid/drops/section_editor_setting_data.rb +1 -1
  15. data/lib/locomotive/steam/liquid/tags/concerns/path.rb +1 -1
  16. data/lib/locomotive/steam/liquid/tags/concerns/section.rb +1 -1
  17. data/lib/locomotive/steam/liquid/tags/section.rb +6 -1
  18. data/lib/locomotive/steam/middlewares/logging.rb +4 -1
  19. data/lib/locomotive/steam/middlewares/site.rb +1 -1
  20. data/lib/locomotive/steam/repositories/content_entry_repository.rb +3 -3
  21. data/lib/locomotive/steam/repositories/content_type_field_select_option_repository.rb +8 -1
  22. data/lib/locomotive/steam/services/asset_host_service.rb +1 -1
  23. data/lib/locomotive/steam/services/url_finder_service.rb +2 -0
  24. data/lib/locomotive/steam/version.rb +1 -1
  25. data/lib/locomotive/steam.rb +2 -2
  26. data/locomotivecms_steam.gemspec +8 -8
  27. data/script/ci/before_build.sh +1 -0
  28. data/spec/fixtures/default/public/fonts/chunkfive-webfont.eot +0 -0
  29. data/spec/fixtures/default/public/fonts/chunkfive-webfont.svg +0 -0
  30. data/spec/fixtures/default/public/fonts/chunkfive-webfont.ttf +0 -0
  31. data/spec/fixtures/default/public/fonts/chunkfive-webfont.woff +0 -0
  32. data/spec/fixtures/default/public/fonts/chunkfive.css +0 -0
  33. data/spec/fixtures/default/public/fonts/chunkfive.otf +0 -0
  34. data/spec/integration/adapters/mongodb_spec.rb +5 -5
  35. data/spec/integration/liquid/drops/content_types_spec.rb +62 -0
  36. data/spec/integration/repositories/content_entry_repository_spec.rb +5 -0
  37. data/spec/unit/liquid/drops/section_block_spec.rb +26 -0
  38. data/spec/unit/liquid/drops/section_content_proxy_spec.rb +61 -2
  39. data/spec/unit/liquid/drops/section_spec.rb +31 -4
  40. data/spec/unit/liquid/tags/section_spec.rb +8 -9
  41. data/spec/unit/middlewares/cache_spec.rb +4 -4
  42. data/spec/unit/middlewares/section_spec.rb +3 -3
  43. data/spec/unit/middlewares/site_spec.rb +11 -1
  44. data/spec/unit/services/url_finder_service_spec.rb +25 -11
  45. metadata +35 -22
@@ -2,10 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  describe Locomotive::Steam::Liquid::Drops::Section do
4
4
 
5
- let(:context) { ::Liquid::Context.new({}, {}, { locale: 'en' }) }
6
- let(:settings) { [] }
7
- let(:definition) { instance_double('SectionDefinition', definition: { 'settings' => settings }) }
8
- let(:drop) { described_class.new(definition, content).tap { |d| d.context = context } }
5
+ let(:context) { ::Liquid::Context.new({}, {}, { locale: 'en' }) }
6
+ let(:settings) { [] }
7
+ let(:definition) { instance_double('SectionDefinition', definition: { 'settings' => settings, 'blocks' => block_definitions }) }
8
+ let(:block_definitions) { [] }
9
+ let(:drop) { described_class.new(definition, content).tap { |d| d.context = context } }
9
10
 
10
11
  describe 'text type setting' do
11
12
 
@@ -23,4 +24,30 @@ describe Locomotive::Steam::Liquid::Drops::Section do
23
24
 
24
25
  end
25
26
 
27
+ describe 'blocks_as_tree' do
28
+
29
+ let(:block_definitions) { [{ 'type' => 'page' }] }
30
+ let(:content) { { 'blocks' => [
31
+ { 'id' => '1', 'type' => 'page', 'settings' => { 'name' => 'Page 1' } },
32
+ { 'id' => '2', 'type' => 'page', 'settings' => { 'name' => 'Page 2' } },
33
+ { 'id' => '2.1', 'type' => 'page', 'depth' => 1, 'settings' => { 'name' => 'Page 2.1' } },
34
+ { 'id' => '2.2', 'type' => 'page', 'depth' => 1, 'settings' => { 'name' => 'Page 2.2' } },
35
+ { 'id' => '2.2.1', 'type' => 'page', 'depth' => 2, 'settings' => { 'name' => 'Page 2.2.1' } },
36
+ { 'id' => '2.2.2', 'type' => 'page', 'depth' => 2, 'settings' => { 'name' => 'Page 2.2.2' } },
37
+ { 'id' => '2.2.2.1', 'type' => 'page', 'depth' => 3, 'settings' => { 'name' => 'Page 2.2.2.1' } },
38
+ { 'id' => '2.3', 'type' => 'page', 'depth' => 1, 'settings' => { 'name' => 'Page 2.3' } },
39
+ { 'id' => '3', 'type' => 'page', 'depth' => 0, 'settings' => { 'name' => 'Page 3' } },
40
+ ] } }
41
+
42
+ subject { drop.blocks_as_tree }
43
+
44
+ it 'represents the blocks as a tree (node + leaves)' do
45
+ expect(subject.map { |drop| drop.id }).to eq(%w(1 2 3))
46
+ expect(subject[1].leaves.map { |drop| drop.id }).to eq(%w(2.1 2.2 2.3))
47
+ expect(subject[1].leaves[1].leaves.map { |drop| drop.id }).to eq(%w(2.2.1 2.2.2))
48
+ expect(subject[1].leaves[1].leaves[1].leaves.map { |drop| drop.id }).to eq(%w(2.2.2.1))
49
+ end
50
+
51
+ end
52
+
26
53
  end
@@ -224,24 +224,23 @@ describe Locomotive::Steam::Liquid::Tags::Section do
224
224
  '</div>' }
225
225
  end
226
226
 
227
- context 'with an id within the content' do
228
- let(:source) { 'Locomotive {% section header %}'}
227
+ context 'with an id within the content (section rendered by the section middleware)' do
228
+ let(:source) { '{% section header %}'}
229
229
  let(:alt_content) {
230
230
  {
231
- id: 'site-header',
232
- settings: { brand: 'Locomotive' },
231
+ id: 'dropzone-42',
232
+ settings: { brand: 'NoCoffee' },
233
233
  blocks: []
234
234
  }.deep_stringify_keys
235
235
  }
236
236
 
237
- it { is_expected.to eq 'Locomotive '\
238
- '<div id="locomotive-section-site-header" '\
237
+ it { is_expected.to eq '<div id="locomotive-section-dropzone-42" '\
239
238
  'class="locomotive-section my-awesome-header" '\
240
239
  'data-locomotive-section-type="header">'\
241
- '<span id="site-header-section"></span>'\
240
+ '<span id="dropzone-42-section"></span>'\
242
241
  'built by '\
243
- '<strong data-locomotive-editor-setting="section-site-header.brand">'\
244
- 'Locomotive'\
242
+ '<strong data-locomotive-editor-setting="section-dropzone-42.brand">'\
243
+ 'NoCoffee'\
245
244
  '</strong>'\
246
245
  '</div>' }
247
246
 
@@ -55,11 +55,11 @@ describe Locomotive::Steam::Middlewares::Cache do
55
55
 
56
56
  let(:response) { nil }
57
57
 
58
- before { expect(cache).to receive(:read).with('2fae60bf8d7d9c0dce6cabcac8288267').and_return(response) }
58
+ before { expect(cache).to receive(:read).with('9c535e0c37793cf8134e8b88b2517197').and_return(response) }
59
59
 
60
60
  context 'the cache is empty' do
61
61
 
62
- before { expect(cache).to receive(:write).with('2fae60bf8d7d9c0dce6cabcac8288267', Marshal.dump([200, {}, ["Hello world!"]])) }
62
+ before { expect(cache).to receive(:write).with('9c535e0c37793cf8134e8b88b2517197', Marshal.dump([200, {}, ["Hello world!"]])) }
63
63
 
64
64
  it 'tells the CDN to cache the page and also cache it internally' do
65
65
  is_expected.to eq ['max-age=0, s-maxage=3600, public, must-revalidate', 'Accept-Language']
@@ -69,7 +69,7 @@ describe Locomotive::Steam::Middlewares::Cache do
69
69
 
70
70
  subject { send_request[:env]['steam.cache_etag'] }
71
71
 
72
- it { is_expected.to eq '2fae60bf8d7d9c0dce6cabcac8288267' }
72
+ it { is_expected.to eq '9c535e0c37793cf8134e8b88b2517197' }
73
73
 
74
74
  end
75
75
 
@@ -104,7 +104,7 @@ describe Locomotive::Steam::Middlewares::Cache do
104
104
 
105
105
  context 'based on the ETag' do
106
106
 
107
- let(:etag) { '2fae60bf8d7d9c0dce6cabcac8288267' }
107
+ let(:etag) { '9c535e0c37793cf8134e8b88b2517197' }
108
108
 
109
109
  it 'returns a 304 (Not modified) without no cache headers' do
110
110
  expect(subject.first).to eq 304
@@ -47,7 +47,7 @@ describe Locomotive::Steam::Middlewares::Section do
47
47
  is_expected.to eq [
48
48
  200,
49
49
  { "Content-Type" => "text/html" },
50
- [%(<div id="locomotive-section-page-header" class="locomotive-section" data-locomotive-section-type="header"><span id="page-header-section"></span>Here some </div>)]
50
+ [%(<div id="locomotive-section-header" class="locomotive-section" data-locomotive-section-type="header"><span id="header-section"></span>Here some </div>)]
51
51
  ]
52
52
  end
53
53
 
@@ -55,7 +55,7 @@ describe Locomotive::Steam::Middlewares::Section do
55
55
 
56
56
  before do
57
57
  allow(env['steam.request']).to receive(:body).and_return(StringIO.new(
58
- %({ "section_content": { "id": "site-header", "settings": { "name": "modified HTML" } } })
58
+ %({ "section_content": { "id": "dropzone-42", "settings": { "name": "modified HTML" } } })
59
59
  ))
60
60
  end
61
61
 
@@ -63,7 +63,7 @@ describe Locomotive::Steam::Middlewares::Section do
63
63
  is_expected.to eq [
64
64
  200,
65
65
  { "Content-Type" => "text/html" },
66
- [%(<div id="locomotive-section-site-header" class="locomotive-section" data-locomotive-section-type="header"><span id="site-header-section"></span>Here some modified HTML</div>)]
66
+ [%(<div id="locomotive-section-dropzone-42" class="locomotive-section" data-locomotive-section-type="header"><span id="dropzone-42-section"></span>Here some modified HTML</div>)]
67
67
  ]
68
68
  end
69
69
 
@@ -14,12 +14,14 @@ describe Locomotive::Steam::Middlewares::Site do
14
14
  let(:app) { ->(env) { [200, env, 'app'] } }
15
15
  let(:middleware) { Locomotive::Steam::Middlewares::Site.new(app) }
16
16
  let(:is_default_host) { nil }
17
+ let(:live_editing) { false }
17
18
 
18
19
  subject do
19
20
  env = env_for(url, 'steam.services' => services)
20
21
  env['steam.request'] = Rack::Request.new(env)
21
22
  env['steam.site'] = engine_site
22
23
  env['steam.is_default_host'] = is_default_host
24
+ env['steam.live_editing'] = live_editing
23
25
  code, env = middleware.call(env)
24
26
  [code, env['Location']]
25
27
  end
@@ -58,7 +60,7 @@ describe Locomotive::Steam::Middlewares::Site do
58
60
  describe 'redirection' do
59
61
 
60
62
  let(:redirect_to_first_domain) { false }
61
- let(:redirect_to_https) { false }
63
+ let(:redirect_to_https) { false }
62
64
  let(:url) { 'http://acme.com' }
63
65
  let(:site) { instance_double('SiteWithDomains', name: 'Acme', domains: ['www.acme.com', 'acme.com'], redirect_to_first_domain: redirect_to_first_domain, redirect_to_https: redirect_to_https) }
64
66
 
@@ -116,6 +118,14 @@ describe Locomotive::Steam::Middlewares::Site do
116
118
 
117
119
  end
118
120
 
121
+ context 'when editing the page in the editor' do
122
+
123
+ let(:url) { 'https://locomotive.local/editor/foo' }
124
+ let(:live_editing) { true }
125
+ it { is_expected.to eq [200, nil] }
126
+
127
+ end
128
+
119
129
  end
120
130
 
121
131
  end
@@ -73,19 +73,33 @@ describe Locomotive::Steam::UrlFinderService do
73
73
 
74
74
  let(:entry) { instance_double('Product') }
75
75
  let(:page) { instance_double('Page', :content_entry= => true, not_found?: false) }
76
- let(:value) { {
77
- 'type' => 'content_entry',
78
- 'value' => { 'page_id' => 42, 'content_type_slug' => 'products', 'id' => 1 },
79
- 'new_window' => true
80
- } }
81
-
82
- before do
83
- expect(page_finder).to receive(:find_by_id).with(42).and_return(page)
84
- expect(content_entry_finder).to receive(:find).with('products', 1).and_return(entry)
85
- expect(url_builder).to receive(:url_for).with(page).and_return('/my-product')
76
+
77
+ context 'the value is valid content entry' do
78
+ let(:value) { {
79
+ 'type' => 'content_entry',
80
+ 'value' => { 'page_id' => 42, 'content_type_slug' => 'products', 'id' => 1 },
81
+ 'new_window' => true
82
+ } }
83
+
84
+ before do
85
+ expect(page_finder).to receive(:find_by_id).with(42).and_return(page)
86
+ expect(content_entry_finder).to receive(:find).with('products', 1).and_return(entry)
87
+ expect(url_builder).to receive(:url_for).with(page).and_return('/my-product')
88
+ end
89
+
90
+ it { is_expected.to eq(['/my-product', true]) }
86
91
  end
87
92
 
88
- it { is_expected.to eq(['/my-product', true]) }
93
+ context 'the value is nil' do
94
+ let(:value) { nil }
95
+
96
+ before do
97
+ expect(page_finder).to receive(:find).with('404').and_return(page)
98
+ expect(url_builder).to receive(:url_for).with(page).and_return('/404')
99
+ end
100
+
101
+ it { is_expected.to eq(['/404', false]) }
102
+ end
89
103
 
90
104
  end
91
105
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locomotivecms_steam
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.6.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Didier Lafforgue
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-02-28 00:00:00.000000000 Z
14
+ date: 2021-09-03 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake
@@ -33,14 +33,14 @@ dependencies:
33
33
  requirements:
34
34
  - - "~>"
35
35
  - !ruby/object:Gem::Version
36
- version: 2.8.0
36
+ version: 2.13.1
37
37
  type: :development
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - "~>"
42
42
  - !ruby/object:Gem::Version
43
- version: 2.8.0
43
+ version: 2.13.1
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: origin
46
46
  requirement: !ruby/object:Gem::Requirement
@@ -61,28 +61,28 @@ dependencies:
61
61
  requirements:
62
62
  - - "~>"
63
63
  - !ruby/object:Gem::Version
64
- version: 1.10.8
64
+ version: 1.11.0
65
65
  type: :runtime
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
69
  - - "~>"
70
70
  - !ruby/object:Gem::Version
71
- version: 1.10.8
71
+ version: 1.11.0
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: sanitize
74
74
  requirement: !ruby/object:Gem::Requirement
75
75
  requirements:
76
76
  - - "~>"
77
77
  - !ruby/object:Gem::Version
78
- version: 4.6.4
78
+ version: 5.2.1
79
79
  type: :runtime
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
82
82
  requirements:
83
83
  - - "~>"
84
84
  - !ruby/object:Gem::Version
85
- version: 4.6.4
85
+ version: 5.2.1
86
86
  - !ruby/object:Gem::Dependency
87
87
  name: morphine
88
88
  requirement: !ruby/object:Gem::Requirement
@@ -145,14 +145,14 @@ dependencies:
145
145
  requirements:
146
146
  - - "~>"
147
147
  - !ruby/object:Gem::Version
148
- version: 1.13.1
148
+ version: 1.15.0
149
149
  type: :runtime
150
150
  prerelease: false
151
151
  version_requirements: !ruby/object:Gem::Requirement
152
152
  requirements:
153
153
  - - "~>"
154
154
  - !ruby/object:Gem::Version
155
- version: 1.13.1
155
+ version: 1.15.0
156
156
  - !ruby/object:Gem::Dependency
157
157
  name: liquid
158
158
  requirement: !ruby/object:Gem::Requirement
@@ -213,16 +213,22 @@ dependencies:
213
213
  name: dragonfly
214
214
  requirement: !ruby/object:Gem::Requirement
215
215
  requirements:
216
- - - "~>"
216
+ - - ">="
217
+ - !ruby/object:Gem::Version
218
+ version: '1.2'
219
+ - - "<"
217
220
  - !ruby/object:Gem::Version
218
- version: 1.2.0
221
+ version: '1.5'
219
222
  type: :runtime
220
223
  prerelease: false
221
224
  version_requirements: !ruby/object:Gem::Requirement
222
225
  requirements:
223
- - - "~>"
226
+ - - ">="
224
227
  - !ruby/object:Gem::Version
225
- version: 1.2.0
228
+ version: '1.2'
229
+ - - "<"
230
+ - !ruby/object:Gem::Version
231
+ version: '1.5'
226
232
  - !ruby/object:Gem::Dependency
227
233
  name: moneta
228
234
  requirement: !ruby/object:Gem::Requirement
@@ -327,14 +333,14 @@ dependencies:
327
333
  requirements:
328
334
  - - "~>"
329
335
  - !ruby/object:Gem::Version
330
- version: 1.16.2
336
+ version: 2.3.0
331
337
  type: :runtime
332
338
  prerelease: false
333
339
  version_requirements: !ruby/object:Gem::Requirement
334
340
  requirements:
335
341
  - - "~>"
336
342
  - !ruby/object:Gem::Version
337
- version: 1.16.2
343
+ version: 2.3.0
338
344
  - !ruby/object:Gem::Dependency
339
345
  name: RedCloth
340
346
  requirement: !ruby/object:Gem::Requirement
@@ -369,14 +375,14 @@ dependencies:
369
375
  requirements:
370
376
  - - "~>"
371
377
  - !ruby/object:Gem::Version
372
- version: 3.1.0
378
+ version: 3.3.0
373
379
  type: :runtime
374
380
  prerelease: false
375
381
  version_requirements: !ruby/object:Gem::Requirement
376
382
  requirements:
377
383
  - - "~>"
378
384
  - !ruby/object:Gem::Version
379
- version: 3.1.0
385
+ version: 3.3.0
380
386
  - !ruby/object:Gem::Dependency
381
387
  name: duktape
382
388
  requirement: !ruby/object:Gem::Requirement
@@ -778,6 +784,7 @@ files:
778
784
  - spec/fixtures/mongodb/locomotive_translations.metadata.json
779
785
  - spec/integration/adapters/mongodb_spec.rb
780
786
  - spec/integration/integration_helper.rb
787
+ - spec/integration/liquid/drops/content_types_spec.rb
781
788
  - spec/integration/liquid/drops/page_spec.rb
782
789
  - spec/integration/liquid/filters/translate_spec.rb
783
790
  - spec/integration/liquid/tags/paginate_spec.rb
@@ -852,6 +859,7 @@ files:
852
859
  - spec/unit/liquid/drops/metafields_spec.rb
853
860
  - spec/unit/liquid/drops/page_spec.rb
854
861
  - spec/unit/liquid/drops/params_spec.rb
862
+ - spec/unit/liquid/drops/section_block_spec.rb
855
863
  - spec/unit/liquid/drops/section_content_proxy_spec.rb
856
864
  - spec/unit/liquid/drops/section_spec.rb
857
865
  - spec/unit/liquid/drops/session_proxy_spec.rb
@@ -964,14 +972,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
964
972
  requirements:
965
973
  - - ">="
966
974
  - !ruby/object:Gem::Version
967
- version: '2.0'
975
+ version: '2.5'
976
+ - - "<"
977
+ - !ruby/object:Gem::Version
978
+ version: '3'
968
979
  required_rubygems_version: !ruby/object:Gem::Requirement
969
980
  requirements:
970
- - - ">="
981
+ - - ">"
971
982
  - !ruby/object:Gem::Version
972
- version: '0'
983
+ version: 1.3.1
973
984
  requirements: []
974
- rubygems_version: 3.0.6
985
+ rubygems_version: 3.1.4
975
986
  signing_key:
976
987
  specification_version: 4
977
988
  summary: The LocomotiveCMS Steam is the rendering stack used by both Wagon and Engine
@@ -1094,6 +1105,7 @@ test_files:
1094
1105
  - spec/fixtures/mongodb/locomotive_translations.metadata.json
1095
1106
  - spec/integration/adapters/mongodb_spec.rb
1096
1107
  - spec/integration/integration_helper.rb
1108
+ - spec/integration/liquid/drops/content_types_spec.rb
1097
1109
  - spec/integration/liquid/drops/page_spec.rb
1098
1110
  - spec/integration/liquid/filters/translate_spec.rb
1099
1111
  - spec/integration/liquid/tags/paginate_spec.rb
@@ -1168,6 +1180,7 @@ test_files:
1168
1180
  - spec/unit/liquid/drops/metafields_spec.rb
1169
1181
  - spec/unit/liquid/drops/page_spec.rb
1170
1182
  - spec/unit/liquid/drops/params_spec.rb
1183
+ - spec/unit/liquid/drops/section_block_spec.rb
1171
1184
  - spec/unit/liquid/drops/section_content_proxy_spec.rb
1172
1185
  - spec/unit/liquid/drops/section_spec.rb
1173
1186
  - spec/unit/liquid/drops/session_proxy_spec.rb