kuhsaft 2.4.3 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +207 -130
  3. data/app/assets/javascripts/kuhsaft/cms/application.js.coffee.erb +14 -12
  4. data/app/controllers/kuhsaft/cms/admin_controller.rb +1 -1
  5. data/app/controllers/kuhsaft/pages_controller.rb +1 -0
  6. data/app/helpers/kuhsaft/cms/admin_helper.rb +51 -0
  7. data/app/helpers/kuhsaft/cms/pages_helper.rb +1 -1
  8. data/app/helpers/pages_helper.rb +4 -0
  9. data/app/models/kuhsaft/page.rb +6 -1
  10. data/app/models/kuhsaft/page_type.rb +2 -1
  11. data/app/views/shoestrap/base/_form.html.haml +9 -0
  12. data/config/routes.rb +1 -1
  13. data/lib/kuhsaft/version.rb +1 -1
  14. data/spec/controllers/kuhsaft/api/pages_controller_spec.rb +1 -1
  15. data/spec/controllers/kuhsaft/pages_controller_spec.rb +4 -4
  16. data/spec/controllers/kuhsaft/sitemaps_controller_spec.rb +1 -1
  17. data/spec/features/cms_pages_spec.rb +5 -5
  18. data/spec/features/search_spec.rb +10 -10
  19. data/spec/helpers/kuhsaft/cms/admin_helper_spec.rb +5 -5
  20. data/spec/helpers/kuhsaft/cms/pages_helper_spec.rb +4 -4
  21. data/spec/helpers/kuhsaft/pages_helper_spec.rb +4 -4
  22. data/spec/kuhsaft_spec.rb +1 -1
  23. data/spec/lib/brick_list_spec.rb +9 -7
  24. data/spec/lib/engine_spec.rb +2 -2
  25. data/spec/lib/gridded_spec.rb +2 -2
  26. data/spec/lib/image_uploader_mounting_spec.rb +1 -1
  27. data/spec/lib/page_tree_spec.rb +2 -2
  28. data/spec/lib/searchable_spec.rb +1 -1
  29. data/spec/lib/translatable_spec.rb +16 -16
  30. data/spec/models/accordion_brick_spec.rb +6 -6
  31. data/spec/models/accordion_item_brick_spec.rb +7 -7
  32. data/spec/models/anchor_brick_spec.rb +4 -4
  33. data/spec/models/asset_brick_spec.rb +7 -7
  34. data/spec/models/asset_spec.rb +6 -6
  35. data/spec/models/brick_spec.rb +22 -22
  36. data/spec/models/brick_type_filter_spec.rb +12 -12
  37. data/spec/models/column_brick_spec.rb +5 -5
  38. data/spec/models/image_brick_spec.rb +8 -8
  39. data/spec/models/image_size_spec.rb +5 -5
  40. data/spec/models/link_brick_spec.rb +8 -8
  41. data/spec/models/page_spec.rb +50 -50
  42. data/spec/models/placeholder_brick_spec.rb +6 -6
  43. data/spec/models/publish_state_spec.rb +4 -4
  44. data/spec/models/slider_brick_spec.rb +4 -4
  45. data/spec/models/text_brick_spec.rb +4 -4
  46. data/spec/models/two_column_brick_spec.rb +13 -13
  47. data/spec/models/video_brick_spec.rb +4 -4
  48. data/spec/support/write_expectation.rb +2 -2
  49. data/spec/views/kuhsaft/sitemaps/index.xml.haml_spec.rb +3 -3
  50. metadata +13 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 816a54fafbdf7a0080bebfe502d28bc3766c53ae
4
- data.tar.gz: 46ea21de733eabc2fe7286479edcfc611e107f15
3
+ metadata.gz: 8920995ecef8a16d6df914afecf6caf339d32f6d
4
+ data.tar.gz: 0e519f73346a072d9e036a8d9844a087f8f43a1a
5
5
  SHA512:
6
- metadata.gz: b2ad4266fcd26ee4a9ba650bdeb7697d50404dd582ae9745528d561590db7453473e4d993e8ebb9ae31d79cf4a7711bee239a6c0d5112593e3aedec10e89453d
7
- data.tar.gz: 516cfdb3e8dcea474fb9d45ae44075ddfcf65b5d7e9becc002154cefe1d999ae4644ebac717d434f4294ce010323f7ddb00c96a0f337817e7134a6384b25f520
6
+ metadata.gz: d3a07dd131ed1da0cdaf1693d3bcd00968a47a04e3812099408164149f82b4b688dc738423174db85072b47a8e9eccd22c24e469809d6277d97d149f8aade3df
7
+ data.tar.gz: b54269f660a18cf5bf0806dcc30912a2b5e8052b4a806503216ba731cc1d78f401757911081d7ad21578bbfb70f2de5fced30388d4072a2724099957a19c05d3
data/README.md CHANGED
@@ -31,53 +31,67 @@ Kuhsaft requires:
31
31
 
32
32
  Add Kuhsaft to your Gemfile:
33
33
 
34
- gem 'kuhsaft'
34
+ ```ruby
35
+ gem 'kuhsaft'
36
+ ```
35
37
 
36
38
  And run
37
39
 
38
- bundle install
40
+ ```bash
41
+ bundle install
42
+ ```
39
43
 
40
44
  to get the gem
41
45
 
42
46
  Then install the assets and the migrations and run them:
43
47
 
44
- rake kuhsaft:install:migrations
45
- rake db:migrate
46
- rake db:seed
47
- rails generate kuhsaft:assets:install
48
+ ```bash
49
+ rake kuhsaft:install:migrations
50
+ rake db:migrate
51
+ rake db:seed
52
+ rails generate kuhsaft:assets:install
53
+ ```
48
54
 
49
55
  You might want to change the language suffixes on the fields inside the create_kuhsaft_pages migration, depending on your app's default_locale.
50
56
 
51
57
  Mount the kuhsaft engine in your routing file:
52
58
 
53
- MyApp::Application.routes.draw do
54
- # add your app routes here
55
- mount Kuhsaft::Engine => "/"
56
- end
59
+ ```ruby
60
+ MyApp::Application.routes.draw do
61
+ # add your app routes here
62
+ mount Kuhsaft::Engine => '/'
63
+ end
64
+ ```
57
65
 
58
66
  Load the Kuhsaft assets into your app, so you have working grids, widgets etc:
59
67
 
60
- # application.css.sass
61
- @import 'kuhsaft/application'
68
+ ```sass
69
+ # application.css.sass
70
+ @import 'kuhsaft/application'
71
+ ```
62
72
 
63
- # application.js.coffee
64
- //= require 'kuhsaft/application'
73
+ ```coffee
74
+ # application.js.coffee
75
+ //= require 'kuhsaft/application'
76
+ ```
65
77
 
66
78
  Finally, you need to define the image sizes for the image brick or use
67
79
  the defaults:
68
80
 
69
- # your_app/config/initializers/kuhsaft.rb
70
- Rails.application.config.to_prepare do
71
- Kuhsaft::Engine.configure do
72
- config.image_sizes.build_defaults! # creates 960x540 and 320x180 sizes
73
- end
74
- end
81
+ ```ruby
82
+ # your_app/config/initializers/kuhsaft.rb
83
+ Rails.application.config.to_prepare do
84
+ Kuhsaft::Engine.configure do
85
+ config.image_sizes.build_defaults! # creates 960x540 and 320x180 sizes
86
+ end
87
+ end
88
+ ```
75
89
 
76
90
  See "Configuring the image brick" for more details.
77
91
 
78
92
  ## Authentication
79
93
 
80
- Kuhsaft itself does not ship with any form of authentication. However, it is fairly easy to add by plugging into the Kuhsaft::Cms::AdminController. An example with devise:
94
+ Kuhsaft itself does not ship with any form of authentication. However, it is fairly easy to add by plugging into the Kuhsaft::Cms::AdminController. An example with [devise](https://github.com/plataformatec/devise):
81
95
 
82
96
  ```ruby
83
97
  # config/initializers/kuhsaft.rb
@@ -99,7 +113,7 @@ Make sure they are in the `config.assets.precompile` array in environments like
99
113
 
100
114
  There's a dummy app inside spec/dummy. Get it running by executing the following steps:
101
115
 
102
- ```
116
+ ```bash
103
117
  rake setup
104
118
  rake start_dummy
105
119
  ```
@@ -110,56 +124,67 @@ rake start_dummy
110
124
 
111
125
  As defined in the rails docs, load the helpers from our isolated Kuhsaft engine inside your application controller:
112
126
 
113
- class ApplicationController < ActionController::Base
114
- helper Kuhsaft::Engine.helpers
115
- end
127
+ ```ruby
128
+ class ApplicationController < ActionController::Base
129
+ helper Kuhsaft::Engine.helpers
130
+ end
131
+ ```
116
132
 
117
133
  ## Adding sublime video
118
134
 
119
135
  Create an initializer file in your app inside `config/initializers` and set the `sublime_video_token`:
120
136
 
121
- Rails.application.config.to_prepare do
122
- Kuhsaft::Engine.configure do
123
- # Get the token from the MySites section on the sublime video site
124
- config.sublime_video_token = '123abcd'
125
- end
126
- end
137
+ ```ruby
138
+ Rails.application.config.to_prepare do
139
+ Kuhsaft::Engine.configure do
140
+ # Get the token from the MySites section on the sublime video site
141
+ config.sublime_video_token = '123abcd'
142
+ end
143
+ end
144
+ ```
127
145
 
128
146
  Require the sublime javascript with the following helper:
129
147
 
130
- # in your application layout in the head section
131
- sublime_video_include_tag
132
-
148
+ ```ruby
149
+ # in your application layout in the head section
150
+ sublime_video_include_tag
151
+ ```
133
152
 
134
153
  ## Configuring the image brick
135
154
 
136
155
  The image brick can process uploaded images into specific sizes. These sizes can be configured inside the engine configuration. You can also use the built-in default sizes:
137
156
 
138
- # your_app/config/initializers/kuhsaft.rb
139
- Rails.application.config.to_prepare do
140
- Kuhsaft::Engine.configure do
141
- config.image_sizes.build_defaults! # creates 960x540 and 320x180 sizes
142
- end
143
- end
157
+ ```ruby
158
+ # your_app/config/initializers/kuhsaft.rb
159
+ Rails.application.config.to_prepare do
160
+ Kuhsaft::Engine.configure do
161
+ config.image_sizes.build_defaults! # creates 960x540 and 320x180 sizes
162
+ end
163
+ end
164
+ ```
144
165
 
145
166
  You can also remove the default sizes:
146
167
 
147
- # your_app/config/initializers/kuhsaft.rb
148
- Rails.application.config.to_prepare do
149
- Kuhsaft::Engine.configure do
150
- config.image_sizes.clear! # .all is now empty
151
- end
152
- end
168
+ ```ruby
169
+ # your_app/config/initializers/kuhsaft.rb
170
+ Rails.application.config.to_prepare do
171
+ Kuhsaft::Engine.configure do
172
+ config.image_sizes.clear! # .all is now empty
173
+ end
174
+ end
175
+ ```
153
176
 
154
177
  And most importantly, you can add custom sizes:
155
178
 
156
- # your_app/config/initializers/kuhsaft.rb
157
- Rails.application.config.to_prepare do
158
- Kuhsaft::Engine.configure do
159
- config.image_sizes.add(:side_box_vertical, 180, 460)
160
- config.image_sizes.add(:footer_teaser, 320, 220)
161
- end
162
- end
179
+ ```ruby
180
+ # your_app/config/initializers/kuhsaft.rb
181
+ Rails.application.config.to_prepare do
182
+ Kuhsaft::Engine.configure do
183
+ config.image_sizes.add(:side_box_vertical, 180, 460)
184
+ config.image_sizes.add(:footer_teaser, 320, 220)
185
+ end
186
+ end
187
+ ```
163
188
 
164
189
  The `name` option is a unique identifier, which is also used for translating the dropdown in the brick. You can add your translation by using the translation path:
165
190
 
@@ -169,13 +194,15 @@ The `name` option is a unique identifier, which is also used for translating the
169
194
 
170
195
  Implement the `available_display_styles` on a brick model and return an array of css classnames: `['module-big', 'module-small']`. These styles can be applied to a brick instance through the UI. In the frontend, use `to_style_class` to get the configured styles:
171
196
 
172
- %my-brick{ :class => brick.to_style_class}
173
- = brick.text # ... etc
197
+ ```haml
198
+ %my-brick{ class: brick.to_style_class }
199
+ = brick.text # ... etc
200
+ ```
174
201
 
175
202
  After setting up display styles in specific model add your translations
176
203
  for the UI dropdown. E.g. you've added display styles to the TextBrick model:
177
204
 
178
- ```
205
+ ```yaml
179
206
  de:
180
207
  text_brick:
181
208
  display_styles:
@@ -190,7 +217,7 @@ Each instance of a gridded class will have a method `gridded?` wich returns true
190
217
 
191
218
  If the Gridded Module is added to a Custom Brick, it should provide a col_count integer field with default value 0.
192
219
 
193
- ```
220
+ ```ruby
194
221
  add_column :your_awesome_brick, :col_count, :integer, default: 0
195
222
  ```
196
223
 
@@ -199,11 +226,33 @@ add_column :your_awesome_brick, :col_count, :integer, default: 0
199
226
  * Save your partial in `views/kuhsaft/placeholder_bricks/partials/_your_partial.html.haml`
200
227
  * Add translations for your partial in `config/locales/models/kuhsaft/placeholder_brick/locale.yml`
201
228
 
202
- ```
229
+ ```yaml
203
230
  de:
204
231
  your_partial: Your Partial
205
232
  ```
206
233
 
234
+ ## Mixing Custom Models/Views/Controllers with Kuhsaft Pages
235
+
236
+ Use the custom page type:
237
+
238
+ Custom pages behave almost like redirect pages except that they can have content and meta tags like normal pages.
239
+
240
+ What can you use this for: To redirect to a custom controller that does whatever you want and still have CMS content along side it. Example usage in a host app:
241
+
242
+ In Custom Controller that page redirects to:
243
+ ```ruby
244
+ def index
245
+ # could also be extracted into before_action
246
+ @page = Kuhsaft::Page.find(session[:kuhsaft_referrer]) if session[:kuhsaft_referrer]
247
+ @somestuff = Somestuff.new
248
+ end
249
+ ```
250
+
251
+ View:
252
+ ```
253
+ = render file: 'kuhsaft/pages/show'
254
+ ```
255
+
207
256
  ## Invalidating placeholder bricks containing other models on model changes
208
257
 
209
258
  Include the TouchPlaceholders module if your model is used within a
@@ -220,95 +269,115 @@ end
220
269
 
221
270
  If you want to translate your pages into another language, generate a new translation migration:
222
271
 
223
- # translate your pages into french
224
- rails g kuhsaft:translations:add fr
272
+ ```bash
273
+ # translate your pages into french
274
+ rails g kuhsaft:translations:add fr
275
+ ```
225
276
  Or
226
277
 
227
- # translate your pages into swiss german
228
- rails g kuhsaft:translations:add de-CH
278
+ ```bash
279
+ # translate your pages into swiss german
280
+ rails g kuhsaft:translations:add de-CH
281
+ ```
229
282
 
230
283
  This creates a new migration file inside `db/migrate` of your app. Run the migration as you normally do:
231
284
 
232
- rake db:migrate
285
+ ```bash
286
+ rake db:migrate
287
+ ```
233
288
 
234
289
  Finally, add the new translation locale to your `available_locales` inside your apps `application.rb`:
235
290
 
236
- config.available_locales = [:en, :fr]
291
+ ```ruby
292
+ config.available_locales = [:en, :fr]
293
+ ```
237
294
  Or
238
295
 
239
- config.available_locales = [:en, 'de-CH']
296
+ ```ruby
297
+ config.available_locales = [:en, 'de-CH']
298
+ ```
240
299
 
241
300
  ## Adding a language switch
242
301
 
243
302
  Add scope around routes:
244
303
 
245
- scope "(:locale)", locale: /de|en|fr/ do
246
- root 'kuhsaft/pages#show'
247
- end
304
+ ```ruby
305
+ scope "(:locale)", locale: /de|en|fr/ do
306
+ root 'kuhsaft/pages#show'
307
+ end
308
+ ```
248
309
 
249
310
  Set the locale in the ApplicationController in a before_action and set default url options:
250
311
 
251
- before_action :set_locale
312
+ ```ruby
313
+ before_action :set_locale
252
314
 
253
- def set_locale
254
- if I18n.available_locales.map{|sym| sym.to_s }.include?(params[:locale])
255
- I18n.locale = params[:locale]
256
- else
257
- I18n.locale = I18n.default_locale
258
- end
259
- end
315
+ def set_locale
316
+ if I18n.locale_available? params[:locale]
317
+ I18n.locale = params[:locale]
318
+ else
319
+ I18n.locale = I18n.default_locale
320
+ end
321
+ end
260
322
 
261
- def default_url_options(options={})
262
- { locale: I18n.locale }
263
- end
323
+ def default_url_options(options = {})
324
+ { locale: I18n.locale }
325
+ end
326
+ ```
264
327
 
265
328
  Add method to ApplicationHelper which redirects to homepage when current page is not translated.
266
329
  Make sure to have the homepage translated in every available language.
267
330
 
268
- def localized_url(url, target_locale)
269
- page = Kuhsaft::Page.find_by_url("#{I18n.locale}/#{url}")
270
- I18n.with_locale target_locale do
271
- translated_url = page.presence && page.url
272
- if translated_url.present?
273
- "/#{translated_url}"
274
- else
275
- root_path(locale: target_locale)
276
- end
277
- end
331
+ ```ruby
332
+ def localized_url(url, target_locale)
333
+ page = Kuhsaft::Page.find_by_url("#{I18n.locale}/#{url}")
334
+ I18n.with_locale target_locale do
335
+ translated_url = page.try :url
336
+ if translated_url.present?
337
+ "/#{translated_url}"
338
+ else
339
+ root_path(locale: target_locale)
278
340
  end
341
+ end
342
+ end
279
343
 
280
- def language_link(url, locale)
281
- localized_url(params[:url], locale)
282
- end
344
+ def language_link(url, locale)
345
+ localized_url(params[:url], locale)
346
+ end
347
+ ```
283
348
 
284
349
  Add language switch to navigation:
285
350
 
286
- SimpleNavigation::Configuration.run do |navigation|
287
- I18n.available_locales.each do |locale|
288
- primary.item locale, locale.to_s.upcase, language_link(params[:url], locale), highlights_on: Proc.new { I18n.locale == locale }
289
- end
290
- end
351
+ ```ruby
352
+ SimpleNavigation::Configuration.run do |navigation|
353
+ I18n.available_locales.each do |locale|
354
+ primary.item locale, locale.to_s.upcase, language_link(params[:url], locale), highlights_on: Proc.new { I18n.locale == locale }
355
+ end
356
+ end
357
+ ```
291
358
 
292
359
  Make sure to render only pages which are translated and published by using `published` and `translated` scope, so pages
293
360
  without translation and which are not published will not be displayed in the navigation.
294
361
  Here is an example of a possible navigation:
295
362
 
296
- SimpleNavigation::Configuration.run do |navigation|
297
- navigation.items do |primary|
298
- primary.dom_class = 'right'
299
- primary.selected_class = 'active'
300
- Kuhsaft::Page.find_by(slug_de: 'meta-navigation').children.published.translated.each do |page|
301
- primary.item page.id, page.title, page.link, class: 'contact icon'
302
- end
363
+ ```ruby
364
+ SimpleNavigation::Configuration.run do |navigation|
365
+ navigation.items do |primary|
366
+ primary.dom_class = 'right'
367
+ primary.selected_class = 'active'
368
+ Kuhsaft::Page.find_by(slug_de: 'meta-navigation').children.published.translated.each do |page|
369
+ primary.item page.id, page.title, page.link, class: 'contact icon'
370
+ end
303
371
 
304
- primary.item '', 'Sprache', '#', class: 'language icon has-dropdown'do |language|
305
- I18n.available_locales.each do |locale|
306
- language.dom_class = 'dropdown'
307
- language.item locale, language_text(locale), language_link(params[:url], locale), highlights_on: Proc.new { I18n.locale == locale }, class: "icon lang-#{locale}"
308
- end
309
- end
372
+ primary.item '', 'Sprache', '#', class: 'language icon has-dropdown'do |language|
373
+ I18n.available_locales.each do |locale|
374
+ language.dom_class = 'dropdown'
375
+ language.item locale, language_text(locale), language_link(params[:url], locale), highlights_on: Proc.new { I18n.locale == locale }, class: "icon lang-#{locale}"
310
376
  end
311
377
  end
378
+ end
379
+ end
380
+ ```
312
381
 
313
382
  ## Styling the content
314
383
 
@@ -324,19 +393,21 @@ Or if your page is translated, using the `translated` scope and the `published`
324
393
 
325
394
  ### 2 level navigation example using simple-navigation
326
395
 
327
- SimpleNavigation::Configuration.run do |navigation|
328
- navigation.items do |primary|
329
- # build first level
330
- Kuhsaft::Page.roots.published.translated.each do |page|
331
- primary.item page.id, page.title, page.link do |sub_item|
332
- # build second level
333
- page.children.published.translated.each do |subpage|
334
- sub_item.item subpage.id, subpage.title, subpage.link
335
- end
336
- end
396
+ ```ruby
397
+ SimpleNavigation::Configuration.run do |navigation|
398
+ navigation.items do |primary|
399
+ # build first level
400
+ Kuhsaft::Page.roots.published.translated.each do |page|
401
+ primary.item page.id, page.title, page.link do |sub_item|
402
+ # build second level
403
+ page.children.published.translated.each do |subpage|
404
+ sub_item.item subpage.id, subpage.title, subpage.link
337
405
  end
338
406
  end
339
407
  end
408
+ end
409
+ end
410
+ ```
340
411
 
341
412
  ## Use the `page_title` attribute in your app
342
413
 
@@ -344,8 +415,10 @@ Kuhsaft::Pages will provide a `%title` tag containing its `page_title`
344
415
  (or the required `title`if no title is present). Simply yield for
345
416
  `:head` in your `application.html` to use it.
346
417
 
347
- %head
348
- = yield(:head)
418
+ ```haml
419
+ %head
420
+ = yield(:head)
421
+ ```
349
422
 
350
423
  ## Modifying the backend navigation
351
424
 
@@ -369,10 +442,12 @@ Simply override the default partial for the main navigation in your app with you
369
442
  Kuhsaft has a module called `ImageUploaderMounting`. This module mounts the ImageBrickImageUploader
370
443
  and includes a callback method which handles that the image sizes will be updated after save.
371
444
 
372
- class CustomBrick < Brick
373
- include Kuhsaft::ImageUploaderMounting
374
- ...
375
- end
445
+ ```ruby
446
+ class CustomBrick < Brick
447
+ include Kuhsaft::ImageUploaderMounting
448
+ ...
449
+ end
450
+ ```
376
451
 
377
452
  If you do not include this module, then the images will not be changed when selecting one of your own image
378
453
  sizes. See "Configuring the image brick" for more details on creating your own image sizes.
@@ -385,8 +460,10 @@ LIKE fallback for any other ActiveRecord DB.
385
460
  Add a call to the `search_page_form` helper in your views. This renders
386
461
  the default search form. The query will be executed by kuhsaft.
387
462
 
388
- # e.g. _footer.html.haml
389
- = search_page_form
463
+ ```haml
464
+ # e.g. _footer.html.haml
465
+ = search_page_form
466
+ ```
390
467
 
391
468
  To customize the search and result views you can add your own partials
392
469
  to your rails app. The following partials are overridable.
@@ -410,7 +487,7 @@ Add the following lines to your `ck-config.js` file. The first line
410
487
  disables the standard link plugin. The second line enables the adv_link
411
488
  plugin, which we need for the CMS Page link dialogue in CKEditor.
412
489
 
413
- ```
490
+ ```javascript
414
491
  config.removePlugins = 'link'
415
492
  config.extraPlugins = 'adv_link'
416
493
  ```
@@ -420,4 +497,4 @@ following to your existing array `ckeditor/adv_link/*`.
420
497
 
421
498
  # LICENSE
422
499
 
423
- See the file LICENSE.
500
+ See the file [LICENSE](https://github.com/screenconcept/kuhsaft/blob/master/LICENSE).
@@ -23,24 +23,26 @@ CKEDITOR.config.customConfig = "<%= asset_path('kuhsaft/cms/ck-config.js') %>"
23
23
  loadTextEditor = ->
24
24
  CKEDITOR.replaceAll('ckeditor')
25
25
 
26
- updateInputsForRedirectPage = (redirect_url, keywords, description) ->
27
- redirect_url.removeAttr('disabled')
28
- keywords.attr('disabled', 'disabled')
29
- description.attr('disabled', 'disabled')
30
-
31
- clearInputsFromRedirectPage = (redirect_url, keywords, description) ->
32
- redirect_url.attr('disabled', 'disabled')
33
- keywords.removeAttr('disabled')
34
- description.removeAttr('disabled')
26
+ pageType = ->
27
+ $('#page_page_type option:selected').val()
35
28
 
36
29
  checkPageType = ->
37
30
  redirect_url = $('#page_redirect_url')
38
31
  keywords = $('#page_keywords')
39
32
  description = $('#page_description')
40
- if ($('#page_page_type option:selected').val() == 'redirect')
41
- updateInputsForRedirectPage(redirect_url, keywords, description)
33
+ if (pageType() == 'redirect')
34
+ redirect_url.removeAttr('disabled')
35
+ keywords.attr('disabled', 'disabled')
36
+ description.attr('disabled', 'disabled')
37
+ else if (pageType() == 'custom')
38
+ redirect_url.removeAttr('disabled')
39
+ keywords.removeAttr('disabled')
40
+ description.removeAttr('disabled')
42
41
  else
43
- clearInputsFromRedirectPage(redirect_url, keywords, description)
42
+ redirect_url.attr('disabled', 'disabled')
43
+ keywords.removeAttr('disabled')
44
+ description.removeAttr('disabled')
45
+
44
46
 
45
47
  sortableBrick = ->
46
48
  $(".brick-list").each (idx, elem) ->
@@ -10,7 +10,7 @@ module Kuhsaft
10
10
  I18n.locale = params[:content_locale]
11
11
  end
12
12
 
13
- def url_options
13
+ def default_url_options
14
14
  { content_locale: I18n.locale }.merge(super)
15
15
  end
16
16
  end
@@ -12,6 +12,7 @@ module Kuhsaft
12
12
  def show
13
13
  if @page.present? && @page.redirect? && @page.redirect_url.present?
14
14
  redirect_url = @page.redirect_url.sub(/\A\/+/, '') # remove all preceding slashes
15
+ session[:kuhsaft_referrer] = @page.id
15
16
  redirect_to "/#{redirect_url}"
16
17
  elsif @page.present?
17
18
  respond_with @page
@@ -16,6 +16,57 @@ module Kuhsaft
16
16
  link_to locale.to_s.upcase, url_for(
17
17
  action: action, content_locale: locale)
18
18
  end
19
+
20
+ def model_attribute_field(resource, column_name, f)
21
+ if resource.class.respond_to?(:uploaders) && resource.class.uploaders.keys.include?(column_name.to_sym)
22
+ f.input column_name, as: :file
23
+ elsif association_class(resource, column_name) == Kuhsaft::Page
24
+ route_input f, column_name, page_routes
25
+ elsif column_name == :link_url || column_name == :link
26
+ route_input f, column_name, user_selectable_routes
27
+ elsif column_name.to_s.end_with? '_id'
28
+ f.association column_name.to_s.gsub(/_id$/, '').to_sym
29
+ elsif column_name == :body
30
+ f.input column_name, input_html: { class: 'ckeditor text required' }
31
+ else
32
+ f.input column_name
33
+ end
34
+ end
35
+
36
+ def route_input(form, column_name, selectable_routes)
37
+ list_name = "routes_#{column_name}"
38
+ haml_tag :datalist, id: list_name, name: list_name do
39
+ selectable_routes.each { |route| haml_tag :option, value: route }
40
+ end
41
+ form.input column_name, input_html: { list: list_name }, as: 'string'
42
+ end
43
+
44
+ def association_class(resource, column_name)
45
+ association = resource.class.reflect_on_all_associations.find { |r| r.name == column_name.to_sym }
46
+ association_class = association.try :class_name
47
+ association_class.present? ? association_class.constantize : nil
48
+ end
49
+
50
+ # here are some route helpers if you need them in your backend
51
+ def all_selectable_routes
52
+ (page_routes + rails_routes).uniq.sort
53
+ end
54
+
55
+ def page_routes
56
+ Kuhsaft::Page.all_urls
57
+ end
58
+
59
+ def rails_routes
60
+ routes = Rails.application.routes.routes
61
+ routes = routes.select do |r|
62
+ r.verb.match('GET') && !r.requirements.blank? &&
63
+ !r.requirements[:controller].to_s.start_with?('cms') &&
64
+ !r.required_parts.any? &&
65
+ !r.requirements[:controller].to_s.start_with?('rails/')
66
+ end
67
+
68
+ routes.map { |r| _routes.url_for(r.requirements.merge only_path: true).strip }.uniq.sort
69
+ end
19
70
  end
20
71
  end
21
72
  end
@@ -10,7 +10,7 @@ module Kuhsaft
10
10
  end
11
11
 
12
12
  def hide_content_tab?(page)
13
- page.redirect? || !page.translated? || !page.persisted? || page.errors.present?
13
+ page.page_type == Kuhsaft::PageType::REDIRECT || !page.translated? || !page.persisted? || page.errors.present?
14
14
  end
15
15
  end
16
16
  end
@@ -46,4 +46,8 @@ module PagesHelper
46
46
  end
47
47
  end
48
48
  end
49
+
50
+ def on_kuhsaft_page?
51
+ controller.is_a? Kuhsaft::PagesController
52
+ end
49
53
  end