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
@@ -30,7 +30,7 @@ class Kuhsaft::AssetUploader < CarrierWave::Uploader::Base
|
|
30
30
|
|
31
31
|
# Create different versions of your uploaded files:
|
32
32
|
version :thumb do
|
33
|
-
process :resize_to_fill => [
|
33
|
+
process :resize_to_fill => [100, 100]
|
34
34
|
end
|
35
35
|
|
36
36
|
# Add a white list of extensions which are allowed to be uploaded.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
= simple_form_for @asset, :url => url, :html => { :multipart => true } do |f|
|
2
|
+
.lightened-box
|
3
|
+
%h1= page_title
|
4
|
+
= f.input :file, :as => :file
|
5
|
+
= f.input :path, :as => :string, :input_html => { :readonly => true }
|
6
|
+
.clear
|
7
|
+
- if @asset.file.url.present?
|
8
|
+
.darkened-box
|
9
|
+
- if [:jpg, :jpeg, :png].include?(@asset.file_type)
|
10
|
+
.fixed-width-image
|
11
|
+
= link_to image_tag(@asset.file.url), @asset.file.url
|
12
|
+
- else
|
13
|
+
= link_to @asset.name, @asset.file.url
|
14
|
+
.lightened-box
|
15
|
+
= f.button :submit
|
@@ -0,0 +1,11 @@
|
|
1
|
+
- @assets.each do |asset|
|
2
|
+
.asset-pic
|
3
|
+
.thumb
|
4
|
+
- if [:png, :jpg, :jpeg].include? asset.file_type
|
5
|
+
= link_to image_tag(asset.file.thumb.url), edit_cms_asset_path(asset)
|
6
|
+
- else
|
7
|
+
= link_to asset.name, edit_cms_asset_path(asset)
|
8
|
+
.copy
|
9
|
+
%input.string{ :type => :text, :value => asset.file.url }
|
10
|
+
= link_to t('.delete'), cms_asset_path(asset), :confirm => t('.confirm'), :method => :delete
|
11
|
+
.clear
|
@@ -0,0 +1 @@
|
|
1
|
+
$(".page-part[data-id='#{@page_part.id}']").css({border: '2px solid red'}).fadeOut(1200, function(){ $(this).remove() })
|
data/app/{stylesheets/kuhsaft/admin/print.sass → views/kuhsaft/cms/page_parts/edit.html.haml}
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,11 @@
|
|
1
|
+
- unless pages.blank?
|
2
|
+
- pages.each do |page|
|
3
|
+
%li.can-drag{ :'data-id' => page.id, :'data-put-url' => cms_page_path(page) }
|
4
|
+
.branch
|
5
|
+
= link_to page.title.presence || t('.not_translated'), edit_cms_page_path(page), :class => ('to-translate' if page.title.blank?)
|
6
|
+
= link_to t('.add'), new_cms_page_path(:parent_id => page.id), :class => 'icon add-child-page'
|
7
|
+
= link_to t('.delete'), cms_page_path(page), :confirm => t('.confirm'), :method => :delete, :class => 'icon delete' if page.childs.empty?
|
8
|
+
.clear
|
9
|
+
- unless page.childs.empty?
|
10
|
+
%ul.sortable
|
11
|
+
= render :partial => 'branch', :locals => { :pages => page.childs }
|
@@ -0,0 +1,59 @@
|
|
1
|
+
= simple_form_for @page, :url => url do |page|
|
2
|
+
= page.fields_for :localized_pages, @localized_page do |localized|
|
3
|
+
|
4
|
+
.lightened-box
|
5
|
+
%h1{ :class => "#{@page.persisted? ? 'edit' : 'new'}-page" }= page_title
|
6
|
+
= localized.input :locale, :as => :hidden
|
7
|
+
= localized.input :title, :required => false
|
8
|
+
= localized.input :slug, :required => false, :input_html => { :class => :dimmed }
|
9
|
+
.clear
|
10
|
+
|
11
|
+
.page-part-list
|
12
|
+
- @localized_page.page_parts.each do |page_part_object|
|
13
|
+
.colored-box.draggable-box.page-part.can-drag{ :'data-id' => page_part_object.id, :'data-put-url' => cms_page_page_part_path(page_part_object, :page_id => @page) }
|
14
|
+
= localized.fields_for :page_parts, page_part_object do |page_part|
|
15
|
+
.drag-handler
|
16
|
+
.destroy-handler
|
17
|
+
= link_to t('.destroy_page_part'), cms_page_page_part_path(page_part.object, :page_id => @page), :confirm => t('.confirm'), :method => :delete, :remote => true
|
18
|
+
- unless page_part.object.persisted?
|
19
|
+
= page_part.input :type, :as => :hidden, :input_html => { :value => page_part.object.class.to_s }
|
20
|
+
|
21
|
+
= render :partial => page_part.object.edit_partial_path, :locals => { :input_form => page_part }
|
22
|
+
.page-part-helpers
|
23
|
+
= page_part.input :tag_list, :as => :string, :wrapper_html => { :class => 'page-part-tags' }, :input_html => { :placeholder => t('.separate_by_comma') }
|
24
|
+
.clear
|
25
|
+
- if localized.object.persisted? && !@page.redirect?
|
26
|
+
.lightened-box.add-page-part
|
27
|
+
%label.string{ :for => :page_part_type }= t('.add_element')
|
28
|
+
= page.collection_select :page_part_type, Kuhsaft::PagePart::Content.page_part_types, :to_s, :to_name
|
29
|
+
= page.button :submit, :name => :add_page_part, :value => t('.add_page_part')
|
30
|
+
.clear
|
31
|
+
|
32
|
+
.darkened-box
|
33
|
+
%h3.toggle.closed= t('.metainformation')
|
34
|
+
.collapsable.hidden
|
35
|
+
= page.input :parent_id, :collection => Kuhsaft::Page.flat_tree(), :label_method => :nesting_name, :selected => params[:parent_id].presence || page.object.parent_id.presence, :prompt => 'None', :label_html => { :class => :string }
|
36
|
+
= localized.input :page_type, :collection => Kuhsaft::PageType.all, :prompt => false, :label_html => { :class => :string }
|
37
|
+
= localized.input :url, :as => :string if @page.redirect?
|
38
|
+
- unless localized.object.page_type == Kuhsaft::PageType::REDIRECT
|
39
|
+
= localized.input :keywords
|
40
|
+
= localized.input :description, :input_html => { :class => :small }, :label_html => { :class => :string }
|
41
|
+
.lightened-box.publish-information
|
42
|
+
.column.grid-3
|
43
|
+
= localized.radio_button :published, Kuhsaft::PublishState::UNPUBLISHED
|
44
|
+
= localized.label :published, t('.unpublished'), :class => :radio, :for => :kuhsaft_page_localized_pages_attributes_0_published_0
|
45
|
+
.column.grid-3
|
46
|
+
= localized.radio_button :published, Kuhsaft::PublishState::PUBLISHED
|
47
|
+
= localized.label :published, t('.published'), :class => :radio, :for => :kuhsaft_page_localized_pages_attributes_0_published_1
|
48
|
+
.column.grid-5
|
49
|
+
= localized.radio_button :published, Kuhsaft::PublishState::PUBLISHED_AT
|
50
|
+
= localized.label :published, t('.published_at'), :class => :radio, :for => :kuhsaft_page_localized_pages_attributes_0_published_2
|
51
|
+
= localized.text_field :published_at, :class => 'small string', :placeholder => 'dd.mm.yyyy HH:MM'
|
52
|
+
.column.grid-2
|
53
|
+
= page.button :submit
|
54
|
+
.clear
|
55
|
+
|
56
|
+
:javascript
|
57
|
+
$(".toggle").click(function(){
|
58
|
+
$(this).toggleClass("closed").next(".collapsable").toggleClass("hidden")
|
59
|
+
})
|
@@ -0,0 +1,11 @@
|
|
1
|
+
- content_for :cms_language_tabs do
|
2
|
+
- Kuhsaft::Page.translation_locales.each do |locale|
|
3
|
+
%li{ :class => (:current if params[:locale] == locale.to_s) }= link_to locale.to_s, edit_cms_page_path(:locale => locale)
|
4
|
+
|
5
|
+
.page-tree-breadcrumb
|
6
|
+
= link_to(t('.pages'), cms_pages_path)
|
7
|
+
- @page.parent_pages.each do |parent_page|
|
8
|
+
= link_to(parent_page.title, edit_cms_page_path(parent_page))
|
9
|
+
|
10
|
+
.box-container
|
11
|
+
= render :partial => 'form', :locals => { :url => cms_page_path(@page), :page_title => t('.edit_html', :title => @page.title ) }
|
@@ -0,0 +1,8 @@
|
|
1
|
+
- content_for :cms_language_tabs do
|
2
|
+
- Kuhsaft::Page.translation_locales.each do |locale|
|
3
|
+
%li{ :class => (:current if params[:locale] == locale.to_s) }= link_to locale.to_s, cms_pages_path(:locale => locale)
|
4
|
+
|
5
|
+
- content_for :admin_toolbar do
|
6
|
+
= link_to t('.create'), new_cms_page_path, :class => 'button'
|
7
|
+
%ul.pages-root.sortable
|
8
|
+
= render :partial => 'branch', :locals => { :pages => @pages }
|
@@ -0,0 +1,6 @@
|
|
1
|
+
- content_for :cms_language_tabs do
|
2
|
+
- Kuhsaft::Page.translation_locales.each do |locale|
|
3
|
+
%li{ :class => (:current if params[:locale] == locale.to_s) }= link_to locale.to_s, new_cms_page_path(:locale => locale)
|
4
|
+
|
5
|
+
.box-container
|
6
|
+
= render :partial => 'form', :locals => { :url => cms_pages_path, :page_title => t('.new') }
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
= input_form.input :text, :as => :text, :input_html => { :class => :large }
|
@@ -0,0 +1 @@
|
|
1
|
+
!= render_markdown(page_part.text)
|
@@ -1,23 +1,33 @@
|
|
1
1
|
!!!
|
2
2
|
%html
|
3
3
|
%head
|
4
|
-
= stylesheet_link_tag 'kuhsaft/
|
5
|
-
= stylesheet_link_tag 'kuhsaft/admin/print.css', :media => 'print'
|
4
|
+
= stylesheet_link_tag 'kuhsaft/cms/screen.css', :media => 'screen, projection'
|
6
5
|
= stylesheet_link_tag 'kuhsaft/ui-lightness/jquery-ui-1.8.12.custom.css', :media => 'screen, projection'
|
7
|
-
/[if IE]
|
8
|
-
= stylesheet_link_tag 'kuhsaft/admin/ie.css', :media => 'screen, projection'
|
9
6
|
= csrf_meta_tag
|
10
|
-
= javascript_include_tag 'kuhsaft/
|
11
|
-
= javascript_include_tag 'kuhsaft/
|
12
|
-
= javascript_include_tag 'kuhsaft/
|
13
|
-
= javascript_include_tag 'kuhsaft/
|
7
|
+
= javascript_include_tag 'kuhsaft/cms/jquery-1.4.4.js'
|
8
|
+
= javascript_include_tag 'kuhsaft/cms/jquery-ui-1.8.12.custom.min.js'
|
9
|
+
= javascript_include_tag 'kuhsaft/cms/rails.js'
|
10
|
+
= javascript_include_tag 'kuhsaft/cms/application.js'
|
14
11
|
%body{ :class => "#{controller_name}" }
|
15
12
|
#kuhsaft-wrapper
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
.cms-header
|
14
|
+
.container
|
15
|
+
- if respond_to?(:destroy_user_session_path)
|
16
|
+
= link_to(t('.logout'), destroy_user_session_path, :class => :logout)
|
17
|
+
.cms-content-container
|
18
|
+
%ul.cms-module-nav
|
19
|
+
= admin_tab(t('.pages_nav'), cms_pages_path)
|
20
|
+
= admin_tab(t('.assets_nav'), cms_assets_path)
|
21
|
+
= render :partial => 'cms/admin_navigation' rescue ''
|
21
22
|
.clear
|
22
|
-
|
23
|
+
%ul.language-tabs
|
24
|
+
= yield :cms_language_tabs
|
25
|
+
.clear
|
26
|
+
.toolbar
|
27
|
+
= yield :admin_toolbar
|
28
|
+
.clear
|
29
|
+
.cms-content
|
30
|
+
= yield :before_admin_content
|
31
|
+
= yield
|
32
|
+
= yield :after_admin_content
|
23
33
|
= yield :scripts
|
@@ -5,18 +5,40 @@ en:
|
|
5
5
|
pages_nav: 'Pages'
|
6
6
|
assets_nav: 'Assets'
|
7
7
|
kuhsaft:
|
8
|
-
|
8
|
+
page_part:
|
9
|
+
markdown: 'Formatted Text'
|
10
|
+
cms:
|
9
11
|
pages:
|
10
12
|
index:
|
11
|
-
|
13
|
+
create: 'Create new page'
|
14
|
+
new:
|
15
|
+
new: 'Creating new page'
|
16
|
+
edit:
|
17
|
+
edit_html: 'Editing page: <span>%{title}</span>'
|
18
|
+
branch:
|
19
|
+
add: 'Add page'
|
12
20
|
create: 'Create new page'
|
13
21
|
delete: 'Remove page'
|
14
22
|
confirm: 'Are you sure?'
|
15
|
-
|
16
|
-
|
23
|
+
not_translated: 'Not yet translated'
|
24
|
+
form:
|
25
|
+
add_page_part: 'Add element'
|
26
|
+
unpublished: "Save page offline"
|
27
|
+
published: "Publish page"
|
28
|
+
published_at: "Go online on"
|
29
|
+
confirm: 'Are you sure?'
|
30
|
+
destroy_page_part: 'Delete'
|
31
|
+
separate_by_comma: 'Separate tags by comma'
|
17
32
|
current_translation_locale: 'Current translation: %{translation_locale}'
|
18
33
|
assets:
|
19
34
|
index:
|
20
35
|
create: 'Create new asset'
|
21
|
-
|
22
|
-
confirm: 'Are you sure?'
|
36
|
+
list:
|
37
|
+
confirm: 'Are you sure?'
|
38
|
+
delete: 'Delete asset'
|
39
|
+
simple_form:
|
40
|
+
labels:
|
41
|
+
title: 'Page title'
|
42
|
+
slug: 'URL segment'
|
43
|
+
page_part_type: 'Add element'
|
44
|
+
_destroy: 'Delete this element'
|
data/config/routes.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
scope :module => :kuhsaft do
|
3
3
|
scope ':locale' do
|
4
|
-
namespace :
|
5
|
-
resources :pages
|
4
|
+
namespace :cms do
|
5
|
+
resources :pages do
|
6
|
+
resources :page_parts
|
7
|
+
end
|
8
|
+
resources :assets
|
6
9
|
end
|
7
10
|
end
|
8
|
-
|
9
|
-
namespace :admin do
|
10
|
-
resources :assets
|
11
|
-
end
|
12
11
|
end
|
13
|
-
match '/*url' => 'kuhsaft/pages#show'
|
14
|
-
end
|
12
|
+
match '/:locale/*url' => 'kuhsaft/pages#show', :constraints => { :locale => /\w{2}/ }
|
13
|
+
end
|
data/kuhsaft.gemspec
CHANGED
@@ -30,10 +30,11 @@ Gem::Specification.new do |s|
|
|
30
30
|
s.add_development_dependency 'growl'
|
31
31
|
|
32
32
|
s.add_dependency 'rails', '~>3.0'
|
33
|
-
s.add_dependency 'haml', '3.
|
34
|
-
s.add_dependency 'compass', '0.
|
33
|
+
s.add_dependency 'haml', '~> 3.1'
|
34
|
+
s.add_dependency 'compass', '0.11.1'
|
35
35
|
s.add_dependency 'simple_form'
|
36
36
|
s.add_dependency 'carrierwave', '0.5.2'
|
37
37
|
s.add_dependency 'rmagick', '2.12.2'
|
38
38
|
s.add_dependency 'rdiscount'
|
39
|
+
s.add_dependency 'acts-as-taggable-on', '2.0.6'
|
39
40
|
end
|
@@ -23,6 +23,8 @@ module Kuhsaft
|
|
23
23
|
install_migration_once 'add_fulltext_to_localized_page.rb'
|
24
24
|
install_migration_once 'add_page_type_to_localized_pages.rb'
|
25
25
|
install_migration_once 'add_published_at_to_localized_pages.rb'
|
26
|
+
install_migration_once 'add_tags_to_page_part_contents.rb'
|
27
|
+
install_migration_once 'acts_as_taggable_on_migration.rb'
|
26
28
|
end
|
27
29
|
|
28
30
|
private
|
data/lib/kuhsaft.rb
CHANGED
data/lib/kuhsaft/engine.rb
CHANGED
@@ -0,0 +1,68 @@
|
|
1
|
+
module Kuhsaft
|
2
|
+
# If you use this mixin, your class must implement the following methods
|
3
|
+
# siblings(), returns the siblings of the same type of object
|
4
|
+
|
5
|
+
module Orderable
|
6
|
+
def self.included base
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
base.send :include, InstanceMethods
|
9
|
+
base.after_create :set_position
|
10
|
+
end
|
11
|
+
|
12
|
+
module InstanceMethods
|
13
|
+
def increment_position
|
14
|
+
update_attribute :position, position + 1
|
15
|
+
end
|
16
|
+
|
17
|
+
def decrement_position
|
18
|
+
update_attribute :position, position - 1
|
19
|
+
end
|
20
|
+
|
21
|
+
def preceding_sibling
|
22
|
+
siblings.where('position = ?', position - 1).first
|
23
|
+
end
|
24
|
+
|
25
|
+
def succeeding_sibling
|
26
|
+
siblings.where('position = ?', position + 1).first
|
27
|
+
end
|
28
|
+
|
29
|
+
def preceding_siblings
|
30
|
+
siblings.where('position <= ?', position).where('id != ?', id)
|
31
|
+
end
|
32
|
+
|
33
|
+
def succeeding_siblings
|
34
|
+
siblings.where('position >= ?', position).where('id != ?', id)
|
35
|
+
end
|
36
|
+
|
37
|
+
def position_to_top
|
38
|
+
update_attribute :position, 1
|
39
|
+
recount_siblings_position_from 1
|
40
|
+
end
|
41
|
+
|
42
|
+
def recount_siblings_position_from position
|
43
|
+
counter = position
|
44
|
+
succeeding_siblings.each { |s| counter += 1; s.update_attribute(:position, counter) }
|
45
|
+
end
|
46
|
+
|
47
|
+
def reposition before_id
|
48
|
+
if before_id.blank?
|
49
|
+
position_to_top
|
50
|
+
else
|
51
|
+
update_attribute :position, self.class.position_of(before_id) + 1
|
52
|
+
recount_siblings_position_from position
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def set_position
|
57
|
+
initial_position = siblings.blank? ? 1 : siblings.count + 1
|
58
|
+
update_attribute(:position, initial_position)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
module ClassMethods
|
63
|
+
def position_of id
|
64
|
+
self.find(id).position rescue 1
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/kuhsaft/version.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
class ActsAsTaggableOnMigration < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
|
4
|
+
rename_column :contents, :tags, :old_tags
|
5
|
+
|
6
|
+
create_table :tags do |t|
|
7
|
+
t.string :name
|
8
|
+
end
|
9
|
+
|
10
|
+
create_table :taggings do |t|
|
11
|
+
t.references :tag
|
12
|
+
|
13
|
+
# You should make sure that the column created is
|
14
|
+
# long enough to store the required class names.
|
15
|
+
t.references :taggable, :polymorphic => true
|
16
|
+
t.references :tagger, :polymorphic => true
|
17
|
+
|
18
|
+
t.string :context
|
19
|
+
|
20
|
+
t.datetime :created_at
|
21
|
+
end
|
22
|
+
|
23
|
+
add_index :taggings, :tag_id
|
24
|
+
add_index :taggings, [:taggable_id, :taggable_type, :context]
|
25
|
+
|
26
|
+
Kuhsaft::PagePart::Content.all.each do |c|
|
27
|
+
c.tag_list = c.old_tags.gsub(' ', ', ') unless c.old_tags.blank?
|
28
|
+
end
|
29
|
+
|
30
|
+
remove_column(:contents, :old_tags)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.down
|
34
|
+
drop_table :taggings
|
35
|
+
drop_table :tags
|
36
|
+
end
|
37
|
+
end
|