locomotivecms_steam 1.6.0.rc1 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +2 -1
  4. data/Gemfile.lock +39 -38
  5. data/bin/steam.rb +1 -7
  6. data/docker-compose.yml +4 -0
  7. data/lib/locomotive/steam/configuration.rb +13 -0
  8. data/lib/locomotive/steam/entities/site.rb +1 -0
  9. data/lib/locomotive/steam/liquid/tags/concerns/attributes.rb +1 -1
  10. data/lib/locomotive/steam/liquid/tags/concerns/path.rb +2 -2
  11. data/lib/locomotive/steam/liquid/tags/consume.rb +1 -1
  12. data/lib/locomotive/steam/liquid/tags/editable/base.rb +4 -4
  13. data/lib/locomotive/steam/liquid/tags/global_section.rb +1 -1
  14. data/lib/locomotive/steam/liquid/tags/inherited_block.rb +1 -1
  15. data/lib/locomotive/steam/liquid/tags/section.rb +4 -4
  16. data/lib/locomotive/steam/liquid/tags/snippet.rb +10 -0
  17. data/lib/locomotive/steam/liquid/tags/with_scope.rb +1 -1
  18. data/lib/locomotive/steam/middlewares/auth.rb +9 -5
  19. data/lib/locomotive/steam/middlewares/concerns/auth_helpers.rb +1 -1
  20. data/lib/locomotive/steam/middlewares/concerns/helpers.rb +5 -1
  21. data/lib/locomotive/steam/middlewares/concerns/rendering.rb +1 -1
  22. data/lib/locomotive/steam/middlewares/locale.rb +5 -5
  23. data/lib/locomotive/steam/middlewares/logging.rb +2 -4
  24. data/lib/locomotive/steam/middlewares/page.rb +4 -4
  25. data/lib/locomotive/steam/middlewares/path.rb +7 -1
  26. data/lib/locomotive/steam/middlewares/private_access.rb +2 -2
  27. data/lib/locomotive/steam/middlewares/templatized_page.rb +1 -1
  28. data/lib/locomotive/steam/middlewares/timezone.rb +1 -1
  29. data/lib/locomotive/steam/version.rb +1 -1
  30. data/lib/locomotive/steam.rb +7 -0
  31. data/locomotivecms_steam.gemspec +2 -2
  32. data/spec/fixtures/default/app/content_types/accounts.yml +3 -0
  33. data/spec/spec_helper.rb +1 -1
  34. data/spec/support/helpers.rb +2 -4
  35. data/spec/unit/liquid/tags/with_scope_spec.rb +10 -1
  36. data/spec/unit/middlewares/cache_spec.rb +4 -4
  37. data/spec/unit/middlewares/path_spec.rb +70 -0
  38. metadata +17 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c52a8de8a28e60162f058703b686dcd3b4f776a51990bcc90bd1b0ff89609fd7
4
- data.tar.gz: 316c87edf83b117562e961ba666452468af720523bd948ed88cd691438b57937
3
+ metadata.gz: 7df479f835f1f7233945c2da8f3df5e3bfa5186b225ded85197363c63b0c7c5b
4
+ data.tar.gz: d653e2259dccaa5e8d643c9019f7315bad2fdeb7b759d14997dd5ca87b554ba7
5
5
  SHA512:
6
- metadata.gz: b49614cb897afa01b679aabf5c8dbb2b10c5410212a71972dedd462850d97dbfa020d1e1ddb75571881e53f2d6c99b7006d7c1bd410a0f7bd1b7dbe10632832e
7
- data.tar.gz: c7585f401423c84cc9ca593107fe991a390ca4b58969a0ac56f6630df47a13baf9da710c55a7c92e0a4f7a13bce088585e2fa33439b095dcdb2f0774ac5b15a2
6
+ metadata.gz: 5269811d92d7853e44cfd9f481f1bf303e11cd5d99652dda98c02e46ec20f28b43f34a419594c3bdc87c8fba3130316c1c79b4528eb3782710522e8974c324ea
7
+ data.tar.gz: 5faee657e95f13b8a5ab305b149a8739c41c5e698f58715c299363f332a56974bc3011785b21b01fe0552ce64bc907bea25ca200e13acc3616b3e96d02ef7e7b
data/.gitignore CHANGED
@@ -28,3 +28,4 @@ spec/fixtures/default/log/*
28
28
  log
29
29
  dragonfly.log
30
30
  .byebug_history
31
+ TODO.md
data/Gemfile CHANGED
@@ -9,9 +9,10 @@ group :development do
9
9
  # gem 'duktape', github: 'judofyr/duktape.rb', ref: '20ef6a5'
10
10
  # gem 'duktape', github: 'did/duktape.rb', branch: 'any-fixnum'
11
11
 
12
- gem 'puma', '~> 5.3.1'
12
+ gem 'puma', '~> 5.6.4'
13
13
  gem 'haml', '~> 5.2.0'
14
14
 
15
+ gem 'rack', '~> 2.2.3.1'
15
16
  gem 'rack-mini-profiler', '~> 0.10.1'
16
17
  gem 'flamegraph'
17
18
  gem 'stackprof' # ruby 2.1+ only
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- locomotivecms_steam (1.6.0.rc1)
4
+ locomotivecms_steam (1.6.1)
5
5
  RedCloth (~> 4.3.2)
6
6
  autoprefixer-rails (~> 8.0.0)
7
7
  bcrypt (~> 3.1.11)
@@ -19,7 +19,7 @@ PATH
19
19
  moneta (~> 1.0.0)
20
20
  morphine (~> 0.1.1)
21
21
  multi_json (~> 1.15.0)
22
- nokogiri (~> 1.11.0)
22
+ nokogiri (>= 1.11, < 1.14)
23
23
  pony (~> 1.12)
24
24
  rack-cache (~> 1.7.0)
25
25
  rack-rewrite (~> 1.5.1)
@@ -33,18 +33,18 @@ GEM
33
33
  remote: https://rubygems.org/
34
34
  specs:
35
35
  RedCloth (4.3.2)
36
- activesupport (5.2.6)
36
+ activesupport (5.2.8.1)
37
37
  concurrent-ruby (~> 1.0, >= 1.0.2)
38
38
  i18n (>= 0.7, < 2)
39
39
  minitest (~> 5.1)
40
40
  tzinfo (~> 1.1)
41
- addressable (2.8.0)
42
- public_suffix (>= 2.0.2, < 5.0)
41
+ addressable (2.8.1)
42
+ public_suffix (>= 2.0.2, < 6.0)
43
43
  attr_extras (5.2.0)
44
44
  autoprefixer-rails (8.0.0)
45
45
  execjs
46
- bcrypt (3.1.16)
47
- bson (4.11.1)
46
+ bcrypt (3.1.18)
47
+ bson (4.15.0)
48
48
  chronic (0.10.2)
49
49
  chunky_png (1.4.0)
50
50
  coffee-script (2.4.1)
@@ -64,7 +64,7 @@ GEM
64
64
  sass (>= 3.3.0, < 3.5)
65
65
  compass-import-once (1.0.5)
66
66
  sass (>= 3.2, < 3.5)
67
- concurrent-ruby (1.1.7)
67
+ concurrent-ruby (1.1.10)
68
68
  coveralls (0.8.23)
69
69
  json (>= 1.8, < 3)
70
70
  simplecov (~> 0.16.1)
@@ -72,33 +72,33 @@ GEM
72
72
  thor (>= 0.19.4, < 2.0)
73
73
  tins (~> 1.6)
74
74
  crass (1.0.6)
75
- diff-lcs (1.4.4)
76
- docile (1.3.2)
75
+ diff-lcs (1.5.0)
76
+ docile (1.4.0)
77
77
  dragonfly (1.4.0)
78
78
  addressable (~> 2.3)
79
79
  multi_json (~> 1.0)
80
80
  rack (>= 1.3)
81
81
  duktape (2.0.1.1)
82
82
  execjs (2.8.1)
83
- ffi (1.15.4)
83
+ ffi (1.15.5)
84
84
  flamegraph (0.9.5)
85
- haml (5.2.0)
85
+ haml (5.2.2)
86
86
  temple (>= 0.8.0)
87
87
  tilt
88
88
  httparty (0.16.4)
89
89
  mime-types (~> 3.0)
90
90
  multi_xml (>= 0.5.2)
91
- i18n (1.8.5)
91
+ i18n (1.12.0)
92
92
  concurrent-ruby (~> 1.0)
93
93
  i18n-spec (0.6.0)
94
94
  iso
95
- iso (0.3.0)
95
+ iso (0.4.0)
96
96
  i18n
97
- json (2.3.1)
97
+ json (2.6.2)
98
98
  json_spec (1.1.5)
99
99
  multi_json (~> 1.0)
100
100
  rspec (>= 2.0, < 4.0)
101
- kramdown (2.3.1)
101
+ kramdown (2.3.2)
102
102
  rexml
103
103
  liquid (4.0.3)
104
104
  locomotivecms_common (0.4.0)
@@ -108,34 +108,34 @@ GEM
108
108
  stringex (~> 2.8.2)
109
109
  mail (2.7.1)
110
110
  mini_mime (>= 0.1.1)
111
- memory_profiler (0.9.14)
111
+ memory_profiler (1.0.0)
112
112
  mime-types (3.3.1)
113
113
  mime-types-data (~> 3.2015)
114
- mime-types-data (3.2021.0901)
114
+ mime-types-data (3.2022.0105)
115
115
  mimetype-fu (0.1.2)
116
- mini_mime (1.1.1)
117
- mini_portile2 (2.5.3)
118
- minitest (5.14.4)
116
+ mini_mime (1.1.2)
117
+ mini_portile2 (2.8.0)
118
+ minitest (5.16.3)
119
119
  moneta (1.0.0)
120
- mongo (2.13.1)
120
+ mongo (2.13.3)
121
121
  bson (>= 4.8.2, < 5.0.0)
122
122
  morphine (0.1.1)
123
123
  multi_json (1.15.0)
124
124
  multi_xml (0.6.0)
125
- nio4r (2.5.7)
126
- nokogiri (1.11.7)
127
- mini_portile2 (~> 2.5.0)
125
+ nio4r (2.5.8)
126
+ nokogiri (1.13.8)
127
+ mini_portile2 (~> 2.8.0)
128
128
  racc (~> 1.4)
129
129
  nokogumbo (2.0.5)
130
130
  nokogiri (~> 1.8, >= 1.8.4)
131
131
  origin (2.3.1)
132
132
  pony (1.13.1)
133
133
  mail (>= 2.0)
134
- public_suffix (4.0.6)
135
- puma (5.3.2)
134
+ public_suffix (5.0.0)
135
+ puma (5.6.5)
136
136
  nio4r (~> 2.0)
137
- racc (1.5.2)
138
- rack (2.2.3)
137
+ racc (1.6.0)
138
+ rack (2.2.3.1)
139
139
  rack-cache (1.7.2)
140
140
  rack (>= 0.4)
141
141
  rack-mini-profiler (0.10.7)
@@ -145,8 +145,8 @@ GEM
145
145
  rack (>= 1.0, < 3)
146
146
  rack_csrf (2.6.0)
147
147
  rack (>= 1.1.0)
148
- rake (13.0.1)
149
- rb-fsevent (0.11.0)
148
+ rake (13.0.6)
149
+ rb-fsevent (0.11.2)
150
150
  rb-inotify (0.10.1)
151
151
  ffi (~> 1.0)
152
152
  rexml (3.2.5)
@@ -176,19 +176,19 @@ GEM
176
176
  sprockets (3.7.2)
177
177
  concurrent-ruby (~> 1.0)
178
178
  rack (> 1, < 3)
179
- stackprof (0.2.16)
179
+ stackprof (0.2.21)
180
180
  stringex (2.8.5)
181
181
  sync (0.5.0)
182
182
  temple (0.8.2)
183
183
  term-ansicolor (1.7.1)
184
184
  tins (~> 1.0)
185
- thor (1.0.1)
185
+ thor (1.2.1)
186
186
  thread_safe (0.3.6)
187
- tilt (2.0.10)
188
- timecop (0.9.2)
189
- tins (1.26.0)
187
+ tilt (2.0.11)
188
+ timecop (0.9.5)
189
+ tins (1.31.1)
190
190
  sync
191
- tzinfo (1.2.9)
191
+ tzinfo (1.2.10)
192
192
  thread_safe (~> 0.1)
193
193
  uglifier (4.1.20)
194
194
  execjs (>= 0.3.0, < 3)
@@ -206,7 +206,8 @@ DEPENDENCIES
206
206
  memory_profiler
207
207
  mongo (~> 2.13.1)
208
208
  origin (~> 2.3.1)
209
- puma (~> 5.3.1)
209
+ puma (~> 5.6.4)
210
+ rack (~> 2.2.3.1)
210
211
  rack-mini-profiler (~> 0.10.1)
211
212
  rack-test (~> 0.8.2)
212
213
  rake (~> 13.0.1)
data/bin/steam.rb CHANGED
@@ -68,8 +68,6 @@ end.parse!
68
68
  require_relative '../lib/locomotive/steam'
69
69
  require_relative '../lib/locomotive/steam/server'
70
70
 
71
- puts options.inspect
72
-
73
71
  Locomotive::Steam.configure do |config|
74
72
  config.mode = :test
75
73
  config.adapter = options[:adapter]
@@ -77,11 +75,7 @@ Locomotive::Steam.configure do |config|
77
75
  config.asset_path = options[:asset_path]
78
76
  config.asset_host = options[:asset_host]
79
77
  config.minify_assets = false
80
- end
81
-
82
- Locomotive::Common.reset
83
- Locomotive::Common.configure do |config|
84
- config.notifier = Locomotive::Common::Logger.setup(options[:log_file])
78
+ config.log_file = options[:log_file]
85
79
  end
86
80
 
87
81
  app = Locomotive::Steam.to_app
data/docker-compose.yml CHANGED
@@ -12,4 +12,8 @@ services:
12
12
  - ./bundle:/usr/local/bundle
13
13
  depends_on:
14
14
  - db
15
+ labels:
16
+ docky.main.service: True
17
+ docky.user: ubuntu
18
+
15
19
  version: '3'
@@ -102,6 +102,19 @@ module Locomotive
102
102
  attr_accessor :render_404_if_no_site
103
103
  def render_404_if_no_site; @render_404_if_no_site.nil? ? true : @render_404_if_no_site; end
104
104
 
105
+ # Log file
106
+ #
107
+ # default: nil (ENV['LOCOMOTIVE_STEAM_LOG'] || STDOUT)
108
+ #
109
+ attr_accessor :log_file
110
+
111
+ # Log level
112
+ #
113
+ # default: ::Logger::DEBUG
114
+ #
115
+ attr_accessor :log_level
116
+ def log_level; @log_level || ::Logger::DEBUG; end
117
+
105
118
  # Lambda called once a Services instance has been built.
106
119
  # It is used when we want to change one of the services
107
120
  #
@@ -25,6 +25,7 @@ module Locomotive::Steam
25
25
  sections: nil,
26
26
  sections_content: nil,
27
27
  asset_host: nil,
28
+ allow_dots_in_slugs: false,
28
29
  routes: []
29
30
  }.merge(attributes))
30
31
  end
@@ -45,4 +45,4 @@ module Locomotive
45
45
  end
46
46
  end
47
47
  end
48
- end
48
+ end
@@ -29,7 +29,7 @@ module Locomotive
29
29
  handle = @context[@handle] || @handle
30
30
 
31
31
  # is external url?
32
- if handle.to_s =~ Locomotive::Steam::IsHTTP
32
+ if handle =~ Locomotive::Steam::IsHTTP
33
33
  handle
34
34
  elsif page = self.retrieve_page_drop_from_handle(handle) # return a drop or model?
35
35
  # make sure we've got the page/content entry (if templatized)
@@ -104,4 +104,4 @@ module Locomotive
104
104
  end
105
105
  end
106
106
  end
107
- end
107
+ end
@@ -99,4 +99,4 @@ module Locomotive
99
99
  end
100
100
  end
101
101
  end
102
- end
102
+ end
@@ -119,11 +119,11 @@ module Locomotive
119
119
  block: self.current_inherited_block_name,
120
120
  label: label,
121
121
  slug: slug,
122
- hint: attributes[:hint],
123
- priority: attributes[:priority] || 0,
124
- fixed: [true, 'true'].include?(attributes[:fixed]),
122
+ hint: raw_attributes[:hint],
123
+ priority: raw_attributes[:priority] || 0,
124
+ fixed: [true, 'true'].include?(raw_attributes[:fixed]),
125
125
  disabled: false,
126
- inline_editing: [true, 'true'].include?(attributes[:inline_editing]),
126
+ inline_editing: [true, 'true'].include?(raw_attributes[:inline_editing]),
127
127
  from_parent: false,
128
128
  type: @tag_name.to_sym
129
129
  }
@@ -9,7 +9,7 @@ module Locomotive
9
9
  source: :site,
10
10
  id: "site-#{section_type}",
11
11
  key: section_type,
12
- placement: attributes[:placement]&.to_sym
12
+ placement: raw_attributes[:placement]&.to_sym
13
13
  )
14
14
  end
15
15
 
@@ -155,4 +155,4 @@ module Locomotive
155
155
  end
156
156
  end
157
157
  end
158
- end
158
+ end
@@ -24,10 +24,10 @@ module Locomotive
24
24
 
25
25
  def parse(tokens)
26
26
  notify_on_parsing(section_type,
27
- id: "page-#{attributes[:id] || section_type}",
28
- key: (attributes[:id] || section_type).to_s,
29
- label: attributes[:label],
30
- placement: attributes[:placement]&.to_sym
27
+ id: "page-#{raw_attributes[:id] || section_type}",
28
+ key: (raw_attributes[:id] || section_type).to_s,
29
+ label: raw_attributes[:label],
30
+ placement: raw_attributes[:placement]&.to_sym
31
31
  )
32
32
  end
33
33
 
@@ -11,6 +11,16 @@ module Locomotive
11
11
  # NOTE: it doesn't support dynamically choosen template
12
12
  template_name = template_name_expr.respond_to?(:name) ? template_name_expr.name : template_name_expr
13
13
 
14
+ # make sure we keep track of the parsed snippets
15
+ parse_context[:parsed_snippets] ||= []
16
+
17
+ # already parsed? (it happens when doing recursivity with snippets)
18
+ if parse_context[:parsed_snippets].include?(template_name)
19
+ return
20
+ else
21
+ parse_context[:parsed_snippets] << template_name
22
+ end
23
+
14
24
  ActiveSupport::Notifications.instrument('steam.parse.include', page: parse_context[:page], name: template_name)
15
25
 
16
26
  if parse_context[:snippet_finder] && snippet = parse_context[:snippet_finder].find(template_name)
@@ -121,4 +121,4 @@ module Locomotive
121
121
  end
122
122
  end
123
123
  end
124
- end
124
+ end
@@ -30,7 +30,12 @@ module Locomotive::Steam
30
30
  private
31
31
 
32
32
  def sign_up(options)
33
- return if authenticated? || !is_recaptcha_valid?(options.type, options.recaptcha_response)
33
+ return if authenticated?
34
+
35
+ if !is_recaptcha_valid?(options.type, options.recaptcha_response)
36
+ append_message(:invalid_recaptcha_code)
37
+ return
38
+ end
34
39
 
35
40
  status, entry = services.auth.sign_up(options, default_liquid_context, request)
36
41
 
@@ -101,7 +106,7 @@ module Locomotive::Steam
101
106
  end
102
107
 
103
108
  def append_message(message)
104
- log "[Auth] status message = #{message.inspect}"
109
+ debug_log "[Auth] status message = #{message.inspect}"
105
110
 
106
111
  message ||= 'error'
107
112
  liquid_assigns["auth_#{message}"] = "auth_#{message}"
@@ -158,7 +163,7 @@ module Locomotive::Steam
158
163
  end
159
164
 
160
165
  def from
161
- smtp_config['sender'] || 'support@locomotivecms.com'
166
+ smtp_config['sender'] || smtp_config['from'] || 'support@locomotivecms.com'
162
167
  end
163
168
 
164
169
  def subject
@@ -182,7 +187,7 @@ module Locomotive::Steam
182
187
  end
183
188
 
184
189
  def recaptcha_response
185
- params["g-recaptcha-response"]
190
+ params['g-recaptcha-response']
186
191
  end
187
192
 
188
193
  def smtp
@@ -213,7 +218,6 @@ module Locomotive::Steam
213
218
  end
214
219
  end
215
220
 
216
-
217
221
  end
218
222
 
219
223
  end
@@ -19,7 +19,7 @@ module Locomotive::Steam
19
19
 
20
20
  env['steam.authenticated_entry'] = nil if entry.nil?
21
21
 
22
- log "[Auth] authenticated #{type.to_s.singularize} ##{entry&._id.to_s}"
22
+ debug_log "[Auth] authenticated #{type.to_s.singularize} ##{entry&._id.to_s}"
23
23
 
24
24
  liquid_assigns["current_#{type.singularize}"] = entry
25
25
  end
@@ -40,7 +40,7 @@ module Locomotive::Steam
40
40
  def redirect_to(location, type = 301)
41
41
  _location = mounted_on && !location.starts_with?(mounted_on) && (location =~ Locomotive::Steam::IsHTTP).nil? ? "#{mounted_on}#{location}" : location
42
42
 
43
- self.log "Redirected to #{_location}".blue
43
+ self.debug_log "Redirected to #{_location}".blue
44
44
 
45
45
  headers = { 'Content-Type' => HTML_CONTENT_TYPE, 'Location' => _location }
46
46
  inject_cookies(headers)
@@ -83,6 +83,10 @@ module Locomotive::Steam
83
83
  Locomotive::Common::Logger.info (' ' * offset) + msg
84
84
  end
85
85
 
86
+ def debug_log(msg, offset = 2)
87
+ Locomotive::Common::Logger.debug (' ' * offset) + msg
88
+ end
89
+
86
90
  end
87
91
  end
88
92
  end
@@ -28,7 +28,7 @@ module Locomotive::Steam
28
28
  "Your 404 page is missing."
29
29
  end) + " Please create it."
30
30
 
31
- log "[Warning] #{message}".red
31
+ debug_log "[Warning] #{message}".red
32
32
 
33
33
  render_response(message, 404)
34
34
  end
@@ -23,7 +23,7 @@ module Locomotive::Steam
23
23
 
24
24
  set_locale_cookie
25
25
 
26
- log "Locale used: #{locale.upcase}"
26
+ debug_log "Locale used: #{locale.upcase}"
27
27
 
28
28
  I18n.with_locale(locale) do
29
29
  self.next
@@ -48,7 +48,7 @@ module Locomotive::Steam
48
48
 
49
49
  def locale_from_params
50
50
  params[:locale]&.to_sym.tap do |locale|
51
- log 'Locale extracted from the params' unless locale.blank?
51
+ debug_log 'Locale extracted from the params' unless locale.blank?
52
52
  end
53
53
  end
54
54
 
@@ -62,7 +62,7 @@ module Locomotive::Steam
62
62
  env['steam.path'] = path.gsub(/^\/#{$1 + $2}/, '/')
63
63
  env['steam.locale_in_path'] = true
64
64
 
65
- log 'Locale extracted from the path'
65
+ debug_log'Locale extracted from the path'
66
66
 
67
67
  locale.to_sym
68
68
  end
@@ -73,14 +73,14 @@ module Locomotive::Steam
73
73
  .sort { |a, b| b[1] <=> a[1] }
74
74
  .map { |lang, _| lang[0..1].to_sym }
75
75
  .find { |lang| locales.include?(lang) }.tap do |locale|
76
- log 'Locale extracted from the header' unless locale.blank?
76
+ debug_log 'Locale extracted from the header' unless locale.blank?
77
77
  end
78
78
  end
79
79
 
80
80
  def locale_from_cookie
81
81
  if locale = services.cookie.get(cookie_key_name)
82
82
 
83
- log 'Locale extracted from the cookie'
83
+ debug_log 'Locale extracted from the cookie'
84
84
 
85
85
  locale.to_sym
86
86
  end
@@ -14,10 +14,8 @@ module Locomotive::Steam
14
14
 
15
15
  log "Started #{env['REQUEST_METHOD'].upcase} \"#{env['PATH_INFO']}\" at #{now}".light_white, 0
16
16
 
17
- if Locomotive::Steam.configuration.mode == :test
18
- log "Params: #{env.fetch('steam.request').params.inspect}"
19
- end
20
-
17
+ debug_log "Params: #{env.fetch('steam.request').params.inspect}"
18
+
21
19
  app.call(env).tap do |response|
22
20
  done_in_ms = ((Time.now - now) * 10000).truncate / 10.0
23
21
  log "Completed #{code_to_human(response.first)} in #{done_in_ms}ms\n\n".green
@@ -13,10 +13,10 @@ module Locomotive::Steam
13
13
 
14
14
  if page = fetch_page
15
15
  if !page.not_found?
16
- log "Found page \"#{page.title}\" [#{page.fullpath}]"
16
+ debug_log "Found page \"#{page.title}\" [#{page.fullpath}]"
17
17
  else
18
18
  ActiveSupport::Notifications.instrument('steam.render.page_not_found', path: path, locale: locale, default_locale: default_locale)
19
- log "Page not found (#{path.inspect}), rendering the 404 page.".magenta
19
+ debug_log "Page not found (#{path.inspect}), rendering the 404 page.".magenta
20
20
  end
21
21
  end
22
22
 
@@ -47,7 +47,7 @@ module Locomotive::Steam
47
47
  regexp = Regexp.new(/^#{_route}$/i)
48
48
 
49
49
  if (matches = path.match(regexp))
50
- log "Route found! #{route} (#{handle})"
50
+ debug_log "Route found! #{route} (#{handle})"
51
51
 
52
52
  # we want the named route parameters in the request params object
53
53
  # because they will be needed in the liquid template.
@@ -63,7 +63,7 @@ module Locomotive::Steam
63
63
  def fetch_page_from_paths
64
64
  page_finder.match(path).tap do |pages|
65
65
  if pages.size > 1
66
- self.log "Found multiple pages: #{pages.map(&:title).join(', ')}"
66
+ self.debug_log "Found multiple pages: #{pages.map(&:title).join(', ')}"
67
67
  end
68
68
  end.first
69
69
  end
@@ -16,9 +16,15 @@ module Locomotive::Steam
16
16
  protected
17
17
 
18
18
  def set_path!(env)
19
+ site = env['steam.site']
19
20
  path = env['steam.path'].dup
20
21
 
21
- path.gsub!(/\.[a-zA-Z][a-zA-Z0-9]{2,}$/, '')
22
+ if site.allow_dots_in_slugs
23
+ path.gsub!(/\.(html|htm)$/, '')
24
+ else
25
+ path.gsub!(/\.[a-zA-Z][a-zA-Z0-9]{2,}$/, '')
26
+ end
27
+
22
28
  path.gsub!(/^\//, '')
23
29
  path.gsub!(/^[A-Z]:\//, '')
24
30
 
@@ -14,7 +14,7 @@ module Locomotive::Steam
14
14
  return if env['steam.private_access_disabled']
15
15
 
16
16
  if site.private_access
17
- log "Site with private access"
17
+ debug_log "Site with private access"
18
18
 
19
19
  if access_granted?
20
20
  store_password
@@ -28,7 +28,7 @@ module Locomotive::Steam
28
28
 
29
29
  def render_lock_screen
30
30
  if page = services.page_finder.by_handle('lock_screen', false)
31
- log "Found custom lock screen: #{page.title}"
31
+ debug_log "Found custom lock screen: #{page.title}"
32
32
  env['steam.page'] = page
33
33
  else
34
34
  render_response(lock_screen_html, 403)
@@ -26,7 +26,7 @@ module Locomotive::Steam
26
26
  env['steam.content_entry'] = page.content_entry = entry
27
27
 
28
28
  # log it
29
- log "Found content entry: #{entry._label}"
29
+ debug_log "Found content entry: #{entry._label}"
30
30
  else
31
31
  url = services.url_builder.url_for(page_not_found, locale)
32
32
  redirect_to url, 302
@@ -10,7 +10,7 @@ module Locomotive::Steam
10
10
  def _call
11
11
  timezone = site.try(:timezone)
12
12
 
13
- log "Timezone: #{timezone.name}"
13
+ debug_log "Timezone: #{timezone.name}"
14
14
 
15
15
  Time.use_zone(timezone) do
16
16
  self.next
@@ -3,6 +3,6 @@
3
3
  # 1.0.0.alpha < 1.0.0.alpha1 < 1.0.0.beta < 1.0.0.beta2 < 1.0.0.beta11 < 1.0.0.rc1 < 1.0.0
4
4
  module Locomotive
5
5
  module Steam
6
- VERSION = '1.6.0.rc1'
6
+ VERSION = '1.6.1'
7
7
  end
8
8
  end
@@ -48,6 +48,13 @@ module Locomotive
48
48
  def self.configure
49
49
  yield(configuration)
50
50
 
51
+ # configure the logger
52
+ Locomotive::Common.reset
53
+ Locomotive::Common.configure do |config|
54
+ config.notifier = Locomotive::Common::Logger.setup(configuration.log_file)
55
+ config.notifier.level = configuration.log_level
56
+ end
57
+
51
58
  require_relative 'steam/initializers'
52
59
  end
53
60
 
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.add_development_dependency 'mongo', '~> 2.13.1'
21
21
  spec.add_development_dependency 'origin', '~> 2.3.1'
22
22
 
23
- spec.add_dependency 'nokogiri', '~> 1.11.0'
23
+ spec.add_dependency 'nokogiri', '>= 1.11', '< 1.14'
24
24
  spec.add_dependency 'sanitize', '~> 5.2.1'
25
25
  spec.add_dependency 'morphine', '~> 0.1.1'
26
26
  spec.add_dependency 'httparty', '~> 0.16.0'
@@ -48,7 +48,7 @@ Gem::Specification.new do |spec|
48
48
  spec.add_dependency 'mime-types', '~> 3.3.0'
49
49
  spec.add_dependency 'duktape', '~> 2.0.1.1'
50
50
  spec.add_dependency 'pony', '~> 1.12'
51
-
51
+
52
52
  spec.add_dependency 'locomotivecms_common', '~> 0.4.0'
53
53
 
54
54
  spec.required_ruby_version = ['>= 2.5', '< 3']
@@ -22,6 +22,9 @@ order_by: manually
22
22
  # Activate public 'create' API (e.g for a contact form)
23
23
  # public_submission_enabled: false
24
24
 
25
+ # Enable Google Recaptcha to create new public entries
26
+ # recaptcha_required: true
27
+
25
28
  # Array of emails to be notified of new entries made with the public API
26
29
  # public_submission_accounts: ['john@example.com']
27
30
 
data/spec/spec_helper.rb CHANGED
@@ -45,7 +45,7 @@ RSpec.configure do |config|
45
45
  config.filter_run focused: true
46
46
  config.run_all_when_everything_filtered = true
47
47
 
48
- config.before(:all) { remove_logs; setup_common }
48
+ config.before(:all) { remove_logs; reset_logger }
49
49
  config.before { reset! }
50
50
  config.after { reset! }
51
51
  config.order = :random
@@ -19,7 +19,7 @@ module Spec
19
19
  FileUtils.rm_rf(File.expand_path('../../fixtures/default/log', __FILE__))
20
20
  end
21
21
 
22
- def setup_common(logger_output = nil)
22
+ def reset_logger(logger_output = nil)
23
23
  Locomotive::Common.reset
24
24
  Locomotive::Common.configure do |config|
25
25
  logger_output ||= File.join(default_fixture_site_path, 'log/steam.log')
@@ -30,9 +30,6 @@ module Spec
30
30
  def run_server
31
31
  require 'haml'
32
32
 
33
- output = ENV['STEAM_VERBOSE'] ? nil : File.join(default_fixture_site_path, 'log/steam.log')
34
- setup_common(output)
35
-
36
33
  Locomotive::Steam.configure do |config|
37
34
  config.mode = :test
38
35
  config.adapter = { name: :filesystem, path: default_fixture_site_path }
@@ -40,6 +37,7 @@ module Spec
40
37
  config.asset_path = File.expand_path(File.join(default_fixture_site_path, 'public'))
41
38
  config.serve_assets = true
42
39
  config.minify_assets = true
40
+ config.log_file = ENV['STEAM_VERBOSE'] ? nil : File.join(default_fixture_site_path, 'log/steam.log')
43
41
  end
44
42
 
45
43
  Locomotive::Common::Logger.info 'Server started...'
@@ -62,7 +62,7 @@ describe Locomotive::Steam::Liquid::Tags::WithScope do
62
62
  it { expect(conditions['hidden']).to eq false }
63
63
 
64
64
  end
65
-
65
+
66
66
  describe 'decode regexps' do
67
67
 
68
68
  let(:source) { "{% with_scope title: /Like this one|or this one/ %}{% assign conditions = with_scope %}{% endwith_scope %}" }
@@ -146,6 +146,15 @@ describe Locomotive::Steam::Liquid::Tags::WithScope do
146
146
 
147
147
  end
148
148
 
149
+ describe 'In a loop context, each scope should be evaluated correctly' do
150
+ let(:assigns) { {'list' => ['A', 'B', 'C']} }
151
+
152
+ let(:source) { "{% for key in list %}{% with_scope foo: key %}{% assign conditions = with_scope %}{% endwith_scope %}{{ conditions }}{% endfor %}" }
153
+
154
+ it { expect(output).to eq '{"foo"=>"A"}{"foo"=>"B"}{"foo"=>"C"}' }
155
+
156
+ end
157
+
149
158
  end
150
159
 
151
160
  end
@@ -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('7cf53dab8a56bd5d2cbf7610101514fd').and_return(response) }
58
+ before { expect(cache).to receive(:read).with('4fb84e6d3037dcd54979c3461c5a5ffd').and_return(response) }
59
59
 
60
60
  context 'the cache is empty' do
61
61
 
62
- before { expect(cache).to receive(:write).with('7cf53dab8a56bd5d2cbf7610101514fd', Marshal.dump([200, {}, ["Hello world!"]])) }
62
+ before { expect(cache).to receive(:write).with('4fb84e6d3037dcd54979c3461c5a5ffd', 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 '7cf53dab8a56bd5d2cbf7610101514fd' }
72
+ it { is_expected.to eq '4fb84e6d3037dcd54979c3461c5a5ffd' }
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) { '7cf53dab8a56bd5d2cbf7610101514fd' }
107
+ let(:etag) { '4fb84e6d3037dcd54979c3461c5a5ffd' }
108
108
 
109
109
  it 'returns a 304 (Not modified) without no cache headers' do
110
110
  expect(subject.first).to eq 304
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ require_relative '../../../lib/locomotive/steam/middlewares/path'
4
+
5
+ describe Locomotive::Steam::Middlewares::Path do
6
+
7
+ let(:allow_dots_in_slugs) { false }
8
+ let(:site) { instance_double('Site', allow_dots_in_slugs: allow_dots_in_slugs) }
9
+ let(:routes) { {} }
10
+ let(:url) { 'http://models.example.com' }
11
+ let(:path) { 'hello-world' }
12
+ let(:app) { ->(env) { [200, env, 'app'] } }
13
+ let(:middleware) { described_class.new(app) }
14
+
15
+ subject do
16
+ env = env_for(url, 'steam.site' => site)
17
+ env['steam.path'] = path
18
+ env['steam.locale'] = 'en'
19
+ env['steam.request'] = Rack::Request.new(env)
20
+ code, env = middleware.call(env)
21
+ env['steam.path']
22
+ end
23
+
24
+ describe 'allow_dots_in_slugs is off' do
25
+ context 'html extension' do
26
+ let(:path) { 'foo.html' }
27
+ it { is_expected.to eq 'foo' }
28
+ end
29
+
30
+ context 'the path stores a version' do
31
+ let(:path) { 'foo-v1.0' }
32
+ it { is_expected.to eq 'foo-v1.0' }
33
+ end
34
+
35
+ context 'prefixed by 3 letters word' do
36
+ let(:path) { 'foo.bar' }
37
+ it { is_expected.to eq 'foo' }
38
+ end
39
+
40
+ context 'starting by a dot' do
41
+ let(:path) { '.well-known' }
42
+ it { is_expected.to eq '.well-known' }
43
+ end
44
+ end
45
+
46
+ describe 'allow_dots_in_slugs is on' do
47
+ let(:allow_dots_in_slugs) { true }
48
+
49
+ context 'html extension' do
50
+ let(:path) { 'foo.html' }
51
+ it { is_expected.to eq 'foo' }
52
+ end
53
+
54
+ context 'prefixed by a version' do
55
+ let(:path) { 'foo-v1.0' }
56
+ it { is_expected.to eq 'foo-v1.0' }
57
+ end
58
+
59
+ context 'prefixed by 3 letters word' do
60
+ let(:path) { 'foo.bar' }
61
+ it { is_expected.to eq 'foo.bar' }
62
+ end
63
+
64
+ context 'starting by a dot' do
65
+ let(:path) { '.well-known' }
66
+ it { is_expected.to eq '.well-known' }
67
+ end
68
+ end
69
+
70
+ end
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.6.0.rc1
4
+ version: 1.6.1
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: 2021-09-24 00:00:00.000000000 Z
14
+ date: 2022-10-13 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake
@@ -59,16 +59,22 @@ dependencies:
59
59
  name: nokogiri
60
60
  requirement: !ruby/object:Gem::Requirement
61
61
  requirements:
62
- - - "~>"
62
+ - - ">="
63
63
  - !ruby/object:Gem::Version
64
- version: 1.11.0
64
+ version: '1.11'
65
+ - - "<"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.14'
65
68
  type: :runtime
66
69
  prerelease: false
67
70
  version_requirements: !ruby/object:Gem::Requirement
68
71
  requirements:
69
- - - "~>"
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '1.11'
75
+ - - "<"
70
76
  - !ruby/object:Gem::Version
71
- version: 1.11.0
77
+ version: '1.14'
72
78
  - !ruby/object:Gem::Dependency
73
79
  name: sanitize
74
80
  requirement: !ruby/object:Gem::Requirement
@@ -917,6 +923,7 @@ files:
917
923
  - spec/unit/middlewares/locale_spec.rb
918
924
  - spec/unit/middlewares/page_not_found_spec.rb
919
925
  - spec/unit/middlewares/page_spec.rb
926
+ - spec/unit/middlewares/path_spec.rb
920
927
  - spec/unit/middlewares/private_access_spec.rb
921
928
  - spec/unit/middlewares/redirection_spec.rb
922
929
  - spec/unit/middlewares/renderer_spec.rb
@@ -978,11 +985,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
978
985
  version: '3'
979
986
  required_rubygems_version: !ruby/object:Gem::Requirement
980
987
  requirements:
981
- - - ">"
988
+ - - ">="
982
989
  - !ruby/object:Gem::Version
983
- version: 1.3.1
990
+ version: '0'
984
991
  requirements: []
985
- rubygems_version: 3.1.4
992
+ rubygems_version: 3.1.6
986
993
  signing_key:
987
994
  specification_version: 4
988
995
  summary: The LocomotiveCMS Steam is the rendering stack used by both Wagon and Engine
@@ -1238,6 +1245,7 @@ test_files:
1238
1245
  - spec/unit/middlewares/locale_spec.rb
1239
1246
  - spec/unit/middlewares/page_not_found_spec.rb
1240
1247
  - spec/unit/middlewares/page_spec.rb
1248
+ - spec/unit/middlewares/path_spec.rb
1241
1249
  - spec/unit/middlewares/private_access_spec.rb
1242
1250
  - spec/unit/middlewares/redirection_spec.rb
1243
1251
  - spec/unit/middlewares/renderer_spec.rb