locomotivecms_steam 1.1.2 → 1.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/Gemfile.lock +41 -52
  4. data/lib/locomotive/steam/adapters/filesystem/sanitizers/page.rb +30 -35
  5. data/lib/locomotive/steam/adapters/filesystem.rb +8 -0
  6. data/lib/locomotive/steam/adapters/mongodb/command.rb +8 -1
  7. data/lib/locomotive/steam/adapters/mongodb.rb +10 -1
  8. data/lib/locomotive/steam/entities/content_entry.rb +13 -6
  9. data/lib/locomotive/steam/entities/page.rb +4 -0
  10. data/lib/locomotive/steam/entities/site.rb +1 -0
  11. data/lib/locomotive/steam/errors.rb +3 -0
  12. data/lib/locomotive/steam/initializers/dragonfly.rb +3 -5
  13. data/lib/locomotive/steam/initializers/sprockets.rb +10 -0
  14. data/lib/locomotive/steam/liquid/drops/content_entry.rb +8 -0
  15. data/lib/locomotive/steam/liquid/drops/content_entry_collection.rb +1 -1
  16. data/lib/locomotive/steam/liquid/tags/action.rb +59 -0
  17. data/lib/locomotive/steam/middlewares/entry_submission.rb +1 -1
  18. data/lib/locomotive/steam/middlewares/helpers.rb +8 -0
  19. data/lib/locomotive/steam/middlewares/locale.rb +1 -5
  20. data/lib/locomotive/steam/middlewares/locale_redirection.rb +1 -7
  21. data/lib/locomotive/steam/middlewares/renderer.rb +6 -3
  22. data/lib/locomotive/steam/middlewares/site.rb +12 -5
  23. data/lib/locomotive/steam/middlewares/sitemap.rb +6 -2
  24. data/lib/locomotive/steam/middlewares/thread_safe.rb +0 -4
  25. data/lib/locomotive/steam/models/associations/many_to_many.rb +1 -1
  26. data/lib/locomotive/steam/models/entity.rb +5 -0
  27. data/lib/locomotive/steam/models/repository.rb +4 -0
  28. data/lib/locomotive/steam/repositories/content_entry_repository.rb +23 -4
  29. data/lib/locomotive/steam/repositories/content_type_field_repository.rb +4 -0
  30. data/lib/locomotive/steam/services/action_service.rb +92 -0
  31. data/lib/locomotive/steam/services/content_entry_service.rb +114 -0
  32. data/lib/locomotive/steam/services/email_service.rb +102 -0
  33. data/lib/locomotive/steam/services/entry_submission_service.rb +6 -58
  34. data/lib/locomotive/steam/services/liquid_parser_service.rb +6 -0
  35. data/lib/locomotive/steam/services/url_builder_service.rb +5 -2
  36. data/lib/locomotive/steam/services.rb +13 -1
  37. data/lib/locomotive/steam/version.rb +1 -1
  38. data/lib/locomotive/steam.rb +5 -3
  39. data/locomotivecms_steam.gemspec +2 -0
  40. data/spec/fixtures/default/data/messages.yml +0 -0
  41. data/spec/integration/services/content_entry_service_spec.rb +110 -0
  42. data/spec/unit/adapters/filesystem_adapter_spec.rb +10 -0
  43. data/spec/unit/adapters/mongodb_adapter_spec.rb +18 -0
  44. data/spec/unit/entities/content_entry_spec.rb +34 -0
  45. data/spec/unit/entities/editable_element_spec.rb +19 -0
  46. data/spec/unit/entities/page_spec.rb +29 -0
  47. data/spec/unit/liquid/drops/content_entry_collection_spec.rb +4 -0
  48. data/spec/unit/liquid/drops/content_entry_spec.rb +5 -2
  49. data/spec/unit/liquid/tags/action_spec.rb +23 -0
  50. data/spec/unit/liquid/tags/link_to_spec.rb +12 -4
  51. data/spec/unit/liquid/tags/locale_switcher_spec.rb +15 -7
  52. data/spec/unit/liquid/tags/nav_spec.rb +19 -11
  53. data/spec/unit/liquid/tags/path_to_spec.rb +12 -4
  54. data/spec/unit/middlewares/helpers_spec.rb +29 -0
  55. data/spec/unit/middlewares/locale_redirection_spec.rb +11 -29
  56. data/spec/unit/middlewares/site_spec.rb +66 -13
  57. data/spec/unit/middlewares/sitemap_spec.rb +44 -0
  58. data/spec/unit/models/i18n_field_spec.rb +23 -0
  59. data/spec/unit/repositories/content_entry_repository_spec.rb +39 -7
  60. data/spec/unit/repositories/content_type_field_repository_spec.rb +10 -0
  61. data/spec/unit/services/action_service_spec.rb +173 -0
  62. data/spec/unit/services/content_entry_service_spec.rb +63 -0
  63. data/spec/unit/services/email_service_spec.rb +198 -0
  64. data/spec/unit/services/entry_submission_service_spec.rb +28 -112
  65. data/spec/unit/services/url_builder_service_spec.rb +14 -5
  66. metadata +50 -6
  67. data/spec/unit/middlewares/locale_spec.rb +0 -52
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f9df68e43afc27c2b1791937e36cc3755b31516
4
- data.tar.gz: bfea5634abf89f91ebd523b01dd58f51ce6a7d65
3
+ metadata.gz: 2a2b0e0615f8c591f1c412fe1c9f7f4c6a112287
4
+ data.tar.gz: c032bbb2a96e67b56a3ad1941889329ad86d644a
5
5
  SHA512:
6
- metadata.gz: b7fd99e9a39fd88391391d55345cff0e13537cb8b504dd6af0b4c7c8b043ffc6a47c30d9491b18f4e5aee4b78ea8d8ccfabd1cf596356ee727d053d381b361da
7
- data.tar.gz: e62db05b922358598d8841a86a76910e32a2dc7fc3879e034246e2c0aaf1bdbe4bd3a4984e5165c5e0a43a0bc8317d8e373da2da0a495cca1ddca8003c33a7e9
6
+ metadata.gz: 9d458caf6b4e974c00ea5c046cec40273aae8845964478e8c762b6147d177b9119247a73d0d34682f8df427bcdcdac10a9f8eeb1c0b397d4e50b4e44c5be945f
7
+ data.tar.gz: 346b31f343f138e208b95b77edab81f772855ebd499fd4dd98a70c2b5637982d1ef6a02a821584204e71c3d9e2c89110342d8176836fcd89075177d5ed343f4b
data/Gemfile CHANGED
@@ -29,8 +29,8 @@ group :test do
29
29
 
30
30
  gem 'rack-test', '~> 0.6.3'
31
31
 
32
- gem 'codeclimate-test-reporter', '~> 0.4.7', require: false
33
- gem 'coveralls', '~> 0.8.1', require: false
32
+ gem 'codeclimate-test-reporter', '~> 0.4.7', require: false
33
+ gem 'coveralls', '~> 0.8.1', require: false
34
34
  end
35
35
 
36
36
  platform :ruby do
data/Gemfile.lock CHANGED
@@ -1,13 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- locomotivecms_steam (1.1.2)
4
+ locomotivecms_steam (1.2.0.beta1)
5
5
  RedCloth (~> 4.2.9)
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
+ duktape (~> 1.3.0.6)
11
12
  haml (~> 4.0.6)
12
13
  httparty (~> 0.13.6)
13
14
  kramdown (~> 1.10.0)
@@ -18,6 +19,7 @@ PATH
18
19
  moneta (~> 0.8.0)
19
20
  morphine (~> 0.1.1)
20
21
  nokogiri (~> 1.6.7.2)
22
+ pony (~> 1.11)
21
23
  rack-cache (~> 1.6.1)
22
24
  rack-rewrite (~> 1.5.1)
23
25
  rack_csrf (~> 2.5.0)
@@ -29,28 +31,28 @@ GEM
29
31
  remote: https://rubygems.org/
30
32
  specs:
31
33
  RedCloth (4.2.9)
32
- activesupport (4.2.8)
34
+ activesupport (4.2.6)
33
35
  i18n (~> 0.7)
36
+ json (~> 1.7, >= 1.7.7)
34
37
  minitest (~> 5.1)
35
38
  thread_safe (~> 0.3, >= 0.3.4)
36
39
  tzinfo (~> 1.1)
37
- addressable (2.5.0)
38
- public_suffix (~> 2.0, >= 2.0.2)
40
+ addressable (2.4.0)
39
41
  attr_extras (4.4.0)
40
42
  autoprefixer-rails (6.3.3.1)
41
43
  execjs
42
- bson (4.0.2)
43
- byebug (8.2.1)
44
+ bson (4.1.1)
45
+ byebug (8.2.5)
44
46
  chronic (0.10.2)
45
- chunky_png (1.3.8)
47
+ chunky_png (1.3.5)
46
48
  codeclimate-test-reporter (0.4.8)
47
49
  simplecov (>= 0.7.1, < 1.0.0)
48
- coderay (1.1.0)
50
+ coderay (1.1.1)
49
51
  coffee-script (2.4.1)
50
52
  coffee-script-source
51
53
  execjs
52
- coffee-script-source (1.12.2)
53
- colorize (0.8.1)
54
+ coffee-script-source (1.10.0)
55
+ colorize (0.7.7)
54
56
  compass (1.0.3)
55
57
  chunky_png (~> 1.2)
56
58
  compass-core (~> 1.0.2)
@@ -63,10 +65,9 @@ GEM
63
65
  sass (>= 3.3.0, < 3.5)
64
66
  compass-import-once (1.0.5)
65
67
  sass (>= 3.2, < 3.5)
66
- concurrent-ruby (1.0.5)
67
- coveralls (0.8.10)
68
+ concurrent-ruby (1.0.2)
69
+ coveralls (0.8.13)
68
70
  json (~> 1.8)
69
- rest-client (>= 1.6.8, < 2)
70
71
  simplecov (~> 0.11.0)
71
72
  term-ansicolor (~> 1.3)
72
73
  thor (~> 0.19.1)
@@ -74,23 +75,18 @@ GEM
74
75
  crass (1.0.2)
75
76
  diff-lcs (1.2.5)
76
77
  docile (1.1.5)
77
- domain_name (0.5.25)
78
- unf (>= 0.0.5, < 1.0.0)
79
78
  dragonfly (1.0.12)
80
79
  addressable (~> 2.3)
81
80
  multi_json (~> 1.0)
82
81
  rack (>= 1.3.0)
82
+ duktape (1.3.0.6)
83
83
  execjs (2.7.0)
84
- fast_stack (0.1.0)
85
- rake
86
- rake-compiler
87
- ffi (1.9.18)
84
+ fast_stack (0.2.0)
85
+ ffi (1.9.10)
88
86
  flamegraph (0.1.0)
89
87
  fast_stack
90
88
  haml (4.0.7)
91
89
  tilt
92
- http-cookie (1.0.2)
93
- domain_name (~> 0.5)
94
90
  httparty (0.13.7)
95
91
  json (~> 1.8)
96
92
  multi_xml (>= 0.5.2)
@@ -112,24 +108,27 @@ GEM
112
108
  attr_extras (~> 4.4.0)
113
109
  colorize
114
110
  stringex (~> 2.6.0)
111
+ mail (2.6.4)
112
+ mime-types (>= 1.16, < 4)
115
113
  memory_profiler (0.9.6)
116
114
  method_source (0.8.2)
117
115
  mime-types (2.6.2)
118
116
  mimetype-fu (0.1.2)
119
117
  mini_portile2 (2.0.0)
120
- minitest (5.10.1)
121
- moneta (0.8.1)
122
- mongo (2.2.3)
118
+ minitest (5.9.0)
119
+ moneta (0.8.0)
120
+ mongo (2.2.5)
123
121
  bson (~> 4.0)
124
122
  morphine (0.1.1)
125
- multi_json (1.11.2)
126
- multi_xml (0.6.0)
127
- netrc (0.11.0)
123
+ multi_json (1.12.0)
124
+ multi_xml (0.5.5)
128
125
  nokogiri (1.6.7.2)
129
126
  mini_portile2 (~> 2.0.0.rc2)
130
- nokogumbo (1.4.10)
127
+ nokogumbo (1.4.7)
131
128
  nokogiri
132
129
  origin (2.1.1)
130
+ pony (1.11)
131
+ mail (>= 2.0)
133
132
  pry (0.10.3)
134
133
  coderay (~> 1.1.0)
135
134
  method_source (~> 0.8.1)
@@ -137,38 +136,31 @@ GEM
137
136
  pry-byebug (3.3.0)
138
137
  byebug (~> 8.0)
139
138
  pry (~> 0.10)
140
- public_suffix (2.0.5)
141
- puma (2.15.3)
139
+ puma (3.4.0)
142
140
  rack (1.6.4)
143
141
  rack-cache (1.6.1)
144
142
  rack (>= 0.4)
145
- rack-mini-profiler (0.9.8)
146
- rack (>= 1.1.3)
143
+ rack-mini-profiler (0.9.9.2)
144
+ rack (>= 1.2.0)
147
145
  rack-rewrite (1.5.1)
148
146
  rack-test (0.6.3)
149
147
  rack (>= 1.0)
150
148
  rack_csrf (2.5.0)
151
149
  rack (>= 1.1.0)
152
150
  rake (10.4.2)
153
- rake-compiler (0.9.5)
154
- rake
155
- rb-fsevent (0.9.8)
156
- rb-inotify (0.9.8)
151
+ rb-fsevent (0.9.7)
152
+ rb-inotify (0.9.7)
157
153
  ffi (>= 0.5.0)
158
- rest-client (1.8.0)
159
- http-cookie (>= 1.0.2, < 2.0)
160
- mime-types (>= 1.16, < 3.0)
161
- netrc (~> 0.7)
162
154
  rspec (3.4.0)
163
155
  rspec-core (~> 3.4.0)
164
156
  rspec-expectations (~> 3.4.0)
165
157
  rspec-mocks (~> 3.4.0)
166
- rspec-core (3.4.1)
158
+ rspec-core (3.4.4)
167
159
  rspec-support (~> 3.4.0)
168
160
  rspec-expectations (3.4.0)
169
161
  diff-lcs (>= 1.2.0, < 2.0)
170
162
  rspec-support (~> 3.4.0)
171
- rspec-mocks (3.4.0)
163
+ rspec-mocks (3.4.1)
172
164
  diff-lcs (>= 1.2.0, < 2.0)
173
165
  rspec-support (~> 3.4.0)
174
166
  rspec-support (3.4.1)
@@ -176,8 +168,8 @@ GEM
176
168
  crass (~> 1.0.2)
177
169
  nokogiri (>= 1.4.4)
178
170
  nokogumbo (~> 1.4.1)
179
- sass (3.4.23)
180
- simplecov (0.11.1)
171
+ sass (3.4.22)
172
+ simplecov (0.11.2)
181
173
  docile (~> 1.1.0)
182
174
  json (~> 1.8)
183
175
  simplecov-html (~> 0.10.0)
@@ -186,20 +178,17 @@ GEM
186
178
  sprockets (3.5.2)
187
179
  concurrent-ruby (~> 1.0)
188
180
  rack (> 1, < 3)
189
- stackprof (0.2.7)
190
- stringex (2.6.1)
181
+ stackprof (0.2.9)
182
+ stringex (2.6.0)
191
183
  term-ansicolor (1.3.2)
192
184
  tins (~> 1.0)
193
185
  thor (0.19.1)
194
- thread_safe (0.3.6)
195
- tilt (2.0.6)
196
- timecop (0.8.0)
186
+ thread_safe (0.3.5)
187
+ tilt (2.0.4)
188
+ timecop (0.8.1)
197
189
  tins (1.6.0)
198
190
  tzinfo (1.2.2)
199
191
  thread_safe (~> 0.1)
200
- unf (0.1.4)
201
- unf_ext
202
- unf_ext (0.0.7.1)
203
192
  yui-compressor (0.12.0)
204
193
 
205
194
  PLATFORMS
@@ -9,9 +9,8 @@ module Locomotive::Steam
9
9
 
10
10
  def setup(scope)
11
11
  super.tap do
12
- @ids, @parent_ids = {}, {}
13
- @content_types = {}
14
- @localized = locales.inject({}) { |m, l| m[l] = {}; m }
12
+ @ids, @parent_ids, @templatized_ids = {}, {}, {}
13
+ @localized = locales.inject({}) { |m, l| m[l] = {}; m }
15
14
  end
16
15
  end
17
16
 
@@ -22,27 +21,31 @@ module Locomotive::Steam
22
21
 
23
22
  locales.each do |locale|
24
23
  set_default_redirect_type(entity, locale)
25
- modify_if_templatized(entity, locale)
26
24
  end
25
+
26
+ check_and_mark_as_templatized(entity)
27
27
  end
28
28
 
29
29
  def apply_to_dataset(dataset)
30
30
  sorted_collection(dataset.records.values).each do |page|
31
31
  locales.each do |locale|
32
+ set_parent_id(page)
33
+
34
+ modify_if_parent_templatized(page, locale)
35
+
32
36
  # the following method needs to be called first
33
37
  set_fullpath_for(page, locale)
34
38
 
35
- set_parent_id(page)
36
39
  use_default_locale_template_path(page, locale)
37
40
  end
38
-
39
- modify_if_nested_templatized(page)
40
41
  end
41
42
  end
42
43
 
43
44
  # when this is called, the @ids hash has been populated completely
44
45
  def set_parent_id(page)
45
- return if page.not_found?
46
+ page._fullpath ||= page.attributes.delete(:_fullpath)
47
+
48
+ return if page._fullpath == '404'
46
49
 
47
50
  parent_key = parent_fullpath(page)
48
51
 
@@ -69,17 +72,7 @@ module Locomotive::Steam
69
72
  end
70
73
  end
71
74
 
72
- def modify_if_nested_templatized(page)
73
- if content_type = fetch_content_type(parent_fullpath(page))
74
- # not a templatized page but it becomes one because
75
- # its parent is one of them
76
- _modify_if_templatized(page, content_type)
77
- end
78
- end
79
-
80
75
  def set_fullpath_for(page, locale)
81
- page._fullpath ||= page.attributes.delete(:_fullpath)
82
-
83
76
  slug = fullpath = page.slug[locale].try(:to_s)
84
77
 
85
78
  return if slug.blank?
@@ -98,7 +91,7 @@ module Locomotive::Steam
98
91
 
99
92
  page.depth = page[:_fullpath].split('/').size
100
93
 
101
- if page.depth == 1 && system_pages?(page)
94
+ if system_pages?(page)
102
95
  page.depth = 0
103
96
  end
104
97
 
@@ -106,6 +99,7 @@ module Locomotive::Steam
106
99
  end
107
100
 
108
101
  def system_pages?(page)
102
+ page.depth == 1 &&
109
103
  %w(index 404).include?(page.slug.values.compact.first)
110
104
  end
111
105
 
@@ -114,19 +108,11 @@ module Locomotive::Steam
114
108
  end
115
109
 
116
110
  def parent_fullpath(page)
117
- return nil if page._fullpath == 'index'
111
+ return nil if page._fullpath == 'index' || page._fullpath == '404'
118
112
  path = page._fullpath.split('/')[0..-2].join('/')
119
113
  path.blank? ? 'index' : path
120
114
  end
121
115
 
122
- def fetch_content_type(fullpath)
123
- @content_types[fullpath]
124
- end
125
-
126
- def set_content_type(fullpath, value)
127
- @content_types[fullpath] = value
128
- end
129
-
130
116
  def fetch_localized_fullpath(fullpath, locale)
131
117
  @localized[locale][fullpath]
132
118
  end
@@ -139,17 +125,26 @@ module Locomotive::Steam
139
125
  @ids[entity[:_fullpath]] = entity._id
140
126
  end
141
127
 
142
- def modify_if_templatized(page, locale)
128
+ def check_and_mark_as_templatized(page)
143
129
  if content_type = page[:content_type]
144
- _modify_if_templatized(page, content_type)
145
- page[:slug][locale] = Locomotive::Steam::WILDCARD
146
- set_content_type(page[:_fullpath], content_type)
130
+ mark_as_templatized(page, content_type)
147
131
  end
148
132
  end
149
133
 
150
- def _modify_if_templatized(page, content_type)
151
- page[:templatized] = true
152
- page[:target_klass_name] = "Locomotive::ContentEntry#{content_type}"
134
+ def mark_as_templatized(page, content_type)
135
+ @templatized_ids[page._id] = content_type
136
+ page[:templatized] = true
137
+ page[:target_klass_name] = "Locomotive::ContentEntry#{content_type}"
138
+ end
139
+
140
+ def modify_if_parent_templatized(page, locale)
141
+ parent_templatized = @templatized_ids[page.parent_id]
142
+
143
+ if page[:templatized]
144
+ page[:slug][locale] = Locomotive::Steam::WILDCARD unless parent_templatized
145
+ elsif parent_templatized
146
+ mark_as_templatized(page, parent_templatized)
147
+ end
153
148
  end
154
149
 
155
150
  end
@@ -45,6 +45,10 @@ module Locomotive::Steam
45
45
  entity
46
46
  end
47
47
 
48
+ def update(mapper, scope, entity)
49
+ entity
50
+ end
51
+
48
52
  def inc(mapper, entity, attribute, amount = 1)
49
53
  entity.tap do
50
54
  entity[attribute] ||= 0
@@ -64,6 +68,10 @@ module Locomotive::Steam
64
68
  ''
65
69
  end
66
70
 
71
+ def make_id(value)
72
+ value
73
+ end
74
+
67
75
  def count(mapper, scope, &block)
68
76
  query(mapper, scope, &block).count
69
77
  end
@@ -20,6 +20,13 @@ module Locomotive::Steam
20
20
  entity
21
21
  end
22
22
 
23
+ def update(entity)
24
+ entity.tap do
25
+ serialized_entity = @mapper.serialize(entity)
26
+ @collection.find(_id: entity._id).update_one(serialized_entity)
27
+ end
28
+ end
29
+
23
30
  def inc(entity, attribute, amount = 1)
24
31
  entity.tap do
25
32
  @collection.find(_id: entity._id).update_one('$inc' => { attribute => amount })
@@ -29,7 +36,7 @@ module Locomotive::Steam
29
36
  end
30
37
 
31
38
  def delete(entity)
32
- @collection.find(_id: entity._id).delete_one if entity._id
39
+ @collection.find(_id: entity._id).delete_one
33
40
  end
34
41
 
35
42
  end
@@ -27,13 +27,18 @@ module Locomotive::Steam
27
27
  end
28
28
 
29
29
  def find(mapper, scope, id)
30
- query(mapper, scope) { where(_id: BSON::ObjectId.from_string(id)) }.first
30
+ _id = make_id(id)
31
+ query(mapper, scope) { where(_id: _id) }.first
31
32
  end
32
33
 
33
34
  def create(mapper, scope, entity)
34
35
  command(mapper).insert(entity)
35
36
  end
36
37
 
38
+ def update(mapper, scope, entity)
39
+ command(mapper).update(entity)
40
+ end
41
+
37
42
  def inc(mapper, entity, attribute, amount = 1)
38
43
  command(mapper).inc(entity, attribute, amount)
39
44
  end
@@ -46,6 +51,10 @@ module Locomotive::Steam
46
51
  name.to_sym.__send__(operator.to_sym)
47
52
  end
48
53
 
54
+ def make_id(id)
55
+ BSON::ObjectId.from_string(id)
56
+ end
57
+
49
58
  def base_url(mapper, scope, entity = nil)
50
59
  return nil if scope.site.nil?
51
60
 
@@ -76,19 +76,22 @@ module Locomotive::Steam
76
76
  end
77
77
 
78
78
  def to_hash
79
+ hash = {}
80
+
79
81
  # default attributes
80
82
  _attributes = %i(_id _slug _label _visible _position content_type_slug created_at updated_at)
81
83
 
82
84
  # dynamic attributes
83
85
  _attributes += content_type.persisted_field_names
84
86
 
85
- _attributes.inject({}) do |hash, name|
86
- hash[name.to_s] = send(name)
87
- hash
88
- end.tap do |hash|
89
- # errors?
90
- hash['errors'] = self.errors.to_hash.stringify_keys unless self.errors.empty?
87
+ _attributes.each do |name|
88
+ hash[name.to_s] = send(name) rescue nil
91
89
  end
90
+
91
+ # errors?
92
+ hash['errors'] = self.errors.to_hash.stringify_keys unless self.errors.empty?
93
+
94
+ hash
92
95
  end
93
96
 
94
97
  def to_liquid
@@ -184,6 +187,10 @@ module Locomotive::Steam
184
187
  base.blank? ? filename : "#{base}/#{filename}"
185
188
  end
186
189
 
190
+ def to_hash
191
+ { 'url' => url, 'filename' => filename, 'size' => size, 'updated_at' => updated_at }
192
+ end
193
+
187
194
  def to_json
188
195
  url
189
196
  end
@@ -48,6 +48,10 @@ module Locomotive::Steam
48
48
  attributes[:fullpath].values.first == '404'
49
49
  end
50
50
 
51
+ def layout?
52
+ (attributes[:fullpath].values.first =~ Locomotive::Steam::IsLAYOUT) == 0
53
+ end
54
+
51
55
  def source
52
56
  self[:raw_template]
53
57
  end
@@ -13,6 +13,7 @@ module Locomotive::Steam
13
13
  template_version: nil,
14
14
  domains: [],
15
15
  redirect_to_first_domain: false,
16
+ redirect_to_https: false,
16
17
  url_redirections: [],
17
18
  private_access: false,
18
19
  password: nil,
@@ -3,6 +3,9 @@ module Locomotive::Steam
3
3
  class NoSiteException < ::Exception
4
4
  end
5
5
 
6
+ class ActionException < ::Exception
7
+ end
8
+
6
9
  class RenderError < ::StandardError
7
10
 
8
11
  LINES_RANGE = 10
@@ -26,14 +26,12 @@ module Locomotive
26
26
  fetch_url_whitelist /.+/
27
27
  end
28
28
 
29
- if ::Dragonfly.logger.nil?
30
- ::Dragonfly.logger = Locomotive::Common::Logger.instance
31
- end
29
+ ::Dragonfly.logger = Locomotive::Common::Logger
32
30
  end
33
31
 
34
32
  def find_imagemagick_commands
35
- convert = `which convert`.strip.presence || '/usr/local/bin/convert'
36
- identify = `which identify`.strip.presence || '/usr/local/bin/identify'
33
+ convert = ENV['IMAGE_MAGICK_CONVERT'] || `which convert`.strip.presence || '/usr/local/bin/convert'
34
+ identify = ENV['IMAGE_MAGICK_IDENTIFY'] || `which identify`.strip.presence || '/usr/local/bin/identify'
37
35
 
38
36
  if File.exists?(convert)
39
37
  { convert_command: convert, identify_command: identify }
@@ -5,6 +5,8 @@ require 'compass'
5
5
  require 'autoprefixer-rails'
6
6
  require 'open3'
7
7
 
8
+ require 'execjs'
9
+
8
10
  module Locomotive::Steam
9
11
 
10
12
  class YUICompressorRuntimeError < RuntimeError
@@ -65,6 +67,8 @@ module Locomotive::Steam
65
67
 
66
68
  class SprocketsEnvironment < ::Sprockets::Environment
67
69
 
70
+ attr_reader :steam_path
71
+
68
72
  def initialize(root, options = {})
69
73
  super(root)
70
74
 
@@ -75,6 +79,12 @@ module Locomotive::Steam
75
79
  install_yui_compressor(options)
76
80
 
77
81
  install_autoprefixer
82
+
83
+ context_class.class_eval do
84
+ def asset_path(path, options = {})
85
+ path
86
+ end
87
+ end
78
88
  end
79
89
 
80
90
  private
@@ -62,6 +62,10 @@ module Locomotive
62
62
 
63
63
  @_source.content_type.fields_by_name.each do |name, field|
64
64
  case field.type
65
+ when :belongs_to
66
+ hash[name] = liquify_entry(@_source.send(name))._slug
67
+ when :many_to_many
68
+ hash[name] = (@_source.send(name) || []).all.map { |e| liquify_entry(e)._slug }.compact
65
69
  when :file
66
70
  hash[name] = hash["#{name}_url"] = file_field_to_url(hash[name.to_s]) if hash[name.to_s].present?
67
71
  when :select
@@ -77,6 +81,10 @@ module Locomotive
77
81
 
78
82
  protected
79
83
 
84
+ def liquify_entry(entry)
85
+ self.class.new(entry).tap { |drop| drop.context = @context }
86
+ end
87
+
80
88
  def file_field_to_url(field)
81
89
  field.to_liquid.tap { |drop| drop.context = @context }.url
82
90
  end
@@ -5,7 +5,7 @@ module Locomotive
5
5
 
6
6
  class ContentEntryCollection < ::Liquid::Drop
7
7
 
8
- delegate :first, :last, :each, :each_with_index, :empty?, :any?, to: :collection
8
+ delegate :first, :last, :each, :each_with_index, :empty?, :any?, :map, to: :collection
9
9
 
10
10
  def initialize(content_type, repository = nil)
11
11
  @content_type = content_type
@@ -0,0 +1,59 @@
1
+ module Locomotive
2
+ module Steam
3
+ module Liquid
4
+ module Tags
5
+
6
+ # Execute javascript code server side.
7
+ # The API allows you to:
8
+ # - access the current liquid context
9
+ # - modify the session
10
+ # - send emails
11
+ # - find / create / update content entries
12
+ #
13
+ # Usage:
14
+ #
15
+ # {% action "My javascript action" %}
16
+ # var lastPost = allEntries('posts', { 'posted_at.lte': getProp('today'), published: true, order_by: 'posted_at desc' })[0];
17
+ # var views = lastPost.views + 1;
18
+ #
19
+ # updateEntry('posts', lastPost._id, { views: views });
20
+ #
21
+ # setProp('views', views);
22
+ # {% endaction %}
23
+ #
24
+ # <p>Number of views for the last published post: {{ views }}</p>
25
+ #
26
+ class Action < ::Liquid::Block
27
+
28
+ Syntax = /(#{::Liquid::QuotedString}+)/o
29
+
30
+ def initialize(tag_name, markup, options)
31
+ if markup =~ Syntax
32
+ @description = $1.to_s
33
+ else
34
+ raise ::Liquid::SyntaxError.new("Syntax Error in 'action' - Valid syntax: action \"<description>\"")
35
+ end
36
+ super
37
+ end
38
+
39
+ def render(context)
40
+ Locomotive::Common::Logger.info "[action] executing #{@description}"
41
+ service(context).run(super, context['params'], context)
42
+ ''
43
+ end
44
+
45
+ private
46
+
47
+ def service(context)
48
+ context.registers[:services].action
49
+ end
50
+
51
+ end
52
+
53
+ ::Liquid::Template.register_tag('action'.freeze, Action)
54
+
55
+ end
56
+ end
57
+ end
58
+ end
59
+
@@ -59,7 +59,7 @@ module Locomotive::Steam
59
59
  if error_location =~ HTTP_REGEXP
60
60
  redirect_to error_location
61
61
  else
62
- env['PATH_INFO'] = error_location
62
+ env['PATH_INFO'] = make_local_path(error_location)
63
63
  store_in_liquid(entry)
64
64
  self.next
65
65
  end