kuhsaft 0.1.1 → 0.2.legacy
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -2
- data/LICENSE +7 -0
- data/README.md +70 -0
- data/Rakefile +1 -1
- data/app/controllers/kuhsaft/{admin → cms}/admin_controller.rb +2 -2
- data/app/controllers/kuhsaft/{admin → cms}/assets_controller.rb +5 -5
- data/app/controllers/kuhsaft/cms/page_parts_controller.rb +34 -0
- data/app/controllers/kuhsaft/{admin → cms}/pages_controller.rb +12 -11
- data/app/helpers/cms_helper.rb +5 -0
- data/app/helpers/pages_helper.rb +31 -12
- data/app/models/kuhsaft/asset.rb +18 -0
- data/app/models/kuhsaft/localized_page.rb +42 -16
- data/app/models/kuhsaft/page.rb +66 -66
- data/app/models/kuhsaft/page_part/content.rb +23 -2
- data/app/models/kuhsaft/publish_state.rb +2 -6
- data/app/stylesheets/kuhsaft/{admin → cms}/partials/_assets.sass +0 -0
- data/app/stylesheets/kuhsaft/cms/partials/_buttons.sass +13 -0
- data/app/stylesheets/kuhsaft/{admin/ie.sass → cms/partials/_forms.sass} +0 -0
- data/app/stylesheets/kuhsaft/cms/partials/_generic.sass +315 -0
- data/app/stylesheets/kuhsaft/cms/partials/_simple_form.sass +75 -0
- data/app/stylesheets/kuhsaft/{admin → cms}/screen.sass +2 -1
- data/app/uploaders/kuhsaft/asset_uploader.rb +1 -1
- data/app/views/kuhsaft/cms/assets/_form.html.haml +15 -0
- data/app/views/kuhsaft/cms/assets/_list.html.haml +11 -0
- data/app/views/kuhsaft/cms/assets/edit.html.haml +2 -0
- data/app/views/kuhsaft/cms/assets/index.html.haml +3 -0
- data/app/views/kuhsaft/cms/assets/new.html.haml +2 -0
- data/app/views/kuhsaft/cms/page_parts/destroy.js.haml +1 -0
- data/app/{stylesheets/kuhsaft/admin/print.sass → views/kuhsaft/cms/page_parts/edit.html.haml} +0 -0
- data/app/views/kuhsaft/{admin/pages/show.html.haml → cms/page_parts/index.html.haml} +0 -0
- data/app/views/kuhsaft/cms/page_parts/new.html.haml +0 -0
- data/app/views/kuhsaft/cms/page_parts/show.html.haml +0 -0
- data/app/views/kuhsaft/cms/page_parts/update.js.haml +0 -0
- data/app/views/kuhsaft/cms/pages/_branch.html.haml +11 -0
- data/app/views/kuhsaft/cms/pages/_form.html.haml +59 -0
- data/app/views/kuhsaft/cms/pages/edit.html.haml +11 -0
- data/app/views/kuhsaft/cms/pages/index.html.haml +8 -0
- data/app/views/kuhsaft/cms/pages/new.html.haml +6 -0
- data/app/views/kuhsaft/cms/pages/show.html.haml +0 -0
- data/app/views/kuhsaft/page_part/markdowns/_edit_markdown.html.haml +1 -0
- data/app/views/kuhsaft/page_part/markdowns/_show_markdown.html.haml +1 -0
- data/app/views/kuhsaft/pages/show.html.haml +3 -1
- data/app/views/layouts/kuhsaft/admin.html.haml +24 -14
- data/config/locales/kuhsaft.en.yml +28 -6
- data/config/routes.rb +7 -8
- data/kuhsaft.gemspec +3 -2
- data/lib/generators/kuhsaft/install/migrations_generator.rb +2 -0
- data/lib/kuhsaft.rb +3 -0
- data/lib/kuhsaft/engine.rb +1 -0
- data/lib/kuhsaft/orderable.rb +68 -0
- data/lib/kuhsaft/version.rb +1 -1
- data/lib/templates/kuhsaft/install/acts_as_taggable_on_migration.rb +37 -0
- data/lib/templates/kuhsaft/install/add_tags_to_page_part_contents.rb +9 -0
- data/public/images/kuhsaft/add-child-page.png +0 -0
- data/public/images/kuhsaft/delete.png +0 -0
- data/public/images/kuhsaft/header-bg.jpg +0 -0
- data/public/images/kuhsaft/module-nav-tab-bg.png +0 -0
- data/public/images/kuhsaft/page-edit-icon.png +0 -0
- data/public/images/kuhsaft/page-new-icon.png +0 -0
- data/public/images/kuhsaft/page-part-draggable-area.png +0 -0
- data/public/images/kuhsaft/page-tree-breadcrumb-arrow.png +0 -0
- data/public/images/kuhsaft/pages-breadcrumb-icon.png +0 -0
- data/public/images/kuhsaft/tab-bg.png +0 -0
- data/public/images/kuhsaft/toggle-arrow-closed.png +0 -0
- data/public/images/kuhsaft/toggle-arrow-open.png +0 -0
- data/public/images/kuhsaft/wrapper-bg.png +0 -0
- data/public/javascripts/kuhsaft/cms/application.js +31 -0
- data/public/javascripts/kuhsaft/{admin → cms}/jquery-1.4.4.js +0 -0
- data/public/javascripts/kuhsaft/{admin → cms}/jquery-ui-1.8.12.custom.min.js +0 -0
- data/public/javascripts/kuhsaft/{admin → cms}/rails.js +0 -0
- data/spec/controllers/{admin_assets_controller_spec.rb → cms_assets_controller_spec.rb} +5 -5
- data/spec/controllers/{admin_pages_controller_spec.rb → cms_pages_controller_spec.rb} +2 -2
- data/spec/controllers/page_parts_controller_spec.rb +60 -0
- data/spec/dummy/app/controllers/application_controller.rb +1 -0
- data/spec/dummy/config/locales/en.yml +1 -3
- data/spec/dummy/public/javascripts/kuhsaft/cms/application.js +31 -0
- data/spec/dummy/public/javascripts/kuhsaft/cms/jquery-1.4.4.js +7179 -0
- data/spec/dummy/public/javascripts/kuhsaft/cms/jquery-ui-1.8.12.custom.min.js +192 -0
- data/spec/dummy/public/javascripts/kuhsaft/cms/rails.js +157 -0
- data/spec/factories.rb +4 -2
- data/spec/helpers/pages_helper_spec.rb +93 -33
- data/spec/models/asset_spec.rb +18 -2
- data/spec/models/localized_page_spec.rb +225 -124
- data/spec/models/page_part_content_spec.rb +35 -4
- data/spec/models/page_spec.rb +292 -143
- data/spec/models/publish_state_spec.rb +0 -12
- data/spec/requests/cms_pages_spec.rb +27 -0
- data/spec/routing/assets_routing_spec.rb +37 -30
- data/spec/routing/page_part_routing_spec.rb +70 -0
- data/spec/routing/pages_routing_spec.rb +23 -23
- data/spec/support/kuhsaft_spec_helper.rb +3 -0
- metadata +107 -63
- data/README +0 -67
- data/app/stylesheets/kuhsaft/admin/partials/_buttons.sass +0 -216
- data/app/stylesheets/kuhsaft/admin/partials/_generic.sass +0 -48
- data/app/stylesheets/kuhsaft/admin/partials/_pages.sass +0 -46
- data/app/views/kuhsaft/admin/assets/_form.html.haml +0 -3
- data/app/views/kuhsaft/admin/assets/_list.html.haml +0 -11
- data/app/views/kuhsaft/admin/assets/edit.html.haml +0 -1
- data/app/views/kuhsaft/admin/assets/index.html.haml +0 -3
- data/app/views/kuhsaft/admin/assets/new.html.haml +0 -1
- data/app/views/kuhsaft/admin/kuhsaft/page_part/markdowns/_markdown.html.haml +0 -1
- data/app/views/kuhsaft/admin/pages/_branch.html.haml +0 -10
- data/app/views/kuhsaft/admin/pages/_form.html.haml +0 -22
- data/app/views/kuhsaft/admin/pages/edit.html.haml +0 -7
- data/app/views/kuhsaft/admin/pages/index.html.haml +0 -4
- data/app/views/kuhsaft/admin/pages/new.html.haml +0 -3
- data/config/initializers/compass.rb +0 -3
- data/public/images/css3buttons_backgrounds.png +0 -0
- data/public/images/css3buttons_icons.png +0 -0
- data/public/images/drag-handle.png +0 -0
- data/public/javascripts/kuhsaft/admin/application.js +0 -17
- data/spec/dummy/public/images/css3buttons_backgrounds.png +0 -0
- data/spec/dummy/public/images/css3buttons_icons.png +0 -0
- data/spec/dummy/public/images/drag-handle.png +0 -0
data/.rspec
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2011 Screen Concept©
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Kuhsaft. A CMS as simple as it could be
|
2
|
+
|
3
|
+
Yiiihaaaaaa! Howdy, Let's milk the cow!
|
4
|
+
|
5
|
+
## The Who, What and Why?
|
6
|
+
|
7
|
+
Kuhsaft is made by some Rails developers at Screen Concept that got tired of
|
8
|
+
fiddling with unusable content management sytems. We are trying hard to make a
|
9
|
+
minimalistic and developer friendly CMS. Our goal is to provide a system for
|
10
|
+
ourselves and our customers that makes the of-the-shelf website project a
|
11
|
+
hasselfree thing. On one side easy to set up, integrate and customize (good for
|
12
|
+
devs) on the other hand it should be easily usable by anyone.
|
13
|
+
|
14
|
+
# Requirements
|
15
|
+
|
16
|
+
Kuhsaft requires
|
17
|
+
|
18
|
+
* A Rails 3 app to be integrated into
|
19
|
+
* ImageMagick
|
20
|
+
* An ActiveRecord compatible DB
|
21
|
+
|
22
|
+
# Installation
|
23
|
+
|
24
|
+
Add Kuhsaft to your Gemfile:
|
25
|
+
|
26
|
+
gem 'kuhsaft'
|
27
|
+
|
28
|
+
And run
|
29
|
+
|
30
|
+
bundle install
|
31
|
+
|
32
|
+
to get the gem
|
33
|
+
|
34
|
+
Then install the assets and the migrations and run them:
|
35
|
+
|
36
|
+
rails generate kuhsaft:install:assets
|
37
|
+
rails generate kuhsaft:install:migrations
|
38
|
+
rake db:migrate
|
39
|
+
|
40
|
+
If you are upgrading, run those installers again and hopefully we will generate just the migrations you need.
|
41
|
+
|
42
|
+
(NOTE: Steps below should hopefully not be necessary in future versions:)
|
43
|
+
|
44
|
+
Finally, you need to add a before filter to the application controller (for now...)
|
45
|
+
|
46
|
+
ApplicationController < ActionController::Base
|
47
|
+
before_filter :available_locales
|
48
|
+
|
49
|
+
def available_locales
|
50
|
+
Kuhsaft::Page.translation_locales = ['de', 'en', 'fr']
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
If you want to use devise for protecting the admin parts, do this in an initializer:
|
55
|
+
|
56
|
+
Kuhsaft::Cms::PagesController.class_eval do
|
57
|
+
before_filter :authenticate_user!
|
58
|
+
end
|
59
|
+
|
60
|
+
# Usage
|
61
|
+
|
62
|
+
## Building a navigation
|
63
|
+
|
64
|
+
Create a toplevel page and set the page type to "navigation". You can now get the child pages by using the navigation helper with the slug of that page:
|
65
|
+
|
66
|
+
navigation_for(:slug => 'main-navigation') { |pages| ... }
|
67
|
+
|
68
|
+
# LICENSE
|
69
|
+
|
70
|
+
See the file LICENSE.
|
data/Rakefile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Kuhsaft
|
2
|
-
module
|
2
|
+
module Cms
|
3
3
|
class AssetsController < AdminController
|
4
4
|
def index
|
5
5
|
@assets = Kuhsaft::Asset.by_date
|
@@ -14,7 +14,7 @@ module Kuhsaft
|
|
14
14
|
def create
|
15
15
|
@asset = Kuhsaft::Asset.create params[:kuhsaft_asset]
|
16
16
|
@asset.save
|
17
|
-
respond_with @asset, :location =>
|
17
|
+
respond_with @asset, :location => cms_assets_path
|
18
18
|
end
|
19
19
|
|
20
20
|
def edit
|
@@ -25,14 +25,14 @@ module Kuhsaft
|
|
25
25
|
def update
|
26
26
|
@asset = Kuhsaft::Asset.find(params[:id])
|
27
27
|
@asset.update_attributes(params[:kuhsaft_asset])
|
28
|
-
respond_with @asset, :location =>
|
28
|
+
respond_with @asset, :location => cms_assets_path
|
29
29
|
end
|
30
30
|
|
31
31
|
def destroy
|
32
32
|
@asset = Kuhsaft::Asset.find(params[:id])
|
33
33
|
@asset.destroy
|
34
|
-
redirect_to
|
34
|
+
redirect_to cms_assets_path
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
|
-
end
|
38
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Kuhsaft
|
2
|
+
module Cms
|
3
|
+
class PagePartsController < AdminController
|
4
|
+
|
5
|
+
def index
|
6
|
+
end
|
7
|
+
|
8
|
+
def show
|
9
|
+
end
|
10
|
+
|
11
|
+
def new
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
end
|
16
|
+
|
17
|
+
def edit
|
18
|
+
end
|
19
|
+
|
20
|
+
def update
|
21
|
+
if @page_part = Kuhsaft::PagePart::Content.find(params[:id])
|
22
|
+
@page_part.reposition params[:reposition] if params[:reposition].present? || params.key?(:reposition)
|
23
|
+
end
|
24
|
+
render 'update'
|
25
|
+
end
|
26
|
+
|
27
|
+
def destroy
|
28
|
+
@page_part = Kuhsaft::PagePart::Content.find(params[:id])
|
29
|
+
@page_part.destroy
|
30
|
+
render 'destroy'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module Kuhsaft
|
2
|
-
module
|
2
|
+
module Cms
|
3
3
|
class PagesController < AdminController
|
4
|
-
helper :all
|
5
|
-
|
6
4
|
def index
|
7
5
|
@pages = Kuhsaft::Page.root_pages
|
8
6
|
respond_with @pages
|
@@ -16,6 +14,7 @@ module Kuhsaft
|
|
16
14
|
def new
|
17
15
|
@page = Kuhsaft::Page.new
|
18
16
|
@localized_page = @page.localized_pages.find_or_initialize_by_locale(params[:locale])
|
17
|
+
@localized_page.published ||= Kuhsaft::PublishState::UNPUBLISHED
|
19
18
|
respond_with @page
|
20
19
|
end
|
21
20
|
|
@@ -26,32 +25,34 @@ module Kuhsaft
|
|
26
25
|
parent.childs << @page
|
27
26
|
parent.save
|
28
27
|
end
|
29
|
-
respond_with @page, :location =>
|
28
|
+
respond_with @page, :location => edit_cms_page_path(@page)
|
30
29
|
end
|
31
30
|
|
32
31
|
def edit
|
33
32
|
@page = Kuhsaft::Page.find(params[:id])
|
34
33
|
@localized_page = @page.localized_pages.find_or_initialize_by_locale(params[:locale])
|
35
|
-
|
36
|
-
if params[:add_page_part].present?
|
37
|
-
@localized_page.page_parts.build :type => params[:kuhsaft_page][:page_part_type].constantize
|
38
|
-
end
|
39
|
-
|
34
|
+
@localized_page.published ||= Kuhsaft::PublishState::UNPUBLISHED
|
40
35
|
respond_with @page
|
41
36
|
end
|
42
37
|
|
43
38
|
def update
|
44
39
|
@page = Kuhsaft::Page.find(params[:id])
|
40
|
+
|
45
41
|
@page.update_attributes(params[:kuhsaft_page]) if params[:kuhsaft_page].present?
|
46
42
|
# TODO: refactor 'reposition' as a page attribute, so it can be set through update_attributes
|
47
43
|
@page.reposition params[:reposition] if params[:reposition].present? || params.key?(:reposition)
|
48
|
-
|
44
|
+
|
45
|
+
if params[:add_page_part].present?
|
46
|
+
@page.translation.page_parts << params[:kuhsaft_page][:page_part_type].constantize.new
|
47
|
+
end
|
48
|
+
|
49
|
+
respond_with @page, :location => edit_cms_page_path(@page)
|
49
50
|
end
|
50
51
|
|
51
52
|
def destroy
|
52
53
|
@page = Kuhsaft::Page.find(params[:id])
|
53
54
|
@page.destroy
|
54
|
-
redirect_to
|
55
|
+
redirect_to cms_pages_path
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
data/app/helpers/pages_helper.rb
CHANGED
@@ -3,7 +3,8 @@ module PagesHelper
|
|
3
3
|
lang = Kuhsaft::Page.current_translation_locale
|
4
4
|
page = Kuhsaft::Page.find(@page.id).localized_pages.where('locale = ?', lang).first.page
|
5
5
|
page.translation
|
6
|
-
|
6
|
+
yield page if block_given?
|
7
|
+
page
|
7
8
|
rescue
|
8
9
|
end
|
9
10
|
|
@@ -20,26 +21,44 @@ module PagesHelper
|
|
20
21
|
def asset_for id
|
21
22
|
Kuhsaft::Asset.find(id)
|
22
23
|
end
|
24
|
+
|
25
|
+
def render_markdown text
|
26
|
+
RDiscount.new(text).to_html if text.present?
|
27
|
+
end
|
23
28
|
|
24
|
-
def navigation_for
|
25
|
-
if
|
26
|
-
Kuhsaft::
|
27
|
-
|
28
|
-
Kuhsaft::Page.where('parent_id = ?', id)
|
29
|
+
def navigation_for options
|
30
|
+
if options.is_a?(Hash) && slug = options.delete(:slug)
|
31
|
+
pages = Kuhsaft::LocalizedPage.navigation(slug).first.page.childs.current_locale.published rescue []
|
32
|
+
elsif (options.is_a?(Fixnum) && id = options) || id = options.delete(:id)
|
33
|
+
pages = Kuhsaft::Page.published.where('parent_id = ?', id)
|
34
|
+
elsif options.nil?
|
35
|
+
pages = Kuhsaft::Page.published.root_pages
|
29
36
|
end
|
37
|
+
yield pages if block_given? && pages.length > 0
|
38
|
+
pages
|
30
39
|
end
|
31
|
-
|
40
|
+
|
41
|
+
def homepage
|
42
|
+
Kuhsaft::Page.root_pages.first
|
43
|
+
end
|
44
|
+
|
32
45
|
def page_for_level num
|
33
|
-
|
34
|
-
|
46
|
+
input = controller.current_url if controller.respond_to? :current_url
|
47
|
+
input ||= params[:url].presence || ''
|
48
|
+
url = input.split('/').take(num + 1).join('/') unless input.blank?
|
49
|
+
page = Kuhsaft::Page.find_by_url(url)
|
50
|
+
yield page if block_given?
|
51
|
+
page
|
52
|
+
rescue
|
35
53
|
end
|
36
54
|
|
37
55
|
def active_page_class page
|
38
|
-
|
39
|
-
url.
|
56
|
+
input = controller.current_url if controller.respond_to? :current_url
|
57
|
+
input ||= params[:url].presence || ''
|
58
|
+
input.include?(page.url.to_s) ? :active : nil
|
40
59
|
end
|
41
60
|
|
42
61
|
def current_page_class page
|
43
|
-
|
62
|
+
:current if active_page_class(page) == :active
|
44
63
|
end
|
45
64
|
end
|
data/app/models/kuhsaft/asset.rb
CHANGED
@@ -1,4 +1,22 @@
|
|
1
1
|
class Kuhsaft::Asset < ActiveRecord::Base
|
2
2
|
scope :by_date, order('updated_at DESC')
|
3
3
|
mount_uploader :file, Kuhsaft::AssetUploader
|
4
|
+
|
5
|
+
def file_type
|
6
|
+
if file.url.present? && ext = file.url.split('.').last
|
7
|
+
ext.to_sym unless ext.blank?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def name
|
12
|
+
File.basename(file.path) if file.present? && file.path.present?
|
13
|
+
end
|
14
|
+
|
15
|
+
def path
|
16
|
+
file.url
|
17
|
+
end
|
18
|
+
|
19
|
+
def path=val
|
20
|
+
# do nothing
|
21
|
+
end
|
4
22
|
end
|
@@ -1,43 +1,73 @@
|
|
1
1
|
class Kuhsaft::LocalizedPage < ActiveRecord::Base
|
2
2
|
belongs_to :page
|
3
3
|
has_many :page_parts, :class_name => 'Kuhsaft::PagePart::Content', :autosave => true
|
4
|
-
|
5
|
-
scope :
|
4
|
+
|
5
|
+
scope :current_locale, lambda{ where('locale = ?', Kuhsaft::Page.current_translation_locale) }
|
6
6
|
|
7
|
+
scope :published, lambda{
|
8
|
+
where('published = ? OR published_at < ? AND published = ?',
|
9
|
+
Kuhsaft::PublishState::PUBLISHED,
|
10
|
+
DateTime.now,
|
11
|
+
Kuhsaft::PublishState::PUBLISHED_AT
|
12
|
+
)
|
13
|
+
}
|
14
|
+
|
15
|
+
scope :search, lambda{ |term| current_locale.published.where('`fulltext` LIKE ?', "%#{term}%") }
|
16
|
+
scope :navigation, lambda{ |slug|
|
17
|
+
current_locale.published.where('slug = ?', slug).where('page_type = ?', Kuhsaft::PageType::NAVIGATION)
|
18
|
+
}
|
19
|
+
|
7
20
|
before_validation :create_slug, :create_url, :collect_fulltext
|
8
21
|
delegate :childs, :to => :page
|
9
|
-
|
22
|
+
|
10
23
|
validates :title, :presence => true
|
11
24
|
validates :locale, :presence => true
|
12
|
-
validates :slug, :presence => true
|
13
|
-
|
25
|
+
validates :slug, :presence => true
|
26
|
+
validates :url, :uniqueness => true, :unless => :navigation?
|
27
|
+
|
14
28
|
accepts_nested_attributes_for :page_parts, :allow_destroy => true
|
15
|
-
|
29
|
+
|
16
30
|
def published?
|
17
|
-
|
31
|
+
return true if published == Kuhsaft::PublishState::PUBLISHED
|
32
|
+
return false if published == Kuhsaft::PublishState::UNPUBLISHED
|
33
|
+
if published == Kuhsaft::PublishState::PUBLISHED_AT
|
34
|
+
return false if published_at.blank?
|
35
|
+
published_at < DateTime.now
|
36
|
+
else
|
37
|
+
false
|
38
|
+
end
|
18
39
|
end
|
19
|
-
|
40
|
+
|
20
41
|
def locale
|
21
42
|
read_attribute(:locale).to_sym unless read_attribute(:locale).nil?
|
22
43
|
end
|
44
|
+
|
45
|
+
def redirect?
|
46
|
+
page_type == Kuhsaft::PageType::REDIRECT
|
47
|
+
end
|
48
|
+
|
49
|
+
def navigation?
|
50
|
+
page_type == Kuhsaft::PageType::NAVIGATION
|
51
|
+
end
|
23
52
|
|
24
53
|
def create_url
|
25
|
-
return if
|
54
|
+
return if redirect?
|
55
|
+
|
26
56
|
complete_slug = ''
|
27
57
|
if page.present? && page.parent.present?
|
28
58
|
complete_slug << page.parent.url.to_s
|
29
59
|
else
|
30
60
|
complete_slug = "#{self.locale}"
|
31
61
|
end
|
32
|
-
complete_slug << "/#{self.slug}" unless
|
62
|
+
complete_slug << "/#{self.slug}" unless navigation?
|
33
63
|
self.url = complete_slug
|
34
64
|
end
|
35
|
-
|
65
|
+
|
36
66
|
def create_slug
|
37
67
|
has_slug = title.present? && slug.blank?
|
38
68
|
write_attribute(:slug, read_attribute(:title).downcase.parameterize) if has_slug
|
39
69
|
end
|
40
|
-
|
70
|
+
|
41
71
|
def collect_fulltext
|
42
72
|
self.fulltext = page_parts.inject('') do |text, page_part|
|
43
73
|
page_part.class.searchable_attributes.each do |attr|
|
@@ -48,8 +78,4 @@ class Kuhsaft::LocalizedPage < ActiveRecord::Base
|
|
48
78
|
end
|
49
79
|
self.fulltext << [title.to_s, keywords.to_s, description.to_s].join(' ')
|
50
80
|
end
|
51
|
-
|
52
|
-
def allow_empty_slug
|
53
|
-
self.page_type == Kuhsaft::PageType::NAVIGATION
|
54
|
-
end
|
55
81
|
end
|
data/app/models/kuhsaft/page.rb
CHANGED
@@ -1,27 +1,60 @@
|
|
1
1
|
class Kuhsaft::Page < ActiveRecord::Base
|
2
|
+
include Kuhsaft::Orderable
|
3
|
+
|
2
4
|
has_many :localized_pages, :dependent => :destroy
|
3
5
|
has_many :childs, :class_name => 'Kuhsaft::Page', :foreign_key => :parent_id
|
4
6
|
belongs_to :parent, :class_name => 'Kuhsaft::Page', :foreign_key => :parent_id
|
5
7
|
|
8
|
+
scope :published, lambda {
|
9
|
+
includes(:localized_pages).where('localized_pages.published = ? OR localized_pages.published_at < ? AND localized_pages.published = ?',
|
10
|
+
Kuhsaft::PublishState::PUBLISHED,
|
11
|
+
DateTime.now,
|
12
|
+
Kuhsaft::PublishState::PUBLISHED_AT
|
13
|
+
)
|
14
|
+
}
|
15
|
+
|
16
|
+
scope :current_locale, lambda {
|
17
|
+
includes(:localized_pages).where('localized_pages.locale = ?', Kuhsaft::Page.current_translation_locale)
|
18
|
+
}
|
19
|
+
|
6
20
|
scope :root_pages, where('parent_id IS NULL')
|
7
21
|
default_scope order('position ASC')
|
8
22
|
|
9
|
-
delegate :title, :slug, :published, :
|
23
|
+
delegate :title, :slug, :published, :published?, :page_type, :keywords, :description,
|
24
|
+
:locale, :body, :url, :fulltext, :page_parts, :redirect?, :navigation?,
|
10
25
|
:to => :translation, :allow_nil => true
|
11
|
-
|
26
|
+
|
12
27
|
accepts_nested_attributes_for :localized_pages
|
13
|
-
|
28
|
+
|
14
29
|
after_save :save_translation
|
15
|
-
|
16
|
-
|
30
|
+
|
17
31
|
#
|
18
32
|
# Stores the selected type of page_part when created through the form
|
19
33
|
#
|
20
34
|
attr_accessor :page_part_type
|
21
|
-
|
35
|
+
|
22
36
|
def root?
|
23
37
|
parent.nil?
|
24
38
|
end
|
39
|
+
|
40
|
+
def without_self
|
41
|
+
Kuhsaft::Page.where('id != ?', self.id)
|
42
|
+
end
|
43
|
+
|
44
|
+
def parent_pages
|
45
|
+
parent_pages_list = []
|
46
|
+
parent = self
|
47
|
+
|
48
|
+
while parent
|
49
|
+
parent_pages_list << parent unless parent.translation.blank? || parent.translation.navigation?
|
50
|
+
parent = parent.parent
|
51
|
+
end
|
52
|
+
parent_pages_list.reverse
|
53
|
+
end
|
54
|
+
|
55
|
+
def siblings
|
56
|
+
(parent.present? ? parent.childs : Kuhsaft::Page.root_pages).where('id != ?', id)
|
57
|
+
end
|
25
58
|
|
26
59
|
def translation lang = nil
|
27
60
|
lang ||= Kuhsaft::Page.current_translation_locale
|
@@ -34,66 +67,15 @@ class Kuhsaft::Page < ActiveRecord::Base
|
|
34
67
|
@translation.save
|
35
68
|
end
|
36
69
|
childs.each do |child|
|
37
|
-
child.translation.save if child.translation.persisted?
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def increment_position
|
42
|
-
update_attribute :position, position + 1
|
43
|
-
end
|
44
|
-
|
45
|
-
def decrement_position
|
46
|
-
update_attribute :position, position - 1
|
47
|
-
end
|
48
|
-
|
49
|
-
def siblings
|
50
|
-
(parent.present? ? parent.childs : Kuhsaft::Page.root_pages).where('id != ?', id)
|
51
|
-
end
|
52
|
-
|
53
|
-
def preceding_sibling
|
54
|
-
siblings.where('position = ?', position - 1).first
|
55
|
-
end
|
56
|
-
|
57
|
-
def succeeding_sibling
|
58
|
-
siblings.where('position = ?', position + 1).first
|
59
|
-
end
|
60
|
-
|
61
|
-
def preceding_siblings
|
62
|
-
siblings.where('position <= ?', position).where('id != ?', id)
|
63
|
-
end
|
64
|
-
|
65
|
-
def succeeding_siblings
|
66
|
-
siblings.where('position >= ?', position).where('id != ?', id)
|
67
|
-
end
|
68
|
-
|
69
|
-
def position_to_top
|
70
|
-
update_attribute :position, 1
|
71
|
-
recount_siblings_position_from 1
|
72
|
-
end
|
73
|
-
|
74
|
-
def recount_siblings_position_from position
|
75
|
-
counter = position
|
76
|
-
succeeding_siblings.each { |s| counter += 1; s.update_attribute(:position, counter) }
|
77
|
-
end
|
78
|
-
|
79
|
-
def reposition before_id
|
80
|
-
if before_id.blank?
|
81
|
-
position_to_top
|
82
|
-
else
|
83
|
-
update_attribute :position, self.class.position_of(before_id) + 1
|
84
|
-
recount_siblings_position_from position
|
70
|
+
child.translation.save if child.translation.present? && child.translation.persisted?
|
85
71
|
end
|
86
72
|
end
|
87
73
|
|
88
|
-
def set_position
|
89
|
-
update_attribute(:position, siblings.count + 1)
|
90
|
-
end
|
91
|
-
|
92
74
|
def link
|
93
|
-
if translation.page_parts.count == 0 && childs.count > 0
|
75
|
+
if translation.present? && translation.page_parts.count == 0 && childs.count > 0
|
94
76
|
childs.first.link
|
95
77
|
else
|
96
|
-
if translation.
|
78
|
+
if translation.present? && translation.redirect?
|
97
79
|
url
|
98
80
|
else
|
99
81
|
"/#{url}"
|
@@ -101,14 +83,22 @@ class Kuhsaft::Page < ActiveRecord::Base
|
|
101
83
|
end
|
102
84
|
end
|
103
85
|
|
86
|
+
def nesting_name
|
87
|
+
num_dashes = parent_pages.size - 1
|
88
|
+
num_dashes = 0 if num_dashes < 0
|
89
|
+
"#{'-' * num_dashes} #{self.title}".strip
|
90
|
+
end
|
91
|
+
|
104
92
|
class << self
|
105
|
-
def position_of id
|
106
|
-
Kuhsaft::Page.find(id).position rescue 1
|
107
|
-
end
|
108
|
-
|
109
93
|
def find_by_url url
|
110
|
-
translation = Kuhsaft::LocalizedPage.where('url = ?', url)
|
111
|
-
translation.present? && translation.first.present?
|
94
|
+
translation = Kuhsaft::LocalizedPage.published.where('url = ?', url)
|
95
|
+
if translation.present? && translation.first.present?
|
96
|
+
page = translation.first.page
|
97
|
+
page.translation(translation.first.locale)
|
98
|
+
page
|
99
|
+
else
|
100
|
+
nil
|
101
|
+
end
|
112
102
|
end
|
113
103
|
|
114
104
|
def translation_locales
|
@@ -127,5 +117,15 @@ class Kuhsaft::Page < ActiveRecord::Base
|
|
127
117
|
@translation_locale = locale.to_sym
|
128
118
|
I18n.locale = @translation_locale if I18n.available_locales.include?(@translation_locale)
|
129
119
|
end
|
120
|
+
|
121
|
+
def flat_tree pages= nil
|
122
|
+
pages ||= Kuhsaft::Page.root_pages
|
123
|
+
list ||= []
|
124
|
+
pages.each do |page|
|
125
|
+
list << page
|
126
|
+
flat_tree(page.childs).each { |p| list << p } if page.childs.count > 0
|
127
|
+
end
|
128
|
+
list
|
129
|
+
end
|
130
130
|
end
|
131
131
|
end
|