cardboard_cms 0.1.8 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +4 -5
  3. data/README.md +14 -14
  4. data/app/assets/javascripts/cardboard/admin.js +3 -24
  5. data/app/assets/javascripts/cardboard/datepicker.js +1 -5
  6. data/app/assets/javascripts/cardboard/rich_text.js +1 -1
  7. data/app/assets/javascripts/cardboard/search_filter.js +1 -1
  8. data/app/assets/stylesheets/cardboard/_bootstrap-select.css.scss +1 -1
  9. data/app/assets/stylesheets/cardboard/_framework.css.scss +1 -1
  10. data/app/assets/stylesheets/cardboard/_main_topbar.css.scss +1 -1
  11. data/app/controllers/cardboard/pages_controller.rb +25 -1
  12. data/app/controllers/pages_controller.rb +12 -11
  13. data/app/helpers/cardboard/resource_helper.rb +1 -1
  14. data/app/models/cardboard/field/boolean.rb +1 -1
  15. data/app/models/cardboard/field.rb +21 -9
  16. data/app/models/cardboard/page.rb +19 -30
  17. data/app/models/cardboard/page_part.rb +13 -46
  18. data/app/models/cardboard/setting.rb +3 -0
  19. data/app/models/cardboard/template.rb +15 -0
  20. data/app/views/cardboard/fields/_base_input.html.slim +1 -1
  21. data/app/views/cardboard/fields/_boolean.html.slim +2 -2
  22. data/app/views/cardboard/fields/_date.html.slim +1 -1
  23. data/app/views/cardboard/fields/_external_link.html.slim +2 -2
  24. data/app/views/cardboard/fields/_file.html.slim +4 -4
  25. data/app/views/cardboard/fields/_image.html.slim +2 -2
  26. data/app/views/cardboard/fields/_resource_link.html.slim +2 -2
  27. data/app/views/cardboard/fields/_rich_text.html.slim +1 -1
  28. data/app/views/cardboard/fields/_string.html.slim +1 -1
  29. data/app/views/cardboard/pages/_error.html.slim +1 -1
  30. data/app/views/cardboard/pages/_part_fields.html.slim +19 -0
  31. data/app/views/cardboard/pages/_sidebar.html.slim +8 -4
  32. data/app/views/cardboard/pages/_url_field.html.slim +6 -8
  33. data/app/views/cardboard/pages/edit.html.slim +24 -15
  34. data/app/views/cardboard/pages/new.html.slim +7 -0
  35. data/app/views/cardboard/pages/show.html.slim +3 -3
  36. data/app/views/cardboard/resources/_advanced_search.html.slim +1 -1
  37. data/app/views/cardboard/resources/_search_helper.html.slim +3 -3
  38. data/app/views/cardboard/resources/_simple_search.html.slim +1 -1
  39. data/app/views/cardboard/settings/index.html.slim +12 -3
  40. data/app/views/cardboard/super_user/index.html.slim +1 -1
  41. data/app/views/layouts/cardboard/_main_sidebar.html.slim +1 -1
  42. data/app/views/layouts/cardboard/_main_topbar.html.slim +1 -1
  43. data/app/views/layouts/cardboard/application.html.slim +1 -1
  44. data/cardboard.gemspec +1 -1
  45. data/config/routes.rb +2 -0
  46. data/db/migrate/1_create_cardboard.rb +63 -0
  47. data/lib/cardboard/engine.rb +1 -11
  48. data/lib/cardboard/helpers/seed.rb +31 -30
  49. data/lib/cardboard/version.rb +1 -1
  50. data/lib/cardboard_cms.rb +6 -2
  51. data/lib/generators/cardboard/install/install_generator.rb +5 -13
  52. data/lib/tasks/cardboard_tasks.rake +5 -3
  53. data/test/dummy/app/views/{pages → templates}/about-us.html.slim +0 -0
  54. data/test/dummy/app/views/templates/home.html.slim +5 -0
  55. data/test/dummy/config/cardboard.yml +1 -1
  56. data/test/dummy/db/schema.rb +7 -39
  57. data/test/dummy/db/seeds.rb +1 -1
  58. data/test/factories.rb +40 -1
  59. data/test/integration/page_editing_test.rb +2 -1
  60. data/test/integration/seeding_test.rb +16 -31
  61. data/test/models/field_test.rb +42 -28
  62. data/test/models/page_test.rb +1 -1
  63. data/test/models/template_test.rb +11 -0
  64. data/test/test_helper.rb +5 -1
  65. metadata +13 -29
  66. data/app/views/cardboard/pages/_subpart_fields.html.slim +0 -20
  67. data/lib/generators/cardboard/install/templates/migrations/1_create_cardboard_fields.rb +0 -21
  68. data/lib/generators/cardboard/install/templates/migrations/2_create_cardboard_page_parts.rb +0 -17
  69. data/lib/generators/cardboard/install/templates/migrations/3_create_cardboard_pages.rb +0 -18
  70. data/lib/generators/cardboard/install/templates/migrations/4_create_cardboard_settings.rb +0 -14
  71. data/test/dummy/app/views/pages/home.html.slim +0 -3
  72. data/test/dummy/db/migrate/20130426021522_create_news_posts.rb +0 -10
  73. data/test/dummy/db/migrate/20130501195423_create_icescreams.rb +0 -10
  74. data/test/dummy/db/migrate/20130502165540_create_beans.rb +0 -12
  75. data/test/dummy/db/migrate/20130522151358_create_cardboard_fields.rb +0 -21
  76. data/test/dummy/db/migrate/20130522151359_create_cardboard_page_parts.rb +0 -17
  77. data/test/dummy/db/migrate/20130522151400_create_cardboard_pages.rb +0 -18
  78. data/test/dummy/db/migrate/20130522151401_create_cardboard_settings.rb +0 -14
  79. data/test/dummy/db/migrate/20130607132558_create_admins.rb +0 -9
  80. data/vendor/assets/javascripts/cardboard/jquery.pjax.js +0 -840
@@ -1 +1 @@
1
- = f.input :value, label: f.object.label || f.object.identifier.titleize, as: :date_picker, hint: f.object.hint, placeholder: f.object.placeholder, required: f.object.required
1
+ = f.input :value, label: field[:label] || identifier.titleize, as: :date_picker, hint: field[:hint], placeholder: field[:placeholder], required: field[:required] != false
@@ -1,2 +1,2 @@
1
- = f.input :value, label: false, hint: f.object.hint do
2
- = link_to f.object.label || f.object.value , f.object.value
1
+ = f.input :value, label: false, hint: field[:hint] do
2
+ = link_to field[:label] || field[:value] , field[:value]
@@ -1,8 +1,8 @@
1
- = f.input :value, label: f.object.identifier, hint: f.object.hint, placeholder: f.object.placeholder, required: f.object.required do
1
+ = f.input :value, label: field[:label] || identifier.titleize, hint: field[:hint], placeholder: field[:placeholder], required: field[:required] != false do
2
2
 
3
- - if f.object.value_uid.present?
4
- p= link_to "#{f.object.value.name} (#{number_to_human_size f.object.value.size})", f.object.value.url, "data-skip-pjax" => true
5
- - unless f.object.required
3
+ - if f.object.value_uid
4
+ p= link_to "#{f.object.value.name} (#{number_to_human_size f.object.value.size})", f.object.value.url
5
+ - unless field[:required]
6
6
  = f.input :remove_value, as: :boolean, inline_label: "Delete file?", label: false, :wrapper => :default
7
7
 
8
8
  = f.hidden_field :retained_value
@@ -1,9 +1,9 @@
1
- = f.input :value, label: f.object.label || f.object.identifier.titleize, hint: f.object.hint, placeholder: f.object.placeholder, required: f.object.required do
1
+ = f.input :value, label: field[:label] || identifier.titleize, hint: field[:hint], placeholder: field[:placeholder], required: field[:required] != false do
2
2
 
3
3
  - if f.object.value_uid.present?
4
4
  = image_tag f.object.value.thumb('600x150>').url
5
5
  br
6
- - unless f.object.required
6
+ - unless field[:required]
7
7
  = f.input :remove_value, inline_label: "Delete file?", label: false, as: :boolean, :wrapper => :default
8
8
 
9
9
  = f.input_field :value, as: :file
@@ -1,2 +1,2 @@
1
- = f.input :value, label: false, hint: f.object.hint do
2
- = link_to f.object.label || f.object.value , {controller: "cardboard/#{f.object.value}", action: :index}
1
+ = f.input :value, label: false, hint: field[:hint] do
2
+ = link_to field[:label] || field[:value] , {controller: "cardboard/#{field[:value]}", action: :index}
@@ -1,3 +1,3 @@
1
1
 
2
2
 
3
- = f.input :value, label: f.object.label || f.object.identifier.titleize, as: f.object.type, hint: f.object.hint, placeholder: f.object.placeholder, required: f.object.required
3
+ = f.input :value, label: field[:label] || identifier.titleize, as: field[:type], hint: field[:hint], placeholder: field[:placeholder], required: field[:required] != false
@@ -1 +1 @@
1
- = f.input :value, label: f.object.label || f.object.identifier.titleize, as: f.object.type, hint: f.object.hint, placeholder: f.object.placeholder, required: f.object.required
1
+ = f.input :value, label: field[:label] || identifier.titleize, as: field[:type], hint: field[:hint], placeholder: field[:placeholder], required: field[:required] != false
@@ -1,5 +1,5 @@
1
1
 
2
- h1 views/pages/#{missing_file}.html...
2
+ h1 views/templates/#{missing_file}.html...
3
3
 
4
4
  p make sure to overwrite this file with your own!
5
5
 
@@ -0,0 +1,19 @@
1
+ .nested-fields
2
+ = f.hidden_field :identifier, :value => part_identifier
3
+
4
+ - if part_hash[:repeatable]
5
+ .right= link_to_remove_association "x", f, class: "btn btn-danger"
6
+
7
+ - part_hash[:fields].each do |field_identifier, field|
8
+
9
+ - fields = part.fields.find{|ob| ob.identifier == field_identifier}
10
+
11
+ = f.simple_fields_for :fields, fields do |w|
12
+ = w.hidden_field :type, :value => "Cardboard::Field::#{field[:type].camelize}"
13
+ = w.hidden_field :identifier, :value => field_identifier
14
+
15
+ - begin
16
+ = render "cardboard/fields/#{field[:type]}", f: w, field: field, identifier: field_identifier
17
+ - rescue ActionView::MissingTemplate => e
18
+ = render "cardboard/fields/base_input", f: w, field: field, identifier: field_identifier
19
+
@@ -1,7 +1,11 @@
1
- .input-append
2
- input id="sidebar_page_search" type="text" placeholder="Search by Title"
3
- button type="submit" class="btn"
4
- i.icon-search
1
+ form class="form-inline"
2
+ => link_to pages_new_path, class:"btn btn-primary" do
3
+ i.icon-plus
4
+
5
+ .input-append style="width: 160px"
6
+ input id="sidebar_page_search" type="text" placeholder="Search Pages"
7
+ button type="submit" class="btn"
8
+ i.icon-search
5
9
 
6
10
  #content_pages data-update-url="#{pages_sort_path}"
7
11
  = nested_pages do |page, subpages|
@@ -1,17 +1,15 @@
1
- / -# TODO: put the parent and slug side by side and name the new field URL
2
- / -# also maybe change the dropdown to an autocomplete
3
- / -# f.input :parent_url, :collection => Cardboard::Page.preordered.all.inject(["/"]){|result, elm| result << elm.url unless elm.id == @page.id; result}, include_blank: false
4
1
 
5
2
  = f.input :url, required: true, wrapper_html:{class: f.object.errors.messages[:slug] ? "error" : nil}, hint: f.object.root? ? "This page is your home page" : nil do
6
3
  - if f.object.root?
7
4
  .btn(disabled)=> "/"
8
5
  ' or
9
6
  .input-prepend style="display:inline"
10
- .add-on
11
- - if @page.new_record?
12
- = f.select :parent_url, options_for_select(@page.parent_url_options, f.object.parent_url)
13
- - else
14
- = f.object.parent_url
7
+ = f.select :parent_url, options_for_select(@page.parent_url_options, f.object.parent_url)
8
+ / .add-on
9
+ / - if @page.new_record?
10
+ / = f.select :parent_url, options_for_select(@page.parent_url_options, f.object.parent_url)
11
+ / - else
12
+ / = f.object.parent_url
15
13
 
16
14
  = f.text_field :slug
17
15
 
@@ -1,6 +1,11 @@
1
1
  h1
2
2
  = @page.title
3
- .right= link_to "Live preview", @page.url, class:"btn", target: '_blank', 'data-skip-pjax' => true
3
+ - unless @page.template.is_page?
4
+ small
5
+ =<> link_to page_path(@page), method: :delete, data: { confirm: 'You are about to delete this page. Are you sure?' }, class: "red" do
6
+ i.icon-trash
7
+ .right
8
+ = link_to "View Page", @page.url, class:"btn-large btn", target: '_blank'
4
9
 
5
10
  = simple_form_for @page, html: {:multipart => true} do |f|
6
11
  = f.error_notification
@@ -8,6 +13,10 @@ h1
8
13
 
9
14
  = render "url_field", f: f
10
15
 
16
+ - unless @page.template.is_page?
17
+ label Template
18
+ = @page.template.name
19
+
11
20
  = f.input :in_menu, label: false, inline_label: "Display in main menu?"
12
21
 
13
22
  = field_set_tag "SEO" do
@@ -19,23 +28,23 @@ h1
19
28
  = seo.input key, required: false
20
29
 
21
30
 
22
-
23
- - for part in @page.parts.sort_by(&:position)
24
- = f.simple_fields_for :parts, part do |g|
25
-
26
- = field_set_tag part.identifier.titleize do
27
- = g.error :base, class: "alert-error"
28
31
 
29
- / sort puts nil at the end, in the case of new parts
30
- - for subpart in part.subparts.sort{|a,b| a.position && b.position ? a.position <=> b.position : a.position ? -1 : 1 }
31
- = g.simple_fields_for :subparts, subpart do |y|
32
+ - @page.template_hash.each do |part_identifier, part_hash|
32
33
 
33
- = render "subpart_fields", f: y, subpart: subpart
34
+ = field_set_tag part_hash[:title] || part_identifier.titleize do
35
+
36
+ - if parts = @page.parts.select{|ob| ob.identifier == part_identifier}
37
+ - parts.sort!{|a,b| a.position && b.position ? a.position <=> b.position : a.position ? -1 : 1 }
38
+
39
+ - parts.each do |part|
40
+ = f.simple_fields_for :parts, part do |g|
41
+ = render "part_fields", f: g, part: part, part_hash: part_hash, part_identifier: part_identifier
34
42
 
35
- - if part.repeatable?
36
- .links
37
- / the "links" class is important for the cocoon gem
38
- = link_to_add_association "Add another #{part.identifier.singularize.titleize}", g, :subparts, :render_options => {:locals => {:subpart => part.new_subpart }}, class: "btn btn-block"
43
+ - if part_hash[:repeatable]
44
+ .links
45
+ / the "links" class is important for the cocoon gem
46
+ = link_to_add_association "Add another #{part_hash[:repeatable]}", f, :parts, render_options: {locals: {part_hash: part_hash, part: @page.parts.build(identifier: part_identifier), part_identifier: part_identifier}}, class: "btn btn-block"
47
+
39
48
 
40
49
  .form-actions
41
50
  = f.button :submit, "Save", class:"btn-primary"
@@ -0,0 +1,7 @@
1
+ h1 Create a new page
2
+
3
+ = simple_form_for @page do |f|
4
+ / = f.input :identifier, hint: "Pick a name for this page so it can be accessed from the code"
5
+ = f.input :title
6
+ = f.input :template_id, as: :select, collection: Cardboard::Template.where(is_page: false), :include_blank => false
7
+ = f.submit "Create", class: "btn"
@@ -1,9 +1,9 @@
1
- - if lookup_context.exists?(current_page.identifier, 'pages', false)
1
+ - if lookup_context.exists?(current_page.template.identifier, 'templates', false)
2
2
 
3
3
  - content_for :seo do
4
4
  = render "cardboard/pages/seo"
5
5
 
6
- = render template: "pages/#{current_page.identifier}"
6
+ = render template: "templates/#{current_page.template.identifier}"
7
7
 
8
8
  - elsif Rails.env.development?
9
- = render "cardboard/pages/error", missing_file: current_page.identifier
9
+ = render "cardboard/pages/error", missing_file: current_page.template.identifier
@@ -1,4 +1,4 @@
1
- = search_form_for @q, url: {}, :html =>{"data-pjax"=>true} do |f|
1
+ = search_form_for @q, url: {} do |f|
2
2
  = hidden_field_tag :s, "advanced"
3
3
  - (params[:q] || {}).each do |q,v|
4
4
  = f.hidden_field q, :value => v
@@ -1,5 +1,5 @@
1
- - models = klass.pluralize
2
- - model_title = klass.titleize
1
+ - models = klass.underscore.pluralize
2
+ - model_title = klass.demodulize.titleize
3
3
 
4
4
  table#filter_search_header
5
5
  tr
@@ -12,6 +12,6 @@ table#filter_search_header
12
12
 
13
13
  - if options[:new_button]
14
14
  td style="text-align:right"
15
- = link_to(options[:new_button][:label] || "New #{model_title}", options[:new_button][:url] || {controller: "cardboard/#{models}", action: :new}, class: "btn pull-right", style:"min-width:90px;")
15
+ = link_to(options[:new_button][:label] || "New #{model_title}", options[:new_button][:url] || {controller: models, action: :new}, class: "btn pull-right", style:"min-width:90px;")
16
16
 
17
17
 
@@ -1,4 +1,4 @@
1
- = search_form_for @q, url: {}, :html =>{"data-pjax"=>true} do |f|
1
+ = search_form_for @q, url: {} do |f|
2
2
  = hidden_field_tag :s, "simple"
3
3
 
4
4
  .input-append
@@ -2,7 +2,16 @@ h1 Settings
2
2
 
3
3
  - if @setting
4
4
  = simple_form_for @setting do |s|
5
- - for field in @setting.fields
6
- = s.fields_for :fields, field do |f|
7
- = render "cardboard/fields/#{field.type}", f: f rescue render "cardboard/fields/base_input", f: f
5
+ - @setting.template.each do |field_identifier, field|
6
+
7
+ - fields = @setting.fields.find{|ob| ob.identifier == field_identifier}
8
+ / - if fields.nil?
9
+ / - fields = @setting.fields.build(type: "Cardboard::Field::#{field[:type].camelize}", identifier: field_identifier, default: field[:default] )
10
+
11
+ = s.fields_for :fields, fields do |f|
12
+ - begin
13
+ = render "cardboard/fields/#{field[:type]}", f: f, field: field, identifier: field_identifier
14
+ - rescue ActionView::MissingTemplate => e
15
+ = render "cardboard/fields/base_input", f: f, field: field, identifier: field_identifier
16
+
8
17
  = s.button :submit
@@ -4,7 +4,7 @@
4
4
  - for part in page.parts
5
5
  .indent
6
6
  h3= part.identifier
7
- - for field in part.subparts.first.fields
7
+ - for field in part.fields
8
8
  .indent= field.identifier
9
9
 
10
10
  = content_tag(:div, subpages, class: "indent") if subpages.present?
@@ -1,6 +1,6 @@
1
1
  #menu
2
2
  - if Cardboard.used_as_cms? && cardboard_user_can_manage?(:pages)
3
- = main_sidebar_nav_link "Pages", pages_path, id: "nav_dashboard_link", "data-skip-pjax" => true
3
+ = main_sidebar_nav_link "Pages", pages_path, id: "nav_dashboard_link"
4
4
 
5
5
 
6
6
  - Cardboard.resource_controllers.reject{|x|x.menu == false}.sort! { |a,b| a.menu[:priority] <=> b.menu[:priority] }.each do |controller|
@@ -28,5 +28,5 @@
28
28
 
29
29
  ul.dropdown-menu
30
30
  li= link_to "Account", my_account_path
31
- li= link_to "Logout", main_app.send(Cardboard.application.logout_link_path), :method => :delete, "data-skip-pjax" => true
31
+ li= link_to "Logout", main_app.send(Cardboard.application.logout_link_path), :method => :delete
32
32
 
@@ -20,7 +20,7 @@ html lang=I18n.locale
20
20
  #content_sidebar class="#{'toggle' if params[:controller] =~ /pages/}"
21
21
  #pages_sidebar= render 'cardboard/pages/sidebar'
22
22
 
23
- #content.container-fluid(data-pjax-container class="#{'toggle' if params[:controller] =~ /pages/}")
23
+ #content.container-fluid class="#{'toggle' if params[:controller] =~ /pages/}"
24
24
  = render 'layouts/cardboard/flash_message'
25
25
  = yield
26
26
 
data/cardboard.gemspec CHANGED
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
41
41
  s.add_dependency 'dragonfly', '~> 1.0'
42
42
  s.add_dependency 'chronic'
43
43
  s.add_dependency 'ransack', '>= 1.0.0'
44
- s.add_dependency 'rack-pjax'
44
+ s.add_dependency 'turbolinks'
45
45
  s.add_dependency 'decorators'
46
46
  s.add_dependency 'jquery-ui-rails'
47
47
  s.add_dependency 'select2-rails'
data/config/routes.rb CHANGED
@@ -4,8 +4,10 @@ Cardboard::Engine.routes.draw do
4
4
  get "my_account", to: "my_account#edit"
5
5
  patch "my_account", to: "my_account#update"
6
6
 
7
+ get "pages/new", to: "pages#new"
7
8
  post "pages/sort", to: "pages#sort"
8
9
  get "pages/:id", to: "pages#edit"
10
+
9
11
  resources :pages
10
12
 
11
13
  get "/yoda", to: "super_user#index"
@@ -0,0 +1,63 @@
1
+ class CreateCardboard < ActiveRecord::Migration
2
+ def change
3
+ #Fields
4
+ create_table :cardboard_fields do |t|
5
+ t.string :identifier
6
+ t.string :type
7
+ t.text :value_uid
8
+ t.integer :object_with_field_id
9
+ t.string :object_with_field_type
10
+
11
+ t.timestamps
12
+ end
13
+ add_index :cardboard_fields, :identifier
14
+ add_index :cardboard_fields, [:object_with_field_id, :object_with_field_type], :name => 'parent_object'
15
+
16
+ #Page Parts
17
+ create_table :cardboard_page_parts do |t|
18
+ t.string :identifier
19
+ t.integer :position
20
+ t.belongs_to :page
21
+
22
+ t.timestamps
23
+ end
24
+ add_index :cardboard_page_parts, :page_id
25
+ add_index :cardboard_page_parts, :identifier
26
+
27
+ #Pages
28
+ create_table :cardboard_pages do |t|
29
+ t.string :title
30
+ t.string :path
31
+ t.string :slug
32
+ t.text :slugs_backup
33
+ t.integer :position
34
+ t.text :meta_seo
35
+ t.boolean :in_menu, default: true
36
+ t.string :identifier, unique: true
37
+ t.belongs_to :template
38
+
39
+ t.timestamps
40
+ end
41
+ add_index :cardboard_pages, [:path, :slug], :unique => true
42
+ add_index :cardboard_pages, :identifier, :unique => true
43
+
44
+ #Settings
45
+ create_table :cardboard_settings do |t|
46
+ t.string :name
47
+ t.text :value
48
+ t.text :default_value
49
+ t.text :template
50
+
51
+ end
52
+ add_index :cardboard_settings, :name
53
+
54
+ #Templates
55
+ create_table :cardboard_templates do |t|
56
+ t.string :name
57
+ t.text :fields
58
+ t.string :identifier
59
+ t.boolean :is_page
60
+ t.timestamps
61
+ end
62
+ end
63
+ end
@@ -15,7 +15,7 @@ require 'slim'
15
15
  require 'ransack'
16
16
  require 'kaminari'
17
17
  require 'kaminari-bootstrap'
18
- require 'rack-pjax'
18
+ require 'turbolinks'
19
19
  require 'jquery-ui-rails'
20
20
  require 'decorators'
21
21
  require 'bootstrap-wysihtml5-rails'
@@ -55,12 +55,6 @@ module Cardboard
55
55
 
56
56
  # Load custom resource controllers in development (already loaded in production)
57
57
  Cardboard.set_resource_controllers
58
- # if Rails.env.development?
59
- # Dir[Rails.root.join('app/controllers/cardboard/*_controller.rb')].map.each do |controller|
60
- # require_dependency controller
61
- # end
62
- # end
63
- # Cardboard.resource_controllers = Cardboard::AdminController.descendants
64
58
  end
65
59
 
66
60
  initializer "precompile hook", :group => :all do |app|
@@ -72,10 +66,6 @@ module Cardboard
72
66
  Dragonfly.app.fetch_file_whitelist.push(/app\/assets\/files/)
73
67
  end
74
68
 
75
- initializer "pjax hook" do |app|
76
- app.config.middleware.use Rack::Pjax
77
- end
78
-
79
69
  rake_tasks do
80
70
  Dir[File.join(File.dirname(__FILE__),'../tasks/*.rake')].each { |f| load f }
81
71
  end
@@ -5,41 +5,44 @@ module Cardboard
5
5
  module Seed
6
6
  extend ActiveSupport::Concern
7
7
 
8
- def self.populate_pages(filehash = nil)
9
- pages = filehash ? filehash[:pages] : {}
10
- pages.each do |id, page|
8
+ def self.populate_templates(templates)
9
+ templates ||= {}
10
+ templates.each do |id, template|
11
+ db_template = Cardboard::Template.where(identifier: id.to_s).first_or_initialize
12
+ db_template.update_attributes!(name: template[:title] || template[:name] || id.to_s, fields: template[:parts], is_page: false)
13
+ end
14
+ end
15
+
16
+ def self.populate_pages(pages)
17
+ pages ||= {}
11
18
 
19
+ # add the page
20
+ pages.each do |id, page|
21
+ # create the template
22
+ db_template = Cardboard::Template.where(identifier: id.to_s).first_or_initialize
23
+ db_template.update_attributes!(name: page[:title] || page[:name] || id.to_s, fields: page[:parts], is_page: true)
24
+
12
25
  db_page = Cardboard::Page.where(identifier: id.to_s).first_or_initialize
13
26
  db_page.position_position = page[:position] || :last
27
+ db_page.template = db_template
14
28
  db_page.update_attributes!(page.slice(:title, :parent_id))
15
29
 
16
30
  self.populate_parts(page[:parts], db_page)
17
31
  end
18
-
19
- for remove_page in Cardboard::Page.all.map(&:identifier) - pages.map{|k,v|k.to_s}
20
- Cardboard::Page.where(identifier: remove_page).first.destroy
21
- end
22
-
23
- Cardboard::Page.create(identifier: "index", path: "/") if Cardboard::Page.root.nil?
24
32
  end
25
33
 
26
-
27
34
  def self.populate_parts(page_parts, db_page)
35
+ # called from the page controller
28
36
  page_parts ||= {}
29
37
  page_parts.each do |id, part|
30
- db_part = db_page.parts.where(identifier: id.to_s).first_or_initialize
31
- db_part.part_position_position = part[:position] || :last
32
- db_part.update_attributes!(:repeatable => part[:repeatable])
33
-
34
- db_part.subparts.first_or_create!
35
38
 
36
- db_part.subparts.each do |db_part|
37
- self.populate_fields(part[:fields], db_part)
38
- end
39
- end
40
- for remove_part in db_page.parts.map(&:identifier) - page_parts.map{|k,v|k.to_s}
41
- db_page.parts.where(identifier: remove_part).first.destroy
39
+ db_part = db_page.parts.where(identifier: id.to_s).first_or_create
40
+
41
+ self.populate_fields(part[:fields], db_part)
42
42
  end
43
+ # for remove_part in db_page.parts.map(&:identifier) - page_parts.map{|k,v|k.to_s}
44
+ # db_page.parts.where(identifier: remove_part).first.destroy
45
+ # end
43
46
  end
44
47
 
45
48
  def self.populate_fields(fields, object)
@@ -48,9 +51,8 @@ module Cardboard
48
51
  db_field = Field.where(identifier: id.to_s, object_with_field: object).first_or_initialize
49
52
  db_field.type = "Cardboard::Field::#{(field[:type] || "string").camelize}"
50
53
  db_field.seeding = true
51
- db_field.position_position = field[:position] || :last
52
54
  begin
53
- db_field.update_attributes!(field.reject{|k,v| ["type", "position"].include?(k)})
55
+ db_field.update_attributes!(field.select{|k,v| ["default", "value"].include?(k)})
54
56
  rescue Exception => e
55
57
  # Output validation errors
56
58
  puts "-- ERROR --"
@@ -61,19 +63,18 @@ module Cardboard
61
63
  end
62
64
 
63
65
  #remove fields no longer in the seed file
64
- for remove_field in object.fields.map(&:identifier) - fields.map{|k,v|k.to_s}
65
- object.fields.where(identifier: remove_field).first.destroy
66
- end
66
+ # for remove_field in object.fields.map(&:identifier) - fields.map{|k,v|k.to_s}
67
+ # object.fields.where(identifier: remove_field).first.destroy
68
+ # end
67
69
  end
68
70
 
69
- def self.populate_settings(filehash = nil)
70
- settings = filehash ? filehash[:settings] : nil
71
+ def self.populate_settings(settings)
71
72
  if settings
72
73
  db_settings = Cardboard::Setting.first_or_create
74
+ db_settings.update_attributes!(template: settings)
73
75
  self.populate_fields(settings, db_settings)
74
76
  end
75
- Cardboard::Setting.add("company_name", type: "string", default: Cardboard.application.site_title, position: 0)
76
- # Cardboard::Setting.add("google_analytics", type: "string", position: 1)
77
+ Cardboard::Setting.add("company_name", type: "string", default: Cardboard.application.site_title, seeding: true)
77
78
  end
78
79
 
79
80
  end
@@ -1,3 +1,3 @@
1
1
  module Cardboard
2
- VERSION = "0.1.8"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/cardboard_cms.rb CHANGED
@@ -7,6 +7,10 @@ module Cardboard
7
7
 
8
8
  attr_accessor :application, :resource_controllers
9
9
 
10
+ def resource_controllers
11
+ @resource_controllers ||= Cardboard::ResourceController.descendants
12
+ end
13
+
10
14
  def application
11
15
  @application ||= ::Cardboard::Application.new
12
16
  end
@@ -17,15 +21,15 @@ module Cardboard
17
21
  end
18
22
 
19
23
  def used_as_cms?
20
- @used_as_cms = Cardboard::Page.count > 0 if @used_as_cms.nil? #handle false
24
+ @used_as_cms = Cardboard::Template.count > 0 if @used_as_cms.nil? #handle false
21
25
  @used_as_cms
22
26
  end
23
27
 
24
28
  def set_resource_controllers
29
+ # might not be needed in production
25
30
  Dir[Rails.root.join('app/controllers/cardboard/*_controller.rb')].map.each do |controller|
26
31
  require_dependency controller
27
32
  end
28
- Cardboard.resource_controllers = Cardboard::ResourceController.descendants
29
33
  end
30
34
 
31
35
  # Gets called within the initializer
@@ -50,7 +50,7 @@ module Cardboard
50
50
 
51
51
  def setup_directory
52
52
  empty_directory "app/controllers/cardboard"
53
- empty_directory "app/views/pages"
53
+ empty_directory "app/views/templates"
54
54
  end
55
55
 
56
56
  def setup_routes
@@ -63,20 +63,12 @@ module Cardboard
63
63
  generate "cardboard:assets"
64
64
  end
65
65
 
66
- def create_migrations
67
- p "Copying over migrations..."
68
- Dir["#{self.class.source_root}/migrations/*.rb"].sort.each do |filepath|
69
- name = File.basename(filepath)
70
- migration_template "migrations/#{name}", "db/migrate/#{name.gsub(/^\d+_/,'')}"
71
- sleep 1
66
+ def install_migrations
67
+ puts "Copying over migrations..."
68
+ Dir.chdir(Rails.root) do
69
+ `rake cardboard:install:migrations`
72
70
  end
73
71
  end
74
- # def install_migrations
75
- # puts "Copying over migrations..."
76
- # Dir.chdir(Rails.root) do
77
- # `rake cardboard:install:migrations`
78
- # end
79
- # end
80
72
 
81
73
  protected
82
74
 
@@ -14,9 +14,11 @@ task 'cardboard:seed' => :environment do
14
14
  puts "Error: You must first create a cardboard.yml file in your application config folder"
15
15
  end
16
16
 
17
-
18
- Cardboard::Seed.populate_pages(file_hash)
19
- Cardboard::Seed.populate_settings(file_hash)
17
+ if file_hash
18
+ Cardboard::Seed.populate_pages(file_hash[:pages])
19
+ Cardboard::Seed.populate_templates(file_hash[:templates])
20
+ Cardboard::Seed.populate_settings(file_hash[:settings])
21
+ end
20
22
 
21
23
  end
22
24
 
@@ -0,0 +1,5 @@
1
+ h1 This is the home page
2
+
3
+ | which was edited
4
+
5
+ = current_page.get("intro.text1")
@@ -1,5 +1,5 @@
1
1
 
2
- pages:
2
+ templates:
3
3
  #---
4
4
  home:
5
5
  title: Welcome