kuhsaft 2.4.3 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +207 -130
- data/app/assets/javascripts/kuhsaft/cms/application.js.coffee.erb +14 -12
- data/app/controllers/kuhsaft/cms/admin_controller.rb +1 -1
- data/app/controllers/kuhsaft/pages_controller.rb +1 -0
- data/app/helpers/kuhsaft/cms/admin_helper.rb +51 -0
- data/app/helpers/kuhsaft/cms/pages_helper.rb +1 -1
- data/app/helpers/pages_helper.rb +4 -0
- data/app/models/kuhsaft/page.rb +6 -1
- data/app/models/kuhsaft/page_type.rb +2 -1
- data/app/views/shoestrap/base/_form.html.haml +9 -0
- data/config/routes.rb +1 -1
- data/lib/kuhsaft/version.rb +1 -1
- data/spec/controllers/kuhsaft/api/pages_controller_spec.rb +1 -1
- data/spec/controllers/kuhsaft/pages_controller_spec.rb +4 -4
- data/spec/controllers/kuhsaft/sitemaps_controller_spec.rb +1 -1
- data/spec/features/cms_pages_spec.rb +5 -5
- data/spec/features/search_spec.rb +10 -10
- data/spec/helpers/kuhsaft/cms/admin_helper_spec.rb +5 -5
- data/spec/helpers/kuhsaft/cms/pages_helper_spec.rb +4 -4
- data/spec/helpers/kuhsaft/pages_helper_spec.rb +4 -4
- data/spec/kuhsaft_spec.rb +1 -1
- data/spec/lib/brick_list_spec.rb +9 -7
- data/spec/lib/engine_spec.rb +2 -2
- data/spec/lib/gridded_spec.rb +2 -2
- data/spec/lib/image_uploader_mounting_spec.rb +1 -1
- data/spec/lib/page_tree_spec.rb +2 -2
- data/spec/lib/searchable_spec.rb +1 -1
- data/spec/lib/translatable_spec.rb +16 -16
- data/spec/models/accordion_brick_spec.rb +6 -6
- data/spec/models/accordion_item_brick_spec.rb +7 -7
- data/spec/models/anchor_brick_spec.rb +4 -4
- data/spec/models/asset_brick_spec.rb +7 -7
- data/spec/models/asset_spec.rb +6 -6
- data/spec/models/brick_spec.rb +22 -22
- data/spec/models/brick_type_filter_spec.rb +12 -12
- data/spec/models/column_brick_spec.rb +5 -5
- data/spec/models/image_brick_spec.rb +8 -8
- data/spec/models/image_size_spec.rb +5 -5
- data/spec/models/link_brick_spec.rb +8 -8
- data/spec/models/page_spec.rb +50 -50
- data/spec/models/placeholder_brick_spec.rb +6 -6
- data/spec/models/publish_state_spec.rb +4 -4
- data/spec/models/slider_brick_spec.rb +4 -4
- data/spec/models/text_brick_spec.rb +4 -4
- data/spec/models/two_column_brick_spec.rb +13 -13
- data/spec/models/video_brick_spec.rb +4 -4
- data/spec/support/write_expectation.rb +2 -2
- data/spec/views/kuhsaft/sitemaps/index.xml.haml_spec.rb +3 -3
- metadata +13 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8920995ecef8a16d6df914afecf6caf339d32f6d
|
4
|
+
data.tar.gz: 0e519f73346a072d9e036a8d9844a087f8f43a1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
34
|
+
```ruby
|
35
|
+
gem 'kuhsaft'
|
36
|
+
```
|
35
37
|
|
36
38
|
And run
|
37
39
|
|
38
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
61
|
-
|
68
|
+
```sass
|
69
|
+
# application.css.sass
|
70
|
+
@import 'kuhsaft/application'
|
71
|
+
```
|
62
72
|
|
63
|
-
|
64
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
114
|
-
|
115
|
-
|
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
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|
-
|
131
|
-
|
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
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
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
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
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
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
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
|
-
|
173
|
-
|
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
|
-
|
224
|
-
|
272
|
+
```bash
|
273
|
+
# translate your pages into french
|
274
|
+
rails g kuhsaft:translations:add fr
|
275
|
+
```
|
225
276
|
Or
|
226
277
|
|
227
|
-
|
228
|
-
|
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
|
-
|
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
|
-
|
291
|
+
```ruby
|
292
|
+
config.available_locales = [:en, :fr]
|
293
|
+
```
|
237
294
|
Or
|
238
295
|
|
239
|
-
|
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
|
-
|
246
|
-
|
247
|
-
|
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
|
-
|
312
|
+
```ruby
|
313
|
+
before_action :set_locale
|
252
314
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
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
|
-
|
262
|
-
|
263
|
-
|
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
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
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
|
-
|
281
|
-
|
282
|
-
|
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
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
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
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
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
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
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
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
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
|
-
|
348
|
-
|
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
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
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
|
-
|
389
|
-
|
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
|
-
|
27
|
-
|
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 (
|
41
|
-
|
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
|
-
|
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) ->
|
@@ -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.
|
13
|
+
page.page_type == Kuhsaft::PageType::REDIRECT || !page.translated? || !page.persisted? || page.errors.present?
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|