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.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -1
  3. data/Gemfile +3 -6
  4. data/Gemfile.lock +39 -39
  5. data/README.md +2 -2
  6. data/lib/locomotive/steam/adapters/filesystem/sanitizers/section.rb +62 -16
  7. data/lib/locomotive/steam/adapters/filesystem/sanitizers/site.rb +15 -1
  8. data/lib/locomotive/steam/adapters/filesystem/yaml_loader.rb +30 -9
  9. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb +1 -1
  10. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/page.rb +1 -1
  11. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/section.rb +14 -2
  12. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/site.rb +1 -1
  13. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/translation.rb +1 -1
  14. data/lib/locomotive/steam/adapters/mongodb.rb +1 -1
  15. data/lib/locomotive/steam/entities/content_entry.rb +0 -1
  16. data/lib/locomotive/steam/entities/site.rb +4 -0
  17. data/lib/locomotive/steam/errors.rb +54 -18
  18. data/lib/locomotive/steam/liquid/drops/content_entry.rb +1 -1
  19. data/lib/locomotive/steam/liquid/drops/content_entry_collection.rb +1 -1
  20. data/lib/locomotive/steam/liquid/drops/content_types.rb +1 -1
  21. data/lib/locomotive/steam/liquid/drops/inherited_block.rb +28 -0
  22. data/lib/locomotive/steam/liquid/drops/metafields.rb +2 -2
  23. data/lib/locomotive/steam/liquid/drops/params.rb +1 -1
  24. data/lib/locomotive/steam/liquid/drops/section.rb +10 -2
  25. data/lib/locomotive/steam/liquid/drops/section_content_proxy.rb +13 -2
  26. data/lib/locomotive/steam/liquid/drops/section_editor_setting_data.rb +1 -1
  27. data/lib/locomotive/steam/liquid/drops/session_proxy.rb +1 -1
  28. data/lib/locomotive/steam/liquid/file_system.rb +46 -0
  29. data/lib/locomotive/steam/liquid/filters/array.rb +61 -0
  30. data/lib/locomotive/steam/liquid/filters/misc.rb +12 -2
  31. data/lib/locomotive/steam/liquid/filters/number.rb +13 -12
  32. data/lib/locomotive/steam/liquid/filters/text.rb +4 -0
  33. data/lib/locomotive/steam/liquid/patches.rb +58 -19
  34. data/lib/locomotive/steam/liquid/tags/alt_page_links.rb +9 -5
  35. data/lib/locomotive/steam/liquid/tags/concerns/attributes.rb +47 -0
  36. data/lib/locomotive/steam/liquid/tags/concerns/path.rb +18 -31
  37. data/lib/locomotive/steam/liquid/tags/concerns/section.rb +22 -11
  38. data/lib/locomotive/steam/liquid/tags/consume.rb +26 -33
  39. data/lib/locomotive/steam/liquid/tags/csrf.rb +2 -2
  40. data/lib/locomotive/steam/liquid/tags/editable/base.rb +30 -20
  41. data/lib/locomotive/steam/liquid/tags/editable/control.rb +2 -2
  42. data/lib/locomotive/steam/liquid/tags/editable/file.rb +11 -11
  43. data/lib/locomotive/steam/liquid/tags/editable/text.rb +5 -5
  44. data/lib/locomotive/steam/liquid/tags/extends.rb +56 -8
  45. data/lib/locomotive/steam/liquid/tags/global_section.rb +6 -6
  46. data/lib/locomotive/steam/liquid/tags/google_analytics.rb +16 -6
  47. data/lib/locomotive/steam/liquid/tags/hybrid.rb +8 -4
  48. data/lib/locomotive/steam/liquid/tags/inherited_block.rb +90 -13
  49. data/lib/locomotive/steam/liquid/tags/inline_editor.rb +4 -4
  50. data/lib/locomotive/steam/liquid/tags/link_to.rb +2 -1
  51. data/lib/locomotive/steam/liquid/tags/locale_switcher.rb +25 -21
  52. data/lib/locomotive/steam/liquid/tags/model_form.rb +38 -17
  53. data/lib/locomotive/steam/liquid/tags/nav.rb +4 -4
  54. data/lib/locomotive/steam/liquid/tags/page_not_found.rb +19 -0
  55. data/lib/locomotive/steam/liquid/tags/paginate.rb +13 -7
  56. data/lib/locomotive/steam/liquid/tags/path_to.rb +1 -0
  57. data/lib/locomotive/steam/liquid/tags/redirect_to.rb +34 -0
  58. data/lib/locomotive/steam/liquid/tags/section.rb +34 -33
  59. data/lib/locomotive/steam/liquid/tags/sections_dropzone.rb +1 -1
  60. data/lib/locomotive/steam/liquid/tags/seo.rb +2 -4
  61. data/lib/locomotive/steam/liquid/tags/session_assign.rb +1 -0
  62. data/lib/locomotive/steam/liquid/tags/snippet.rb +21 -29
  63. data/lib/locomotive/steam/liquid/tags/with_scope.rb +61 -27
  64. data/lib/locomotive/steam/liquid.rb +3 -1
  65. data/lib/locomotive/steam/middlewares/cache.rb +117 -0
  66. data/lib/locomotive/steam/middlewares/concerns/helpers.rb +22 -8
  67. data/lib/locomotive/steam/middlewares/concerns/liquid_context.rb +5 -1
  68. data/lib/locomotive/steam/middlewares/concerns/rendering.rb +53 -0
  69. data/lib/locomotive/steam/middlewares/impersonated_entry.rb +4 -0
  70. data/lib/locomotive/steam/middlewares/locale.rb +2 -2
  71. data/lib/locomotive/steam/middlewares/locale_redirection.rb +1 -1
  72. data/lib/locomotive/steam/middlewares/logging.rb +1 -0
  73. data/lib/locomotive/steam/middlewares/page_not_found.rb +37 -0
  74. data/lib/locomotive/steam/middlewares/redirection.rb +1 -1
  75. data/lib/locomotive/steam/middlewares/renderer.rb +4 -26
  76. data/lib/locomotive/steam/middlewares/thread_safe.rb +0 -4
  77. data/lib/locomotive/steam/models/pager.rb +1 -0
  78. data/lib/locomotive/steam/server.rb +3 -1
  79. data/lib/locomotive/steam/services/action_service.rb +5 -0
  80. data/lib/locomotive/steam/services/auth_service.rb +9 -9
  81. data/lib/locomotive/steam/services/cookie_service.rb +1 -0
  82. data/lib/locomotive/steam/services/external_api_service.rb +5 -0
  83. data/lib/locomotive/steam/services/liquid_parser_service.rb +4 -2
  84. data/lib/locomotive/steam/services/page_finder_service.rb +1 -1
  85. data/lib/locomotive/steam/services/recaptcha_service.rb +4 -2
  86. data/lib/locomotive/steam/version.rb +1 -1
  87. data/lib/locomotive/steam.rb +5 -1
  88. data/locomotivecms_steam.gemspec +4 -4
  89. data/spec/fixtures/default/app/views/pages/basic.liquid.haml +1 -0
  90. data/spec/fixtures/default/app/views/pages/music.liquid.haml +6 -0
  91. data/spec/fixtures/default/app/views/sections/carousel.liquid +15 -16
  92. data/spec/fixtures/default/app/views/sections/footer.liquid +37 -3
  93. data/spec/fixtures/default/app/views/sections/header.liquid +47 -10
  94. data/spec/fixtures/default/app/views/sections/misc/hero.liquid +28 -0
  95. data/spec/fixtures/default/config/metafields_schema.yml +3 -0
  96. data/spec/integration/liquid/tags/section_spec.rb +82 -0
  97. data/spec/integration/repositories/content_entry_repository_spec.rb +9 -0
  98. data/spec/integration/server/basic_spec.rb +2 -2
  99. data/spec/integration/server/metafields_spec.rb +1 -0
  100. data/spec/integration/services/content_entry_service_spec.rb +12 -0
  101. data/spec/support/helpers.rb +1 -0
  102. data/spec/support/liquid.rb +32 -2
  103. data/spec/support/mongo.rb +1 -0
  104. data/spec/unit/adapters/filesystem/sanitizers/section_spec.rb +66 -40
  105. data/spec/unit/adapters/filesystem/yaml_loaders/section_spec.rb +25 -0
  106. data/spec/unit/errors_spec.rb +1 -1
  107. data/spec/unit/liquid/drops/content_entry_collection_spec.rb +3 -3
  108. data/spec/unit/liquid/drops/content_entry_spec.rb +4 -4
  109. data/spec/unit/liquid/drops/content_types_spec.rb +2 -2
  110. data/spec/unit/liquid/drops/metafields_spec.rb +8 -8
  111. data/spec/unit/liquid/drops/params_spec.rb +5 -5
  112. data/spec/unit/liquid/drops/section_content_proxy_spec.rb +69 -18
  113. data/spec/unit/liquid/drops/section_spec.rb +1 -1
  114. data/spec/unit/liquid/file_system_spec.rb +25 -0
  115. data/spec/unit/liquid/filters/array_spec.rb +140 -0
  116. data/spec/unit/liquid/filters/misc_spec.rb +21 -3
  117. data/spec/unit/liquid/filters/number_spec.rb +4 -4
  118. data/spec/unit/liquid/filters/text_spec.rb +4 -0
  119. data/spec/unit/liquid/tags/alt_page_links_spec.rb +19 -2
  120. data/spec/unit/liquid/tags/authorize_spec.rb +1 -1
  121. data/spec/unit/liquid/tags/editable/text_spec.rb +32 -4
  122. data/spec/unit/liquid/tags/extends_spec.rb +115 -28
  123. data/spec/unit/liquid/tags/global_section_spec.rb +4 -3
  124. data/spec/unit/liquid/tags/google_analytics_spec.rb +21 -2
  125. data/spec/unit/liquid/tags/inherited_block_spec.rb +18 -4
  126. data/spec/unit/liquid/tags/inline_editor_spec.rb +11 -0
  127. data/spec/unit/liquid/tags/link_to_spec.rb +1 -1
  128. data/spec/unit/liquid/tags/model_form_spec.rb +7 -0
  129. data/spec/unit/liquid/tags/page_not_found_spec.rb +14 -0
  130. data/spec/unit/liquid/tags/redirect_to_spec.rb +171 -0
  131. data/spec/unit/liquid/tags/section_spec.rb +43 -3
  132. data/spec/unit/liquid/tags/sections_dropzone_spec.rb +0 -1
  133. data/spec/unit/liquid/tags/snippet_spec.rb +9 -8
  134. data/spec/unit/liquid/tags/with_scope_spec.rb +80 -60
  135. data/spec/unit/middlewares/cache_spec.rb +186 -0
  136. data/spec/unit/middlewares/impersonated_entry_spec.rb +7 -0
  137. data/spec/unit/middlewares/locale_redirection_spec.rb +7 -0
  138. data/spec/unit/middlewares/locale_spec.rb +8 -1
  139. data/spec/unit/middlewares/page_not_found_spec.rb +46 -0
  140. data/spec/unit/middlewares/redirection_spec.rb +8 -0
  141. data/spec/unit/middlewares/renderer_spec.rb +64 -6
  142. data/spec/unit/middlewares/section_spec.rb +1 -0
  143. data/spec/unit/models/pager_spec.rb +11 -1
  144. data/spec/unit/repositories/section_repository_spec.rb +1 -1
  145. data/spec/unit/services/action_service_spec.rb +23 -3
  146. data/spec/unit/services/page_redirection_service_spec.rb +2 -2
  147. data/spec/unit/services/recaptcha_service_spec.rb +1 -1
  148. metadata +50 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2811bbc4085bab4ef718204d051285c1922ec6208d8173c0f2f7d21996eed632
4
- data.tar.gz: dc8b0c4d1b7ec7a85006511f8aad93647e4fa7e1a12dda2fde0dc20f1cabb9b5
3
+ metadata.gz: 43525e692c1a13260c2947fd4a37d83b95b965b656b84f3dc20c12812c4275e4
4
+ data.tar.gz: efeb033805d15e48d592da3e818f9a77eef521e0aca112f33f20f4f44897a2be
5
5
  SHA512:
6
- metadata.gz: a4b744dfee082181c392bb21c56ff4f9a9d761be3066405ff17bc3007a25f3a519dc266bc409d39eb55ee6ea76ab1525b35daacdd17ef900d13637351a17c6b9
7
- data.tar.gz: fc28966e95e7e9809aa7e3f153d7343d610659602d39af2c92364bd2213be064ed4b6d270b07b1eefd4c5e8fa3150e57821c5db2b58c92147708c4f911ea7b06
6
+ metadata.gz: 2a8491bdb94fda3b92834494b505235c550a689e66fb82e3d19c4f7620f8eb75e09ce5aef12bc79a1a517c9c1a54e85b96763f878313a3bdb869e78491e336ea
7
+ data.tar.gz: 825b2519f250a5618cf9c34aeb16444cd84f91d5d6f332d32ed8b7fec913ec6c7b943e81d23c7ae23333373aeb112ca0b4d58cd45ad72ece27928c148e940c69
data/.travis.yml CHANGED
@@ -2,7 +2,8 @@ language: ruby
2
2
  services: mongodb
3
3
  before_script: ./script/ci/before_build.sh
4
4
  rvm:
5
- - 2.5.0
5
+ - 2.6.1
6
+ - 2.6.5
6
7
  env:
7
8
  - CODECLIMATE_REPO_TOKEN=3fa74f2ade25037fccd7261090acbdeae232639c3a83aafb80ee428ec16b8cf9
8
9
  addons:
data/Gemfile CHANGED
@@ -5,14 +5,11 @@ gemspec
5
5
  group :development do
6
6
  gem 'locomotivecms_common', github: 'locomotivecms/common', ref: '4d1bd56'
7
7
  # gem 'locomotivecms_common', path: '../common'
8
- # gem 'locomotivecms_models', '~> 0.0.1', path: '../models'
9
- # gem 'locomotivecms_models', '0.0.1.pre.alpha'
10
- # gem 'locomotivecms-liquid', path: '/Users/didier/Documents/LocomotiveCMS/gems/liquid'
11
- # gem 'duktape', path: '/Users/didier/Documents/NoCoffee/ProjectsX/duktape.rb'
8
+ # gem 'duktape', path: '../tmp/duktape.rb'
12
9
  # gem 'duktape', github: 'judofyr/duktape.rb', ref: '20ef6a5'
13
- # gem 'thin'
10
+ # gem 'duktape', github: 'did/duktape.rb', branch: 'any-fixnum'
14
11
 
15
- gem 'puma'
12
+ gem 'puma', '~> 4.3.0'
16
13
  gem 'haml', '~> 5.0.4'
17
14
 
18
15
  gem 'rack-mini-profiler', '~> 0.10.1'
data/Gemfile.lock CHANGED
@@ -1,5 +1,5 @@
1
1
  GIT
2
- remote: git://github.com/locomotivecms/common.git
2
+ remote: https://github.com/locomotivecms/common.git
3
3
  revision: 4d1bd565246262ab4b1b824e21c7847846f4cc5c
4
4
  ref: 4d1bd56
5
5
  specs:
@@ -12,7 +12,7 @@ GIT
12
12
  PATH
13
13
  remote: .
14
14
  specs:
15
- locomotivecms_steam (1.5.0.rc0)
15
+ locomotivecms_steam (1.5.0.rc1)
16
16
  RedCloth (~> 4.3.2)
17
17
  autoprefixer-rails (~> 8.0.0)
18
18
  bcrypt (~> 3.1.11)
@@ -20,17 +20,17 @@ PATH
20
20
  coffee-script (~> 2.4.1)
21
21
  compass (~> 1.0.3)
22
22
  dragonfly (~> 1.2.0)
23
- duktape (~> 1.6.1.0)
23
+ duktape (~> 2.0.1.1)
24
24
  httparty (~> 0.16.0)
25
25
  kramdown (~> 1.16.2)
26
- locomotivecms-solid (~> 4.0.1)
26
+ liquid (~> 4.0.3)
27
27
  locomotivecms_common (~> 0.3.1)
28
28
  mime-types (~> 3.1.0)
29
29
  mimetype-fu (~> 0.1.2)
30
30
  moneta (~> 1.0.0)
31
31
  morphine (~> 0.1.1)
32
32
  multi_json (~> 1.13.1)
33
- nokogiri (~> 1.8.2)
33
+ nokogiri (~> 1.10.4)
34
34
  pony (~> 1.12)
35
35
  rack-cache (~> 1.7.0)
36
36
  rack-rewrite (~> 1.5.1)
@@ -44,18 +44,18 @@ GEM
44
44
  remote: https://rubygems.org/
45
45
  specs:
46
46
  RedCloth (4.3.2)
47
- activesupport (5.2.2)
47
+ activesupport (5.2.3)
48
48
  concurrent-ruby (~> 1.0, >= 1.0.2)
49
49
  i18n (>= 0.7, < 2)
50
50
  minitest (~> 5.1)
51
51
  tzinfo (~> 1.1)
52
- addressable (2.6.0)
53
- public_suffix (>= 2.0.2, < 4.0)
52
+ addressable (2.7.0)
53
+ public_suffix (>= 2.0.2, < 5.0)
54
54
  attr_extras (5.2.0)
55
55
  autoprefixer-rails (8.0.0)
56
56
  execjs
57
- bcrypt (3.1.12)
58
- bson (4.4.2)
57
+ bcrypt (3.1.13)
58
+ bson (4.5.0)
59
59
  chronic (0.10.2)
60
60
  chunky_png (1.3.11)
61
61
  codeclimate-test-reporter (0.4.8)
@@ -77,23 +77,23 @@ GEM
77
77
  sass (>= 3.3.0, < 3.5)
78
78
  compass-import-once (1.0.5)
79
79
  sass (>= 3.2, < 3.5)
80
- concurrent-ruby (1.1.4)
81
- coveralls (0.8.22)
80
+ concurrent-ruby (1.1.5)
81
+ coveralls (0.8.23)
82
82
  json (>= 1.8, < 3)
83
83
  simplecov (~> 0.16.1)
84
84
  term-ansicolor (~> 1.3)
85
- thor (~> 0.19.4)
85
+ thor (>= 0.19.4, < 2.0)
86
86
  tins (~> 1.6)
87
- crass (1.0.4)
87
+ crass (1.0.5)
88
88
  diff-lcs (1.3)
89
- docile (1.3.1)
89
+ docile (1.3.2)
90
90
  dragonfly (1.2.0)
91
91
  addressable (~> 2.3)
92
92
  multi_json (~> 1.0)
93
93
  rack (>= 1.3)
94
- duktape (1.6.1.0)
94
+ duktape (2.0.1.1)
95
95
  execjs (2.7.0)
96
- ffi (1.10.0)
96
+ ffi (1.11.2)
97
97
  flamegraph (0.9.5)
98
98
  haml (5.0.4)
99
99
  temple (>= 0.8.0)
@@ -101,7 +101,7 @@ GEM
101
101
  httparty (0.16.4)
102
102
  mime-types (~> 3.0)
103
103
  multi_xml (>= 0.5.2)
104
- i18n (1.5.3)
104
+ i18n (1.6.0)
105
105
  concurrent-ruby (~> 1.0)
106
106
  i18n-spec (0.6.0)
107
107
  iso
@@ -112,35 +112,35 @@ GEM
112
112
  multi_json (~> 1.0)
113
113
  rspec (>= 2.0, < 4.0)
114
114
  kramdown (1.16.2)
115
- locomotivecms-liquid (4.0.0)
116
- locomotivecms-solid (4.0.1)
117
- locomotivecms-liquid (~> 4.0.0)
115
+ liquid (4.0.3)
118
116
  mail (2.7.1)
119
117
  mini_mime (>= 0.1.1)
120
- memory_profiler (0.9.12)
118
+ memory_profiler (0.9.14)
121
119
  mime-types (3.1)
122
120
  mime-types-data (~> 3.2015)
123
- mime-types-data (3.2019.0331)
121
+ mime-types-data (3.2019.1009)
124
122
  mimetype-fu (0.1.2)
125
- mini_mime (1.0.1)
126
- mini_portile2 (2.3.0)
123
+ mini_mime (1.0.2)
124
+ mini_portile2 (2.4.0)
127
125
  minitest (5.11.3)
128
126
  moneta (1.0.0)
129
- mongo (2.5.3)
130
- bson (>= 4.3.0, < 5.0.0)
127
+ mongo (2.8.0)
128
+ bson (>= 4.4.2, < 5.0.0)
131
129
  morphine (0.1.1)
132
130
  multi_json (1.13.1)
133
131
  multi_xml (0.6.0)
134
- nokogiri (1.8.5)
135
- mini_portile2 (~> 2.3.0)
132
+ nio4r (2.5.2)
133
+ nokogiri (1.10.5)
134
+ mini_portile2 (~> 2.4.0)
136
135
  nokogumbo (1.5.0)
137
136
  nokogiri
138
137
  origin (2.3.1)
139
138
  pony (1.13.1)
140
139
  mail (>= 2.0)
141
- public_suffix (3.0.3)
142
- puma (3.12.0)
143
- rack (2.0.6)
140
+ public_suffix (4.0.1)
141
+ puma (4.3.0)
142
+ nio4r (~> 2.0)
143
+ rack (2.0.7)
144
144
  rack-cache (1.7.2)
145
145
  rack (>= 0.4)
146
146
  rack-mini-profiler (0.10.7)
@@ -150,7 +150,7 @@ GEM
150
150
  rack (>= 1.0, < 3)
151
151
  rack_csrf (2.6.0)
152
152
  rack (>= 1.1.0)
153
- rake (12.3.2)
153
+ rake (12.3.3)
154
154
  rb-fsevent (0.10.3)
155
155
  rb-inotify (0.10.0)
156
156
  ffi (~> 1.0)
@@ -182,14 +182,14 @@ GEM
182
182
  rack (> 1, < 3)
183
183
  stackprof (0.2.12)
184
184
  stringex (2.8.5)
185
- temple (0.8.0)
185
+ temple (0.8.1)
186
186
  term-ansicolor (1.7.1)
187
187
  tins (~> 1.0)
188
- thor (0.19.4)
188
+ thor (0.20.3)
189
189
  thread_safe (0.3.6)
190
190
  tilt (2.0.9)
191
191
  timecop (0.9.1)
192
- tins (1.20.2)
192
+ tins (1.21.1)
193
193
  tzinfo (1.2.5)
194
194
  thread_safe (~> 0.1)
195
195
  uglifier (4.1.20)
@@ -208,9 +208,9 @@ DEPENDENCIES
208
208
  locomotivecms_common!
209
209
  locomotivecms_steam!
210
210
  memory_profiler
211
- mongo (~> 2.5.1)
211
+ mongo (~> 2.8.0)
212
212
  origin (~> 2.3.1)
213
- puma
213
+ puma (~> 4.3.0)
214
214
  rack-mini-profiler (~> 0.10.1)
215
215
  rack-test (~> 0.8.2)
216
216
  rake (~> 12.3.0)
@@ -219,4 +219,4 @@ DEPENDENCIES
219
219
  timecop (~> 0.9.1)
220
220
 
221
221
  BUNDLED WITH
222
- 1.17.3
222
+ 2.0.2
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Steam
2
2
 
3
- [![Code Climate](https://codeclimate.com/github/locomotivecms/steam/badges/gpa.svg)](https://codeclimate.com/github/locomotivecms/steam) [![Dependency Status](https://gemnasium.com/locomotivecms/steam.svg)](https://gemnasium.com/locomotivecms/steam) [![Build Status](https://travis-ci.org/locomotivecms/steam.svg?branch=master)](https://travis-ci.org/locomotivecms/steam) [![Coverage Status](https://coveralls.io/repos/locomotivecms/steam/badge.svg?branch=master)](https://coveralls.io/r/locomotivecms/steam?branch=master) [![Gitter](https://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg)](https://gitter.im/locomotivecms/steam)
3
+ [![Code Climate](https://codeclimate.com/github/locomotivecms/steam/badges/gpa.svg)](https://codeclimate.com/github/locomotivecms/steam) [![Build Status](https://travis-ci.com/locomotivecms/steam.svg?branch=master)](https://travis-ci.com/locomotivecms/steam) [![Coverage Status](https://coveralls.io/repos/locomotivecms/steam/badge.svg?branch=master)](https://coveralls.io/r/locomotivecms/steam?branch=master) [![Gitter](https://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg)](https://gitter.im/locomotivecms/steam)
4
4
 
5
5
  The rendering stack used by both Wagon and Engine (WIP). It includes:
6
6
 
@@ -94,4 +94,4 @@ Note: you do not need to prefix with bundle exec as the docky-ruby image already
94
94
 
95
95
  ## License
96
96
 
97
- Copyright (c) 2018 NoCoffee. MIT Licensed, see MIT-LICENSE for details.
97
+ Copyright (c) 2019 NoCoffee. MIT Licensed, see MIT-LICENSE for details.
@@ -7,32 +7,78 @@ module Locomotive::Steam
7
7
  include Adapters::Filesystem::Sanitizer
8
8
 
9
9
  def apply_to_entity(entity)
10
- super
11
- parse_json(entity)
10
+ super.tap do
11
+ # allow multiple ways of defining global and preset content
12
+ handle_aliases(entity.definition)
13
+
14
+ # Utilize global defaults for dropzone preset
15
+ # when `use_default` is defined
16
+ fill_presets(entity.definition)
17
+
18
+ # use the default setting values if some settings
19
+ # are not set in the default object
20
+ set_default_values(entity.definition)
21
+ end
12
22
  end
13
23
 
14
24
  private
15
25
 
16
- def parse_json(entity)
17
- content = File.read(entity.template_path)
18
- match = content.match(JSON_FRONTMATTER_REGEXP)
26
+ def handle_aliases(definition)
27
+ # Dropzone presets -> presets
28
+ if presets = definition.delete('dropzone_presets')
29
+ definition['presets'] = presets
30
+ end
31
+
32
+ # Global content -> default
33
+ if default = definition.delete('global_content')
34
+ definition['default'] = default
35
+ end
36
+ end
19
37
 
20
- raise_parsing_error(entity, content) if match.nil?
38
+ def fill_presets(definition)
39
+ if definition.key?('default') && definition.key?('presets')
40
+ definition['presets'].each_with_index do |preset_definition, preset_index|
41
+ next unless preset_definition.delete('use_default') == true
21
42
 
22
- json, template = match[:json], match[:template]
43
+ settings = preset_definition['settings'] ||= {}
23
44
 
24
- begin
25
- entity.definition = MultiJson.load(json)
26
- rescue MultiJson::ParseError => e
27
- raise Locomotive::Steam::JsonParsingError.new(e, entity.template_path, json)
28
- end
45
+ # Fallback to use setting `default` key for Standalone/Global section settings and block settings
46
+ definition['default']['settings'].each do |name, value|
47
+ settings[name] ||= value
48
+ end
29
49
 
30
- entity.template = template
50
+ preset_definition['blocks'] = (preset_definition['blocks'] || []) + definition['default']['blocks']
51
+ end
52
+ end
31
53
  end
32
54
 
33
- def raise_parsing_error(entity, content)
34
- message = 'Your section requires a valid JSON header'
35
- raise Locomotive::Steam::ParsingRenderingError.new(message, entity.template_path, content, 0, nil)
55
+ def set_default_values(definition)
56
+ content = definition['default']
57
+
58
+ return if content.nil?
59
+
60
+ settings = content['settings'] ||= {}
61
+
62
+ definition['settings'].each do |setting|
63
+ settings[setting['id']] ||= setting['default']
64
+ end
65
+
66
+ # no definition of blocks, no need to continue
67
+ return if definition['blocks'].blank?
68
+
69
+ # now, take care of the different type of blocks
70
+ blocks = content['blocks'] ||= []
71
+
72
+ blocks.each do |block|
73
+ _definition = definition['blocks'].find { |d| d['type'] == block['type'] }
74
+
75
+ next if _definition.nil?
76
+
77
+ _definition['settings'].each do |setting|
78
+ block['settings'] ||= {}
79
+ block['settings'][setting['id']] ||= setting['default']
80
+ end
81
+ end
36
82
  end
37
83
 
38
84
  end
@@ -10,6 +10,8 @@ module Locomotive::Steam
10
10
  def apply_to_entity(entity)
11
11
  entity.metafields_schema = clean_metafields_schema(entity.metafields_schema)
12
12
  entity.routes = build_routes(entity.routes)
13
+
14
+ apply_metafields_samples(entity)
13
15
  end
14
16
 
15
17
  private
@@ -20,7 +22,7 @@ module Locomotive::Steam
20
22
  schema.each_with_index.map do |(namespace, definitions), position|
21
23
  {
22
24
  name: namespace.to_s,
23
- label: localized_label(definitions.delete(:label), namespace.to_s), # { default: namespace.to_s }.merge(definitions.delete(:label) || {}),
25
+ label: localized_label(definitions.delete(:label), namespace.to_s),
24
26
  fields: parse_metafields(definitions.delete(:fields)),
25
27
  position: definitions.delete(:position) || position
26
28
  }.merge(definitions)
@@ -40,6 +42,18 @@ module Locomotive::Steam
40
42
  end
41
43
  end
42
44
 
45
+ def apply_metafields_samples(entity)
46
+ entity.metafields_schema&.each do |namespace|
47
+ namespace[:fields].each do |field|
48
+ next unless field[:sample].present?
49
+
50
+ entity.metafields ||= {}
51
+ entity.metafields[namespace[:name]] ||= {}
52
+ entity.metafields[namespace[:name]][field[:name]] ||= field[:sample]
53
+ end
54
+ end
55
+ end
56
+
43
57
  def localized_label(label, default)
44
58
  case label
45
59
  when Hash then label
@@ -18,16 +18,29 @@ module Locomotive::Steam
18
18
  @scope = scope
19
19
  end
20
20
 
21
- def _load(path, frontmatter = false, &block)
21
+ def _load(path, frontmatter = false, strict = false, &block)
22
22
  if File.exists?(path)
23
23
  yaml = File.open(path).read.force_encoding('utf-8')
24
24
  template = nil
25
25
 
26
- if frontmatter && match = yaml.match(FRONTMATTER_REGEXP)
26
+ # JSON header?
27
+ if frontmatter && match = yaml.match(JSON_FRONTMATTER_REGEXP)
28
+ json, template = match[:json], match[:template]
29
+ safe_json_load(json, template, path, &block)
30
+
31
+ # YAML header?
32
+ elsif frontmatter && match = yaml.match(strict ? YAML_FRONTMATTER_REGEXP : FRONTMATTER_REGEXP)
27
33
  yaml, template = match[:yaml], match[:template]
28
- end
34
+ safe_yaml_load(yaml, template, path, &block)
29
35
 
30
- safe_yaml_load(yaml, template, path, &block)
36
+ elsif frontmatter
37
+ message = 'Your file requires a valid YAML or JSON header'
38
+ raise Locomotive::Steam::TemplateError.new(message, path, yaml, 0, nil)
39
+
40
+ # YAML by default
41
+ else
42
+ safe_yaml_load(yaml, template, path, &block)
43
+ end
31
44
  else
32
45
  Locomotive::Common::Logger.error "No #{path} file found"
33
46
  {}
@@ -46,18 +59,26 @@ module Locomotive::Steam
46
59
  end
47
60
  end
48
61
 
49
- def safe_json_load(path)
50
- return {} unless File.exists?(path)
51
-
52
- json = File.read(path)
62
+ def safe_json_load(json, template, path, &block)
63
+ return {} if json.blank?
53
64
 
54
65
  begin
55
- MultiJson.load(json)
66
+ MultiJson.load(json).tap do |attributes|
67
+ block.call(attributes, template) if block_given?
68
+ end
56
69
  rescue MultiJson::ParseError => e
57
70
  raise Locomotive::Steam::JsonParsingError.new(e, path, json)
58
71
  end
59
72
  end
60
73
 
74
+ def safe_json_file_load(path)
75
+ return {} unless File.exists?(path)
76
+
77
+ json = File.read(path)
78
+
79
+ safe_json_load(json, nil, path)
80
+ end
81
+
61
82
  def template_extensions
62
83
  @extensions ||= %w(liquid haml)
63
84
  end
@@ -18,7 +18,7 @@ module Locomotive
18
18
  def load_list
19
19
  [].tap do |list|
20
20
  each(content_type_slug) do |label, attributes, position|
21
- _attributes = { _position: position, _label: label.to_s }.merge(attributes)
21
+ _attributes = { _position: position, _label: label.to_s }.merge(attributes || {})
22
22
 
23
23
  modify_for_selects(_attributes)
24
24
  modify_for_associations(_attributes)
@@ -61,7 +61,7 @@ module Locomotive
61
61
  def load_data
62
62
  Dir.glob(File.join(data_path, '**', '*.json')).each do |filepath|
63
63
  filepath =~ /#{data_path}\/([a-z]+)\//
64
- data = safe_json_load(filepath)
64
+ data = safe_json_file_load(filepath)
65
65
  locale = $1.to_sym
66
66
 
67
67
  next unless locales.include?($1.to_sym)
@@ -16,11 +16,22 @@ module Locomotive
16
16
 
17
17
  def load_list
18
18
  Dir.glob(File.join(path, "*.{#{template_extensions.join(',')}}")).map do |filepath|
19
- slug = File.basename(filepath).split('.').first
20
- build(filepath, slug.permalink)
19
+ load_file(filepath)
21
20
  end
22
21
  end
23
22
 
23
+ def load_file(filepath)
24
+ slug = File.basename(filepath).split('.').first
25
+ attributes = build(filepath, slug.permalink)
26
+
27
+ _load(filepath, true, true) do |definition, template|
28
+ attributes[:definition] = definition
29
+ attributes[:template] = template
30
+ end
31
+
32
+ attributes
33
+ end
34
+
24
35
  def build(filepath, slug)
25
36
  {
26
37
  name: slug.humanize,
@@ -32,6 +43,7 @@ module Locomotive
32
43
  def path
33
44
  @path ||= File.join(site_path, 'app', 'views', 'sections')
34
45
  end
46
+
35
47
  end
36
48
  end
37
49
  end
@@ -27,7 +27,7 @@ module Locomotive
27
27
  def load_from_env
28
28
  return {} if env == :local
29
29
 
30
- safe_json_load(File.join(site_path, 'data', env.to_s, 'site.json')).symbolize_keys
30
+ safe_json_file_load(File.join(site_path, 'data', env.to_s, 'site.json')).symbolize_keys
31
31
  end
32
32
 
33
33
  def load_metafields_schema
@@ -26,7 +26,7 @@ module Locomotive
26
26
  end
27
27
 
28
28
  def _load_from_env
29
- safe_json_load(File.join(site_path, 'data', env.to_s, 'translations.json'))
29
+ safe_json_file_load(File.join(site_path, 'data', env.to_s, 'translations.json'))
30
30
  end
31
31
 
32
32
  def path
@@ -62,7 +62,7 @@ module Locomotive::Steam
62
62
  def base_url(mapper, scope, entity = nil)
63
63
  return nil if scope.site.nil?
64
64
 
65
- # Note: mimic Carrierwave behaviour
65
+ # Note: mimic the Carrierwave behavior
66
66
  base = "/sites/#{scope.site._id.to_s}"
67
67
 
68
68
  case mapper.name
@@ -121,7 +121,6 @@ module Locomotive::Steam
121
121
  _cast_value(field)
122
122
  rescue Exception => e
123
123
  Locomotive::Common::Logger.info "[#{content_type.slug}][#{_label}] Unable to cast the \"#{name}\" field, reason: #{e.message}".yellow
124
- puts e.message
125
124
  nil
126
125
  end
127
126
  end
@@ -7,6 +7,9 @@ module Locomotive::Steam
7
7
  def initialize(attributes = {})
8
8
  super({
9
9
  cache_enabled: false,
10
+ cache_control: nil,
11
+ cache_vary: nil,
12
+ bypass_browser_locale: false,
10
13
  prefix_default_locale: false,
11
14
  updated_at: nil,
12
15
  content_version: nil,
@@ -20,6 +23,7 @@ module Locomotive::Steam
20
23
  metafields_schema: {},
21
24
  metafields: nil,
22
25
  sections: nil,
26
+ sections_content: nil,
23
27
  asset_host: nil,
24
28
  routes: []
25
29
  }.merge(attributes))