knowledge_base 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +3 -1
  3. data/app/models/knowledge_base/category_article_association.rb +1 -2
  4. data/app/models/knowledge_base/section.rb +1 -5
  5. data/app/models/knowledge_base/sectionables/attachments.rb +7 -0
  6. data/app/models/knowledge_base/sectionables/attachments/attachment.rb +5 -0
  7. data/app/models/knowledge_base/sectionables/attachments/list.rb +5 -0
  8. data/app/models/knowledge_base/sectionables/gallery.rb +3 -7
  9. data/app/models/knowledge_base/sectionables/gallery/image.rb +1 -3
  10. data/app/models/knowledge_base/sectionables/image.rb +3 -7
  11. data/app/models/knowledge_base/sectionables/links.rb +3 -5
  12. data/app/models/knowledge_base/sectionables/links/link.rb +1 -6
  13. data/app/models/knowledge_base/sectionables/links/list.rb +5 -0
  14. data/app/models/knowledge_base/sectionables/list.rb +3 -7
  15. data/app/models/knowledge_base/sectionables/list/item.rb +1 -1
  16. data/app/models/knowledge_base/sectionables/sectionable.rb +3 -7
  17. data/app/models/knowledge_base/sectionables/text.rb +3 -5
  18. data/app/models/knowledge_base/sectionables/video.rb +3 -11
  19. data/app/uploaders/knowledge_base/generic_file_uploader.rb +7 -0
  20. data/app/uploaders/knowledge_base/image_uploader.rb +0 -48
  21. data/app/views/knowledge_base/articles/_article.html.erb +3 -3
  22. data/app/views/knowledge_base/articles/_search.html.erb +6 -0
  23. data/app/views/knowledge_base/articles/index.html.erb +11 -0
  24. data/app/views/knowledge_base/categories/_category.html.erb +2 -2
  25. data/app/views/knowledge_base/sectionables/attachments/lists/_list.html.erb +14 -0
  26. data/app/views/knowledge_base/sectionables/links/lists/_list.html.erb +13 -0
  27. data/app/views/knowledge_base/sectionables/lists/_list.html.erb +4 -0
  28. data/app/views/knowledge_base/sectionables/texts/_text.html.erb +4 -0
  29. data/app/views/knowledge_base/sectionables/videos/_video.html.erb +4 -1
  30. data/config/locales/en.yml +131 -0
  31. data/config/locales/nb.yml +94 -15
  32. data/config/routes.rb +2 -0
  33. data/db/migrate/20140318125210_default_position_fields.rb +10 -0
  34. data/db/migrate/20140318210722_change_knowledge_base_gallery_description_to_text.rb +9 -0
  35. data/db/migrate/20140320125825_add_image_to_texts.rb +5 -0
  36. data/db/migrate/20140325083548_add_image_to_sectionables_lists.rb +5 -0
  37. data/db/migrate/20140404234850_create_knowledge_base_sectionables_attachments.rb +8 -0
  38. data/db/migrate/20140410184906_create_knowledge_base_sectionables_attachment_lists.rb +7 -0
  39. data/db/migrate/20140410185528_add_attachment_list_reference_to_knowledge_base_sectionables_attachments.rb +8 -0
  40. data/db/migrate/20140410191611_migrate_attachments_over_to_lists.rb +49 -0
  41. data/db/migrate/20140410203342_rename_attachment_lists_to_attachments_lists.rb +5 -0
  42. data/db/migrate/20140410205056_rename_attachments_to_attachments_attachments.rb +5 -0
  43. data/db/migrate/20140410224403_rename_links_to_links_lists.rb +5 -0
  44. data/db/migrate/20140410231048_fix_sectionable_types_for_attachments.rb +13 -0
  45. data/db/migrate/20140410231433_fix_sectionable_types_for_links.rb +13 -0
  46. data/db/migrate/20140430112603_add_description_to_knowledge_base_attachments_attachment.rb +5 -0
  47. data/db/migrate/20140430112633_add_description_to_knowledge_base_links_link.rb +5 -0
  48. data/db/migrate/20140820114750_add_custom_style_to_knowledge_base_sectionables.rb +21 -0
  49. data/db/migrate/20140821081854_remove_custom_style_from_non_sectionables.rb +8 -0
  50. data/db/migrate/20140821085102_rename_custom_style_to_style.rb +11 -0
  51. data/db/migrate/20140821151832_add_title_to_knowledge_base_sectionables_videos.rb +5 -0
  52. data/db/migrate/20140930121510_add_title_to_attachment_lists.rb +5 -0
  53. data/fixtures/parrot.png +0 -0
  54. data/fixtures/sample.pdf +0 -0
  55. data/lib/generators/knowledge_base/active_admin/USAGE +8 -0
  56. data/lib/generators/knowledge_base/active_admin/active_admin_generator.rb +9 -0
  57. data/lib/generators/knowledge_base/active_admin/templates/article.rb +92 -0
  58. data/lib/generators/knowledge_base/active_admin/templates/category.rb +70 -0
  59. data/lib/generators/knowledge_base/active_admin/templates/sectionables/attachments/list.rb +25 -0
  60. data/lib/generators/knowledge_base/active_admin/templates/sectionables/gallery.rb +44 -0
  61. data/lib/generators/knowledge_base/active_admin/templates/sectionables/image.rb +37 -0
  62. data/lib/generators/knowledge_base/active_admin/templates/sectionables/links/list.rb +35 -0
  63. data/lib/generators/knowledge_base/active_admin/templates/sectionables/list.rb +48 -0
  64. data/lib/generators/knowledge_base/active_admin/templates/sectionables/text.rb +42 -0
  65. data/lib/generators/knowledge_base/active_admin/templates/sectionables/video.rb +20 -0
  66. data/lib/knowledge_base.rb +3 -0
  67. data/lib/knowledge_base/concerns/controllers/articles_controller.rb +21 -2
  68. data/lib/knowledge_base/concerns/controllers/categories_controller.rb +3 -2
  69. data/lib/knowledge_base/concerns/models.rb +31 -0
  70. data/lib/knowledge_base/concerns/models/article.rb +4 -3
  71. data/lib/knowledge_base/concerns/models/category.rb +2 -3
  72. data/lib/knowledge_base/concerns/models/category_article_association.rb +8 -0
  73. data/lib/knowledge_base/concerns/models/section.rb +13 -0
  74. data/lib/knowledge_base/concerns/models/sectionables/attachments/attachment.rb +11 -0
  75. data/lib/knowledge_base/concerns/models/sectionables/attachments/list.rb +15 -0
  76. data/lib/knowledge_base/concerns/models/sectionables/gallery.rb +17 -0
  77. data/lib/knowledge_base/concerns/models/sectionables/gallery/image.rb +9 -0
  78. data/lib/knowledge_base/concerns/models/sectionables/image.rb +13 -0
  79. data/lib/knowledge_base/concerns/models/sectionables/links/link.rb +7 -0
  80. data/lib/knowledge_base/concerns/models/sectionables/links/list.rb +15 -0
  81. data/lib/knowledge_base/concerns/models/sectionables/list.rb +17 -0
  82. data/lib/knowledge_base/concerns/models/sectionables/list/item.rb +7 -0
  83. data/lib/knowledge_base/concerns/models/sectionables/sectionable.rb +28 -0
  84. data/lib/knowledge_base/concerns/models/sectionables/text.rb +13 -0
  85. data/lib/knowledge_base/concerns/models/sectionables/video.rb +15 -0
  86. data/lib/knowledge_base/configuration.rb +10 -17
  87. data/lib/knowledge_base/engine.rb +4 -0
  88. data/lib/knowledge_base/seeds.rb +7 -3
  89. data/lib/knowledge_base/version.rb +1 -1
  90. data/spec/controllers/knowledge_base/articles_controller_spec.rb +15 -4
  91. data/spec/controllers/knowledge_base/categories_controller_spec.rb +1 -1
  92. data/spec/dummy/db/development.sqlite3 +0 -0
  93. data/spec/dummy/db/schema.rb +39 -13
  94. data/spec/dummy/db/test.sqlite3 +0 -0
  95. data/spec/dummy/log/development.log +887 -0
  96. data/spec/dummy/log/test.log +999 -0
  97. data/spec/factories/knowledge_base_articles.rb +3 -3
  98. data/spec/factories/knowledge_base_categories.rb +3 -3
  99. data/spec/factories/knowledge_base_sectionables_attachment_lists.rb +6 -0
  100. data/spec/lib/knowledge_base/configuration_spec.rb +32 -8
  101. data/spec/lib/knowledge_base_spec.rb +3 -3
  102. data/spec/models/knowledge_base/article_spec.rb +0 -1
  103. data/spec/models/knowledge_base/category_article_association_spec.rb +0 -1
  104. data/spec/models/knowledge_base/category_spec.rb +0 -1
  105. data/spec/models/knowledge_base/section_spec.rb +0 -1
  106. data/spec/models/knowledge_base/sectionables/attachments/attachment_spec.rb +6 -0
  107. data/spec/models/knowledge_base/sectionables/attachments/list_spec.rb +13 -0
  108. data/spec/models/knowledge_base/sectionables/gallery/image_spec.rb +0 -1
  109. data/spec/models/knowledge_base/sectionables/gallery_spec.rb +0 -1
  110. data/spec/models/knowledge_base/sectionables/image_spec.rb +0 -1
  111. data/spec/models/knowledge_base/sectionables/links/link_spec.rb +0 -1
  112. data/spec/models/knowledge_base/sectionables/links_spec.rb +0 -1
  113. data/spec/models/knowledge_base/sectionables/list/item_spec.rb +0 -1
  114. data/spec/models/knowledge_base/sectionables/list_spec.rb +0 -1
  115. data/spec/models/knowledge_base/sectionables/sectionable_spec.rb +34 -0
  116. data/spec/models/knowledge_base/sectionables/text_spec.rb +0 -1
  117. data/spec/models/knowledge_base/sectionables/video_spec.rb +0 -7
  118. data/spec/spec_helper.rb +3 -0
  119. data/spec/views/knowledge_base/articles/show.html.erb_spec.rb +0 -1
  120. data/spec/views/knowledge_base/categories/index.html.erb_spec.rb +0 -1
  121. data/spec/views/knowledge_base/categories/show.html.erb_spec.rb +0 -1
  122. metadata +179 -7
  123. data/app/views/knowledge_base/sectionables/links/_links.html.erb +0 -5
@@ -0,0 +1,70 @@
1
+ ActiveAdmin.register KnowledgeBase::Category do
2
+ menu parent: I18n.t('activerecord.models.knowledge_base')
3
+
4
+ index do
5
+ selectable_column
6
+
7
+ column :id
8
+ column :title
9
+ column :slug
10
+ column :published_at
11
+
12
+ column :published?, sortable: :published_at do |category|
13
+ css_class, label = category.published? ? [ :yes, t('texts.yes') ]
14
+ : [ :no, t('texts.no') ]
15
+
16
+ status_tag label, css_class
17
+ end
18
+
19
+ default_actions
20
+ end
21
+
22
+ show do |category|
23
+ columns do
24
+ column do
25
+ attributes_table do
26
+ row :id
27
+ row :title
28
+ row :slug
29
+ row :description do
30
+ simple_format category.description
31
+ end
32
+ row :category
33
+ row :position
34
+ row :published_at
35
+ row :created__at
36
+ row :updated_at
37
+ row :articles do
38
+ links = category.articles.map do |articles|
39
+ link_to articles.title, [ :admin, :knowledge_base, articles ]
40
+ end
41
+
42
+ raw links.join(", ")
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ form do |f|
50
+ f.inputs do
51
+ f.input :title
52
+ f.input :slug
53
+ f.input :description
54
+ f.input :published_at
55
+ f.has_many :category_article_associations, sortable: :position do |f|
56
+ f.input :article
57
+
58
+ f.input :_destroy, as: :boolean, label: I18n.t('destroy')
59
+ end
60
+ end
61
+
62
+ f.actions
63
+ end
64
+
65
+ controller do
66
+ def find_resource
67
+ scoped_collection.friendly.find params[:id]
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,25 @@
1
+ ActiveAdmin.register KnowledgeBase::Sectionables::Attachments::List do
2
+ menu parent: I18n.t('activerecord.models.knowledge_base/section/kind.other')
3
+
4
+ index do
5
+ selectable_column
6
+
7
+ column :links do |list|
8
+ list.attachments.map(&:title).join ", "
9
+ end
10
+
11
+ actions
12
+ end
13
+
14
+ form do |f|
15
+ f.has_many :attachments do |f|
16
+ f.input :title
17
+ f.input :file
18
+ f.input :description
19
+
20
+ f.input :style
21
+ end
22
+
23
+ f.actions
24
+ end
25
+ end
@@ -0,0 +1,44 @@
1
+ ActiveAdmin.register KnowledgeBase::Sectionables::Gallery do
2
+ menu parent: I18n.t('activerecord.models.knowledge_base/section/kind.other')
3
+
4
+ index do
5
+ column :id
6
+ column :title
7
+ column :description
8
+
9
+ default_actions
10
+ end
11
+
12
+ form do |f|
13
+ f.inputs do
14
+ f.input :title
15
+ f.input :description
16
+
17
+ f.input :style
18
+
19
+ f.has_many :images, sortable: :position do |f|
20
+ f.input :caption
21
+
22
+ image_hint = f.object.new_record? ? nil : f.template.image_tag(f.object.image.medium)
23
+ f.input :image, hint: image_hint
24
+
25
+ f.input :_destroy, as: :boolean, label: I18n.t('destroy')
26
+ end
27
+ end
28
+
29
+ f.actions
30
+ end
31
+
32
+ show do |gallery|
33
+ attributes_table do
34
+ row :id
35
+ row :title
36
+ row :description
37
+ row :images do
38
+ gallery.images.map do |image|
39
+ image_tag(image.image.medium)
40
+ end.join(" ").html_safe
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,37 @@
1
+ ActiveAdmin.register KnowledgeBase::Sectionables::Image do
2
+ menu parent: I18n.t('activerecord.models.knowledge_base/section/kind.other')
3
+
4
+ form do |f|
5
+ f.inputs do
6
+ f.input :caption
7
+
8
+ image_hint = f.object.new_record? ? nil : f.template.image_tag(f.object.image.medium)
9
+ f.input :image, hint: image_hint
10
+
11
+ f.input :style
12
+ end
13
+
14
+ f.actions
15
+ end
16
+
17
+ index as: :grid do |i|
18
+ link_to image_tag(i.image.medium), admin_knowledge_base_sectionables_image_path(i)
19
+ end
20
+
21
+ index do
22
+ column :id
23
+ column :caption
24
+
25
+ default_actions
26
+ end
27
+
28
+ show do |image|
29
+ attributes_table do
30
+ row :id
31
+ row :caption
32
+ row :image do
33
+ image_tag image.image
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,35 @@
1
+ ActiveAdmin.register KnowledgeBase::Sectionables::Links::List do
2
+ menu parent: I18n.t('activerecord.models.knowledge_base/section/kind.other')
3
+
4
+ index do
5
+ column :id
6
+ column :links do |links|
7
+ links.links.map { |link| link_to link.title, link.url }.join(", ").html_safe
8
+ end
9
+
10
+ default_actions
11
+ end
12
+
13
+ form do |f|
14
+ f.has_many :links, sortable: :position do |f|
15
+ f.input :title
16
+ f.input :description
17
+ f.input :url
18
+
19
+ f.input :style
20
+ end
21
+
22
+ f.actions
23
+ end
24
+
25
+ show do |links|
26
+ attributes_table do
27
+ row :id
28
+ row :links do
29
+ links.links.map { |link| link_to link.title, link.url }.join(", ").html_safe
30
+ end
31
+ row :created_at
32
+ row :updated_at
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,48 @@
1
+ ActiveAdmin.register KnowledgeBase::Sectionables::List do
2
+ menu parent: I18n.t('activerecord.models.knowledge_base/section/kind.other')
3
+
4
+ index do
5
+ column :id
6
+ column :title
7
+
8
+ default_actions
9
+ end
10
+
11
+ form do |f|
12
+ f.inputs do
13
+ f.input :title
14
+ f.input :description
15
+
16
+ image_hint = f.object.new_record? ? nil : f.template.image_tag(f.object.image.medium)
17
+ f.input :image, hint: image_hint
18
+ f.input :remove_image, as: :boolean
19
+
20
+ f.input :style
21
+
22
+ f.has_many :items, sortable: :position do |f|
23
+ f.input :title
24
+ f.input :body
25
+
26
+ f.input :_destroy, as: :boolean, label: I18n.t('destroy')
27
+ end
28
+ end
29
+
30
+ f.actions
31
+ end
32
+
33
+ show do |list|
34
+ attributes_table do
35
+ row :id
36
+ row :title
37
+ row :description
38
+ row :created_at
39
+ row :updated_at
40
+ end
41
+
42
+ list.items.each do |item|
43
+ panel item.title do
44
+ para em item.body
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,42 @@
1
+ ActiveAdmin.register KnowledgeBase::Sectionables::Text do
2
+ menu parent: I18n.t('activerecord.models.knowledge_base/section/kind.other')
3
+
4
+ form do |f|
5
+ f.inputs do
6
+ f.input :heading
7
+ f.input :lead
8
+ f.input :body
9
+
10
+ image_hint = f.object.new_record? ? nil : f.template.image_tag(f.object.image.medium)
11
+ f.input :image, hint: image_hint
12
+ f.input :remove_image, as: :boolean
13
+
14
+ f.input :style
15
+ end
16
+
17
+ f.actions
18
+ end
19
+
20
+ index do
21
+ column :id
22
+ column :heading
23
+
24
+ default_actions
25
+ end
26
+
27
+ show do |text|
28
+ attributes_table do
29
+ row :id
30
+ row :image do
31
+ image_tag text.image.medium
32
+ end
33
+ row :created_at
34
+ row :updated_at
35
+ end
36
+
37
+ header h1 text.heading
38
+ para strong text.lead
39
+
40
+ para text.body
41
+ end
42
+ end
@@ -0,0 +1,20 @@
1
+ ActiveAdmin.register KnowledgeBase::Sectionables::Video do
2
+ menu parent: I18n.t('activerecord.models.knowledge_base/section/kind.other')
3
+
4
+ index do
5
+ column :id
6
+ column :url
7
+
8
+ default_actions
9
+ end
10
+
11
+ show do |video|
12
+ attributes_table do
13
+ row :id
14
+ row :address
15
+ row :created_at
16
+ row :updated_at
17
+ row :style
18
+ end
19
+ end
20
+ end
@@ -2,6 +2,9 @@ require "knowledge_base/engine"
2
2
  require "knowledge_base/configuration"
3
3
  require "knowledge_base/concerns"
4
4
  require "carrierwave"
5
+ require "enumerize"
6
+ require "embeddable"
7
+ require "ransack"
5
8
 
6
9
  module KnowledgeBase
7
10
  class << self
@@ -5,14 +5,33 @@ module KnowledgeBase
5
5
  included do
6
6
  before_action :set_category
7
7
 
8
+ def index
9
+ if @category
10
+ scope = @category.articles
11
+ else
12
+ scope = Article.all
13
+ end
14
+
15
+ scope = scope.published
16
+
17
+ @search = scope.search params[:q]
18
+ @articles = @search.result.includes(:sections)
19
+ end
20
+
8
21
  def show
9
- @article = @category.articles.friendly.find params[:id]
22
+ if @category
23
+ scope = @category.articles
24
+ else
25
+ scope = Article.all
26
+ end
27
+
28
+ @article = scope.published.friendly.find params[:id]
10
29
  end
11
30
 
12
31
  private
13
32
 
14
33
  def set_category
15
- @category = Category.friendly.find params[:category_id]
34
+ @category = Category.friendly.find params[:category_id] if params.has_key? :category_id
16
35
  end
17
36
  end
18
37
  end
@@ -4,11 +4,12 @@ module KnowledgeBase
4
4
 
5
5
  included do
6
6
  def index
7
- @categories = Category.all
7
+ @categories = Category.published
8
8
  end
9
9
 
10
10
  def show
11
- @category = Category.friendly.find params[:id]
11
+ @category = Category.published.friendly.find params[:id]
12
+ @articles = @category.articles.published
12
13
  end
13
14
  end
14
15
  end
@@ -1,4 +1,35 @@
1
1
  module KnowledgeBase::Concerns::Models
2
2
  require 'knowledge_base/concerns/models/category'
3
3
  require 'knowledge_base/concerns/models/article'
4
+ require 'knowledge_base/concerns/models/category_article_association'
5
+ require 'knowledge_base/concerns/models/section'
6
+
7
+ module Sectionables
8
+ require 'knowledge_base/concerns/models/sectionables/gallery'
9
+ require 'knowledge_base/concerns/models/sectionables/image'
10
+ require 'knowledge_base/concerns/models/sectionables/list'
11
+ require 'knowledge_base/concerns/models/sectionables/sectionable'
12
+ require 'knowledge_base/concerns/models/sectionables/text'
13
+ require 'knowledge_base/concerns/models/sectionables/video'
14
+
15
+ module Attachments
16
+ require 'knowledge_base/concerns/models/sectionables/attachments/attachment'
17
+ require 'knowledge_base/concerns/models/sectionables/attachments/list'
18
+ end
19
+
20
+ module Gallery
21
+ require 'knowledge_base/concerns/models/sectionables/gallery/image'
22
+ end
23
+
24
+ module Links
25
+ require 'knowledge_base/concerns/models/sectionables/links/link'
26
+ require 'knowledge_base/concerns/models/sectionables/links/list'
27
+ end
28
+
29
+ module List
30
+ require 'knowledge_base/concerns/models/sectionables/list/item'
31
+ end
32
+
33
+ end
34
+
4
35
  end
@@ -4,16 +4,17 @@ module KnowledgeBase::Concerns::Models::Article
4
4
  included do
5
5
  extend FriendlyId
6
6
 
7
- publishable
7
+ publishable on: :published_at
8
8
 
9
9
  friendly_id :title, use: :slugged
10
10
 
11
11
  has_many :category_article_associations
12
12
  has_many :categories, through: :category_article_associations
13
- has_many :sections, -> { order 'position ASC' }, as: :container
13
+ has_many :sections, -> { order 'position ASC' }, as: :container,
14
+ dependent: :destroy
14
15
 
15
16
  accepts_nested_attributes_for :category_article_associations
16
- accepts_nested_attributes_for :sections
17
+ accepts_nested_attributes_for :sections, allow_destroy: true
17
18
 
18
19
  def to_s
19
20
  title