kuhsaft 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/README.md +28 -12
  2. data/app/assets/javascripts/kuhsaft/cms/application.js.coffee +48 -0
  3. data/app/assets/stylesheets/kuhsaft/cms/application.css.sass +14 -0
  4. data/app/controllers/kuhsaft/cms/pages_controller.rb +6 -8
  5. data/app/helpers/kuhsaft/cms/pages_helper.rb +6 -2
  6. data/app/models/kuhsaft/accordion_brick.rb +4 -0
  7. data/app/models/kuhsaft/brick.rb +10 -0
  8. data/app/models/kuhsaft/brick_type.rb +2 -1
  9. data/app/models/kuhsaft/brick_type_filter.rb +20 -0
  10. data/app/models/kuhsaft/image_brick.rb +4 -0
  11. data/app/models/kuhsaft/link_brick.rb +4 -0
  12. data/app/models/kuhsaft/page.rb +12 -0
  13. data/app/models/kuhsaft/placeholder_brick.rb +4 -0
  14. data/app/models/kuhsaft/slider_brick.rb +4 -0
  15. data/app/models/kuhsaft/text_brick.rb +4 -0
  16. data/app/models/kuhsaft/video_brick.rb +4 -0
  17. data/app/views/kuhsaft/cms/admin/_brick_type_dropdown.html.haml +14 -10
  18. data/app/views/kuhsaft/cms/admin/_flash.html.haml +4 -0
  19. data/app/views/kuhsaft/cms/admin/_main_navigation.html.haml +1 -1
  20. data/app/views/kuhsaft/cms/bricks/_brick_item.html.haml +1 -0
  21. data/app/views/kuhsaft/cms/pages/_branch.html.haml +1 -1
  22. data/app/views/kuhsaft/cms/pages/_form.html.haml +1 -1
  23. data/app/views/kuhsaft/cms/pages/edit.html.haml +0 -1
  24. data/app/views/layouts/kuhsaft/cms/application.html.haml +2 -0
  25. data/config/locales/views/kuhsaft/cms/admin/de.yml +1 -0
  26. data/config/locales/views/layouts/de.yml +3 -1
  27. data/lib/kuhsaft.rb +3 -3
  28. data/lib/kuhsaft/brick_list.rb +15 -0
  29. data/lib/kuhsaft/version.rb +1 -1
  30. data/spec/lib/brick_list_spec.rb +11 -0
  31. data/spec/models/accordion_brick_spec.rb +6 -0
  32. data/spec/models/brick_spec.rb +15 -0
  33. data/spec/models/brick_type_filter_spec.rb +64 -0
  34. data/spec/models/image_brick_spec.rb +6 -0
  35. data/spec/models/link_brick_spec.rb +6 -0
  36. data/spec/models/page_spec.rb +15 -0
  37. data/spec/models/placeholder_brick_spec.rb +6 -0
  38. data/spec/models/slider_brick_spec.rb +6 -0
  39. data/spec/models/text_brick_spec.rb +6 -0
  40. data/spec/models/video_brick_spec.rb +6 -0
  41. metadata +27 -7
  42. data/app/assets/javascripts/kuhsaft/cms/application.js +0 -23
data/README.md CHANGED
@@ -66,8 +66,10 @@ Kuhsaft itself does not ship with any form of authentication. However, it is fai
66
66
 
67
67
  ```ruby
68
68
  # config/initializers/kuhsaft.rb
69
- Kuhsaft::Cms::AdminController.class_eval do
70
- before_filter :authenticate_user!
69
+ Rails.application.config.to_prepare do
70
+ Kuhsaft::Cms::AdminController.class_eval do
71
+ before_filter :authenticate_user!
72
+ end
71
73
  end
72
74
  ```
73
75
 
@@ -103,9 +105,11 @@ As defined in the rails docs, load the helpers from our isolated Kuhsaft engine
103
105
 
104
106
  Create an initializer file in your app inside `config/initializers` and set the `sublime_video_token`:
105
107
 
106
- Kuhsaft::Engine.configure do
107
- # Get the token from the MySites section on the sublime video site
108
- config.sublime_video_token = '123abcd'
108
+ Rails.application.config.to_prepare do
109
+ Kuhsaft::Engine.configure do
110
+ # Get the token from the MySites section on the sublime video site
111
+ config.sublime_video_token = '123abcd'
112
+ end
109
113
  end
110
114
 
111
115
  Require the sublime javascript with the following helper:
@@ -119,23 +123,29 @@ Require the sublime javascript with the following helper:
119
123
  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:
120
124
 
121
125
  # your_app/config/initializers/kuhsaft.rb
122
- Kuhsaft::Engine.configure do
123
- config.image_sizes.build_defaults! # creates 960x540 and 320x180 sizes
126
+ Rails.application.config.to_prepare do
127
+ Kuhsaft::Engine.configure do
128
+ config.image_sizes.build_defaults! # creates 960x540 and 320x180 sizes
129
+ end
124
130
  end
125
131
 
126
132
  You can also remove the default sizes:
127
133
 
128
134
  # your_app/config/initializers/kuhsaft.rb
129
- Kuhsaft::Engine.configure do
130
- config.image_sizes.clear! # .all is now empty
135
+ Rails.application.config.to_prepare do
136
+ Kuhsaft::Engine.configure do
137
+ config.image_sizes.clear! # .all is now empty
138
+ end
131
139
  end
132
140
 
133
141
  And most importantly, you can add custom sizes:
134
142
 
135
143
  # your_app/config/initializers/kuhsaft.rb
136
- Kuhsaft::Engine.configure do
137
- config.image_sizes.add(:side_box_vertical, 180, 460)
138
- config.image_sizes.add(:footer_teaser, 320, 220)
144
+ Rails.application.config.to_prepare do
145
+ Kuhsaft::Engine.configure do
146
+ config.image_sizes.add(:side_box_vertical, 180, 460)
147
+ config.image_sizes.add(:footer_teaser, 320, 220)
148
+ end
139
149
  end
140
150
 
141
151
  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:
@@ -167,6 +177,12 @@ Finally, add the new translation locale to your `available_locales` inside your
167
177
 
168
178
  config.available_locales = [:en, :fr]
169
179
 
180
+ ## Styling the content
181
+
182
+ By default, the text editor lets you add the following tags, for which you should supply some styles in your app:
183
+
184
+ p, h1, h2, h3, ul, ol, table, a, strong, em
185
+
170
186
  ## Building a navigation
171
187
 
172
188
  Building a navigation is simple, access to the page tree is available through the common methods built into the ancestry gem. Just make sure you are only accessing published pages for your production site, using the `published` scope.
@@ -0,0 +1,48 @@
1
+ # This is a manifest file that'll be compiled into including all the files listed below.
2
+ # Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ # be included in the compiled file accessible from http://example.com/assets/application.js
4
+ # It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ # the compiled file.
6
+ #
7
+ #= require jquery
8
+ #= require jquery-ui
9
+ #= require jquery_ujs
10
+ #= require redactor
11
+ #= require bootstrap
12
+ #= require_tree .
13
+
14
+ loadTextEditor = (elem) ->
15
+ elem.find(".js-editor").redactor(
16
+ buttons: ['html', '|', 'formatting', '|', 'bold', 'italic', 'deleted', '|', 'unorderedlist', 'orderedlist', 'outdent', 'indent', '|', 'table', 'link']
17
+ formattingTags: ['h1', 'h2', 'h3', 'p']
18
+ )
19
+
20
+ checkPageType = ->
21
+ redirect_url_input = $('#page_url')
22
+ if ($('#page_page_type option:selected').val() == 'redirect')
23
+ redirect_url_input.removeAttr('disabled')
24
+ else
25
+ redirect_url_input.attr('disabled', 'disabled')
26
+
27
+ sortableBrick = ->
28
+ $(".brick-list").each (idx, elem) ->
29
+ $(elem).sortable(
30
+ handle: '.brick-item-header',
31
+ axis: "y",
32
+ update: (event, ui) ->
33
+ $(this).find(".brick-item").each (idx, elem) ->
34
+ $(this).find("input.position-field").val(idx+1)
35
+ $(this).children('form').trigger('submit')
36
+ )
37
+
38
+ $(document).ajaxSuccess ->
39
+ loadTextEditor($("body"))
40
+ sortableBrick()
41
+
42
+ $(document).ready ->
43
+ loadTextEditor($(document))
44
+ checkPageType()
45
+ sortableBrick()
46
+ $('#page_page_type').change ->
47
+ checkPageType()
48
+
@@ -15,6 +15,10 @@ $borderRadiusSmall: 0px
15
15
 
16
16
  // base styles
17
17
 
18
+ body
19
+ // disable page skipping when changing tabs in page form
20
+ overflow: scroll
21
+
18
22
  h1
19
23
  margin-top: 1em
20
24
  margin-bottom: 0.5em
@@ -109,6 +113,12 @@ form
109
113
  border-bottom: 1px solid #ccc
110
114
  padding: 0.35em 0
111
115
 
116
+ .unpublished
117
+ background-color: #f1f1f1
118
+
119
+ a
120
+ color: #666
121
+
112
122
  .branch-group
113
123
  .branch-group
114
124
  .branch-title
@@ -122,4 +132,8 @@ form
122
132
  .branch-title
123
133
  margin-left: 6em
124
134
 
135
+ #flash
136
+ p
137
+ margin: 0
138
+
125
139
  @import bootstrap-responsive
@@ -21,6 +21,7 @@ module Kuhsaft
21
21
  @page = Kuhsaft::Page.create params[:page]
22
22
 
23
23
  if @page.valid?
24
+ flash[:success] = t('layouts.kuhsaft.cms.flash.success', :subject => Kuhsaft::Page.model_name.human)
24
25
  respond_with @page, :location => kuhsaft.edit_cms_page_path(@page)
25
26
  else
26
27
  render 'new'
@@ -35,15 +36,12 @@ module Kuhsaft
35
36
 
36
37
  def update
37
38
  @page = Kuhsaft::Page.find(params[:id])
38
- @page.update_attributes(params[:page]) if params[:page].present?
39
- # TODO: refactor 'reposition' as a page attribute, so it can be set through update_attributes
40
- @page.reposition params[:reposition] if params[:reposition].present? || params.key?(:reposition)
41
-
42
- if params[:add_page_part].present?
43
- @page.bricks << params[:page][:page_part_type].constantize.new
39
+ if @page.update_attributes(params[:page])
40
+ flash[:success] = t('layouts.kuhsaft.cms.flash.success', :subject => Kuhsaft::Page.model_name.human)
41
+ respond_with @page, :location => kuhsaft.edit_cms_page_path(@page)
42
+ else
43
+ render 'edit'
44
44
  end
45
-
46
- respond_with @page, :location => kuhsaft.edit_cms_page_path(@page)
47
45
  end
48
46
 
49
47
  def destroy
@@ -3,11 +3,15 @@ module Kuhsaft
3
3
  module PagesHelper
4
4
 
5
5
  def content_tab_active(page)
6
- :active if page.persisted?
6
+ if page.errors.blank?
7
+ :active if page.persisted?
8
+ end
7
9
  end
8
10
 
9
11
  def metadata_tab_active(page)
10
- :active unless page.persisted?
12
+ if page.errors.present? || !page.persisted?
13
+ :active
14
+ end
11
15
  end
12
16
  end
13
17
  end
@@ -12,5 +12,9 @@ module Kuhsaft
12
12
  def to_style_class
13
13
  [super, 'accordion'].join(' ')
14
14
  end
15
+
16
+ def allowed_brick_types
17
+ %w(Kuhsaft::AccordionItemBrick)
18
+ end
15
19
  end
16
20
  end
@@ -23,12 +23,22 @@ module Kuhsaft
23
23
  :brick_list_type,
24
24
  :presence => true
25
25
 
26
+ after_initialize do
27
+ self.position ||= has_siblings? ? brick_list.bricks.maximum(:position).to_i + 1 : 1
28
+ end
29
+
26
30
  def to_edit_partial_path
27
31
  path = self.to_partial_path.split '/'
28
32
  path << 'edit'
29
33
  path.join '/'
30
34
  end
31
35
 
36
+ def has_siblings?
37
+ if brick_list
38
+ brick_list.bricks.any?
39
+ end
40
+ end
41
+
32
42
  #
33
43
  # The child partial can contain your own implementation
34
44
  # of how the brick renders it's child in the edit form.
@@ -2,6 +2,7 @@ module Kuhsaft
2
2
  class BrickType < ActiveRecord::Base
3
3
  attr_accessible :disabled, :class_name, :group
4
4
  scope :grouped, order('`group`, `id` asc')
5
- scope :enabled, where('disabled IS NOT false')
5
+ scope :enabled, where('disabled IS NOT "false"')
6
+ scope :constrained, lambda { |list| where(:class_name => list) }
6
7
  end
7
8
  end
@@ -0,0 +1,20 @@
1
+
2
+ module Kuhsaft
3
+ class BrickTypeFilter < SimpleDelegator
4
+
5
+ def empty?
6
+ !(respond_to?(:user_can_add_childs?) && user_can_add_childs? && !allowed.empty?)
7
+ end
8
+
9
+ def allowed
10
+ if Kuhsaft::BrickType.enabled.count.zero?
11
+ []
12
+ elsif allowed_brick_types.empty?
13
+ Kuhsaft::BrickType.enabled
14
+ else
15
+ Kuhsaft::BrickType.enabled.constrained(allowed_brick_types)
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -15,5 +15,9 @@ module Kuhsaft
15
15
  def collect_fulltext
16
16
  [super, caption].join(' ')
17
17
  end
18
+
19
+ def user_can_add_childs?
20
+ false
21
+ end
18
22
  end
19
23
  end
@@ -15,5 +15,9 @@ module Kuhsaft
15
15
  def collect_fulltext
16
16
  [super, caption].join(' ')
17
17
  end
18
+
19
+ def user_can_add_childs?
20
+ false
21
+ end
18
22
  end
19
23
  end
@@ -51,6 +51,14 @@ class Kuhsaft::Page < ActiveRecord::Base
51
51
  published == Kuhsaft::PublishState::PUBLISHED
52
52
  end
53
53
 
54
+ def state_class
55
+ if published?
56
+ 'published'
57
+ else
58
+ 'unpublished'
59
+ end
60
+ end
61
+
54
62
  def redirect?
55
63
  page_type == Kuhsaft::PageType::REDIRECT
56
64
  end
@@ -110,4 +118,8 @@ class Kuhsaft::Page < ActiveRecord::Base
110
118
  def to_style_class
111
119
  'kuhsaft-page'
112
120
  end
121
+
122
+ def allowed_brick_types
123
+ Kuhsaft::BrickType.enabled.pluck(:class_name) - ['Kuhsaft::AccordionItemBrick']
124
+ end
113
125
  end
@@ -7,5 +7,9 @@ module Kuhsaft
7
7
  def self.available_partials
8
8
  @partials ||= Kuhsaft::PartialExtractor.new.partials(PARTIAL_PATH)
9
9
  end
10
+
11
+ def user_can_add_childs?
12
+ false
13
+ end
10
14
  end
11
15
  end
@@ -11,6 +11,10 @@ module Kuhsaft
11
11
  [super, 'carousel', 'slide'].join(' ')
12
12
  end
13
13
 
14
+ def allowed_brick_types
15
+ %w(Kuhsaft::ImageBrick Kuhsaft::VideoBrick)
16
+ end
17
+
14
18
  end
15
19
  end
16
20
 
@@ -2,6 +2,10 @@ module Kuhsaft
2
2
  class TextBrick < Brick
3
3
  attr_accessible :text, :read_more_text
4
4
 
5
+ def user_can_add_childs?
6
+ false
7
+ end
8
+
5
9
  def collect_fulltext
6
10
  [super, text, read_more_text].join(' ')
7
11
  end
@@ -16,5 +16,9 @@ module Kuhsaft
16
16
  def self.source_types
17
17
  [YOUTUBE, VIMEO, EXTERNAL]
18
18
  end
19
+
20
+ def user_can_add_childs?
21
+ false
22
+ end
19
23
  end
20
24
  end
@@ -1,10 +1,14 @@
1
- - if brick_list.respond_to?(:user_can_add_childs?) && brick_list.user_can_add_childs? && Kuhsaft::BrickType.count > 0
2
- %a.btn.btn-small.btn-primary.dropdown-toggle{ 'data-toggle' => 'dropdown', 'href' => '#' }
3
- = t('.add_element')
4
- %span.caret
5
- %ul.dropdown-menu.pull-right
6
- - Kuhsaft::BrickType.grouped.group_by(&:group).each do |group, types|
7
- - types.each do |type|
8
- %li
9
- = link_to type.class_name.constantize.model_name.human, kuhsaft.cms_bricks_path(:brick => { :type => type.class_name, :brick_list_id => brick_list.id, :brick_list_type => brick_list.brick_list_type }), :remote => true, :method => :post
10
- .divider
1
+ - unless brick_list.brick_types.empty?
2
+ - if brick_list.brick_types.allowed.count > 1
3
+ %a.btn.btn-small.btn-primary.dropdown-toggle{ 'data-toggle' => 'dropdown', 'href' => '#' }
4
+ = t('.add_element')
5
+ %span.caret
6
+ %ul.dropdown-menu.pull-right
7
+ - brick_list.brick_types.allowed.grouped.group_by(&:group).each do |group, types|
8
+ - types.each do |type|
9
+ %li
10
+ = link_to type.class_name.constantize.model_name.human, kuhsaft.cms_bricks_path(:brick => { :type => type.class_name, :brick_list_id => brick_list.id, :brick_list_type => brick_list.brick_list_type }), :remote => true, :method => :post
11
+ .divider
12
+ - else
13
+ - brick_list.brick_types.allowed.each do |type|
14
+ = link_to t('.add_specific_element', :name => type.class_name.constantize.model_name.human), kuhsaft.cms_bricks_path(:brick => { :type => type.class_name, :brick_list_id => brick_list.id, :brick_list_type => brick_list.brick_list_type }), :remote => true, :method => :post, :class => 'btn btn-small btn-primary'
@@ -0,0 +1,4 @@
1
+ #flash
2
+ - flash.each do |key, value|
3
+ .alert{ :class => "#{key} alert-#{key}" }
4
+ %p= value
@@ -1,4 +1,4 @@
1
- = link_to 'Kuhsaft CMS', '#', :class => 'brand'
1
+ = link_to 'Kuhsaft CMS', cms_root_path, :class => 'brand'
2
2
  %p.navbar-text.pull-right
3
3
  = link_to t('.logout'), '', :method => :delete
4
4
  %ul.nav
@@ -1,5 +1,6 @@
1
1
  .brick-item{ :id => brick.to_brick_item_id, :class => brick.to_style_class }
2
2
  = simple_form_for brick, :as => :brick, :url => kuhsaft.cms_brick_path(brick), :remote => true, :html => { :id => nil } do |form|
3
+ = form.hidden_field :position, :class => 'position-field'
3
4
  .brick-item-header.clearfix
4
5
  .pull-left
5
6
  - if brick.caption.present?
@@ -1,7 +1,7 @@
1
1
  - unless pages.blank?
2
2
  - pages.each do |page|
3
3
  .branch-group{ :'data-id' => page.id, :'data-put-url' => kuhsaft.cms_page_path(page) }
4
- .row-fluid.branch
4
+ .row-fluid.branch{ :class => page.state_class }
5
5
  .span9
6
6
  .branch-title
7
7
  = link_to page.title.presence, kuhsaft.edit_cms_page_path(page), :class => 'btn btn-link'
@@ -11,7 +11,7 @@
11
11
  = form.input :slug, :required => false, :input_html => { :class => :span5 }
12
12
  = form.input :parent_id, :collection => Kuhsaft::Page.flat_tree, :label_method => :nesting_name, :selected => params[:parent_id].presence || @page.parent_id.presence, :prompt => 'None', :input_html => { :class => :span3 }
13
13
  = form.input :page_type, :collection => Kuhsaft::PageType.all, :prompt => false, :input_html => { :class => :span3 }
14
- = form.input :url, :as => :string if @page.redirect?
14
+ = form.input :url, :as => :string
15
15
  = form.input :keywords, :input_html => { :class => :span5 }
16
16
  = form.input :description, :as => :text, :input_html => { :class => :span5, :rows => 4 }
17
17
  = form.input :published, :as => :boolean
@@ -1,4 +1,3 @@
1
- = render 'content_language_switch'
2
1
  %ul.breadcrumb
3
2
  %li
4
3
  = link_to Kuhsaft::Page.model_name.human(:count => 2), kuhsaft.cms_pages_path
@@ -16,5 +16,7 @@
16
16
  .container.cms
17
17
  .row-fluid
18
18
  .span-12
19
+ = render 'content_language_switch'
20
+ = render 'flash', :flash => flash
19
21
  = yield
20
22
  = javascript_include_tag 'kuhsaft/cms/application.js'
@@ -5,6 +5,7 @@ de:
5
5
  confirm_delete: '"%{name}" wirklich löschen?'
6
6
  brick_type_dropdown:
7
7
  add_element: 'Element hinzufügen'
8
+ add_specific_element: '%{name} hinzufügen'
8
9
  empty_state:
9
10
  empty: 'Hier ist bisher noch nichts...'
10
11
 
@@ -1,6 +1,8 @@
1
- de:
1
+ en:
2
2
  layouts:
3
3
  kuhsaft:
4
4
  cms:
5
5
  application:
6
6
  logout: 'Abmelden'
7
+ flash:
8
+ success: '%{subject} wurde erfolgreich gespeichert.'
@@ -1,6 +1,3 @@
1
- require 'kuhsaft/engine'
2
- require 'compass-rails'
3
-
4
1
  module Kuhsaft
5
2
  require 'kuhsaft/engine'
6
3
  require 'kuhsaft/orderable'
@@ -11,6 +8,9 @@ module Kuhsaft
11
8
  require 'carrierwave'
12
9
  require 'rdiscount'
13
10
  require 'compass'
11
+ require 'compass-rails'
12
+ require 'jquery-rails'
14
13
  require 'ancestry'
15
14
  require 'bootstrap-sass'
15
+ require 'haml'
16
16
  end
@@ -67,5 +67,20 @@ module Kuhsaft
67
67
  end
68
68
  end
69
69
 
70
+ #
71
+ # Return a list of classnames which can be added as childs
72
+ # Return an empty array if you want no constraints
73
+ #
74
+ def allowed_brick_types
75
+ []
76
+ end
77
+
78
+ #
79
+ # Returns all possible brick types which can be added as child to this brick list instance
80
+ #
81
+ def brick_types
82
+ @brick_types ||= Kuhsaft::BrickTypeFilter.new(self)
83
+ end
84
+
70
85
  end
71
86
  end
@@ -1,3 +1,3 @@
1
1
  module Kuhsaft
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -36,4 +36,15 @@ describe Kuhsaft::BrickList do
36
36
  end
37
37
  end
38
38
 
39
+ describe '#allowed_brick_types' do
40
+ it 'returns an array of possible classes as strings' do
41
+ brick.allowed_brick_types.should be_a(Array)
42
+ end
43
+ end
44
+
45
+ describe '#brick_types' do
46
+ it 'returns a Kuhsaft::BrickTypeFilter' do
47
+ brick.brick_types.should be_a(Kuhsaft::BrickTypeFilter)
48
+ end
49
+ end
39
50
  end
@@ -29,4 +29,10 @@ describe Kuhsaft::AccordionBrick do
29
29
  accordion_brick.to_style_class.should == 'kuhsaft-accordion-brick accordion'
30
30
  end
31
31
  end
32
+
33
+ describe '#allowed_brick_types' do
34
+ it 'only allows AccordionItems' do
35
+ accordion_brick.allowed_brick_types.should == %w(Kuhsaft::AccordionItemBrick)
36
+ end
37
+ end
32
38
  end
@@ -70,6 +70,21 @@ describe Kuhsaft::Brick do
70
70
  end
71
71
  end
72
72
 
73
+ describe '#has_siblings?' do
74
+ it 'returns false if the brick has no siblings' do
75
+ brick = Kuhsaft::Brick.new
76
+ brick.has_siblings?.should be_false
77
+ end
78
+
79
+ it 'returns true if the brick has siblings' do
80
+ item1, item2, item3 = mock, mock, Kuhsaft::Brick.new
81
+ item1.stub(:bricks).and_return([item2, item3])
82
+ item2.stub(:brick_list).and_return(item1)
83
+ item3.stub(:brick_list).and_return(item1)
84
+ item3.has_siblings?.should be_true
85
+ end
86
+ end
87
+
73
88
  describe '#to_edit_childs_partial_path' do
74
89
  it 'returns the path to the form partial' do
75
90
  Kuhsaft::TextBrick.new.to_edit_childs_partial_path.should == 'kuhsaft/text_bricks/text_brick/childs'
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kuhsaft::BrickTypeFilter do
4
+ let :brick_list do
5
+ Kuhsaft::Page.new
6
+ end
7
+
8
+ let :brick_type_filter do
9
+ Kuhsaft::BrickTypeFilter.new(brick_list)
10
+ end
11
+
12
+ describe '#empty?' do
13
+ context 'when the user cant add childs' do
14
+ before do
15
+ brick_list.stub(:user_can_add_childs?).and_return(false)
16
+ end
17
+
18
+ it 'returns true' do
19
+ brick_type_filter.empty?.should be_true
20
+ end
21
+ end
22
+
23
+ context 'when there are no bricks to be added' do
24
+ before do
25
+ brick_type_filter.stub(:allowed).and_return([])
26
+ end
27
+
28
+ it 'returns true' do
29
+ brick_type_filter.empty?.should be_true
30
+ end
31
+ end
32
+ end
33
+
34
+ describe '#allowed' do
35
+ context 'when no brick types are registered' do
36
+ it 'returns an empty array' do
37
+ Kuhsaft::BrickType.stub_chain(:count, :zero?).and_return(true)
38
+ brick_type_filter.allowed.should be_empty
39
+ end
40
+ end
41
+
42
+ context 'when brick types are registered' do
43
+ before do
44
+ Kuhsaft::BrickType.stub_chain(:enabled, :count, :zero?).and_return(false)
45
+ end
46
+
47
+ context 'when there are no constraints' do
48
+ it 'returns all enabled brick types' do
49
+ brick_list.stub(:allowed_brick_types).and_return([])
50
+ Kuhsaft::BrickType.should_receive(:enabled)
51
+ brick_type_filter.allowed
52
+ end
53
+ end
54
+
55
+ context 'when there are constraints' do
56
+ it 'constrains the enabled types' do
57
+ brick_list.stub(:allowed_brick_types).and_return(['Kuhsaft::TextBrick'])
58
+ Kuhsaft::BrickType.enabled.should_receive(:constrained).with(['Kuhsaft::TextBrick'])
59
+ brick_type_filter.allowed
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -33,4 +33,10 @@ describe Kuhsaft::ImageBrick do
33
33
  image_brick.should_not respond_to(:bricks)
34
34
  end
35
35
  end
36
+
37
+ describe '#user_can_add_childs?' do
38
+ it 'returns false' do
39
+ image_brick.user_can_add_childs?.should be_false
40
+ end
41
+ end
36
42
  end
@@ -42,4 +42,10 @@ describe Kuhsaft::LinkBrick do
42
42
  link_brick.to_style_class.should == 'kuhsaft-link-brick pdf'
43
43
  end
44
44
  end
45
+
46
+ describe '#user_can_add_childs?' do
47
+ it 'returns false' do
48
+ link_brick.user_can_add_childs?.should be_false
49
+ end
50
+ end
45
51
  end
@@ -72,6 +72,21 @@ describe Kuhsaft::Page do
72
72
  end
73
73
  end
74
74
 
75
+ describe "#state_class" do
76
+
77
+ let(:page) { Kuhsaft::Page.new }
78
+
79
+ it 'returns publsihed as string when page is published' do
80
+ page.published == Kuhsaft::PublishState::PUBLISHED
81
+ page.state_class == 'published'
82
+ end
83
+
84
+ it 'returns unpublsihed as string when page is unpublished' do
85
+ page.published == Kuhsaft::PublishState::UNPUBLISHED
86
+ page.state_class == 'unpublished'
87
+ end
88
+ end
89
+
75
90
  describe '#without_self' do
76
91
  it 'returns pages but not itself' do
77
92
  2.times { create(:page) }
@@ -37,4 +37,10 @@ describe Kuhsaft::PlaceholderBrick do
37
37
  placeholder_brick.should_not respond_to(:bricks)
38
38
  end
39
39
  end
40
+
41
+ describe '#user_can_add_childs?' do
42
+ it 'returns false' do
43
+ placeholder_brick.user_can_add_childs?.should be_false
44
+ end
45
+ end
40
46
  end
@@ -17,4 +17,10 @@ describe Kuhsaft::SliderBrick do
17
17
  slider_brick.to_style_class.should == 'kuhsaft-slider-brick carousel slide'
18
18
  end
19
19
  end
20
+
21
+ describe '#allowed_brick_types' do
22
+ it 'only allows ImageBricks and VideoBricks' do
23
+ slider_brick.allowed_brick_types.should == %w(Kuhsaft::ImageBrick Kuhsaft::VideoBrick)
24
+ end
25
+ end
20
26
  end
@@ -11,4 +11,10 @@ describe Kuhsaft::TextBrick do
11
11
  text_brick.should_not respond_to(:bricks)
12
12
  end
13
13
  end
14
+
15
+ describe '#user_can_add_childs?' do
16
+ it 'returns false' do
17
+ text_brick.user_can_add_childs?.should be_false
18
+ end
19
+ end
14
20
  end
@@ -23,4 +23,10 @@ describe Kuhsaft::VideoBrick do
23
23
  video_brick.should_not respond_to(:bricks)
24
24
  end
25
25
  end
26
+
27
+ describe '#user_can_add_childs?' do
28
+ it 'returns false' do
29
+ video_brick.user_can_add_childs?.should be_false
30
+ end
31
+ end
26
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kuhsaft
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-02-06 00:00:00.000000000 Z
14
+ date: 2013-02-25 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec
@@ -132,7 +132,7 @@ dependencies:
132
132
  requirements:
133
133
  - - ~>
134
134
  - !ruby/object:Gem::Version
135
- version: '3.2'
135
+ version: 3.2.11
136
136
  type: :runtime
137
137
  prerelease: false
138
138
  version_requirements: !ruby/object:Gem::Requirement
@@ -140,7 +140,7 @@ dependencies:
140
140
  requirements:
141
141
  - - ~>
142
142
  - !ruby/object:Gem::Version
143
- version: '3.2'
143
+ version: 3.2.11
144
144
  - !ruby/object:Gem::Dependency
145
145
  name: haml
146
146
  requirement: !ruby/object:Gem::Requirement
@@ -189,6 +189,22 @@ dependencies:
189
189
  - - ! '>='
190
190
  - !ruby/object:Gem::Version
191
191
  version: '0'
192
+ - !ruby/object:Gem::Dependency
193
+ name: coffee-rails
194
+ requirement: !ruby/object:Gem::Requirement
195
+ none: false
196
+ requirements:
197
+ - - ! '>='
198
+ - !ruby/object:Gem::Version
199
+ version: '0'
200
+ type: :runtime
201
+ prerelease: false
202
+ version_requirements: !ruby/object:Gem::Requirement
203
+ none: false
204
+ requirements:
205
+ - - ! '>='
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
192
208
  - !ruby/object:Gem::Dependency
193
209
  name: simple_form
194
210
  requirement: !ruby/object:Gem::Requirement
@@ -292,7 +308,7 @@ extensions: []
292
308
  extra_rdoc_files: []
293
309
  files:
294
310
  - app/assets/javascripts/kuhsaft/application.js
295
- - app/assets/javascripts/kuhsaft/cms/application.js
311
+ - app/assets/javascripts/kuhsaft/cms/application.js.coffee
296
312
  - app/assets/javascripts/kuhsaft/cms/customizations.js
297
313
  - app/assets/stylesheets/kuhsaft/application.css.sass
298
314
  - app/assets/stylesheets/kuhsaft/cms/application.css.sass
@@ -313,6 +329,7 @@ files:
313
329
  - app/models/kuhsaft/asset.rb
314
330
  - app/models/kuhsaft/brick.rb
315
331
  - app/models/kuhsaft/brick_type.rb
332
+ - app/models/kuhsaft/brick_type_filter.rb
316
333
  - app/models/kuhsaft/cms.rb
317
334
  - app/models/kuhsaft/column_brick.rb
318
335
  - app/models/kuhsaft/image_brick.rb
@@ -336,6 +353,7 @@ files:
336
353
  - app/views/kuhsaft/cms/admin/_brick_type_dropdown.html.haml
337
354
  - app/views/kuhsaft/cms/admin/_content_language_switch.html.haml
338
355
  - app/views/kuhsaft/cms/admin/_empty_state.html.haml
356
+ - app/views/kuhsaft/cms/admin/_flash.html.haml
339
357
  - app/views/kuhsaft/cms/admin/_main_navigation.html.haml
340
358
  - app/views/kuhsaft/cms/assets/_form.html.haml
341
359
  - app/views/kuhsaft/cms/assets/_list.html.haml
@@ -460,6 +478,7 @@ files:
460
478
  - spec/models/accordion_item_brick_spec.rb
461
479
  - spec/models/asset_spec.rb
462
480
  - spec/models/brick_spec.rb
481
+ - spec/models/brick_type_filter_spec.rb
463
482
  - spec/models/column_brick_spec.rb
464
483
  - spec/models/image_brick_spec.rb
465
484
  - spec/models/image_size_spec.rb
@@ -487,7 +506,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
487
506
  version: '0'
488
507
  segments:
489
508
  - 0
490
- hash: -4283102983573575769
509
+ hash: -1611496846059765268
491
510
  required_rubygems_version: !ruby/object:Gem::Requirement
492
511
  none: false
493
512
  requirements:
@@ -496,7 +515,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
496
515
  version: '0'
497
516
  segments:
498
517
  - 0
499
- hash: -4283102983573575769
518
+ hash: -1611496846059765268
500
519
  requirements: []
501
520
  rubyforge_project: kuhsaft
502
521
  rubygems_version: 1.8.24
@@ -547,6 +566,7 @@ test_files:
547
566
  - spec/models/accordion_item_brick_spec.rb
548
567
  - spec/models/asset_spec.rb
549
568
  - spec/models/brick_spec.rb
569
+ - spec/models/brick_type_filter_spec.rb
550
570
  - spec/models/column_brick_spec.rb
551
571
  - spec/models/image_brick_spec.rb
552
572
  - spec/models/image_size_spec.rb
@@ -1,23 +0,0 @@
1
- // This is a manifest file that'll be compiled into including all the files listed below.
2
- // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
- // be included in the compiled file accessible from http://example.com/assets/application.js
4
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
- // the compiled file.
6
- //
7
- //= require jquery
8
- //= require jquery_ujs
9
- //= require redactor
10
- //= require bootstrap
11
- //= require_tree .
12
-
13
- function loadTextEditor(elem){
14
- elem.find(".js-editor").redactor({})
15
- }
16
-
17
- $(function(){
18
- loadTextEditor($("body"))
19
- })
20
-
21
- $("body").ajaxSuccess(function(){
22
- loadTextEditor($("body"))
23
- })