lato_blog 2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +27 -0
  4. data/Rakefile +5 -0
  5. data/app/assets/config/lato_blog_manifest.js +2 -0
  6. data/app/assets/javascripts/lato_blog/application.js +19 -0
  7. data/app/assets/javascripts/lato_blog/initializers/Fields.js +56 -0
  8. data/app/assets/javascripts/lato_blog/initializers/Posts.js +54 -0
  9. data/app/assets/stylesheets/lato_blog/_helpers.scss +37 -0
  10. data/app/assets/stylesheets/lato_blog/application.scss +20 -0
  11. data/app/assets/stylesheets/lato_blog/fields/_composed.scss +7 -0
  12. data/app/assets/stylesheets/lato_blog/fields/_datetime.scss +0 -0
  13. data/app/assets/stylesheets/lato_blog/fields/_editor.scss +3 -0
  14. data/app/assets/stylesheets/lato_blog/fields/_fields.scss +8 -0
  15. data/app/assets/stylesheets/lato_blog/fields/_general.scss +9 -0
  16. data/app/assets/stylesheets/lato_blog/fields/_geolocalization.scss +3 -0
  17. data/app/assets/stylesheets/lato_blog/fields/_image.scss +3 -0
  18. data/app/assets/stylesheets/lato_blog/fields/_relay.scss +121 -0
  19. data/app/assets/stylesheets/lato_blog/fields/_text.scss +3 -0
  20. data/app/assets/stylesheets/lato_blog/pages/_categories.scss +18 -0
  21. data/app/assets/stylesheets/lato_blog/pages/_pages.scss +2 -0
  22. data/app/assets/stylesheets/lato_blog/pages/_posts.scss +25 -0
  23. data/app/assets/stylesheets/lato_blog/theme.scss.erb +12 -0
  24. data/app/assets/stylesheets/lato_blog/widgets/_switchlang.scss +3 -0
  25. data/app/assets/stylesheets/lato_blog/widgets/_widgets.scss +1 -0
  26. data/app/controllers/lato_blog/api/api_controller.rb +5 -0
  27. data/app/controllers/lato_blog/api/categories_controller.rb +51 -0
  28. data/app/controllers/lato_blog/api/posts_controller.rb +93 -0
  29. data/app/controllers/lato_blog/application_controller.rb +13 -0
  30. data/app/controllers/lato_blog/back/back_controller.rb +45 -0
  31. data/app/controllers/lato_blog/back/categories_controller.rb +141 -0
  32. data/app/controllers/lato_blog/back/post_fields_controller.rb +86 -0
  33. data/app/controllers/lato_blog/back/posts_controller.rb +340 -0
  34. data/app/controllers/lato_blog/doc/doc_controller.rb +16 -0
  35. data/app/controllers/lato_blog/doc/fields_controller.rb +19 -0
  36. data/app/controllers/lato_blog/doc/general_controller.rb +11 -0
  37. data/app/helpers/lato_blog/application_helper.rb +13 -0
  38. data/app/helpers/lato_blog/fields_helper.rb +100 -0
  39. data/app/jobs/lato_blog/application_job.rb +4 -0
  40. data/app/mailers/lato_blog/application_mailer.rb +6 -0
  41. data/app/models/lato_blog/application_record.rb +5 -0
  42. data/app/models/lato_blog/category.rb +119 -0
  43. data/app/models/lato_blog/category/entity_helpers.rb +55 -0
  44. data/app/models/lato_blog/category/serializer_helpers.rb +66 -0
  45. data/app/models/lato_blog/category_parent.rb +9 -0
  46. data/app/models/lato_blog/category_post.rb +35 -0
  47. data/app/models/lato_blog/post.rb +112 -0
  48. data/app/models/lato_blog/post/entity_helpers.rb +42 -0
  49. data/app/models/lato_blog/post/serializer_helpers.rb +85 -0
  50. data/app/models/lato_blog/post_field.rb +50 -0
  51. data/app/models/lato_blog/post_field/entity_helpers.rb +5 -0
  52. data/app/models/lato_blog/post_field/serializer_helpers.rb +127 -0
  53. data/app/models/lato_blog/post_parent.rb +20 -0
  54. data/app/views/lato_blog/back/back/switch_current_language.js +2 -0
  55. data/app/views/lato_blog/back/categories/edit.html.erb +44 -0
  56. data/app/views/lato_blog/back/categories/index.html.erb +18 -0
  57. data/app/views/lato_blog/back/categories/new.html.erb +40 -0
  58. data/app/views/lato_blog/back/categories/shared/_form.html.erb +38 -0
  59. data/app/views/lato_blog/back/categories/shared/edit/_edit_child_tree.html.erb +23 -0
  60. data/app/views/lato_blog/back/categories/shared/edit/_edit_child_tree_level.html.erb +7 -0
  61. data/app/views/lato_blog/back/categories/shared/edit/_edit_informations.html.erb +24 -0
  62. data/app/views/lato_blog/back/categories/shared/edit/_edit_languages.html.erb +38 -0
  63. data/app/views/lato_blog/back/categories/shared/new/_new_informations.html.erb +21 -0
  64. data/app/views/lato_blog/back/post_fields/create_relay_field.js.erb +14 -0
  65. data/app/views/lato_blog/back/post_fields/destroy_relay_field.js.erb +14 -0
  66. data/app/views/lato_blog/back/post_fields/fields/_composed.html.erb +24 -0
  67. data/app/views/lato_blog/back/post_fields/fields/_datetime.html.erb +17 -0
  68. data/app/views/lato_blog/back/post_fields/fields/_editor.html.erb +17 -0
  69. data/app/views/lato_blog/back/post_fields/fields/_geolocalization.html.erb +22 -0
  70. data/app/views/lato_blog/back/post_fields/fields/_image.html.erb +18 -0
  71. data/app/views/lato_blog/back/post_fields/fields/_relay.html.erb +39 -0
  72. data/app/views/lato_blog/back/post_fields/fields/_text.html.erb +17 -0
  73. data/app/views/lato_blog/back/post_fields/index.html.erb +28 -0
  74. data/app/views/lato_blog/back/posts/edit.html.erb +48 -0
  75. data/app/views/lato_blog/back/posts/index.html.erb +38 -0
  76. data/app/views/lato_blog/back/posts/new.html.erb +40 -0
  77. data/app/views/lato_blog/back/posts/shared/_fields.html.erb +13 -0
  78. data/app/views/lato_blog/back/posts/shared/_form.html.erb +69 -0
  79. data/app/views/lato_blog/back/posts/shared/edit/_edit_categories.html.erb +36 -0
  80. data/app/views/lato_blog/back/posts/shared/edit/_edit_informations.html.erb +26 -0
  81. data/app/views/lato_blog/back/posts/shared/edit/_edit_languages.html.erb +40 -0
  82. data/app/views/lato_blog/back/posts/shared/edit/_edit_pubblication_datetime.html.erb +24 -0
  83. data/app/views/lato_blog/back/posts/shared/edit/_edit_status_switch.html.erb +27 -0
  84. data/app/views/lato_blog/back/posts/shared/index/_index.html.erb +28 -0
  85. data/app/views/lato_blog/back/posts/shared/index/_index_informations.html.erb +37 -0
  86. data/app/views/lato_blog/back/posts/shared/index/_index_status_switch.html.erb +29 -0
  87. data/app/views/lato_blog/back/posts/shared/new/_new_informations.html.erb +21 -0
  88. data/app/views/lato_blog/doc/doc/index.html.erb +83 -0
  89. data/app/views/lato_blog/doc/fields/composed.html.erb +87 -0
  90. data/app/views/lato_blog/doc/fields/datetime.html.erb +0 -0
  91. data/app/views/lato_blog/doc/fields/editor.html.erb +1 -0
  92. data/app/views/lato_blog/doc/fields/geolocalization.html.erb +1 -0
  93. data/app/views/lato_blog/doc/fields/image.html.erb +70 -0
  94. data/app/views/lato_blog/doc/fields/relay.html.erb +87 -0
  95. data/app/views/lato_blog/doc/fields/text.html.erb +70 -0
  96. data/app/views/lato_blog/doc/general/api.html.erb +0 -0
  97. data/app/views/lato_blog/doc/general/installation.html.erb +49 -0
  98. data/app/views/lato_blog/doc/general/personalization.html.erb +0 -0
  99. data/app/views/lato_blog/partials/_relay_destroy_button.html.erb +5 -0
  100. data/app/views/lato_blog/widgets/_switchlang.html.erb +20 -0
  101. data/config/configs.yml +109 -0
  102. data/config/initializers/assets.rb +4 -0
  103. data/config/initializers/init_system.rb +22 -0
  104. data/config/languages/default.yml +87 -0
  105. data/config/languages/it.yml +87 -0
  106. data/config/routes.rb +16 -0
  107. data/config/routes/api.rb +11 -0
  108. data/config/routes/back.rb +17 -0
  109. data/config/routes/doc.rb +19 -0
  110. data/db/migrate/20170504222008_create_lato_blog_posts.rb +19 -0
  111. data/db/migrate/20170504223521_create_lato_blog_post_parents.rb +9 -0
  112. data/db/migrate/20170516063317_create_lato_blog_categories.rb +16 -0
  113. data/db/migrate/20170516063320_create_lato_blog_category_parents.rb +9 -0
  114. data/db/migrate/20170516063330_create_lato_blog_category_posts.rb +10 -0
  115. data/db/migrate/20170516063330_create_lato_blog_post_fields.rb +18 -0
  116. data/lib/lato_blog.rb +6 -0
  117. data/lib/lato_blog/engine.rb +15 -0
  118. data/lib/lato_blog/interface.rb +17 -0
  119. data/lib/lato_blog/interfaces/categories.rb +34 -0
  120. data/lib/lato_blog/interfaces/fields.rb +195 -0
  121. data/lib/lato_blog/interfaces/languages.rb +15 -0
  122. data/lib/lato_blog/interfaces/posts.rb +13 -0
  123. data/lib/lato_blog/version.rb +3 -0
  124. data/lib/tasks/lato_blog_tasks.rake +4 -0
  125. metadata +223 -0
@@ -0,0 +1,4 @@
1
+ # Style
2
+ Rails.application.config.assets.precompile += %w( lato_blog/application.css )
3
+ # Javascript
4
+ Rails.application.config.assets.precompile += %w( lato_blog/application.js )
@@ -0,0 +1,22 @@
1
+ include LatoBlog::Interface
2
+
3
+ # set languages identifier.
4
+ BLOG_LANGUAGES_IDENTIFIER = blog__get_languages_identifier
5
+
6
+ # set posts possible status.
7
+ BLOG_POSTS_STATUS = {
8
+ deleted: 'deleted',
9
+ drafted: 'drafted',
10
+ published: 'published'
11
+ }
12
+
13
+ # create default category.
14
+ if ActiveRecord::Base.connection.table_exists?('lato_blog_category_parents') &&
15
+ ActiveRecord::Base.connection.table_exists?('lato_blog_categories')
16
+ blog__create_default_category
17
+ end
18
+
19
+ # sync config fields with primary fields.
20
+ if ActiveRecord::Base.connection.table_exists?('lato_blog_post_fields')
21
+ blog__sync_config_post_fields_with_db_post_fields
22
+ end
@@ -0,0 +1,87 @@
1
+ menu:
2
+ posts: Articles
3
+ posts_new: Add new
4
+ posts_index: Show all
5
+ posts_categories: Categories
6
+ post_fields: Fields
7
+ documentation: Doc. Blog
8
+
9
+ pages:
10
+ posts: Articles
11
+ posts_new: New article
12
+ posts_edit: Edit article
13
+ post_fields: Fields
14
+ categories: Categories
15
+ categories_new: New category
16
+ categories_edit: Edit category
17
+ documentation: Documentation
18
+
19
+ flashes:
20
+ post_create_success: The Article was created successfully
21
+ post_not_found: Article not found
22
+ deleted_posts_not_found: There are not deleted articles
23
+ deleted_posts_destroy_success: All deleted posts are destroyed
24
+ post_update_success: The Article was updated successfully
25
+ post_status_not_accepted: The status selected can not be accepted for the article.
26
+ post_publication_datetime_not_accepted: The date for the article can not be accepted.
27
+ post_destroy_success: The Article was destroied successfully
28
+ category_create_success: The Category was created successfully
29
+ category_not_found: Category not found
30
+ category_update_success: The Category was updated successfully
31
+ category_destroy_success: The Category was destroied successfully
32
+ post_categories_not_accepted: There are not categories selected
33
+ post_update_fields_warning: The post is updated but we have some problems with fields
34
+ post_field_not_found: Field not found
35
+ post_field_destroy_success: The Field was destroied successfully
36
+
37
+ forms:
38
+ id: Id
39
+ title: Title
40
+ subtitle: Subtitle
41
+ language: Language
42
+ content: Content
43
+ excerpt: Excerpt
44
+ publication: Publication
45
+ category_father: Category father
46
+ permalink: Permalink
47
+
48
+ mixed:
49
+ languages: Languages
50
+ no_languages: There are not languages on the system
51
+ published_posts: Public articles
52
+ drafted_posts: Drafted articles
53
+ deleted_posts: Deleted articles
54
+ switch_status: Switch status
55
+ update: Update
56
+ save: Save
57
+ create: Create
58
+ show: Show
59
+ cancel: Cancel
60
+ info: Informations
61
+ new_post: New article
62
+ empty_trash: Empty trash
63
+ empty_trash_message: Are you sure to continue? All the deleted articles will be completely destroyed.
64
+ empty_trash_positive: Yes, I'm sure
65
+ empty_trash_negative: No, I don't want
66
+ current_language: Current language
67
+ current_status: Current status
68
+ publication_date: Date of pubblication
69
+ creation_date: Date of creation
70
+ update_date: Date of update
71
+ superuser_creator: Superuser creator
72
+ status: Status
73
+ change_publication_datetime: Change publication date
74
+ child_tree: Child tree
75
+ change_categories: Change categories
76
+ number_of_posts: Number of posts
77
+ key: Key
78
+ typology: Typology
79
+ visibility: Visibility
80
+ post_fields_warning: 'WARNING: Deleting fields could lead to the complete loss of some item data!'
81
+ post_id: Post id
82
+ post_field_id: Post field id
83
+
84
+ posts_status:
85
+ published: Published
86
+ drafted: Drafted
87
+ deleted: Deleted
@@ -0,0 +1,87 @@
1
+ menu:
2
+ posts: Articoli
3
+ posts_new: Aggiungi nuovo
4
+ posts_index: Visualizza tutti
5
+ posts_categories: Categorie
6
+ post_fields: Campi
7
+ documentation: Doc. Blog
8
+
9
+ pages:
10
+ posts: Articoli
11
+ posts_new: Nuovo articolo
12
+ posts_edit: Modifica articolo
13
+ post_fields: Campi
14
+ categories: Categorie
15
+ categories_new: Nuova categoria
16
+ categories_edit: Modifica categoria
17
+ documentation: Documentazione
18
+
19
+ flashes:
20
+ post_create_success: Articolo creato con successo
21
+ post_not_found: Articolo non trovato
22
+ deleted_posts_not_found: Non ci sono articoli nel cestino
23
+ deleted_posts_destroy_success: Tutti gli articoli del cestino sono stati eliminati
24
+ post_update_success: Articolo aggiornato con successo
25
+ post_status_not_accepted: Lo stato selezionato non può essere accettato per l'articolo.
26
+ post_publication_datetime_not_accepted: La data selezionata non può essere accettata per l'articolo.
27
+ post_destroy_success: Articolo eliminato con successo
28
+ category_create_success: Categoria creata con successo
29
+ category_not_found: Categoria non trovata
30
+ category_update_success: Categoria aggiornata con successo
31
+ category_destroy_success: Categoria eliminata con successo
32
+ post_categories_not_accepted: Non ci sono categorie selezionate
33
+ post_update_fields_warning: L'articolo è stato aggiornato ma ci sono state problematiche con il salvataggio dei campi
34
+ post_field_not_found: Campo non trovato
35
+ post_field_destroy_success: Campo eliminato con successo
36
+
37
+ forms:
38
+ id: Id
39
+ title: Titolo
40
+ subtitle: Sottotitolo
41
+ language: Lingua
42
+ content: Contenuto
43
+ excerpt: Riassunto
44
+ publication: Pubblicazione
45
+ category_father: Categoria padre
46
+ permalink: Permalink
47
+
48
+ mixed:
49
+ languages: Lingue
50
+ no_languages: Non ci sono lingue nel sistema
51
+ published_posts: Articoli pubblici
52
+ drafted_posts: Articoli in bozza
53
+ deleted_posts: Articoli nel cestino
54
+ switch_status: Aggiorna stato
55
+ update: Aggiorna
56
+ save: Salva
57
+ create: Crea
58
+ show: Visualizza
59
+ cancel: Cancella
60
+ info: Informazioni
61
+ new_post: Nuovo articolo
62
+ empty_trash: Svuota cestino
63
+ empty_trash_message: Sicuro di continuare? Tutti gli articoli nel cestino verranno rimossi definitivamente.
64
+ empty_trash_positive: Conferma
65
+ empty_trash_negative: Annulla
66
+ current_language: Lingua corrente
67
+ current_status: Stato corrente
68
+ publication_date: Data di pubblicazione
69
+ creation_date: Data di creazione
70
+ update_date: Data di aggioranmento
71
+ superuser_creator: Creato da
72
+ status: Stato
73
+ change_publication_datetime: Aggiorna data di pubblicazione
74
+ child_tree: Albero dei figli
75
+ change_categories: Aggiorna categorie
76
+ number_of_posts: Numero di articoli
77
+ key: Chiave
78
+ typology: Tipologia
79
+ visibility: Visibilità
80
+ post_fields_warning: 'ATTENZIONE: L'eliminazione dei campi può causare la perdita definitiva di alcuni dati degli articoli!'
81
+ post_id: Id articolo
82
+ post_field_id: Id campo
83
+
84
+ posts_status:
85
+ published: Pubblico
86
+ drafted: Bozza
87
+ deleted: Cestinato
data/config/routes.rb ADDED
@@ -0,0 +1,16 @@
1
+ LatoBlog::Engine.routes.draw do
2
+
3
+ # load custom routes files
4
+ def draw(routes_name)
5
+ instance_eval(File.read(LatoBlog::Engine.root.join("config/routes/#{routes_name}.rb")))
6
+ end
7
+
8
+ # set root path
9
+ root 'application#index'
10
+
11
+ # import routes
12
+ draw :api
13
+ draw :back
14
+ draw :doc
15
+
16
+ end
@@ -0,0 +1,11 @@
1
+ namespace :api do
2
+
3
+ # posts
4
+ get 'posts', to: 'posts#index', as: 'posts_index'
5
+ get 'post', to: 'posts#show', as: 'posts_show'
6
+
7
+ # categories
8
+ get 'categories', to: 'categories#index', as: 'categories_index'
9
+ get 'category', to: 'categories#show', as: 'categories_show'
10
+
11
+ end
@@ -0,0 +1,17 @@
1
+ # main routes
2
+ get 'switch_current_language', to: 'back/back#switch_current_language', as: 'switch_current_language'
3
+
4
+ # posts
5
+ resources :posts, module: 'back'
6
+ post 'posts_extra/update_status', to: 'back/posts#update_status', as: 'posts_update_status'
7
+ post 'posts_extra/update_publication_datetime', to: 'back/posts#update_publication_datetime', as: 'posts_update_publication_datetime'
8
+ post 'posts_extra/update_categories', to: 'back/posts#update_categories', as: 'posts_update_categories'
9
+ get 'posts_extra/destroy_all_deleted', to: 'back/posts#destroy_all_deleted', as: 'posts_destroy_all_deleted'
10
+
11
+ # post fields
12
+ resources :post_fields, module: 'back', only: [:index, :destroy]
13
+ post 'post_fields_extra/create_relay_field', to: 'back/post_fields#create_relay_field', as: 'post_fields_create_relay_field'
14
+ post 'post_fields_extra/destroy_relay_field', to: 'back/post_fields#destroy_relay_field', as: 'post_fields_destroy_relay_field'
15
+
16
+ # categories
17
+ resources :categories, module: 'back'
@@ -0,0 +1,19 @@
1
+ namespace :doc do
2
+
3
+ root 'doc#index'
4
+
5
+ # general
6
+ get 'general_installation', to: 'general#installation', as: 'general_installation'
7
+ get 'general_personalization', to: 'general#personalization', as: 'general_personalization'
8
+ get 'general_api', to: 'general#api', as: 'general_api'
9
+
10
+ # fields
11
+ get 'fields_text', to: 'fields#text', as: 'fields_text'
12
+ get 'fields_datetime', to: 'fields#datetime', as: 'fields_datetime'
13
+ get 'fields_editor', to: 'fields#editor', as: 'fields_editor'
14
+ get 'fields_geolocalization', to: 'fields#geolocalization', as: 'fields_geolocalization'
15
+ get 'fields_image', to: 'fields#image', as: 'fields_image'
16
+ get 'fields_composed', to: 'fields#composed', as: 'fields_composed'
17
+ get 'fields_relay', to: 'fields#relay', as: 'fields_relay'
18
+
19
+ end
@@ -0,0 +1,19 @@
1
+ class CreateLatoBlogPosts < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :lato_blog_posts do |t|
4
+ t.string :title
5
+ t.string :subtitle
6
+ t.text :excerpt
7
+ t.text :content
8
+
9
+ t.string :meta_permalink
10
+ t.string :meta_status
11
+ t.string :meta_language
12
+
13
+ t.integer :lato_core_superuser_creator_id
14
+ t.integer :lato_blog_post_parent_id
15
+
16
+ t.timestamps
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ class CreateLatoBlogPostParents < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :lato_blog_post_parents do |t|
4
+ t.datetime :publication_datetime
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ class CreateLatoBlogCategories < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :lato_blog_categories do |t|
4
+ t.string :title
5
+
6
+ t.string :meta_permalink
7
+ t.string :meta_language
8
+
9
+ t.integer :lato_core_superuser_creator_id
10
+ t.integer :lato_blog_category_parent_id
11
+ t.integer :lato_blog_category_id
12
+
13
+ t.timestamps
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ class CreateLatoBlogCategoryParents < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :lato_blog_category_parents do |t|
4
+ t.boolean :meta_default
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ class CreateLatoBlogCategoryPosts < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :lato_blog_category_posts do |t|
4
+ t.integer :lato_blog_category_id
5
+ t.integer :lato_blog_post_id
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ class CreateLatoBlogPostFields < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :lato_blog_post_fields do |t|
4
+ t.integer :lato_blog_post_id
5
+ t.string :key
6
+ t.string :typology
7
+ t.integer :position
8
+ t.text :value
9
+
10
+ t.text :meta_datas
11
+ t.boolean :meta_visible
12
+
13
+ t.integer :lato_blog_post_field_id
14
+
15
+ t.timestamps
16
+ end
17
+ end
18
+ end
data/lib/lato_blog.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "lato_blog/engine"
2
+ require "lato_blog/interface"
3
+
4
+ module LatoBlog
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,15 @@
1
+ module LatoBlog
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace LatoBlog
4
+
5
+ require 'rubygems'
6
+
7
+ # add routes support
8
+ initializer 'Add gem routes to application', before: :load_config_initializers do
9
+ Rails.application.routes.append do
10
+ mount LatoBlog::Engine, at: '/lato/blog'
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ module LatoBlog
2
+ module Interface
3
+
4
+ require 'lato_blog/interfaces/languages'
5
+ include LatoBlog::Interface::Languages
6
+
7
+ require 'lato_blog/interfaces/posts'
8
+ include LatoBlog::Interface::Posts
9
+
10
+ require 'lato_blog/interfaces/categories'
11
+ include LatoBlog::Interface::Categories
12
+
13
+ require 'lato_blog/interfaces/fields'
14
+ include LatoBlog::Interface::Fields
15
+
16
+ end
17
+ end
@@ -0,0 +1,34 @@
1
+ module LatoBlog
2
+
3
+ # This module contains a list of functions used to manage categories for the blog.
4
+ module Interface::Categories
5
+
6
+ # This function create the default category if it not exists.
7
+ def blog__create_default_category
8
+ category_parent = LatoBlog::CategoryParent.find_by(meta_default: true)
9
+ return if category_parent
10
+
11
+ category_parent = LatoBlog::CategoryParent.new(meta_default: true)
12
+ throw 'Impossible to create default category parent' unless category_parent.save
13
+
14
+ languages = blog__get_languages_identifier
15
+ languages.each do |language|
16
+ category = LatoBlog::Category.new(
17
+ title: 'Default',
18
+ meta_permalink: "default_#{language}",
19
+ meta_language: language,
20
+ lato_core_superuser_creator_id: 1,
21
+ lato_blog_category_parent_id: category_parent.id
22
+ )
23
+ throw 'Impossible to create default category' unless category.save
24
+ end
25
+ end
26
+
27
+ # This function cleans all old category parents without any child.
28
+ def blog__clean_category_parents
29
+ category_parents = LatoBlog::CategoryParent.all
30
+ category_parents.map { |cp| cp.destroy if cp.categories.empty? }
31
+ end
32
+
33
+ end
34
+ end