locomotivecms_steam 1.2.0.beta1 → 1.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -1
  3. data/Gemfile.lock +36 -36
  4. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb +9 -1
  5. data/lib/locomotive/steam/decorators/page_decorator.rb +20 -0
  6. data/lib/locomotive/steam/decorators/template_decorator.rb +0 -1
  7. data/lib/locomotive/steam/entities/content_entry.rb +5 -4
  8. data/lib/locomotive/steam/entities/content_type.rb +5 -0
  9. data/lib/locomotive/steam/entities/page.rb +1 -2
  10. data/lib/locomotive/steam/liquid/drops/base.rb +17 -13
  11. data/lib/locomotive/steam/liquid/drops/content_entry.rb +5 -1
  12. data/lib/locomotive/steam/liquid/drops/metafields.rb +8 -3
  13. data/lib/locomotive/steam/liquid/filters/misc.rb +1 -1
  14. data/lib/locomotive/steam/liquid/filters/resize.rb +1 -1
  15. data/lib/locomotive/steam/liquid/tags/with_scope.rb +12 -1
  16. data/lib/locomotive/steam/middlewares/entry_submission.rb +23 -4
  17. data/lib/locomotive/steam/middlewares/page.rb +12 -2
  18. data/lib/locomotive/steam/middlewares/renderer.rb +7 -6
  19. data/lib/locomotive/steam/middlewares/sitemap.rb +11 -0
  20. data/lib/locomotive/steam/middlewares/thread_safe.rb +4 -0
  21. data/lib/locomotive/steam/models/i18n_field.rb +1 -1
  22. data/lib/locomotive/steam/repositories/content_type_field_repository.rb +3 -1
  23. data/lib/locomotive/steam/server.rb +0 -1
  24. data/lib/locomotive/steam/services/external_api_service.rb +8 -1
  25. data/lib/locomotive/steam/services/image_resizer_service.rb +1 -1
  26. data/lib/locomotive/steam/services/page_finder_service.rb +4 -0
  27. data/lib/locomotive/steam/version.rb +1 -1
  28. data/locomotivecms_steam.gemspec +4 -5
  29. data/spec/fixtures/default/app/views/pages/all.liquid.haml +4 -1
  30. data/spec/fixtures/default/app/views/pages/contact.liquid.haml +8 -1
  31. data/spec/fixtures/default/app/views/pages/events.liquid.haml +7 -0
  32. data/spec/fixtures/default/app/views/pages/tags/nav_in_deep.liquid.haml +2 -2
  33. data/spec/fixtures/default/data/updates.yml +4 -2
  34. data/spec/integration/server/contact_form_spec.rb +13 -0
  35. data/spec/integration/server/nav_spec.rb +4 -0
  36. data/spec/integration/server/sitemap_spec.rb +2 -2
  37. data/spec/support/helpers.rb +2 -0
  38. data/spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb +17 -0
  39. data/spec/unit/decorators/page_decorator_spec.rb +36 -0
  40. data/spec/unit/decorators/template_decorator_spec.rb +1 -0
  41. data/spec/unit/entities/content_type_spec.rb +34 -0
  42. data/spec/unit/entities/page_spec.rb +0 -24
  43. data/spec/unit/liquid/drops/content_entry_spec.rb +10 -2
  44. data/spec/unit/liquid/drops/metafields_spec.rb +35 -6
  45. data/spec/unit/liquid/filters/resize_spec.rb +17 -0
  46. data/spec/unit/liquid/tags/with_scope_spec.rb +15 -0
  47. data/spec/unit/middlewares/page_spec.rb +63 -0
  48. data/spec/unit/middlewares/renderer_spec.rb +2 -4
  49. data/spec/unit/middlewares/sitemap_spec.rb +41 -1
  50. data/spec/unit/services/external_api_service_spec.rb +10 -0
  51. data/spec/unit/services/image_resizer_service_spec.rb +3 -3
  52. metadata +15 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a2b0e0615f8c591f1c412fe1c9f7f4c6a112287
4
- data.tar.gz: c032bbb2a96e67b56a3ad1941889329ad86d644a
3
+ metadata.gz: eb33db62c8a0c967f8dd571468e3c0a152db1672
4
+ data.tar.gz: 67c92ee1c3f7bdf143bc1b565a8864317fd406bf
5
5
  SHA512:
6
- metadata.gz: 9d458caf6b4e974c00ea5c046cec40273aae8845964478e8c762b6147d177b9119247a73d0d34682f8df427bcdcdac10a9f8eeb1c0b397d4e50b4e44c5be945f
7
- data.tar.gz: 346b31f343f138e208b95b77edab81f772855ebd499fd4dd98a70c2b5637982d1ef6a02a821584204e71c3d9e2c89110342d8176836fcd89075177d5ed343f4b
6
+ metadata.gz: e34e6da025b0744a580ca22fb69578e9418c55f983594d90b3943da2ad90bb1d40b510a449b6d04f3ded70e74dce10fc2aba251677c5ef61c2bf81c7ee72fb57
7
+ data.tar.gz: 666be2d79e33b713d4f3601a4adfaf35b09a4a45bcdfd292c03b5b81d7e5e76bcedd867a02d422b09738d6014283e727787a91c0fa2e817e828ef4b18813a4a6
data/Gemfile CHANGED
@@ -11,8 +11,9 @@ group :development do
11
11
  # gem 'thin'
12
12
  gem 'puma'
13
13
  gem 'yui-compressor', '~> 0.12.0'
14
+ gem 'haml', '~> 4.0.6'
14
15
 
15
- gem 'rack-mini-profiler'
16
+ gem 'rack-mini-profiler', '~> 0.10.1'
16
17
  gem 'flamegraph'
17
18
  gem 'stackprof' # ruby 2.1+ only
18
19
  gem 'memory_profiler'
data/Gemfile.lock CHANGED
@@ -1,15 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- locomotivecms_steam (1.2.0.beta1)
5
- RedCloth (~> 4.2.9)
4
+ locomotivecms_steam (1.2.0.rc1)
5
+ RedCloth (~> 4.3.2)
6
6
  autoprefixer-rails (~> 6.3.3.1)
7
7
  chronic (~> 0.10.2)
8
8
  coffee-script (~> 2.4.1)
9
9
  compass (~> 1.0.3)
10
10
  dragonfly (~> 1.0.12)
11
11
  duktape (~> 1.3.0.6)
12
- haml (~> 4.0.6)
13
12
  httparty (~> 0.13.6)
14
13
  kramdown (~> 1.10.0)
15
14
  locomotivecms-solid (~> 4.0.1)
@@ -18,7 +17,7 @@ PATH
18
17
  mimetype-fu (~> 0.1.2)
19
18
  moneta (~> 0.8.0)
20
19
  morphine (~> 0.1.1)
21
- nokogiri (~> 1.6.7.2)
20
+ nokogiri (~> 1.6.8)
22
21
  pony (~> 1.11)
23
22
  rack-cache (~> 1.6.1)
24
23
  rack-rewrite (~> 1.5.1)
@@ -30,8 +29,8 @@ PATH
30
29
  GEM
31
30
  remote: https://rubygems.org/
32
31
  specs:
33
- RedCloth (4.2.9)
34
- activesupport (4.2.6)
32
+ RedCloth (4.3.2)
33
+ activesupport (4.2.7)
35
34
  i18n (~> 0.7)
36
35
  json (~> 1.7, >= 1.7.7)
37
36
  minitest (~> 5.1)
@@ -44,7 +43,7 @@ GEM
44
43
  bson (4.1.1)
45
44
  byebug (8.2.5)
46
45
  chronic (0.10.2)
47
- chunky_png (1.3.5)
46
+ chunky_png (1.3.6)
48
47
  codeclimate-test-reporter (0.4.8)
49
48
  simplecov (>= 0.7.1, < 1.0.0)
50
49
  coderay (1.1.1)
@@ -52,7 +51,7 @@ GEM
52
51
  coffee-script-source
53
52
  execjs
54
53
  coffee-script-source (1.10.0)
55
- colorize (0.7.7)
54
+ colorize (0.8.1)
56
55
  compass (1.0.3)
57
56
  chunky_png (~> 1.2)
58
57
  compass-core (~> 1.0.2)
@@ -66,12 +65,12 @@ GEM
66
65
  compass-import-once (1.0.5)
67
66
  sass (>= 3.2, < 3.5)
68
67
  concurrent-ruby (1.0.2)
69
- coveralls (0.8.13)
70
- json (~> 1.8)
71
- simplecov (~> 0.11.0)
68
+ coveralls (0.8.15)
69
+ json (>= 1.8, < 3)
70
+ simplecov (~> 0.12.0)
72
71
  term-ansicolor (~> 1.3)
73
72
  thor (~> 0.19.1)
74
- tins (~> 1.6.0)
73
+ tins (>= 1.6.0, < 2)
75
74
  crass (1.0.2)
76
75
  diff-lcs (1.2.5)
77
76
  docile (1.1.5)
@@ -81,10 +80,8 @@ GEM
81
80
  rack (>= 1.3.0)
82
81
  duktape (1.3.0.6)
83
82
  execjs (2.7.0)
84
- fast_stack (0.2.0)
85
- ffi (1.9.10)
86
- flamegraph (0.1.0)
87
- fast_stack
83
+ ffi (1.9.14)
84
+ flamegraph (0.9.5)
88
85
  haml (4.0.7)
89
86
  tilt
90
87
  httparty (0.13.7)
@@ -93,7 +90,7 @@ GEM
93
90
  i18n (0.7.0)
94
91
  i18n-spec (0.6.0)
95
92
  iso
96
- iso (0.2.1)
93
+ iso (0.2.2)
97
94
  i18n
98
95
  json (1.8.3)
99
96
  json_spec (1.1.4)
@@ -114,33 +111,35 @@ GEM
114
111
  method_source (0.8.2)
115
112
  mime-types (2.6.2)
116
113
  mimetype-fu (0.1.2)
117
- mini_portile2 (2.0.0)
114
+ mini_portile2 (2.1.0)
118
115
  minitest (5.9.0)
119
116
  moneta (0.8.0)
120
- mongo (2.2.5)
117
+ mongo (2.2.7)
121
118
  bson (~> 4.0)
122
119
  morphine (0.1.1)
123
- multi_json (1.12.0)
120
+ multi_json (1.12.1)
124
121
  multi_xml (0.5.5)
125
- nokogiri (1.6.7.2)
126
- mini_portile2 (~> 2.0.0.rc2)
127
- nokogumbo (1.4.7)
122
+ nokogiri (1.6.8)
123
+ mini_portile2 (~> 2.1.0)
124
+ pkg-config (~> 1.1.7)
125
+ nokogumbo (1.4.9)
128
126
  nokogiri
129
- origin (2.1.1)
127
+ origin (2.2.0)
128
+ pkg-config (1.1.7)
130
129
  pony (1.11)
131
130
  mail (>= 2.0)
132
- pry (0.10.3)
131
+ pry (0.10.4)
133
132
  coderay (~> 1.1.0)
134
133
  method_source (~> 0.8.1)
135
134
  slop (~> 3.4)
136
135
  pry-byebug (3.3.0)
137
136
  byebug (~> 8.0)
138
137
  pry (~> 0.10)
139
- puma (3.4.0)
140
- rack (1.6.4)
138
+ puma (3.6.0)
139
+ rack (2.0.1)
141
140
  rack-cache (1.6.1)
142
141
  rack (>= 0.4)
143
- rack-mini-profiler (0.9.9.2)
142
+ rack-mini-profiler (0.10.1)
144
143
  rack (>= 1.2.0)
145
144
  rack-rewrite (1.5.1)
146
145
  rack-test (0.6.3)
@@ -169,9 +168,9 @@ GEM
169
168
  nokogiri (>= 1.4.4)
170
169
  nokogumbo (~> 1.4.1)
171
170
  sass (3.4.22)
172
- simplecov (0.11.2)
171
+ simplecov (0.12.0)
173
172
  docile (~> 1.1.0)
174
- json (~> 1.8)
173
+ json (>= 1.8, < 3)
175
174
  simplecov-html (~> 0.10.0)
176
175
  simplecov-html (0.10.0)
177
176
  slop (3.6.0)
@@ -179,14 +178,14 @@ GEM
179
178
  concurrent-ruby (~> 1.0)
180
179
  rack (> 1, < 3)
181
180
  stackprof (0.2.9)
182
- stringex (2.6.0)
181
+ stringex (2.6.1)
183
182
  term-ansicolor (1.3.2)
184
183
  tins (~> 1.0)
185
184
  thor (0.19.1)
186
185
  thread_safe (0.3.5)
187
- tilt (2.0.4)
186
+ tilt (2.0.5)
188
187
  timecop (0.8.1)
189
- tins (1.6.0)
188
+ tins (1.12.0)
190
189
  tzinfo (1.2.2)
191
190
  thread_safe (~> 0.1)
192
191
  yui-compressor (0.12.0)
@@ -199,15 +198,16 @@ DEPENDENCIES
199
198
  codeclimate-test-reporter (~> 0.4.7)
200
199
  coveralls (~> 0.8.1)
201
200
  flamegraph
201
+ haml (~> 4.0.6)
202
202
  i18n-spec (~> 0.6.0)
203
203
  json_spec (~> 1.1.4)
204
204
  locomotivecms_steam!
205
205
  memory_profiler
206
- mongo (~> 2.2.3)
207
- origin (~> 2.1.1)
206
+ mongo (~> 2.2.7)
207
+ origin (~> 2.2.0)
208
208
  pry-byebug (~> 3.3.0)
209
209
  puma
210
- rack-mini-profiler
210
+ rack-mini-profiler (~> 0.10.1)
211
211
  rack-test (~> 0.6.3)
212
212
  rake (~> 10.4.2)
213
213
  rspec (~> 3.4.0)
@@ -31,7 +31,15 @@ module Locomotive
31
31
 
32
32
  def modify_for_selects(attributes)
33
33
  content_type.select_fields.each do |field|
34
- attributes[:"#{field.name}_id"] = attributes.delete(field.name.to_sym)
34
+ if (option = attributes.delete(field.name.to_sym)).is_a?(Hash)
35
+ attributes[:"#{field.name}_id"] = option.inject({}) do |memo, (locale, name)|
36
+ field.select_options.scope.locale = locale
37
+ memo[locale] = field.select_options.by_name(name).try(:_id)
38
+ memo
39
+ end
40
+ else
41
+ attributes[:"#{field.name}_id"] = option
42
+ end
35
43
  end
36
44
  end
37
45
 
@@ -0,0 +1,20 @@
1
+ require_relative 'template_decorator'
2
+
3
+ module Locomotive
4
+ module Steam
5
+ module Decorators
6
+
7
+ class PageDecorator < TemplateDecorator
8
+
9
+ def redirect?
10
+ redirect.nil? ? redirect_url.present? : redirect
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+
19
+
20
+
@@ -1,4 +1,3 @@
1
- require 'haml'
2
1
  require_relative 'i18n_decorator'
3
2
 
4
3
  module Locomotive
@@ -164,16 +164,17 @@ module Locomotive::Steam
164
164
  end
165
165
 
166
166
  def _cast_select(field)
167
- _cast_convertor(:"#{field.name}_id") do |value|
168
- field.select_options.find(value).try(:name)
167
+ _cast_convertor(:"#{field.name}_id", true) do |value, locale|
168
+ name = field.select_options.find(value).try(:name)
169
+ locale.nil? ? name : name.try(:[], locale)
169
170
  end
170
171
  end
171
172
 
172
- def _cast_convertor(name, &block)
173
+ def _cast_convertor(name, nil_locale = false, &block)
173
174
  if (value = attributes[name]).respond_to?(:translations)
174
175
  value.apply(&block)
175
176
  else
176
- yield(value)
177
+ nil_locale ? yield(value, nil) : yield(value)
177
178
  end
178
179
  end
179
180
 
@@ -30,9 +30,14 @@ module Locomotive::Steam
30
30
  end
31
31
 
32
32
  def localized_names
33
+ # FIXME: select_fields ALWAYS returns I18nField even if the site is not localized
33
34
  fields.localized_names + select_fields.map(&:name)
34
35
  end
35
36
 
37
+ def localized?
38
+ !fields.localized_names.blank?
39
+ end
40
+
36
41
  def persisted_field_names
37
42
  [].tap do |names|
38
43
  fields_by_name.each do |name, field|
@@ -21,7 +21,7 @@ module Locomotive::Steam
21
21
  raw_template: nil,
22
22
  source: nil,
23
23
  editable_elements: {},
24
- redirect: false,
24
+ redirect: nil,
25
25
  redirect_url: {},
26
26
  redirect_type: nil,
27
27
  parent_id: nil,
@@ -33,7 +33,6 @@ module Locomotive::Steam
33
33
  def listed?; !!listed; end
34
34
  def published?; !!published; end
35
35
  def templatized?; !!templatized; end
36
- def redirect?; redirect.nil? ? redirect_url.present? : redirect; end
37
36
 
38
37
  def content_type_id
39
38
  self.target_klass_name =~ Locomotive::Steam::CONTENT_ENTRY_ENGINE_CLASS_NAME
@@ -14,30 +14,34 @@ module Locomotive
14
14
  (@_source.respond_to?(:id) ? @_source.id : nil) || 'new'
15
15
  end
16
16
 
17
+ def as_json(options = nil)
18
+ @_source.as_json(options)
19
+ end
20
+
21
+ protected
22
+
17
23
  # converts an array of records to an array of liquid drops
18
- def self.liquify(*records, &block)
24
+ def liquify(*records, &block)
19
25
  i = -1
20
26
  records =
21
27
  records.inject [] do |all, r|
22
- i+=1
28
+ i += 1
23
29
  attrs = (block && block.arity == 1) ? [r] : [r, i]
24
- all << (block ? block.call(*attrs) : r.to_liquid)
30
+ all << (block ? block.call(*attrs) : r.to_liquid).tap do |_r|
31
+ # For unknown reasons, Liquid doesn't always set the context
32
+ #
33
+ # Example:
34
+ # {{ site.index.children | map: 'title' | join: " - " }}
35
+ # was not working before
36
+ #
37
+ _r.context = @context if _r.respond_to?(:context=)
38
+ end
25
39
  all
26
40
  end
27
41
  records.compact!
28
42
  records
29
43
  end
30
44
 
31
- def as_json(options = nil)
32
- @_source.as_json(options)
33
- end
34
-
35
- protected
36
-
37
- def liquify(*records, &block)
38
- self.class.liquify(*records, &block)
39
- end
40
-
41
45
  def _source
42
46
  @_source
43
47
  end
@@ -43,7 +43,11 @@ module Locomotive
43
43
  end
44
44
 
45
45
  def errors
46
- @_source.errors.messages.to_hash.stringify_keys
46
+ if @_source.errors.blank?
47
+ false
48
+ else
49
+ @_source.errors.messages.to_hash.stringify_keys
50
+ end
47
51
  end
48
52
 
49
53
  def before_method(meth)
@@ -22,7 +22,7 @@ module Locomotive
22
22
 
23
23
  def find_value(name)
24
24
  if field = fields[name]
25
- safe_value(t(values[name], field['localized']))
25
+ safe_value(t(values[name], field['localized']), field['type'])
26
26
  else
27
27
  Locomotive::Common::Logger.warn "[Liquid template] unknown site metafield \"#{name}\" under #{@namespace['name']}"
28
28
  nil
@@ -66,8 +66,13 @@ module Locomotive
66
66
  value[key]
67
67
  end
68
68
 
69
- def safe_value(value)
70
- value.blank? ? nil : value
69
+ def safe_value(value, type = 'string')
70
+ case type
71
+ when 'boolean'
72
+ ['1', 'true', true].include?(value) ? true : false
73
+ else
74
+ value.blank? ? nil : value
75
+ end
71
76
  end
72
77
 
73
78
  end
@@ -31,7 +31,7 @@ module Locomotive
31
31
  ::Liquid::StandardFilters::InputIterator.new(input).map do |e|
32
32
  e = e.call if e.is_a?(Proc)
33
33
 
34
- if property == "to_liquid".freeze
34
+ if property == 'to_liquid'.freeze
35
35
  e
36
36
  elsif property == 'to_f'.freeze
37
37
  e.to_f
@@ -5,7 +5,7 @@ module Locomotive
5
5
  module Resize
6
6
 
7
7
  def resize(input, resize_string)
8
- @context.registers[:services].image_resizer.resize(input, resize_string) || input
8
+ @context.registers[:services].image_resizer.resize(input, resize_string)
9
9
  end
10
10
 
11
11
  end
@@ -20,6 +20,12 @@ module Locomotive
20
20
 
21
21
  SYMBOL_OPERATORS_REGEXP = /(\w+\.(#{OPERATORS.join('|')})){1}\s*\:/o
22
22
 
23
+ REGEX_OPTIONS = {
24
+ 'i' => Regexp::IGNORECASE,
25
+ 'm' => Regexp::MULTILINE,
26
+ 'x' => Regexp::EXTENDED
27
+ }
28
+
23
29
  # register the tag
24
30
  tag_name :with_scope
25
31
 
@@ -54,7 +60,12 @@ module Locomotive
54
60
  def cast_value(value)
55
61
  case value
56
62
  when Array then value.map { |_value| cast_value(_value) }
57
- when /^\/[^\/]*\/$/ then Regexp.new(value[1..-2])
63
+ when /^\/([^\/]*)\/([imx]+)?$/
64
+ _value, options_str = $1, $2
65
+ options = options_str.blank? ? nil : options_str.split('').uniq.inject(0) do |_options, letter|
66
+ _options |= REGEX_OPTIONS[letter]
67
+ end
68
+ Regexp.new(_value, options)
58
69
  else
59
70
  value.respond_to?(:_id) ? value.send(:_source) : value
60
71
  end