guider_cms 1.4.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 (67) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +133 -0
  4. data/Rakefile +32 -0
  5. data/app/assets/config/guider_cms_manifest.js +4 -0
  6. data/app/assets/images/guider_cms/down.jpg +0 -0
  7. data/app/assets/images/guider_cms/down.png +0 -0
  8. data/app/assets/images/guider_cms/up.png +0 -0
  9. data/app/assets/stylesheets/guider_cms/application.css +78 -0
  10. data/app/assets/stylesheets/guider_cms/articles.css +18 -0
  11. data/app/assets/stylesheets/guider_cms/categories.css +4 -0
  12. data/app/assets/stylesheets/guider_cms/current_user_articles.css +4 -0
  13. data/app/assets/stylesheets/guider_cms/subcategories.css +4 -0
  14. data/app/assets/stylesheets/scaffold.css +80 -0
  15. data/app/controllers/guider_cms/application_controller.rb +6 -0
  16. data/app/controllers/guider_cms/articles_controller.rb +232 -0
  17. data/app/controllers/guider_cms/categories_controller.rb +112 -0
  18. data/app/controllers/guider_cms/current_user_articles_controller.rb +14 -0
  19. data/app/controllers/guider_cms/subcategories_controller.rb +35 -0
  20. data/app/helpers/guider_cms/application_helper.rb +70 -0
  21. data/app/helpers/guider_cms/articles_helper.rb +32 -0
  22. data/app/helpers/guider_cms/categories_helper.rb +4 -0
  23. data/app/helpers/guider_cms/current_user_articles_helper.rb +4 -0
  24. data/app/helpers/guider_cms/subcategories_helper.rb +4 -0
  25. data/app/jobs/guider_cms/application_job.rb +4 -0
  26. data/app/mailers/guider_cms/application_mailer.rb +6 -0
  27. data/app/models/guider_cms/application_record.rb +5 -0
  28. data/app/models/guider_cms/article.rb +26 -0
  29. data/app/models/guider_cms/category.rb +10 -0
  30. data/app/views/guider_cms/articles/_form.html.erb +51 -0
  31. data/app/views/guider_cms/articles/edit.html.erb +5 -0
  32. data/app/views/guider_cms/articles/index.html.erb +540 -0
  33. data/app/views/guider_cms/articles/new.html.erb +5 -0
  34. data/app/views/guider_cms/articles/show.html.erb +68 -0
  35. data/app/views/guider_cms/categories/_form.html.erb +50 -0
  36. data/app/views/guider_cms/categories/edit.html.erb +6 -0
  37. data/app/views/guider_cms/categories/index.html.erb +76 -0
  38. data/app/views/guider_cms/categories/new.html.erb +7 -0
  39. data/app/views/guider_cms/current_user_articles/index.html.erb +32 -0
  40. data/app/views/guider_cms/subcategories/_form.html.erb +15 -0
  41. data/app/views/guider_cms/subcategories/new.html.erb +5 -0
  42. data/app/views/layouts/guider_cms/application.html.erb +22 -0
  43. data/config/initializers/friendly_id.rb +107 -0
  44. data/config/initializers/kaminari_config.rb +14 -0
  45. data/config/routes.rb +53 -0
  46. data/db/migrate/20200823094047_create_guider_cms_categories.rb +9 -0
  47. data/db/migrate/20200823094214_create_guider_cms_articles.rb +13 -0
  48. data/db/migrate/20200823095230_add_parent_id_to_guider_cms_categories.rb +5 -0
  49. data/db/migrate/20200823095828_create_guider_cms_category_hierarchies.rb +16 -0
  50. data/db/migrate/20200823095934_add_is_root_category_ro_guider_categories.rb +5 -0
  51. data/db/migrate/20200823100111_add_slug_to_articles.rb +6 -0
  52. data/db/migrate/20200823100118_create_friendly_id_slugs.rb +21 -0
  53. data/db/migrate/20200824104656_add_slug_to_guider_cms_categories.rb +6 -0
  54. data/db/migrate/20200827170106_add_view_type_to_guider_categories.rb +5 -0
  55. data/db/migrate/20200831182803_add_keywords_to_guider_cms_articles.rb +5 -0
  56. data/db/migrate/20200902203407_add_position_to_guider_cms_articles.rb +5 -0
  57. data/lib/generators/guider_cms/controller_generator.rb +33 -0
  58. data/lib/generators/guider_cms/install_generator.rb +34 -0
  59. data/lib/generators/guider_cms/routes_generator.rb +34 -0
  60. data/lib/generators/guider_cms/views_generator.rb +35 -0
  61. data/lib/generators/templates/README +20 -0
  62. data/lib/generators/templates/guider_cms.rb +4 -0
  63. data/lib/guider_cms.rb +10 -0
  64. data/lib/guider_cms/engine.rb +9 -0
  65. data/lib/guider_cms/version.rb +3 -0
  66. data/lib/tasks/guider_cms_tasks.rake +4 -0
  67. metadata +227 -0
@@ -0,0 +1,5 @@
1
+ <h1>New Article</h1>
2
+
3
+ <%= render 'form', article: @article %>
4
+ <br/>
5
+ <%= link_to 'Back', content_new_back_path(root: @root) %>
@@ -0,0 +1,68 @@
1
+ <% title @article.title %>
2
+ <% meta_tag :description, @article.description %>
3
+ <% meta_tag :keywords, @article.keywords %>
4
+
5
+
6
+ <h1><%= @article.title %></h1>
7
+
8
+ <% if @article.header_image.attached? %>
9
+ <%= image_tag(main_app.url_for(@article.header_image), width: "100%") %>
10
+ <% end %>
11
+
12
+ <%= @article.body %>
13
+
14
+ <br/>
15
+ <% if current_user && current_user.id == @article.author_id %>
16
+ <% if @selected_category == @root %>
17
+ <%= link_to 'Edit', root_content_edit_path(root: @root) %>
18
+ <% else %>
19
+ <%= link_to 'Edit', edit_content_path(@article.id, root: @root, selected_category: @selected_category) %> |
20
+ <% end %>
21
+ <% end %>
22
+
23
+ <% if current_user && current_user.id == @article.author_id %>
24
+ <%= link_to 'Delete', article_path(@article.id), method: :delete %> |
25
+ <% end %>
26
+
27
+ <% if request.original_url.include?('your_articles') %>
28
+ <%= link_to "Back", user_articles_path %>
29
+ <% else %>
30
+ <% if @selected_category == @root %>
31
+ <%= link_to 'Back', content_new_back_path(root: @root) %>
32
+ <% else %>
33
+ <%= link_to 'Back', contents_path(root: @root, selected_category: @selected_category) %>
34
+ <% end %>
35
+ <% end %>
36
+
37
+ <br/>
38
+ <br/>
39
+
40
+ <% if @selected_category_class.articles.length > 1 %>
41
+ <h3>More related contents</h3>
42
+ <div class="row">
43
+ <div class="card-columns">
44
+ <% @selected_category_class.articles.each do |article| %>
45
+ <% if article.id != @article.id %>
46
+ <div class="card" style="margin-bottom: 2vh;">
47
+ <% if article.header_image.attached? %>
48
+ <%= image_tag(main_app.url_for(article.header_image), class: "card-img-top") %>
49
+ <% else %>
50
+ <% if article.body.embeds.find{|embeds| embeds.image?} %>
51
+ <%= image_tag(main_app.url_for(article.body.embeds.find{|embeds| embeds.image?}), class: "card-img-top") %>
52
+ <% end %>
53
+ <% end %>
54
+ <div class="card-body">
55
+ <h5 class="card-title"><%= article.title %></h5>
56
+ <p class="card-text"> <%= article.description[0..500].gsub(/\s\w+$/,'...') %></p>
57
+ <% if @selected_category_class.parent.nil? %>
58
+ <%= link_to "Read Now", root_articles_path(article, root: @root_category.slug || @root_category.classification), class: "btn btn-primary"%>
59
+ <% else %>
60
+ <%= link_to "Read Now", content_path(article, root: @root_category.slug || @root_category.classification, selected_category: @selected_category_class.slug || @selected_category_class.classification), class: "btn btn-primary"%>
61
+ <% end %>
62
+ </div>
63
+ </div>
64
+ <% end %>
65
+ <% end %>
66
+ </div>
67
+ </div>
68
+ <% end %>
@@ -0,0 +1,50 @@
1
+ <%= form_with(model: category, local: true) do |form| %>
2
+ <% if category.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(category.errors.count, "error") %> prohibited this category from being saved:</h2>
5
+
6
+ <ul>
7
+ <% category.errors.full_messages.each do |message| %>
8
+ <li><%= message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+
15
+ <div class="form-group">
16
+ <h5><%= form.label :name%></h5>
17
+ <p>The name of the category you want to create</p>
18
+ <%= form.text_field :classification, class: "form-control", required: true %>
19
+ </div>
20
+
21
+
22
+ <% if @root_categories != [] %>
23
+ <div class="form-group">
24
+ <h5><%= form.label :parent_id %></h5>
25
+ <p>If you want your category to be a parent, then leave this empty, otherwise if you want it to
26
+ be a child of a category you have already created then select the desired category</p>
27
+ <%= form.select :parent_id, options_for_select(category_options_array()) , {include_blank: true} ,class: "form-control" %>
28
+ </div>
29
+ <% end %>
30
+
31
+ <div class="form-group">
32
+ <%= form.label :header_image %>
33
+ <%= form.file_field :header_image %>
34
+ </div>
35
+
36
+ <% if @category && @category.parent_id.nil? %>
37
+ <div class="form-group">
38
+ <h5>View type</h5>
39
+ <p>Grid view type will have everything in a grid whereas menu will have categories listed on the left</p>
40
+ <b>This input will only be considered, if the category being created does not have a parent</b>
41
+ <%= form.select :view_type, @view_type, {include_blank: true}, class: "form-control" %>
42
+ </div>
43
+ <% end %>
44
+
45
+
46
+
47
+ <div class="actions">
48
+ <%= form.submit "Create Category", class: "btn btn-outline-primary" %>
49
+ </div>
50
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing Article</h1>
2
+
3
+ <%= render 'form', category: @category %>
4
+
5
+ <%= link_to 'Show', @article %> |
6
+ <%= link_to 'Back', root_categories_path %>
@@ -0,0 +1,76 @@
1
+ <%
2
+ def draw_tree(node)
3
+ node.children.each do |category|
4
+ %>
5
+
6
+ <% if category.classification %>
7
+ <li>
8
+ <%= category.classification %>
9
+ (Slug: <%= category.slug %>)
10
+ <%= link_to "Edit", edit_categories_path(category) %>
11
+ <%= link_to 'Destroy', category, method: :delete, data: { confirm: 'Are you sure?' } %>
12
+ </li>
13
+ <% end %>
14
+ <%
15
+ if category.children.any?
16
+ %>
17
+ <ul><% draw_tree(category) %></ul>
18
+ <%
19
+ end
20
+ %>
21
+
22
+ <%
23
+ end; nil
24
+ end
25
+ %>
26
+
27
+
28
+
29
+
30
+
31
+
32
+ <h1>Listing Categories</h1>
33
+
34
+
35
+ <% @categories.each do |category| %>
36
+ <ul>
37
+ <li>
38
+ <%= category.classification %>
39
+ (Slug: <%= category.slug %>)
40
+ <%= link_to "Edit", edit_categories_path(category) %>
41
+ <%= link_to 'Destroy', category, method: :delete, data: { confirm: 'Are you sure?' } %>
42
+ </li>
43
+ <% if category.children.any? %>
44
+ <ul><%= draw_tree(category) %></ul>
45
+ <% end %>
46
+ </ul>
47
+ <% end %>
48
+
49
+ <%= link_to "Back", content_new_back_path(root: @root) %>
50
+
51
+ <%
52
+ def draw_tree(node)
53
+ node.children.each do |category|
54
+ %>
55
+
56
+ <% if category.classification %>
57
+ <tr>
58
+ <td><%= category.classification %></td>
59
+ <td><%= link_to "Edit", edit_categories_path(category) %></td>
60
+ <td><%= link_to 'Destroy', category, method: :delete, data: { confirm: 'Are you sure?' } %></td>
61
+ </tr>
62
+ <% end %>
63
+ <%
64
+ if category.children.any?
65
+ %>
66
+
67
+ <%= draw_tree(category) %>
68
+
69
+ <%
70
+ end
71
+ %>
72
+
73
+ <%
74
+ end; nil
75
+ end
76
+ %>
@@ -0,0 +1,7 @@
1
+ <div>
2
+ <%= render 'form', category: @category %>
3
+
4
+ <% if !(@root.nil?) %>
5
+ <%= link_to "Back", content_new_back_path(root: @root.slug || @root.classification) %>
6
+ <% end %>
7
+ </div>
@@ -0,0 +1,32 @@
1
+ <h1> Your Articles </h1>
2
+ <div>
3
+ <div class="row">
4
+ <% @articles.each do |article| %>
5
+ <div class="col-xs-12 col-sm-4 col-md-4">
6
+ <%= link_to user_article_path(article, root: article.category.ancestors.last.classification, selected_category: article.category.classification), class: "grid-link" do %>
7
+ <div class="grid-style">
8
+ <div class="container">
9
+ <% if article.header_image.attached? %>
10
+ <%= image_tag(main_app.url_for(article.header_image), width: "100%") %>
11
+ <% else %>
12
+ <% if article.body.embeds.find{|embeds| embeds.image?} %>
13
+ <%= image_tag(main_app.url_for(article.body.embeds.find{|embeds| embeds.image?}), width: "100%") %>
14
+ <% end %>
15
+ <% end %>
16
+ <br /><br />
17
+ <h5><%= article.title %></h5>
18
+ <p><%= article.description %></p>
19
+ </div>
20
+ </div>
21
+ <% end %>
22
+ </div>
23
+ <% end %>
24
+ </div>
25
+
26
+
27
+
28
+
29
+ <%= link_to "Back", content_new_back_path(root: @root) %>
30
+
31
+
32
+ </div>
@@ -0,0 +1,15 @@
1
+ <%= form_with scope: :subcategory, url: subcategories_path , local: true do |form| %>
2
+ <div class="form-group">
3
+ <%= form.label :category %>
4
+ <%= form.select :category, @categories.collect {|c| [c.classification, c.classification]} , {include_blank: true} ,class: "form-control" %>
5
+ </div>
6
+
7
+ <div class="form-group">
8
+ <%= form.label :subcategory %><br>
9
+ <%= form.text_field :subcategory, class: "form-control" %>
10
+ </div>
11
+
12
+ <div class="actions">
13
+ <%= form.submit "Create Subcategory", class: "btn btn-outline-primary" %>
14
+ </div>
15
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <h1>New Subcategory</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', content_new_back_path(root: @root) %>
@@ -0,0 +1,22 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Guider</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "guider_cms/application", media: "all" %>
9
+ <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
10
+ </head>
11
+ <body>
12
+ <% if notice %>
13
+ <p class="alert alert-success"><%= notice %></p>
14
+ <% end %>
15
+ <% if alert %>
16
+ <p class="alert alert-danger"><%= alert %></p>
17
+ <% end %>
18
+ <div class="container">
19
+ <%= yield %>
20
+ </div>
21
+ </body>
22
+ </html>
@@ -0,0 +1,107 @@
1
+ # FriendlyId Global Configuration
2
+ #
3
+ # Use this to set up shared configuration options for your entire application.
4
+ # Any of the configuration options shown here can also be applied to single
5
+ # models by passing arguments to the `friendly_id` class method or defining
6
+ # methods in your model.
7
+ #
8
+ # To learn more, check out the guide:
9
+ #
10
+ # http://norman.github.io/friendly_id/file.Guide.html
11
+
12
+ FriendlyId.defaults do |config|
13
+ # ## Reserved Words
14
+ #
15
+ # Some words could conflict with Rails's routes when used as slugs, or are
16
+ # undesirable to allow as slugs. Edit this list as needed for your app.
17
+ config.use :reserved
18
+
19
+ config.reserved_words = %w(new edit index session login logout users admin
20
+ stylesheets assets javascripts images)
21
+
22
+ # This adds an option to treat reserved words as conflicts rather than exceptions.
23
+ # When there is no good candidate, a UUID will be appended, matching the existing
24
+ # conflict behavior.
25
+
26
+ # config.treat_reserved_as_conflict = true
27
+
28
+ # ## Friendly Finders
29
+ #
30
+ # Uncomment this to use friendly finders in all models. By default, if
31
+ # you wish to find a record by its friendly id, you must do:
32
+ #
33
+ # MyModel.friendly.find('foo')
34
+ #
35
+ # If you uncomment this, you can do:
36
+ #
37
+ # MyModel.find('foo')
38
+ #
39
+ # This is significantly more convenient but may not be appropriate for
40
+ # all applications, so you must explicity opt-in to this behavior. You can
41
+ # always also configure it on a per-model basis if you prefer.
42
+ #
43
+ # Something else to consider is that using the :finders addon boosts
44
+ # performance because it will avoid Rails-internal code that makes runtime
45
+ # calls to `Module.extend`.
46
+ #
47
+ # config.use :finders
48
+ #
49
+ # ## Slugs
50
+ #
51
+ # Most applications will use the :slugged module everywhere. If you wish
52
+ # to do so, uncomment the following line.
53
+ #
54
+ # config.use :slugged
55
+ #
56
+ # By default, FriendlyId's :slugged addon expects the slug column to be named
57
+ # 'slug', but you can change it if you wish.
58
+ #
59
+ # config.slug_column = 'slug'
60
+ #
61
+ # By default, slug has no size limit, but you can change it if you wish.
62
+ #
63
+ # config.slug_limit = 255
64
+ #
65
+ # When FriendlyId can not generate a unique ID from your base method, it appends
66
+ # a UUID, separated by a single dash. You can configure the character used as the
67
+ # separator. If you're upgrading from FriendlyId 4, you may wish to replace this
68
+ # with two dashes.
69
+ #
70
+ # config.sequence_separator = '-'
71
+ #
72
+ # Note that you must use the :slugged addon **prior** to the line which
73
+ # configures the sequence separator, or else FriendlyId will raise an undefined
74
+ # method error.
75
+ #
76
+ # ## Tips and Tricks
77
+ #
78
+ # ### Controlling when slugs are generated
79
+ #
80
+ # As of FriendlyId 5.0, new slugs are generated only when the slug field is
81
+ # nil, but if you're using a column as your base method can change this
82
+ # behavior by overriding the `should_generate_new_friendly_id?` method that
83
+ # FriendlyId adds to your model. The change below makes FriendlyId 5.0 behave
84
+ # more like 4.0.
85
+ # Note: Use(include) Slugged module in the config if using the anonymous module.
86
+ # If you have `friendly_id :name, use: slugged` in the model, Slugged module
87
+ # is included after the anonymous module defined in the initializer, so it
88
+ # overrides the `should_generate_new_friendly_id?` method from the anonymous module.
89
+ #
90
+ # config.use :slugged
91
+ # config.use Module.new {
92
+ # def should_generate_new_friendly_id?
93
+ # slug.blank? || <your_column_name_here>_changed?
94
+ # end
95
+ # }
96
+ #
97
+ # FriendlyId uses Rails's `parameterize` method to generate slugs, but for
98
+ # languages that don't use the Roman alphabet, that's not usually sufficient.
99
+ # Here we use the Babosa library to transliterate Russian Cyrillic slugs to
100
+ # ASCII. If you use this, don't forget to add "babosa" to your Gemfile.
101
+ #
102
+ # config.use Module.new {
103
+ # def normalize_friendly_id(text)
104
+ # text.to_slug.normalize! :transliterations => [:russian, :latin]
105
+ # end
106
+ # }
107
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ Kaminari.configure do |config|
4
+ config.default_per_page = 10
5
+ config.max_per_page = nil
6
+ config.window = 3
7
+ config.outer_window = 0
8
+ config.left = 0
9
+ config.right = 0
10
+ config.page_method_name = :page
11
+ config.param_name = :page
12
+ config.max_pages = nil
13
+ config.params_on_first_page = false
14
+ end
@@ -0,0 +1,53 @@
1
+ GuiderCms::Engine.routes.draw do
2
+
3
+
4
+
5
+ get '/guider_index', to: 'articles#index', as: 'guider_home'
6
+
7
+ get '/category/new', to: 'categories#new', as: 'new_optimized_category'
8
+
9
+ get '/your_articles', to: 'current_user_articles#index', as: 'user_articles'
10
+
11
+ get '/your_articles/:root/:selected_category/:id', to: 'articles#show', as: 'user_article'
12
+
13
+ get '/:root/create_new_subcategories', to: 'subcategories#new', as: 'new_subcategory'
14
+
15
+
16
+ get '/root_categories', to: 'categories#index', as: 'root_categories'
17
+
18
+ get 'categories/:id/edit', to: 'categories#edit', as: 'edit_categories'
19
+
20
+
21
+ # :root_category/:category
22
+
23
+ # get '/:root/:selected_category/:id/edit', to: 'articles#edit', as: 'edit_content'
24
+
25
+ get '/move_higher/:id', to: 'articles#edit_article_position_one_backward', as: 'move_article_backward'
26
+
27
+ get '/move_lower/:id', to: 'articles#edit_article_position_one_forward', as: 'move_article_forward'
28
+
29
+ get '/:root/new', to: 'articles#new', as: 'new_content'
30
+
31
+
32
+ get '/:root/:id/edit', to: 'articles#edit', as: 'root_content_edit'
33
+
34
+ get '/:root/', to: 'articles#index', as: 'content_new_back'
35
+
36
+ get '/:root/content/:id', to: 'articles#show', as: 'root_articles'
37
+
38
+ get '/:root/:selected_category', to: 'articles#index', as: 'contents'
39
+
40
+
41
+ get '/:root/:selected_category/:id', to: 'articles#show', as: 'content'
42
+
43
+ get '/:root/:selected_category/:id/edit', to: 'articles#edit', as: 'edit_content'
44
+
45
+ resources :categories
46
+
47
+ resources :subcategories
48
+
49
+ resources :articles
50
+
51
+ get 'user_articles', to: 'current_user_articles#index'
52
+
53
+ end