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.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -5
- data/README.md +14 -14
- data/app/assets/javascripts/cardboard/admin.js +3 -24
- data/app/assets/javascripts/cardboard/datepicker.js +1 -5
- data/app/assets/javascripts/cardboard/rich_text.js +1 -1
- data/app/assets/javascripts/cardboard/search_filter.js +1 -1
- data/app/assets/stylesheets/cardboard/_bootstrap-select.css.scss +1 -1
- data/app/assets/stylesheets/cardboard/_framework.css.scss +1 -1
- data/app/assets/stylesheets/cardboard/_main_topbar.css.scss +1 -1
- data/app/controllers/cardboard/pages_controller.rb +25 -1
- data/app/controllers/pages_controller.rb +12 -11
- data/app/helpers/cardboard/resource_helper.rb +1 -1
- data/app/models/cardboard/field/boolean.rb +1 -1
- data/app/models/cardboard/field.rb +21 -9
- data/app/models/cardboard/page.rb +19 -30
- data/app/models/cardboard/page_part.rb +13 -46
- data/app/models/cardboard/setting.rb +3 -0
- data/app/models/cardboard/template.rb +15 -0
- data/app/views/cardboard/fields/_base_input.html.slim +1 -1
- data/app/views/cardboard/fields/_boolean.html.slim +2 -2
- data/app/views/cardboard/fields/_date.html.slim +1 -1
- data/app/views/cardboard/fields/_external_link.html.slim +2 -2
- data/app/views/cardboard/fields/_file.html.slim +4 -4
- data/app/views/cardboard/fields/_image.html.slim +2 -2
- data/app/views/cardboard/fields/_resource_link.html.slim +2 -2
- data/app/views/cardboard/fields/_rich_text.html.slim +1 -1
- data/app/views/cardboard/fields/_string.html.slim +1 -1
- data/app/views/cardboard/pages/_error.html.slim +1 -1
- data/app/views/cardboard/pages/_part_fields.html.slim +19 -0
- data/app/views/cardboard/pages/_sidebar.html.slim +8 -4
- data/app/views/cardboard/pages/_url_field.html.slim +6 -8
- data/app/views/cardboard/pages/edit.html.slim +24 -15
- data/app/views/cardboard/pages/new.html.slim +7 -0
- data/app/views/cardboard/pages/show.html.slim +3 -3
- data/app/views/cardboard/resources/_advanced_search.html.slim +1 -1
- data/app/views/cardboard/resources/_search_helper.html.slim +3 -3
- data/app/views/cardboard/resources/_simple_search.html.slim +1 -1
- data/app/views/cardboard/settings/index.html.slim +12 -3
- data/app/views/cardboard/super_user/index.html.slim +1 -1
- data/app/views/layouts/cardboard/_main_sidebar.html.slim +1 -1
- data/app/views/layouts/cardboard/_main_topbar.html.slim +1 -1
- data/app/views/layouts/cardboard/application.html.slim +1 -1
- data/cardboard.gemspec +1 -1
- data/config/routes.rb +2 -0
- data/db/migrate/1_create_cardboard.rb +63 -0
- data/lib/cardboard/engine.rb +1 -11
- data/lib/cardboard/helpers/seed.rb +31 -30
- data/lib/cardboard/version.rb +1 -1
- data/lib/cardboard_cms.rb +6 -2
- data/lib/generators/cardboard/install/install_generator.rb +5 -13
- data/lib/tasks/cardboard_tasks.rake +5 -3
- data/test/dummy/app/views/{pages → templates}/about-us.html.slim +0 -0
- data/test/dummy/app/views/templates/home.html.slim +5 -0
- data/test/dummy/config/cardboard.yml +1 -1
- data/test/dummy/db/schema.rb +7 -39
- data/test/dummy/db/seeds.rb +1 -1
- data/test/factories.rb +40 -1
- data/test/integration/page_editing_test.rb +2 -1
- data/test/integration/seeding_test.rb +16 -31
- data/test/models/field_test.rb +42 -28
- data/test/models/page_test.rb +1 -1
- data/test/models/template_test.rb +11 -0
- data/test/test_helper.rb +5 -1
- metadata +13 -29
- data/app/views/cardboard/pages/_subpart_fields.html.slim +0 -20
- data/lib/generators/cardboard/install/templates/migrations/1_create_cardboard_fields.rb +0 -21
- data/lib/generators/cardboard/install/templates/migrations/2_create_cardboard_page_parts.rb +0 -17
- data/lib/generators/cardboard/install/templates/migrations/3_create_cardboard_pages.rb +0 -18
- data/lib/generators/cardboard/install/templates/migrations/4_create_cardboard_settings.rb +0 -14
- data/test/dummy/app/views/pages/home.html.slim +0 -3
- data/test/dummy/db/migrate/20130426021522_create_news_posts.rb +0 -10
- data/test/dummy/db/migrate/20130501195423_create_icescreams.rb +0 -10
- data/test/dummy/db/migrate/20130502165540_create_beans.rb +0 -12
- data/test/dummy/db/migrate/20130522151358_create_cardboard_fields.rb +0 -21
- data/test/dummy/db/migrate/20130522151359_create_cardboard_page_parts.rb +0 -17
- data/test/dummy/db/migrate/20130522151400_create_cardboard_pages.rb +0 -18
- data/test/dummy/db/migrate/20130522151401_create_cardboard_settings.rb +0 -14
- data/test/dummy/db/migrate/20130607132558_create_admins.rb +0 -9
- data/vendor/assets/javascripts/cardboard/jquery.pjax.js +0 -840
@@ -1 +1 @@
|
|
1
|
-
= f.input :value, label:
|
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:
|
2
|
-
= link_to
|
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:
|
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
|
4
|
-
p= link_to "#{f.object.value.name} (#{number_to_human_size f.object.value.size})", f.object.value.url
|
5
|
-
- unless
|
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:
|
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
|
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:
|
2
|
-
= link_to
|
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:
|
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:
|
1
|
+
= f.input :value, label: field[:label] || identifier.titleize, as: field[:type], hint: field[:hint], placeholder: field[:placeholder], required: field[:required] != false
|
@@ -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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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, '
|
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: "
|
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,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:
|
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
|
|
@@ -2,7 +2,16 @@ h1 Settings
|
|
2
2
|
|
3
3
|
- if @setting
|
4
4
|
= simple_form_for @setting do |s|
|
5
|
-
-
|
6
|
-
|
7
|
-
|
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
|
@@ -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"
|
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
|
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
|
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 '
|
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
|
data/lib/cardboard/engine.rb
CHANGED
@@ -15,7 +15,7 @@ require 'slim'
|
|
15
15
|
require 'ransack'
|
16
16
|
require 'kaminari'
|
17
17
|
require 'kaminari-bootstrap'
|
18
|
-
require '
|
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.
|
9
|
-
|
10
|
-
|
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.
|
37
|
-
|
38
|
-
|
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.
|
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
|
-
|
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(
|
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,
|
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
|
data/lib/cardboard/version.rb
CHANGED
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::
|
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/
|
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
|
67
|
-
|
68
|
-
Dir
|
69
|
-
|
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
|
-
|
19
|
-
|
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
|
|
File without changes
|