cms9 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +192 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/config/cms9_manifest.js +2 -0
  6. data/app/assets/images/cms9/cms9_logo.png +0 -0
  7. data/app/assets/images/cms9/cms9_logo_readme.png +0 -0
  8. data/app/assets/images/cms9/favicon-128.png +0 -0
  9. data/app/assets/images/cms9/favicon-16.png +0 -0
  10. data/app/assets/images/cms9/favicon-32.png +0 -0
  11. data/app/assets/images/cms9/favicon-64.png +0 -0
  12. data/app/assets/images/cms9/iCheck/flat/blue.png +0 -0
  13. data/app/assets/images/cms9/iCheck/flat/blue@2x.png +0 -0
  14. data/app/assets/javascripts/cms9/admin_lte.js +763 -0
  15. data/app/assets/javascripts/cms9/application.js +18 -0
  16. data/app/assets/javascripts/cms9/cable.js +13 -0
  17. data/app/assets/javascripts/cms9/multiple_values_selection.js +70 -0
  18. data/app/assets/javascripts/cms9/post_fields.js +5 -0
  19. data/app/assets/javascripts/cms9/posts.js +37 -0
  20. data/app/assets/stylesheets/cms9/admin_lte.scss +4932 -0
  21. data/app/assets/stylesheets/cms9/admin_lte_skins.css +1770 -0
  22. data/app/assets/stylesheets/cms9/application.scss +7 -0
  23. data/app/assets/stylesheets/cms9/fields.scss +3 -0
  24. data/app/assets/stylesheets/cms9/post_definitions.scss +28 -0
  25. data/app/assets/stylesheets/cms9/posts.scss +3 -0
  26. data/app/assets/stylesheets/cms9/welcome.scss +20 -0
  27. data/app/controllers/cms9/application_controller.rb +34 -0
  28. data/app/controllers/cms9/fields_controller.rb +4 -0
  29. data/app/controllers/cms9/post_definitions_controller.rb +85 -0
  30. data/app/controllers/cms9/post_fields_controller.rb +108 -0
  31. data/app/controllers/cms9/posts_controller.rb +76 -0
  32. data/app/controllers/cms9/welcome_controller.rb +8 -0
  33. data/app/helpers/cms9/application_helper.rb +58 -0
  34. data/app/helpers/cms9/fields_helper.rb +4 -0
  35. data/app/helpers/cms9/post_definitions_helper.rb +4 -0
  36. data/app/helpers/cms9/post_fields_helper.rb +4 -0
  37. data/app/helpers/cms9/posts_helper.rb +4 -0
  38. data/app/helpers/cms9/welcome_helper.rb +4 -0
  39. data/app/jobs/cms9/application_job.rb +4 -0
  40. data/app/mailers/cms9/application_mailer.rb +6 -0
  41. data/app/models/ckeditor/asset.rb +9 -0
  42. data/app/models/ckeditor/attachment_file.rb +9 -0
  43. data/app/models/ckeditor/picture.rb +14 -0
  44. data/app/models/cms9/application_record.rb +5 -0
  45. data/app/models/cms9/event.rb +7 -0
  46. data/app/models/cms9/field.rb +20 -0
  47. data/app/models/cms9/post.rb +16 -0
  48. data/app/models/cms9/post_definition.rb +25 -0
  49. data/app/models/cms9/post_field.rb +23 -0
  50. data/app/views/cms9/fields/index.html.erb +0 -0
  51. data/app/views/cms9/post_definitions/edit.html.erb +81 -0
  52. data/app/views/cms9/post_definitions/index.html.erb +48 -0
  53. data/app/views/cms9/post_definitions/new.html.erb +41 -0
  54. data/app/views/cms9/post_fields/_field_form.html.erb +46 -0
  55. data/app/views/cms9/post_fields/_image_sizer.html.erb +2 -0
  56. data/app/views/cms9/post_fields/_select.html.erb +24 -0
  57. data/app/views/cms9/post_fields/_select_blank.html.erb +10 -0
  58. data/app/views/cms9/post_fields/edit.html.erb +14 -0
  59. data/app/views/cms9/post_fields/new.html.erb +14 -0
  60. data/app/views/cms9/posts/_post_form.html.erb +13 -0
  61. data/app/views/cms9/posts/edit.html.erb +14 -0
  62. data/app/views/cms9/posts/index.html.erb +42 -0
  63. data/app/views/cms9/posts/inputs/_date.html.erb +2 -0
  64. data/app/views/cms9/posts/inputs/_date_time.html.erb +2 -0
  65. data/app/views/cms9/posts/inputs/_image.html.erb +19 -0
  66. data/app/views/cms9/posts/inputs/_number.html.erb +2 -0
  67. data/app/views/cms9/posts/inputs/_select_multiple.html.erb +7 -0
  68. data/app/views/cms9/posts/inputs/_select_single.html.erb +2 -0
  69. data/app/views/cms9/posts/inputs/_text.html.erb +2 -0
  70. data/app/views/cms9/posts/inputs/_text_area.html.erb +2 -0
  71. data/app/views/cms9/posts/inputs/_time.html.erb +2 -0
  72. data/app/views/cms9/posts/new.html.erb +14 -0
  73. data/app/views/cms9/welcome/_post.html.erb +46 -0
  74. data/app/views/cms9/welcome/_post_definition.html.erb +36 -0
  75. data/app/views/cms9/welcome/index.html.erb +57 -0
  76. data/app/views/layouts/cms9/application.html.erb +100 -0
  77. data/config/initializers/assets.rb +4 -0
  78. data/config/initializers/ckeditor.rb +59 -0
  79. data/config/initializers/ckeditor_dragonfly.rb +19 -0
  80. data/config/initializers/ckeditor_init.rb +3 -0
  81. data/config/initializers/dragonfly.rb +26 -0
  82. data/config/routes.rb +11 -0
  83. data/db/migrate/cms9_create.rb +73 -0
  84. data/db/schema.rb +49 -0
  85. data/db/seeds.rb +7 -0
  86. data/lib/cms9.rb +24 -0
  87. data/lib/cms9/engine.rb +24 -0
  88. data/lib/cms9/version.rb +3 -0
  89. data/lib/events/cms9_events.rb +50 -0
  90. data/lib/generators/cms9/install/install_generator.rb +81 -0
  91. data/lib/generators/cms9/install/templates/ckeditor_config.js +14 -0
  92. data/lib/generators/cms9/install/templates/cms9_configurator.rb +4 -0
  93. data/lib/sdk/cms9.rb +138 -0
  94. data/lib/tasks/cms9_tasks.rake +4 -0
  95. metadata +423 -0
@@ -0,0 +1,4 @@
1
+ module Cms9
2
+ module FieldsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Cms9
2
+ module PostDefinitionsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Cms9
2
+ module PostFieldsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Cms9
2
+ module PostsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Cms9
2
+ module WelcomeHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Cms9
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Cms9
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ module Cms9
2
+ class Ckeditor::Asset < ActiveRecord::Base
3
+ include Ckeditor::Orm::ActiveRecord::AssetBase
4
+ include Ckeditor::Backend::Dragonfly
5
+
6
+ dragonfly_accessor :data, app: :ckeditor
7
+ validates :data, presence: true
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Cms9
2
+ class Ckeditor::AttachmentFile < Ckeditor::Asset
3
+ validates_property :ext, of: :data, in: attachment_file_types unless attachment_file_types.empty?
4
+
5
+ def url_thumb
6
+ Ckeditor::Utils.filethumb(filename)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module Cms9
2
+ class Ckeditor::Picture < Ckeditor::Asset
3
+ validates_property :format, of: :data, in: image_file_types unless image_file_types.empty?
4
+ validates_property :image?, of: :data, as: true, message: :invalid
5
+
6
+ def url_content
7
+ data.thumb('800x800>').url
8
+ end
9
+
10
+ def url_thumb
11
+ data.thumb('118x100#').url(url_thumb_options)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Cms9
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Cms9
2
+ class Event < ApplicationRecord
3
+ belongs_to :post
4
+ belongs_to :post_definition
5
+ belongs_to :post_field
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ module Cms9
2
+ class Field < ApplicationRecord
3
+ belongs_to :post_field
4
+ belongs_to :post, optional: true
5
+ dragonfly_accessor :image
6
+
7
+ def to_s
8
+ case self.post_field.field_type
9
+ when 'text', 'text_area', 'number', 'select_single', 'date', 'time', 'date_time'
10
+ return self.value
11
+ when 'select_multiple'
12
+ return self.value.split(',')
13
+ when 'image'
14
+ return !self.image_uid.blank? ? self.image.url : ''
15
+ else
16
+ return ''
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ module Cms9
2
+ class Post < ApplicationRecord
3
+ belongs_to :post_definition
4
+ has_many :fields, dependent: :destroy
5
+
6
+ accepts_nested_attributes_for :fields
7
+
8
+ def field(name)
9
+ @cache_fields ||= self.fields.joins(:post_field).includes(:post_field)
10
+ .map { |field| [field.post_field.name, field] }
11
+ .to_h
12
+ @cache_fields[name]
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ module Cms9
2
+ class PostDefinition < ApplicationRecord
3
+ validates :name, presence: true, uniqueness: { case_sensitive: false },
4
+ length: { minimum: 3 }
5
+
6
+ has_many :post_fields, dependent: :destroy
7
+ has_many :posts, dependent: :destroy
8
+
9
+
10
+ def fields
11
+ if @cache_fields.nil?
12
+ @cache_fields = self.post_fields.map { |field| [field.name, field] }.to_h
13
+ end
14
+
15
+ @cache_fields.values
16
+ end
17
+
18
+ # Get field by name
19
+ def field(name)
20
+ fields()
21
+ @cache_fields[name]
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ module Cms9
2
+ class PostField < ApplicationRecord
3
+ validates :name, presence: true, length: { minimum:3, maximum: 15 }
4
+ validates :field_type, presence: true
5
+
6
+ belongs_to :post_definition
7
+ attr_accessor :multi_values
8
+
9
+ def self.all_types
10
+ return [
11
+ { key: 'text', display_name: 'Text' },
12
+ { key: 'text_area', display_name: 'Text Area' },
13
+ { key: 'number', display_name: 'Number'},
14
+ { key: 'select_single', display_name: 'Select Single' },
15
+ { key: 'select_multiple', display_name: 'Select Multiple' },
16
+ { key: 'date', display_name: 'Date' },
17
+ { key: 'time', display_name: 'Time' },
18
+ { key: 'date_time', display_name: 'Date & Time' },
19
+ { key: 'image', display_name: 'Image' }
20
+ ]
21
+ end
22
+ end
23
+ end
File without changes
@@ -0,0 +1,81 @@
1
+ <div class="row">
2
+ <div class="col-md-12">
3
+ <div class="box box-info">
4
+ <div class="box-header">
5
+ <h3 class="box-title">
6
+ Edit Post Type
7
+ </h3>
8
+ </div>
9
+ <div class="box-body">
10
+ <h3><%= @post.name %></h3>
11
+ <%= form_for @post do |f| %>
12
+ <% if @post.errors.any? %>
13
+
14
+ <div class="callout callout-danger">
15
+ <h4>
16
+ <%= pluralize(@post.errors.count, "error") %> prohibited
17
+ this from being saved:
18
+ </h4>
19
+
20
+ <div>
21
+ <% @post.errors.full_messages.each do |msg| %>
22
+ <p><%= msg %></p>
23
+ <% end %>
24
+ </div>
25
+ </div>
26
+
27
+ <% end %>
28
+
29
+ <%= f.label :name %><br>
30
+
31
+ <div class="input-group">
32
+ <%= f.text_field :name, { class: "form-control", required: true } %>
33
+
34
+ <div class="input-group-btn">
35
+ <%= f.submit class: 'btn btn-primary'%>
36
+ </div>
37
+ </div>
38
+ <% end %>
39
+
40
+ <hr/>
41
+ <!-- ///////////// -->
42
+
43
+ <h4>Fields</h4>
44
+ <%= link_to 'Add Field', new_post_field_path(post_definition_id: @post.id, post: @post.name), { class: 'btn btn-primary', style: 'margin-bottom: 30px; margin-top: 15px'} %>
45
+ <table class="table">
46
+ <thead>
47
+ <th>Name</th>
48
+ <th>Type</th>
49
+ <th>Required</th>
50
+ <th></th>
51
+ </thead>
52
+ <tbody>
53
+ <% @post.post_fields.each do |field| %>
54
+ <tr>
55
+ <td><%= field.name %></td>
56
+ <td><%= Cms9::PostField.all_types.find { |h| h[:key] == field.field_type }[:display_name] %></td>
57
+ <td class="required-field-icons">
58
+ <% if field.required %>
59
+ <i class="fa fa-check" aria-hidden="true"></i>
60
+ <% else %>
61
+ <i class="fa fa-times" aria-hidden="true"></i>
62
+ <% end %>
63
+ </td>
64
+ <td style="text-align: right;">
65
+ <% if field != @post.post_fields.all.first %>
66
+ <%= link_to "Edit", edit_post_field_path(field, { post: @post.name }),
67
+ class: 'btn btn-primary btn-sm'%>
68
+ <%= link_to "Delete", post_field_path(field),
69
+ method: :delete,
70
+ data: { confirm: 'Are you sure?' },
71
+ class: 'btn btn-danger btn-sm'%>
72
+ <% end %></td>
73
+ </tr>
74
+ <% end %>
75
+ </tbody>
76
+ </table>
77
+
78
+ </div>
79
+ </div>
80
+ </div>
81
+ </div>
@@ -0,0 +1,48 @@
1
+ <div class="row">
2
+ <div class="col-md-12">
3
+ <div class="box box-info">
4
+ <div class="box-header">
5
+ <i class="fa fa-folder"></i>
6
+ <h3 class="box-title">Post Types</h3>
7
+
8
+ <div class="pull-right box-tools">
9
+ <%= link_to 'New Post Type', new_post_definition_path, class: 'btn btn-primary' %>
10
+ </div>
11
+ </div>
12
+ <div class="box-body">
13
+ <table class="table table-striped">
14
+ <thead>
15
+ <tr>
16
+ <th>Name</th>
17
+ <th style="width:20px;">Count</th>
18
+ <th style="width:120px;">Created</th>
19
+ <th style="width:120px;">Last Update</th>
20
+ <th style="width:140px;">Actions</th>
21
+ </tr>
22
+ </thead>
23
+
24
+ <tbody>
25
+ <% @posts.each do |post| %>
26
+ <tr>
27
+ <td><%= post.name %></td>
28
+ <td><%= Cms9::Post.where(post_definition: post).count %></td>
29
+ <td><%= distance_of_time_in_words_to_now(post.created_at) %></td>
30
+ <td>User #<%= post.user_id %></td>
31
+ <td>
32
+ <%= link_to "Edit", edit_post_definition_path(post),
33
+ class: 'btn btn-primary btn-sm'%>
34
+ <%= link_to "Delete", post_definition_path(post),
35
+ method: :delete,
36
+ data: { confirm: 'Are you sure?' },
37
+ class: 'btn btn-danger btn-sm'%>
38
+ </td>
39
+ </tr>
40
+ <% end %>
41
+ </tbody>
42
+ <%= paginate @posts %>
43
+ </table>
44
+
45
+ </div>
46
+ </div>
47
+ </div>
48
+ </div>
@@ -0,0 +1,41 @@
1
+ <div class="row">
2
+ <div class="col-md-12">
3
+ <div class="box box-info">
4
+ <div class="box-header">
5
+ <h3 class="box-title">
6
+ New Post Definition
7
+ </h3>
8
+ </div>
9
+ <div class="box-body">
10
+ <%= form_for @post do |f| %>
11
+
12
+ <% if @post.errors.any? %>
13
+
14
+ <div class="callout callout-danger">
15
+ <h4>
16
+ <%= pluralize(@post.errors.count, "error") %> prohibited
17
+ this article from being saved:
18
+ </h4>
19
+
20
+ <div>
21
+ <% @post.errors.full_messages.each do |msg| %>
22
+ <p><%= msg %></p>
23
+ <% end %>
24
+ </div>
25
+ </div>
26
+
27
+ <% end %>
28
+
29
+ <div class="form-group">
30
+ <%= f.label :name %><br>
31
+ <%= f.text_field :name, { class: "form-control", required: true } %>
32
+ </div>
33
+
34
+ <%= f.submit class: 'btn btn-primary' %>
35
+
36
+ <% end %>
37
+
38
+ </div>
39
+ </div>
40
+ </div>
41
+ </div>
@@ -0,0 +1,46 @@
1
+ <%= form_for @field do |f| %>
2
+ <% if @field.errors.any? %>
3
+
4
+ <div class="callout callout-danger">
5
+ <h4>
6
+ <%= pluralize(@field.errors.count, "error") %> prohibited
7
+ this article from being saved:
8
+ </h4>
9
+
10
+ <div>
11
+ <% @field.errors.full_messages.each do |msg| %>
12
+ <p><%= msg %></p>
13
+ <% end %>
14
+ </div>
15
+ </div>
16
+
17
+ <% end %>
18
+
19
+ <%= f.label :name %><br>
20
+ <%= f.text_field :name, { class: "form-control", required: true }%>
21
+ <%= f.label :field_type %><br>
22
+ <%= f.select :field_type, Cms9::PostField.all_types.map { |a| [a[:display_name], a[:key]] },
23
+ { prompt: 'Select Type' }, { class: 'form-control type-selector', disabled: edit, required: true } %>
24
+
25
+ <div id="valueSet" style="display: none;">
26
+ <p style="margin-top: 20px; font-weight: bold;">Multiple choices (naming without special characters)</p>
27
+ <%= render 'select', { f: f, edit: edit } %>
28
+ </div>
29
+ <a href="javascript:;" id="addNewValue" class="btn btn-primary btn-sm" style="visibility: hidden;">Add New Choice</a>
30
+
31
+ <div id="selector_" style="display: none;">
32
+ <%= render 'select_blank', { f: f } %>
33
+ </div>
34
+
35
+ <div id="image_sizer" style="display: none;">
36
+ <%= render 'image_sizer', { f: f } %>
37
+ </div>
38
+
39
+ <div class="checkbox" style="margin-top: 10px;">
40
+ <span style="margin-right: 30px;">Required</span>
41
+ <%= hidden_field_tag :required, false %>
42
+ <%= f.check_box :required, {}, true %>
43
+ </div>
44
+ <%= f.hidden_field :post_definition_id %>
45
+ <%= f.submit class: 'btn btn-primary', style: 'margin-top: 30px;' %>
46
+ <% end %>
@@ -0,0 +1,2 @@
1
+ <label>Image size (e.g 300x200, 400x, 300x300#)</label>
2
+ <%= f.text_field :metadata, { class: 'form-control image-sizer' }%>
@@ -0,0 +1,24 @@
1
+ <% if edit && ( @field.field_type == 'select_single' || @field.field_type == 'select_multiple' ) %>
2
+ <% @field.metadata.split(',').each do |input| %>
3
+ <% if !input.blank? %>
4
+ <div class="multi-block col-md-12" style="padding: 0;">
5
+ <div class="col-md-10 input-group" style="padding: 0; margin-bottom: 10px;">
6
+ <%= text_field_tag 'multi_values[]', input, { class: 'form-control multi-pick', pattern: '^[\w ]+$', required: true } %>
7
+ <% if !(@field.metadata.split(',').first == input) %>
8
+ <div class="input-group-btn">
9
+ <a href="javascript:;" onclick="deleteChoice(this)" class="btn btn-danger btn-delete-choice">
10
+ <i class="fa fa-trash-o" aria-hidden="true"></i>
11
+ </a>
12
+ </div>
13
+ <% end %>
14
+ </div>
15
+ </div>
16
+ <% end %>
17
+ <% end %>
18
+ <% else %>
19
+ <div class="multi-block col-md-12" style="padding: 0;">
20
+ <div class="col-md-10" style="padding: 0; margin-bottom: 10px;">
21
+ <%= text_field_tag 'multi_values[]', nil, { class: 'form-control multi-pick', pattern: '^[\w ]+$', required: false } %>
22
+ </div>
23
+ </div>
24
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <div class="multi-block col-md-12" style="padding: 0;">
2
+ <div class="col-md-10 input-group" style="padding: 0; margin-bottom: 10px;">
3
+ <%= text_field_tag 'multi_values[]', nil, { class: 'form-control multi-pick', pattern: '^[\w ]+$', required: false } %>
4
+ <div class="input-group-btn">
5
+ <a href="javascript:;" onclick="deleteChoice(this)" class="btn btn-danger btn-delete-choice">
6
+ <i class="fa fa-trash-o" aria-hidden="true"></i>
7
+ </a>
8
+ </div>
9
+ </div>
10
+ </div>