README.md in kuhsaft-2.4.3 vs README.md in kuhsaft-2.5.0
- old
+ new
@@ -29,57 +29,71 @@
# Installation
Add Kuhsaft to your Gemfile:
- gem 'kuhsaft'
+```ruby
+gem 'kuhsaft'
+```
And run
- bundle install
+```bash
+bundle install
+```
to get the gem
Then install the assets and the migrations and run them:
- rake kuhsaft:install:migrations
- rake db:migrate
- rake db:seed
- rails generate kuhsaft:assets:install
+```bash
+rake kuhsaft:install:migrations
+rake db:migrate
+rake db:seed
+rails generate kuhsaft:assets:install
+```
You might want to change the language suffixes on the fields inside the create_kuhsaft_pages migration, depending on your app's default_locale.
Mount the kuhsaft engine in your routing file:
- MyApp::Application.routes.draw do
- # add your app routes here
- mount Kuhsaft::Engine => "/"
- end
+```ruby
+MyApp::Application.routes.draw do
+ # add your app routes here
+ mount Kuhsaft::Engine => '/'
+end
+```
Load the Kuhsaft assets into your app, so you have working grids, widgets etc:
- # application.css.sass
- @import 'kuhsaft/application'
+```sass
+# application.css.sass
+@import 'kuhsaft/application'
+```
- # application.js.coffee
- //= require 'kuhsaft/application'
+```coffee
+# application.js.coffee
+//= require 'kuhsaft/application'
+```
Finally, you need to define the image sizes for the image brick or use
the defaults:
- # your_app/config/initializers/kuhsaft.rb
- Rails.application.config.to_prepare do
- Kuhsaft::Engine.configure do
- config.image_sizes.build_defaults! # creates 960x540 and 320x180 sizes
- end
- end
+```ruby
+# your_app/config/initializers/kuhsaft.rb
+Rails.application.config.to_prepare do
+ Kuhsaft::Engine.configure do
+ config.image_sizes.build_defaults! # creates 960x540 and 320x180 sizes
+ end
+end
+```
See "Configuring the image brick" for more details.
## Authentication
-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:
+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):
```ruby
# config/initializers/kuhsaft.rb
Rails.application.config.to_prepare do
Kuhsaft::Cms::AdminController.class_eval do
@@ -97,87 +111,100 @@
## Testing
There's a dummy app inside spec/dummy. Get it running by executing the following steps:
-```
+```bash
rake setup
rake start_dummy
```
# Usage
## Making Kuhsaft helpers available to your app
As defined in the rails docs, load the helpers from our isolated Kuhsaft engine inside your application controller:
- class ApplicationController < ActionController::Base
- helper Kuhsaft::Engine.helpers
- end
+```ruby
+class ApplicationController < ActionController::Base
+ helper Kuhsaft::Engine.helpers
+end
+```
## Adding sublime video
Create an initializer file in your app inside `config/initializers` and set the `sublime_video_token`:
- Rails.application.config.to_prepare do
- Kuhsaft::Engine.configure do
- # Get the token from the MySites section on the sublime video site
- config.sublime_video_token = '123abcd'
- end
- end
+```ruby
+Rails.application.config.to_prepare do
+ Kuhsaft::Engine.configure do
+ # Get the token from the MySites section on the sublime video site
+ config.sublime_video_token = '123abcd'
+ end
+end
+```
Require the sublime javascript with the following helper:
- # in your application layout in the head section
- sublime_video_include_tag
+```ruby
+# in your application layout in the head section
+sublime_video_include_tag
+```
-
## Configuring the image brick
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:
- # your_app/config/initializers/kuhsaft.rb
- Rails.application.config.to_prepare do
- Kuhsaft::Engine.configure do
- config.image_sizes.build_defaults! # creates 960x540 and 320x180 sizes
- end
- end
+```ruby
+# your_app/config/initializers/kuhsaft.rb
+Rails.application.config.to_prepare do
+ Kuhsaft::Engine.configure do
+ config.image_sizes.build_defaults! # creates 960x540 and 320x180 sizes
+ end
+end
+```
You can also remove the default sizes:
- # your_app/config/initializers/kuhsaft.rb
- Rails.application.config.to_prepare do
- Kuhsaft::Engine.configure do
- config.image_sizes.clear! # .all is now empty
- end
- end
+```ruby
+# your_app/config/initializers/kuhsaft.rb
+Rails.application.config.to_prepare do
+ Kuhsaft::Engine.configure do
+ config.image_sizes.clear! # .all is now empty
+ end
+end
+```
And most importantly, you can add custom sizes:
- # your_app/config/initializers/kuhsaft.rb
- Rails.application.config.to_prepare do
- Kuhsaft::Engine.configure do
- config.image_sizes.add(:side_box_vertical, 180, 460)
- config.image_sizes.add(:footer_teaser, 320, 220)
- end
- end
+```ruby
+# your_app/config/initializers/kuhsaft.rb
+Rails.application.config.to_prepare do
+ Kuhsaft::Engine.configure do
+ config.image_sizes.add(:side_box_vertical, 180, 460)
+ config.image_sizes.add(:footer_teaser, 320, 220)
+ end
+end
+```
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:
activerecord.attributes.kuhsaft/image_size.sizes.#{name}
## Configuring custom styles for bricks
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:
- %my-brick{ :class => brick.to_style_class}
- = brick.text # ... etc
+```haml
+%my-brick{ class: brick.to_style_class }
+ = brick.text # ... etc
+```
After setting up display styles in specific model add your translations
for the UI dropdown. E.g. you've added display styles to the TextBrick model:
-```
+```yaml
de:
text_brick:
display_styles:
style1: 'My Style 1'
style2: 'My Style 2'
@@ -188,24 +215,46 @@
Include the Kuhsaft::Gridded Module on every Brick you want to display in a grid. Default grid options are 1 to 12 (representing columns) wich can be configured via the class method `available_grid_sizes` (should return an array of integers).
Each instance of a gridded class will have a method `gridded?` wich returns true if a column size is set.
If the Gridded Module is added to a Custom Brick, it should provide a col_count integer field with default value 0.
-```
+```ruby
add_column :your_awesome_brick, :col_count, :integer, default: 0
```
## Adding custom templates with placeholder bricks
* Save your partial in `views/kuhsaft/placeholder_bricks/partials/_your_partial.html.haml`
* Add translations for your partial in `config/locales/models/kuhsaft/placeholder_brick/locale.yml`
-```
+```yaml
de:
your_partial: Your Partial
```
+## Mixing Custom Models/Views/Controllers with Kuhsaft Pages
+
+Use the custom page type:
+
+Custom pages behave almost like redirect pages except that they can have content and meta tags like normal pages.
+
+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:
+
+In Custom Controller that page redirects to:
+```ruby
+ def index
+ # could also be extracted into before_action
+ @page = Kuhsaft::Page.find(session[:kuhsaft_referrer]) if session[:kuhsaft_referrer]
+ @somestuff = Somestuff.new
+ end
+```
+
+View:
+```
+= render file: 'kuhsaft/pages/show'
+```
+
## Invalidating placeholder bricks containing other models on model changes
Include the TouchPlaceholders module if your model is used within a
placeholder brick and define which templates it appears in:
@@ -218,99 +267,119 @@
## Adding additional content languages
If you want to translate your pages into another language, generate a new translation migration:
- # translate your pages into french
- rails g kuhsaft:translations:add fr
+```bash
+# translate your pages into french
+rails g kuhsaft:translations:add fr
+```
Or
- # translate your pages into swiss german
- rails g kuhsaft:translations:add de-CH
+```bash
+# translate your pages into swiss german
+rails g kuhsaft:translations:add de-CH
+```
This creates a new migration file inside `db/migrate` of your app. Run the migration as you normally do:
- rake db:migrate
+```bash
+rake db:migrate
+```
Finally, add the new translation locale to your `available_locales` inside your apps `application.rb`:
- config.available_locales = [:en, :fr]
+```ruby
+config.available_locales = [:en, :fr]
+```
Or
- config.available_locales = [:en, 'de-CH']
+```ruby
+config.available_locales = [:en, 'de-CH']
+```
## Adding a language switch
Add scope around routes:
- scope "(:locale)", locale: /de|en|fr/ do
- root 'kuhsaft/pages#show'
- end
+```ruby
+scope "(:locale)", locale: /de|en|fr/ do
+ root 'kuhsaft/pages#show'
+end
+```
Set the locale in the ApplicationController in a before_action and set default url options:
- before_action :set_locale
+```ruby
+before_action :set_locale
- def set_locale
- if I18n.available_locales.map{|sym| sym.to_s }.include?(params[:locale])
- I18n.locale = params[:locale]
- else
- I18n.locale = I18n.default_locale
- end
- end
+def set_locale
+ if I18n.locale_available? params[:locale]
+ I18n.locale = params[:locale]
+ else
+ I18n.locale = I18n.default_locale
+ end
+end
- def default_url_options(options={})
- { locale: I18n.locale }
- end
+def default_url_options(options = {})
+ { locale: I18n.locale }
+end
+```
Add method to ApplicationHelper which redirects to homepage when current page is not translated.
Make sure to have the homepage translated in every available language.
- def localized_url(url, target_locale)
- page = Kuhsaft::Page.find_by_url("#{I18n.locale}/#{url}")
- I18n.with_locale target_locale do
- translated_url = page.presence && page.url
- if translated_url.present?
- "/#{translated_url}"
- else
- root_path(locale: target_locale)
- end
- end
+```ruby
+def localized_url(url, target_locale)
+ page = Kuhsaft::Page.find_by_url("#{I18n.locale}/#{url}")
+ I18n.with_locale target_locale do
+ translated_url = page.try :url
+ if translated_url.present?
+ "/#{translated_url}"
+ else
+ root_path(locale: target_locale)
end
+ end
+end
- def language_link(url, locale)
- localized_url(params[:url], locale)
- end
+def language_link(url, locale)
+ localized_url(params[:url], locale)
+end
+```
Add language switch to navigation:
- SimpleNavigation::Configuration.run do |navigation|
- I18n.available_locales.each do |locale|
- primary.item locale, locale.to_s.upcase, language_link(params[:url], locale), highlights_on: Proc.new { I18n.locale == locale }
- end
- end
+```ruby
+SimpleNavigation::Configuration.run do |navigation|
+ I18n.available_locales.each do |locale|
+ primary.item locale, locale.to_s.upcase, language_link(params[:url], locale), highlights_on: Proc.new { I18n.locale == locale }
+ end
+end
+```
Make sure to render only pages which are translated and published by using `published` and `translated` scope, so pages
without translation and which are not published will not be displayed in the navigation.
Here is an example of a possible navigation:
- SimpleNavigation::Configuration.run do |navigation|
- navigation.items do |primary|
- primary.dom_class = 'right'
- primary.selected_class = 'active'
- Kuhsaft::Page.find_by(slug_de: 'meta-navigation').children.published.translated.each do |page|
- primary.item page.id, page.title, page.link, class: 'contact icon'
- end
+```ruby
+SimpleNavigation::Configuration.run do |navigation|
+ navigation.items do |primary|
+ primary.dom_class = 'right'
+ primary.selected_class = 'active'
+ Kuhsaft::Page.find_by(slug_de: 'meta-navigation').children.published.translated.each do |page|
+ primary.item page.id, page.title, page.link, class: 'contact icon'
+ end
- primary.item '', 'Sprache', '#', class: 'language icon has-dropdown'do |language|
- I18n.available_locales.each do |locale|
- language.dom_class = 'dropdown'
- language.item locale, language_text(locale), language_link(params[:url], locale), highlights_on: Proc.new { I18n.locale == locale }, class: "icon lang-#{locale}"
- end
- end
+ primary.item '', 'Sprache', '#', class: 'language icon has-dropdown'do |language|
+ I18n.available_locales.each do |locale|
+ language.dom_class = 'dropdown'
+ language.item locale, language_text(locale), language_link(params[:url], locale), highlights_on: Proc.new { I18n.locale == locale }, class: "icon lang-#{locale}"
end
end
+ end
+end
+```
## Styling the content
By default, the text editor lets you add the following tags, for which you should supply some styles in your app:
@@ -322,32 +391,36 @@
Just make sure you are only accessing published pages for your production site, using the `published` scope.
Or if your page is translated, using the `translated` scope and the `published` scope.
### 2 level navigation example using simple-navigation
- SimpleNavigation::Configuration.run do |navigation|
- navigation.items do |primary|
- # build first level
- Kuhsaft::Page.roots.published.translated.each do |page|
- primary.item page.id, page.title, page.link do |sub_item|
- # build second level
- page.children.published.translated.each do |subpage|
- sub_item.item subpage.id, subpage.title, subpage.link
- end
- end
+```ruby
+SimpleNavigation::Configuration.run do |navigation|
+ navigation.items do |primary|
+ # build first level
+ Kuhsaft::Page.roots.published.translated.each do |page|
+ primary.item page.id, page.title, page.link do |sub_item|
+ # build second level
+ page.children.published.translated.each do |subpage|
+ sub_item.item subpage.id, subpage.title, subpage.link
end
end
end
+ end
+end
+```
## Use the `page_title` attribute in your app
Kuhsaft::Pages will provide a `%title` tag containing its `page_title`
(or the required `title`if no title is present). Simply yield for
`:head` in your `application.html` to use it.
- %head
- = yield(:head)
+```haml
+%head
+ = yield(:head)
+```
## Modifying the backend navigation
Simply override the default partial for the main navigation in your app with your own file at `kuhsaft/cms/admin/_main_navigation.html.haml`
@@ -367,14 +440,16 @@
### Use the Kuhsaft ImageBrickImageUploader for your own Brick
Kuhsaft has a module called `ImageUploaderMounting`. This module mounts the ImageBrickImageUploader
and includes a callback method which handles that the image sizes will be updated after save.
- class CustomBrick < Brick
- include Kuhsaft::ImageUploaderMounting
- ...
- end
+```ruby
+class CustomBrick < Brick
+ include Kuhsaft::ImageUploaderMounting
+ ...
+end
+```
If you do not include this module, then the images will not be changed when selecting one of your own image
sizes. See "Configuring the image brick" for more details on creating your own image sizes.
## Integrating search
@@ -383,12 +458,14 @@
LIKE fallback for any other ActiveRecord DB.
Add a call to the `search_page_form` helper in your views. This renders
the default search form. The query will be executed by kuhsaft.
- # e.g. _footer.html.haml
- = search_page_form
+```haml
+# e.g. _footer.html.haml
+= search_page_form
+```
To customize the search and result views you can add your own partials
to your rails app. The following partials are overridable.
app/views/kuhsaft/search
@@ -408,16 +485,16 @@
### Usage
Add the following lines to your `ck-config.js` file. The first line
disables the standard link plugin. The second line enables the adv_link
plugin, which we need for the CMS Page link dialogue in CKEditor.
-```
+```javascript
config.removePlugins = 'link'
config.extraPlugins = 'adv_link'
```
Do not forget to update your `config.assets.precompile` array. Add the
following to your existing array `ckeditor/adv_link/*`.
# LICENSE
-See the file LICENSE.
+See the file [LICENSE](https://github.com/screenconcept/kuhsaft/blob/master/LICENSE).