locomotivecms_steam 1.2.1 → 1.3.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/Gemfile +3 -2
  4. data/Gemfile.lock +57 -50
  5. data/LICENSE +1 -1
  6. data/README.md +1 -1
  7. data/config/locales/nl.yml +2 -2
  8. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb +8 -0
  9. data/lib/locomotive/steam/adapters/memory/condition.rb +1 -1
  10. data/lib/locomotive/steam/configuration.rb +1 -1
  11. data/lib/locomotive/steam/decorators/template_decorator.rb +1 -1
  12. data/lib/locomotive/steam/entities/content_entry.rb +17 -0
  13. data/lib/locomotive/steam/entities/content_type.rb +1 -0
  14. data/lib/locomotive/steam/entities/content_type_field.rb +1 -0
  15. data/lib/locomotive/steam/entities/editable_element.rb +4 -0
  16. data/lib/locomotive/steam/errors.rb +35 -5
  17. data/lib/locomotive/steam/initializers/sprockets.rb +6 -80
  18. data/lib/locomotive/steam/liquid/drops/page.rb +9 -2
  19. data/lib/locomotive/steam/liquid/filters/date.rb +109 -0
  20. data/lib/locomotive/steam/liquid/tags/action.rb +6 -1
  21. data/lib/locomotive/steam/liquid/tags/authorize.rb +65 -0
  22. data/lib/locomotive/steam/liquid/tags/snippet.rb +10 -2
  23. data/lib/locomotive/steam/liquid/template.rb +3 -1
  24. data/lib/locomotive/steam/middlewares/auth.rb +187 -0
  25. data/lib/locomotive/steam/middlewares/redirection.rb +24 -0
  26. data/lib/locomotive/steam/middlewares/renderer.rb +20 -3
  27. data/lib/locomotive/steam/middlewares/sitemap.rb +3 -1
  28. data/lib/locomotive/steam/middlewares/templatized_page.rb +1 -6
  29. data/lib/locomotive/steam/middlewares/thread_safe.rb +19 -0
  30. data/lib/locomotive/steam/middlewares/url_redirection.rb +14 -1
  31. data/lib/locomotive/steam/repositories.rb +5 -1
  32. data/lib/locomotive/steam/repositories/content_entry_repository.rb +1 -1
  33. data/lib/locomotive/steam/repositories/content_type_field_repository.rb +4 -0
  34. data/lib/locomotive/steam/server.rb +2 -0
  35. data/lib/locomotive/steam/services.rb +9 -1
  36. data/lib/locomotive/steam/services/action_service.rb +26 -7
  37. data/lib/locomotive/steam/services/asset_host_service.rb +6 -1
  38. data/lib/locomotive/steam/services/auth_service.rb +105 -0
  39. data/lib/locomotive/steam/services/content_entry_service.rb +14 -0
  40. data/lib/locomotive/steam/services/external_api_service.rb +59 -25
  41. data/lib/locomotive/steam/services/liquid_parser_service.rb +5 -1
  42. data/lib/locomotive/steam/services/page_redirection_service.rb +29 -0
  43. data/lib/locomotive/steam/version.rb +1 -1
  44. data/locomotivecms_steam.gemspec +18 -16
  45. data/spec/fixtures/default/app/content_types/accounts.yml +59 -0
  46. data/spec/fixtures/default/app/content_types/songs.yml +2 -1
  47. data/spec/fixtures/default/app/views/pages/about_us/john_doe.fr.liquid.haml +5 -1
  48. data/spec/fixtures/default/app/views/pages/about_us/john_doe.liquid.haml +1 -1
  49. data/spec/fixtures/default/app/views/pages/account/forgot_password.liquid +39 -0
  50. data/spec/fixtures/default/app/views/pages/account/me.liquid +15 -0
  51. data/spec/fixtures/default/app/views/pages/account/reset_password.liquid +42 -0
  52. data/spec/fixtures/default/app/views/pages/account/sign_in.liquid +49 -0
  53. data/spec/fixtures/default/app/views/pages/all.liquid.haml +1 -1
  54. data/spec/fixtures/default/app/views/pages/emails/reset_password.liquid +15 -0
  55. data/spec/fixtures/default/app/views/pages/songs/template.liquid.haml +1 -1
  56. data/spec/fixtures/default/config/metafields_schema.yml +10 -0
  57. data/spec/fixtures/default/config/site.yml +5 -0
  58. data/spec/fixtures/default/config/translations.yml +25 -1
  59. data/spec/fixtures/default/data/accounts.yml +15 -0
  60. data/spec/fixtures/mongodb/locomotive_accounts.bson +0 -0
  61. data/spec/fixtures/mongodb/locomotive_accounts.metadata.json +1 -1
  62. data/spec/fixtures/mongodb/locomotive_activities.bson +0 -0
  63. data/spec/fixtures/mongodb/locomotive_activities.metadata.json +1 -1
  64. data/spec/fixtures/mongodb/locomotive_content_assets.bson +0 -0
  65. data/spec/fixtures/mongodb/locomotive_content_assets.metadata.json +1 -1
  66. data/spec/fixtures/mongodb/locomotive_content_entries.bson +0 -0
  67. data/spec/fixtures/mongodb/locomotive_content_entries.metadata.json +1 -1
  68. data/spec/fixtures/mongodb/locomotive_content_types.bson +0 -0
  69. data/spec/fixtures/mongodb/locomotive_content_types.metadata.json +1 -1
  70. data/spec/fixtures/mongodb/locomotive_pages.bson +0 -0
  71. data/spec/fixtures/mongodb/locomotive_pages.metadata.json +1 -1
  72. data/spec/fixtures/mongodb/locomotive_sites.bson +0 -0
  73. data/spec/fixtures/mongodb/locomotive_sites.metadata.json +1 -1
  74. data/spec/fixtures/mongodb/locomotive_snippets.bson +0 -0
  75. data/spec/fixtures/mongodb/locomotive_snippets.metadata.json +1 -1
  76. data/spec/fixtures/mongodb/locomotive_theme_assets.bson +0 -0
  77. data/spec/fixtures/mongodb/locomotive_theme_assets.metadata.json +1 -1
  78. data/spec/fixtures/mongodb/locomotive_translations.bson +0 -0
  79. data/spec/fixtures/mongodb/locomotive_translations.metadata.json +1 -1
  80. data/spec/integration/repositories/content_entry_repository_spec.rb +1 -1
  81. data/spec/integration/repositories/content_type_repository_spec.rb +1 -1
  82. data/spec/integration/repositories/page_repository_spec.rb +3 -3
  83. data/spec/integration/repositories/theme_asset_repository_spec.rb +1 -1
  84. data/spec/integration/repositories/translation_repository_spec.rb +1 -1
  85. data/spec/integration/server/auth_spec.rb +196 -0
  86. data/spec/integration/server/basic_spec.rb +18 -0
  87. data/spec/integration/server/nav_spec.rb +1 -1
  88. data/spec/integration/server/sitemap_spec.rb +1 -1
  89. data/spec/integration/services/content_entry_service_spec.rb +1 -1
  90. data/spec/integration/services/external_api_service_spec.rb +9 -0
  91. data/spec/support/helpers.rb +1 -1
  92. data/spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb +17 -5
  93. data/spec/unit/adapters/filesystem/yaml_loaders/content_type_spec.rb +4 -4
  94. data/spec/unit/adapters/filesystem/yaml_loaders/page_spec.rb +7 -7
  95. data/spec/unit/adapters/filesystem/yaml_loaders/site_spec.rb +1 -1
  96. data/spec/unit/adapters/filesystem/yaml_loaders/translation_spec.rb +1 -1
  97. data/spec/unit/entities/content_entry_spec.rb +10 -0
  98. data/spec/unit/errors_spec.rb +2 -2
  99. data/spec/unit/initializers/sprockets_spec.rb +0 -14
  100. data/spec/unit/liquid/drops/page_spec.rb +3 -2
  101. data/spec/unit/liquid/filters/date_spec.rb +219 -0
  102. data/spec/unit/liquid/tags/action_spec.rb +9 -0
  103. data/spec/unit/liquid/tags/authorize_spec.rb +51 -0
  104. data/spec/unit/liquid/tags/link_to_spec.rb +1 -1
  105. data/spec/unit/liquid/tags/paginate_spec.rb +1 -1
  106. data/spec/unit/liquid/tags/snippet_spec.rb +10 -0
  107. data/spec/unit/middlewares/auth_spec.rb +31 -0
  108. data/spec/unit/middlewares/redirection_spec.rb +37 -0
  109. data/spec/unit/middlewares/url_redirection_spec.rb +20 -1
  110. data/spec/unit/services/action_service_spec.rb +57 -1
  111. data/spec/unit/services/asset_host_service_spec.rb +15 -0
  112. data/spec/unit/services/auth_service_spec.rb +156 -0
  113. data/spec/unit/services/external_api_service_spec.rb +22 -0
  114. data/spec/unit/services/page_redirection_service_spec.rb +49 -0
  115. metadata +96 -40
  116. data/CHANGELOG.md +0 -29
  117. data/spec/fixtures/mongodb/system.indexes.bson +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0638993657ef4d9c1daeacceaf92343dced8b62
4
- data.tar.gz: 88c03d05c185a8e33de76a7c83f0414d9c463ec0
3
+ metadata.gz: 2f196a0b63817aacbd1564c4f1e48f11f3d9a099
4
+ data.tar.gz: f2abdbd4a45e167bec4ec66ed0e4fe8ecb51f41a
5
5
  SHA512:
6
- metadata.gz: 81a06d2a759297e8177148cba1d9a00bf1baf925d4335465f82e03541362259855056a68b6656a6be41d140713fd4cd1755fc9890985b4ba2d698a30e9904ac5
7
- data.tar.gz: 008df971169a7c5c267bf2eb521276ca35814006e038b90b4ac57723971d00ab270824f7a9517e78743b91d80e5639ef0d7c192486494916103a509245791c8e
6
+ metadata.gz: 70e71b96955c2395129bfb9c42b83a581592a7c55ec814b682b3f3919a2b55d63c87a42fe5fc671600ff4674202c19d6c2e462d9581fd2341f820fbe2d3027c8
7
+ data.tar.gz: efc45f6d8acb3117e4b9154830b1b43fbeb299358c60e57d606692b0eb3a86fe0ea4ac05d095f080331bcb0ea6358a9d8f23cbed96311bac21239f4de40a4c39
data/.travis.yml CHANGED
@@ -2,7 +2,7 @@ language: ruby
2
2
  services: mongodb
3
3
  before_script: ./script/ci/before_build.sh
4
4
  rvm:
5
- - 2.2.3
5
+ - 2.3.3
6
6
  env:
7
7
  - CODECLIMATE_REPO_TOKEN=3fa74f2ade25037fccd7261090acbdeae232639c3a83aafb80ee428ec16b8cf9
8
8
  addons:
data/Gemfile CHANGED
@@ -8,9 +8,10 @@ group :development do
8
8
  # gem 'locomotivecms_models', '~> 0.0.1', path: '../models'
9
9
  # gem 'locomotivecms_models', '0.0.1.pre.alpha'
10
10
  # gem 'locomotivecms-liquid', path: '/Users/didier/Documents/LocomotiveCMS/gems/liquid'
11
+ # gem 'duktape', path: '/Users/didier/Documents/NoCoffee/ProjectsX/duktape.rb'
12
+ # gem 'duktape', github: 'judofyr/duktape.rb', ref: '20ef6a5'
11
13
  # gem 'thin'
12
14
  gem 'puma'
13
- gem 'yui-compressor', '~> 0.12.0'
14
15
  gem 'haml', '~> 4.0.6'
15
16
 
16
17
  gem 'rack-mini-profiler', '~> 0.10.1'
@@ -35,5 +36,5 @@ group :test do
35
36
  end
36
37
 
37
38
  platform :ruby do
38
- ruby '2.2.3'
39
+ ruby '2.3.3'
39
40
  end
data/Gemfile.lock CHANGED
@@ -1,30 +1,32 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- locomotivecms_steam (1.2.1)
4
+ locomotivecms_steam (1.3.0.rc1)
5
5
  RedCloth (~> 4.3.2)
6
- autoprefixer-rails (~> 6.3.3.1)
6
+ autoprefixer-rails (~> 6.7.2)
7
+ bcrypt (~> 3.1.11)
7
8
  chronic (~> 0.10.2)
8
9
  coffee-script (~> 2.4.1)
9
10
  compass (~> 1.0.3)
10
- dragonfly (~> 1.0.12)
11
- duktape (~> 1.3.0.6)
12
- httparty (~> 0.13.6)
13
- kramdown (~> 1.10.0)
11
+ dragonfly (~> 1.1.1)
12
+ duktape (~> 1.6.1.0)
13
+ httparty (~> 0.14.0)
14
+ kramdown (~> 1.13.2)
14
15
  locomotivecms-solid (~> 4.0.1)
15
16
  locomotivecms_common (~> 0.2.0)
16
- mime-types (~> 2.6.1)
17
+ mime-types (~> 3.1.0)
17
18
  mimetype-fu (~> 0.1.2)
18
- moneta (~> 0.8.0)
19
+ moneta (~> 1.0.0)
19
20
  morphine (~> 0.1.1)
20
- nokogiri (~> 1.6.8)
21
+ nokogiri (~> 1.7.0.1)
21
22
  pony (~> 1.11)
22
- rack-cache (~> 1.6.1)
23
+ rack-cache (~> 1.7.0)
23
24
  rack-rewrite (~> 1.5.1)
24
- rack_csrf (~> 2.5.0)
25
- sanitize (~> 4.0.1)
26
- sass (~> 3.4.21)
27
- sprockets (~> 3.5.2)
25
+ rack_csrf (~> 2.6.0)
26
+ sanitize (~> 4.4.0)
27
+ sass (~> 3.4.23)
28
+ sprockets (~> 3.7.1)
29
+ uglifier (~> 3.1.6)
28
30
 
29
31
  GEM
30
32
  remote: https://rubygems.org/
@@ -38,9 +40,10 @@ GEM
38
40
  addressable (2.5.0)
39
41
  public_suffix (~> 2.0, >= 2.0.2)
40
42
  attr_extras (4.4.0)
41
- autoprefixer-rails (6.3.3.1)
43
+ autoprefixer-rails (6.7.6)
42
44
  execjs
43
- bson (4.1.1)
45
+ bcrypt (3.1.11)
46
+ bson (4.2.1)
44
47
  byebug (8.2.5)
45
48
  chronic (0.10.2)
46
49
  chunky_png (1.3.8)
@@ -65,38 +68,37 @@ GEM
65
68
  compass-import-once (1.0.5)
66
69
  sass (>= 3.2, < 3.5)
67
70
  concurrent-ruby (1.0.5)
68
- coveralls (0.8.15)
71
+ coveralls (0.8.19)
69
72
  json (>= 1.8, < 3)
70
73
  simplecov (~> 0.12.0)
71
74
  term-ansicolor (~> 1.3)
72
75
  thor (~> 0.19.1)
73
- tins (>= 1.6.0, < 2)
76
+ tins (~> 1.6)
74
77
  crass (1.0.2)
75
- diff-lcs (1.2.5)
78
+ diff-lcs (1.3)
76
79
  docile (1.1.5)
77
- dragonfly (1.0.12)
80
+ dragonfly (1.1.1)
78
81
  addressable (~> 2.3)
79
82
  multi_json (~> 1.0)
80
- rack (>= 1.3.0)
81
- duktape (1.3.0.6)
83
+ rack (>= 1.3)
84
+ duktape (1.6.1.0)
82
85
  execjs (2.7.0)
83
86
  ffi (1.9.18)
84
87
  flamegraph (0.9.5)
85
88
  haml (4.0.7)
86
89
  tilt
87
- httparty (0.13.7)
88
- json (~> 1.8)
90
+ httparty (0.14.0)
89
91
  multi_xml (>= 0.5.2)
90
- i18n (0.7.0)
92
+ i18n (0.8.0)
91
93
  i18n-spec (0.6.0)
92
94
  iso
93
95
  iso (0.2.2)
94
96
  i18n
95
- json (1.8.3)
97
+ json (1.8.6)
96
98
  json_spec (1.1.4)
97
99
  multi_json (~> 1.0)
98
100
  rspec (>= 2.0, < 4.0)
99
- kramdown (1.10.0)
101
+ kramdown (1.13.2)
100
102
  locomotivecms-liquid (4.0.0)
101
103
  locomotivecms-solid (4.0.1)
102
104
  locomotivecms-liquid (~> 4.0.0)
@@ -107,23 +109,25 @@ GEM
107
109
  stringex (~> 2.6.0)
108
110
  mail (2.6.4)
109
111
  mime-types (>= 1.16, < 4)
110
- memory_profiler (0.9.6)
112
+ memory_profiler (0.9.7)
111
113
  method_source (0.8.2)
112
- mime-types (2.6.2)
114
+ mime-types (3.1)
115
+ mime-types-data (~> 3.2015)
116
+ mime-types-data (3.2016.0521)
113
117
  mimetype-fu (0.1.2)
114
118
  mini_portile2 (2.1.0)
115
119
  minitest (5.10.1)
116
- moneta (0.8.1)
117
- mongo (2.2.7)
118
- bson (~> 4.0)
120
+ moneta (1.0.0)
121
+ mongo (2.4.1)
122
+ bson (>= 4.2.1, < 5.0.0)
119
123
  morphine (0.1.1)
120
124
  multi_json (1.12.1)
121
125
  multi_xml (0.6.0)
122
- nokogiri (1.6.8.1)
126
+ nokogiri (1.7.0.1)
123
127
  mini_portile2 (~> 2.1.0)
124
128
  nokogumbo (1.4.10)
125
129
  nokogiri
126
- origin (2.2.0)
130
+ origin (2.3.0)
127
131
  pony (1.11)
128
132
  mail (>= 2.0)
129
133
  pry (0.10.4)
@@ -134,16 +138,16 @@ GEM
134
138
  byebug (~> 8.0)
135
139
  pry (~> 0.10)
136
140
  public_suffix (2.0.5)
137
- puma (3.6.0)
141
+ puma (3.7.0)
138
142
  rack (2.0.1)
139
- rack-cache (1.6.1)
143
+ rack-cache (1.7.0)
140
144
  rack (>= 0.4)
141
- rack-mini-profiler (0.10.1)
145
+ rack-mini-profiler (0.10.2)
142
146
  rack (>= 1.2.0)
143
147
  rack-rewrite (1.5.1)
144
148
  rack-test (0.6.3)
145
149
  rack (>= 1.0)
146
- rack_csrf (2.5.0)
150
+ rack_csrf (2.6.0)
147
151
  rack (>= 1.1.0)
148
152
  rake (10.4.2)
149
153
  rb-fsevent (0.9.8)
@@ -162,7 +166,7 @@ GEM
162
166
  diff-lcs (>= 1.2.0, < 2.0)
163
167
  rspec-support (~> 3.4.0)
164
168
  rspec-support (3.4.1)
165
- sanitize (4.0.1)
169
+ sanitize (4.4.0)
166
170
  crass (~> 1.0.2)
167
171
  nokogiri (>= 1.4.4)
168
172
  nokogumbo (~> 1.4.1)
@@ -173,21 +177,22 @@ GEM
173
177
  simplecov-html (~> 0.10.0)
174
178
  simplecov-html (0.10.0)
175
179
  slop (3.6.0)
176
- sprockets (3.5.2)
180
+ sprockets (3.7.1)
177
181
  concurrent-ruby (~> 1.0)
178
182
  rack (> 1, < 3)
179
- stackprof (0.2.9)
183
+ stackprof (0.2.10)
180
184
  stringex (2.6.1)
181
- term-ansicolor (1.3.2)
185
+ term-ansicolor (1.4.0)
182
186
  tins (~> 1.0)
183
- thor (0.19.1)
187
+ thor (0.19.4)
184
188
  thread_safe (0.3.6)
185
- tilt (2.0.5)
189
+ tilt (2.0.6)
186
190
  timecop (0.8.1)
187
- tins (1.12.0)
191
+ tins (1.13.2)
188
192
  tzinfo (1.2.2)
189
193
  thread_safe (~> 0.1)
190
- yui-compressor (0.12.0)
194
+ uglifier (3.1.6)
195
+ execjs (>= 0.3.0, < 3)
191
196
 
192
197
  PLATFORMS
193
198
  ruby
@@ -202,8 +207,8 @@ DEPENDENCIES
202
207
  json_spec (~> 1.1.4)
203
208
  locomotivecms_steam!
204
209
  memory_profiler
205
- mongo (~> 2.2.7)
206
- origin (~> 2.2.0)
210
+ mongo (~> 2.4.1)
211
+ origin (~> 2.3.0)
207
212
  pry-byebug (~> 3.3.0)
208
213
  puma
209
214
  rack-mini-profiler (~> 0.10.1)
@@ -212,7 +217,9 @@ DEPENDENCIES
212
217
  rspec (~> 3.4.0)
213
218
  stackprof
214
219
  timecop (~> 0.8.0)
215
- yui-compressor (~> 0.12.0)
220
+
221
+ RUBY VERSION
222
+ ruby 2.3.3p222
216
223
 
217
224
  BUNDLED WITH
218
- 1.11.2
225
+ 1.14.6
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 NoCoffee
3
+ Copyright (c) 2017 NoCoffee
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -61,4 +61,4 @@ see the list in the issues section.
61
61
 
62
62
  ## License
63
63
 
64
- Copyright (c) 2016 NoCoffee. MIT Licensed, see LICENSE for details.
64
+ Copyright (c) 2017 NoCoffee. MIT Licensed, see LICENSE for details.
@@ -13,7 +13,7 @@ nl:
13
13
 
14
14
  errors:
15
15
  messages:
16
- blank: "kan ikke være blank"
16
+ blank: "mag niet leeg zijn"
17
17
 
18
18
  number:
19
19
  format:
@@ -157,4 +157,4 @@ nl:
157
157
 
158
158
  pagination:
159
159
  previous: "&laquo; Vorige"
160
- next: "Volgende &raquo;"
160
+ next: "Volgende &raquo;"
@@ -23,6 +23,7 @@ module Locomotive
23
23
  modify_for_selects(_attributes)
24
24
  modify_for_associations(_attributes)
25
25
  modify_for_files(_attributes)
26
+ modify_for_passwords(_attributes)
26
27
 
27
28
  list << _attributes
28
29
  end
@@ -56,6 +57,13 @@ module Locomotive
56
57
  end
57
58
  end
58
59
 
60
+ def modify_for_passwords(attributes)
61
+ content_type.password_fields.each do |field|
62
+ uncrypted_password = attributes.delete(field.name.to_sym)
63
+ attributes[:"#{field.name}_hash"] = BCrypt::Password.create(uncrypted_password)
64
+ end
65
+ end
66
+
59
67
  def file_size(path)
60
68
  return nil if path.blank?
61
69
 
@@ -47,7 +47,7 @@ module Locomotive::Steam
47
47
  protected
48
48
 
49
49
  def entry_value(entry)
50
- value = entry.send(@field)
50
+ value = entry.send(@field) rescue nil # not just it's safe to rely on rescue (hidden errors)
51
51
 
52
52
  if value.respond_to?(:translations)
53
53
  value[@locale]
@@ -65,7 +65,7 @@ module Locomotive
65
65
  attr_accessor :asset_path
66
66
 
67
67
  # If java is installed and if this option is enabled,
68
- # then YUI::JavaScriptCompressor and YUI::CssCompressor are used to minify the css and the javascript.
68
+ # then Uglifier and Sass are used to minify the javascript and the css.
69
69
  #
70
70
  # default: false
71
71
  #
@@ -38,7 +38,7 @@ module Locomotive
38
38
  begin
39
39
  Haml::Engine.new(source).render
40
40
  rescue Haml::SyntaxError => e
41
- raise Steam::RenderError.new(e.message, template_path, source, e.line, e.backtrace)
41
+ raise Steam::RenderError.new(e, template_path, source)
42
42
  end
43
43
  end
44
44
 
@@ -1,4 +1,5 @@
1
1
  require 'chronic'
2
+ require 'bcrypt'
2
3
 
3
4
  module Locomotive::Steam
4
5
 
@@ -131,6 +132,22 @@ module Locomotive::Steam
131
132
  _cast_convertor(field.name, &:to_f)
132
133
  end
133
134
 
135
+ def _cast_json(field)
136
+ _cast_convertor(field.name) do |value|
137
+ if value.respond_to?(:to_h)
138
+ value
139
+ else
140
+ value.blank? ? nil : JSON.parse(value)
141
+ end
142
+ end
143
+ end
144
+
145
+ def _cast_password(field)
146
+ _cast_convertor(:"#{field.name}_hash") do |value|
147
+ value.blank? ? nil : BCrypt::Password.new(value)
148
+ end
149
+ end
150
+
134
151
  def _cast_file(field)
135
152
  _cast_convertor(field.name) do |value, locale|
136
153
  if value.respond_to?(:url)
@@ -8,6 +8,7 @@ module Locomotive::Steam
8
8
  def_delegator :fields, :associations, :association_fields
9
9
  def_delegator :fields, :selects, :select_fields
10
10
  def_delegator :fields, :files, :file_fields
11
+ def_delegator :fields, :passwords, :password_fields
11
12
  def_delegator :fields, :default, :fields_with_default
12
13
 
13
14
  def initialize(attributes = {})
@@ -66,6 +66,7 @@ module Locomotive::Steam
66
66
  when :belongs_to, :select then "#{name}_id"
67
67
  when :many_to_many then "#{name.singularize}_ids"
68
68
  when :has_many then nil
69
+ when :password then nil
69
70
  else name
70
71
  end
71
72
  end
@@ -20,6 +20,10 @@ module Locomotive::Steam
20
20
  self[:source].blank? ? self.content : self[:source]
21
21
  end
22
22
 
23
+ def content
24
+ self[:source].blank? ? self[:content] : self[:source]
25
+ end
26
+
23
27
  def format
24
28
  self[:format] || 'html' # only editable_text elements
25
29
  end
@@ -3,14 +3,22 @@ module Locomotive::Steam
3
3
  class NoSiteException < ::Exception
4
4
  end
5
5
 
6
- class ActionException < ::Exception
6
+ class RedirectionException < ::Exception
7
+
8
+ attr_reader :url
9
+
10
+ def initialize(url)
11
+ @url = url
12
+ super("Redirect to #{url}")
13
+ end
14
+
7
15
  end
8
16
 
9
- class RenderError < ::StandardError
17
+ class ParsingRenderingError < ::StandardError
10
18
 
11
19
  LINES_RANGE = 10
12
20
 
13
- attr_reader :file, :source, :line, :original_backtrace
21
+ attr_accessor :file, :line, :source, :original_backtrace
14
22
 
15
23
  def initialize(message, file, source, line, original_backtrace)
16
24
  @file, @source, @line, @original_backtrace = file, source, line, original_backtrace
@@ -23,10 +31,10 @@ module Locomotive::Steam
23
31
  lines = source.split("\n")
24
32
 
25
33
  start = line - (LINES_RANGE / 2)
26
- start = 0 if start < 0
34
+ start = 1 if start <= 0
27
35
  finish = line + (LINES_RANGE / 2)
28
36
 
29
- (start..finish).map { |i| [i, lines[i]] }
37
+ (start..finish).map { |i| [i, lines[i - 1]] }
30
38
  end
31
39
 
32
40
  def backtrace
@@ -35,4 +43,26 @@ module Locomotive::Steam
35
43
 
36
44
  end
37
45
 
46
+ class RenderError < ParsingRenderingError
47
+
48
+ def initialize(error, file, source)
49
+ message = error.message
50
+ line = error.respond_to?(:line_number) ? error.line_number : error.line
51
+ backtrace = error.backtrace
52
+
53
+ super(message, file, source, line, backtrace)
54
+ end
55
+
56
+ end
57
+
58
+ class ActionError < ParsingRenderingError
59
+
60
+ attr_accessor :action
61
+
62
+ def initialize(error, script)
63
+ super(error.message, nil, script, 0, error.backtrace)
64
+ end
65
+
66
+ end
67
+
38
68
  end