lato_blog 2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +27 -0
- data/Rakefile +5 -0
- data/app/assets/config/lato_blog_manifest.js +2 -0
- data/app/assets/javascripts/lato_blog/application.js +19 -0
- data/app/assets/javascripts/lato_blog/initializers/Fields.js +56 -0
- data/app/assets/javascripts/lato_blog/initializers/Posts.js +54 -0
- data/app/assets/stylesheets/lato_blog/_helpers.scss +37 -0
- data/app/assets/stylesheets/lato_blog/application.scss +20 -0
- data/app/assets/stylesheets/lato_blog/fields/_composed.scss +7 -0
- data/app/assets/stylesheets/lato_blog/fields/_datetime.scss +0 -0
- data/app/assets/stylesheets/lato_blog/fields/_editor.scss +3 -0
- data/app/assets/stylesheets/lato_blog/fields/_fields.scss +8 -0
- data/app/assets/stylesheets/lato_blog/fields/_general.scss +9 -0
- data/app/assets/stylesheets/lato_blog/fields/_geolocalization.scss +3 -0
- data/app/assets/stylesheets/lato_blog/fields/_image.scss +3 -0
- data/app/assets/stylesheets/lato_blog/fields/_relay.scss +121 -0
- data/app/assets/stylesheets/lato_blog/fields/_text.scss +3 -0
- data/app/assets/stylesheets/lato_blog/pages/_categories.scss +18 -0
- data/app/assets/stylesheets/lato_blog/pages/_pages.scss +2 -0
- data/app/assets/stylesheets/lato_blog/pages/_posts.scss +25 -0
- data/app/assets/stylesheets/lato_blog/theme.scss.erb +12 -0
- data/app/assets/stylesheets/lato_blog/widgets/_switchlang.scss +3 -0
- data/app/assets/stylesheets/lato_blog/widgets/_widgets.scss +1 -0
- data/app/controllers/lato_blog/api/api_controller.rb +5 -0
- data/app/controllers/lato_blog/api/categories_controller.rb +51 -0
- data/app/controllers/lato_blog/api/posts_controller.rb +93 -0
- data/app/controllers/lato_blog/application_controller.rb +13 -0
- data/app/controllers/lato_blog/back/back_controller.rb +45 -0
- data/app/controllers/lato_blog/back/categories_controller.rb +141 -0
- data/app/controllers/lato_blog/back/post_fields_controller.rb +86 -0
- data/app/controllers/lato_blog/back/posts_controller.rb +340 -0
- data/app/controllers/lato_blog/doc/doc_controller.rb +16 -0
- data/app/controllers/lato_blog/doc/fields_controller.rb +19 -0
- data/app/controllers/lato_blog/doc/general_controller.rb +11 -0
- data/app/helpers/lato_blog/application_helper.rb +13 -0
- data/app/helpers/lato_blog/fields_helper.rb +100 -0
- data/app/jobs/lato_blog/application_job.rb +4 -0
- data/app/mailers/lato_blog/application_mailer.rb +6 -0
- data/app/models/lato_blog/application_record.rb +5 -0
- data/app/models/lato_blog/category.rb +119 -0
- data/app/models/lato_blog/category/entity_helpers.rb +55 -0
- data/app/models/lato_blog/category/serializer_helpers.rb +66 -0
- data/app/models/lato_blog/category_parent.rb +9 -0
- data/app/models/lato_blog/category_post.rb +35 -0
- data/app/models/lato_blog/post.rb +112 -0
- data/app/models/lato_blog/post/entity_helpers.rb +42 -0
- data/app/models/lato_blog/post/serializer_helpers.rb +85 -0
- data/app/models/lato_blog/post_field.rb +50 -0
- data/app/models/lato_blog/post_field/entity_helpers.rb +5 -0
- data/app/models/lato_blog/post_field/serializer_helpers.rb +127 -0
- data/app/models/lato_blog/post_parent.rb +20 -0
- data/app/views/lato_blog/back/back/switch_current_language.js +2 -0
- data/app/views/lato_blog/back/categories/edit.html.erb +44 -0
- data/app/views/lato_blog/back/categories/index.html.erb +18 -0
- data/app/views/lato_blog/back/categories/new.html.erb +40 -0
- data/app/views/lato_blog/back/categories/shared/_form.html.erb +38 -0
- data/app/views/lato_blog/back/categories/shared/edit/_edit_child_tree.html.erb +23 -0
- data/app/views/lato_blog/back/categories/shared/edit/_edit_child_tree_level.html.erb +7 -0
- data/app/views/lato_blog/back/categories/shared/edit/_edit_informations.html.erb +24 -0
- data/app/views/lato_blog/back/categories/shared/edit/_edit_languages.html.erb +38 -0
- data/app/views/lato_blog/back/categories/shared/new/_new_informations.html.erb +21 -0
- data/app/views/lato_blog/back/post_fields/create_relay_field.js.erb +14 -0
- data/app/views/lato_blog/back/post_fields/destroy_relay_field.js.erb +14 -0
- data/app/views/lato_blog/back/post_fields/fields/_composed.html.erb +24 -0
- data/app/views/lato_blog/back/post_fields/fields/_datetime.html.erb +17 -0
- data/app/views/lato_blog/back/post_fields/fields/_editor.html.erb +17 -0
- data/app/views/lato_blog/back/post_fields/fields/_geolocalization.html.erb +22 -0
- data/app/views/lato_blog/back/post_fields/fields/_image.html.erb +18 -0
- data/app/views/lato_blog/back/post_fields/fields/_relay.html.erb +39 -0
- data/app/views/lato_blog/back/post_fields/fields/_text.html.erb +17 -0
- data/app/views/lato_blog/back/post_fields/index.html.erb +28 -0
- data/app/views/lato_blog/back/posts/edit.html.erb +48 -0
- data/app/views/lato_blog/back/posts/index.html.erb +38 -0
- data/app/views/lato_blog/back/posts/new.html.erb +40 -0
- data/app/views/lato_blog/back/posts/shared/_fields.html.erb +13 -0
- data/app/views/lato_blog/back/posts/shared/_form.html.erb +69 -0
- data/app/views/lato_blog/back/posts/shared/edit/_edit_categories.html.erb +36 -0
- data/app/views/lato_blog/back/posts/shared/edit/_edit_informations.html.erb +26 -0
- data/app/views/lato_blog/back/posts/shared/edit/_edit_languages.html.erb +40 -0
- data/app/views/lato_blog/back/posts/shared/edit/_edit_pubblication_datetime.html.erb +24 -0
- data/app/views/lato_blog/back/posts/shared/edit/_edit_status_switch.html.erb +27 -0
- data/app/views/lato_blog/back/posts/shared/index/_index.html.erb +28 -0
- data/app/views/lato_blog/back/posts/shared/index/_index_informations.html.erb +37 -0
- data/app/views/lato_blog/back/posts/shared/index/_index_status_switch.html.erb +29 -0
- data/app/views/lato_blog/back/posts/shared/new/_new_informations.html.erb +21 -0
- data/app/views/lato_blog/doc/doc/index.html.erb +83 -0
- data/app/views/lato_blog/doc/fields/composed.html.erb +87 -0
- data/app/views/lato_blog/doc/fields/datetime.html.erb +0 -0
- data/app/views/lato_blog/doc/fields/editor.html.erb +1 -0
- data/app/views/lato_blog/doc/fields/geolocalization.html.erb +1 -0
- data/app/views/lato_blog/doc/fields/image.html.erb +70 -0
- data/app/views/lato_blog/doc/fields/relay.html.erb +87 -0
- data/app/views/lato_blog/doc/fields/text.html.erb +70 -0
- data/app/views/lato_blog/doc/general/api.html.erb +0 -0
- data/app/views/lato_blog/doc/general/installation.html.erb +49 -0
- data/app/views/lato_blog/doc/general/personalization.html.erb +0 -0
- data/app/views/lato_blog/partials/_relay_destroy_button.html.erb +5 -0
- data/app/views/lato_blog/widgets/_switchlang.html.erb +20 -0
- data/config/configs.yml +109 -0
- data/config/initializers/assets.rb +4 -0
- data/config/initializers/init_system.rb +22 -0
- data/config/languages/default.yml +87 -0
- data/config/languages/it.yml +87 -0
- data/config/routes.rb +16 -0
- data/config/routes/api.rb +11 -0
- data/config/routes/back.rb +17 -0
- data/config/routes/doc.rb +19 -0
- data/db/migrate/20170504222008_create_lato_blog_posts.rb +19 -0
- data/db/migrate/20170504223521_create_lato_blog_post_parents.rb +9 -0
- data/db/migrate/20170516063317_create_lato_blog_categories.rb +16 -0
- data/db/migrate/20170516063320_create_lato_blog_category_parents.rb +9 -0
- data/db/migrate/20170516063330_create_lato_blog_category_posts.rb +10 -0
- data/db/migrate/20170516063330_create_lato_blog_post_fields.rb +18 -0
- data/lib/lato_blog.rb +6 -0
- data/lib/lato_blog/engine.rb +15 -0
- data/lib/lato_blog/interface.rb +17 -0
- data/lib/lato_blog/interfaces/categories.rb +34 -0
- data/lib/lato_blog/interfaces/fields.rb +195 -0
- data/lib/lato_blog/interfaces/languages.rb +15 -0
- data/lib/lato_blog/interfaces/posts.rb +13 -0
- data/lib/lato_blog/version.rb +3 -0
- data/lib/tasks/lato_blog_tasks.rake +4 -0
- metadata +223 -0
@@ -0,0 +1,119 @@
|
|
1
|
+
module LatoBlog
|
2
|
+
class Category < ApplicationRecord
|
3
|
+
|
4
|
+
include Category::EntityHelpers
|
5
|
+
include Category::SerializerHelpers
|
6
|
+
|
7
|
+
# Validations:
|
8
|
+
|
9
|
+
validates :title, presence: true, length: { maximum: 250 }
|
10
|
+
|
11
|
+
validates :meta_permalink, presence: true, uniqueness: true,
|
12
|
+
length: { maximum: 250 }
|
13
|
+
validates :meta_language, presence: true, length: { maximum: 250 },
|
14
|
+
inclusion: { in: ([nil] + BLOG_LANGUAGES_IDENTIFIER) }
|
15
|
+
|
16
|
+
# Relations:
|
17
|
+
|
18
|
+
belongs_to :category_parent, foreign_key: :lato_blog_category_parent_id,
|
19
|
+
class_name: 'LatoBlog::CategoryParent'
|
20
|
+
|
21
|
+
belongs_to :superuser_creator, foreign_key: :lato_core_superuser_creator_id,
|
22
|
+
class_name: 'LatoCore::Superuser'
|
23
|
+
|
24
|
+
has_many :category_children, foreign_key: :lato_blog_category_id,
|
25
|
+
class_name: 'LatoBlog::Category',
|
26
|
+
dependent: :nullify
|
27
|
+
belongs_to :category_father, foreign_key: :lato_blog_category_id,
|
28
|
+
class_name: 'LatoBlog::Category',
|
29
|
+
optional: true
|
30
|
+
|
31
|
+
has_many :post_relations, foreign_key: :lato_blog_category_id,
|
32
|
+
class_name: 'LatoBlog::CategoryPost',
|
33
|
+
dependent: :destroy
|
34
|
+
has_many :posts, through: :post_relations
|
35
|
+
|
36
|
+
# Scopes:
|
37
|
+
|
38
|
+
scope :roots, -> { where(lato_blog_category_id: nil) }
|
39
|
+
|
40
|
+
# Callbacks:
|
41
|
+
|
42
|
+
before_validation :check_meta_permalink, on: :create
|
43
|
+
|
44
|
+
before_save do
|
45
|
+
self.meta_permalink = meta_permalink.parameterize
|
46
|
+
meta_language.downcase!
|
47
|
+
|
48
|
+
check_category_father_circular_dependency
|
49
|
+
check_category_father_language
|
50
|
+
|
51
|
+
check_lato_blog_category_parent
|
52
|
+
end
|
53
|
+
|
54
|
+
after_destroy do
|
55
|
+
blog__clean_category_parents
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
# This function check if current permalink is valid. If it is not valid it
|
61
|
+
# generate a new from the post title.
|
62
|
+
def check_meta_permalink
|
63
|
+
candidate = (self.meta_permalink ? self.meta_permalink : self.title.parameterize)
|
64
|
+
accepted = nil
|
65
|
+
counter = 0
|
66
|
+
|
67
|
+
while accepted.nil?
|
68
|
+
if LatoBlog::Category.find_by(meta_permalink: candidate)
|
69
|
+
counter += 1
|
70
|
+
candidate = "#{candidate}-#{counter}"
|
71
|
+
else
|
72
|
+
accepted = candidate
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
self.meta_permalink = accepted
|
77
|
+
end
|
78
|
+
|
79
|
+
# This function check the category parent of the category do not create a circular dependency.
|
80
|
+
def check_category_father_circular_dependency
|
81
|
+
return unless self.lato_blog_category_id
|
82
|
+
|
83
|
+
all_children = self.get_all_category_children
|
84
|
+
same_children = all_children.select { |child| child.id === self.lato_blog_category_id }
|
85
|
+
|
86
|
+
if same_children.length > 0
|
87
|
+
errors.add('Category father', 'can not be a children of the category')
|
88
|
+
throw :abort
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# This function check the chategory parent has the same language of the child.
|
93
|
+
def check_category_father_language
|
94
|
+
return unless self.lato_blog_category_id
|
95
|
+
if self.category_father.meta_language != self.meta_language
|
96
|
+
errors.add('Category father', 'must have the same language of the child')
|
97
|
+
throw :abort
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# This function check that the category parent exist and has not others categories for the same language.
|
102
|
+
def check_lato_blog_category_parent
|
103
|
+
category_parent = LatoBlog::CategoryParent.find_by(id: lato_blog_category_parent_id)
|
104
|
+
if !category_parent
|
105
|
+
errors.add('Category parent', 'not exist for the category')
|
106
|
+
throw :abort
|
107
|
+
return
|
108
|
+
end
|
109
|
+
|
110
|
+
same_language_category = category_parent.categories.find_by(meta_language: meta_language)
|
111
|
+
if same_language_category && same_language_category.id != id
|
112
|
+
errors.add('Category parent', 'has another category for the same language')
|
113
|
+
throw :abort
|
114
|
+
return
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module LatoBlog
|
2
|
+
module Category::EntityHelpers
|
3
|
+
|
4
|
+
# This function return the pretty name of the language of the category.
|
5
|
+
def get_pretty_language
|
6
|
+
CONFIGS[:lato_blog][:languages].values.each do |language|
|
7
|
+
return language[:title] if language[:identifier] === self.meta_language
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# This function returns a pretty presentation of the creation date for the post.
|
12
|
+
def get_pretty_created_at
|
13
|
+
self.created_at.strftime('%d/%m/%Y - %H:%M')
|
14
|
+
end
|
15
|
+
|
16
|
+
# This function returns a pretty presentation of the update date for the post.
|
17
|
+
def get_pretty_updated_at
|
18
|
+
self.updated_at.strftime('%d/%m/%Y - %H:%M')
|
19
|
+
end
|
20
|
+
|
21
|
+
# This function returns the name of the superuser creator of the post.
|
22
|
+
def get_superuser_creator_name
|
23
|
+
self.superuser_creator ? self.superuser_creator.get_complete_name : 'Anonymous'
|
24
|
+
end
|
25
|
+
|
26
|
+
# This function return the title of the category father.
|
27
|
+
def get_category_father_title
|
28
|
+
self.category_father.title if self.category_father
|
29
|
+
end
|
30
|
+
|
31
|
+
# This function the post translation for a specific language.
|
32
|
+
def get_translation_for_language language_identifier
|
33
|
+
self.category_parent.categories.find_by(meta_language: language_identifier)
|
34
|
+
end
|
35
|
+
|
36
|
+
# This function return all category children of the current category.
|
37
|
+
def get_all_category_children
|
38
|
+
direct_children = self.category_children
|
39
|
+
all_children = []
|
40
|
+
|
41
|
+
direct_children.each do |direct_child|
|
42
|
+
all_children.push(direct_child)
|
43
|
+
all_children = all_children + direct_child.get_all_category_children
|
44
|
+
end
|
45
|
+
|
46
|
+
all_children
|
47
|
+
end
|
48
|
+
|
49
|
+
# This function return the number of posts of the category.
|
50
|
+
def get_number_of_posts
|
51
|
+
self.posts.length
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module LatoBlog
|
2
|
+
module Category::SerializerHelpers
|
3
|
+
|
4
|
+
# This function serializes a complete version of the category.
|
5
|
+
def serialize
|
6
|
+
serialized = {}
|
7
|
+
|
8
|
+
# set basic info
|
9
|
+
serialized[:id] = id
|
10
|
+
serialized[:title] = title
|
11
|
+
serialized[:meta_language] = meta_language
|
12
|
+
serialized[:meta_permalink] = meta_permalink
|
13
|
+
|
14
|
+
# add category father informations
|
15
|
+
serialized[:category_father] = category_father ? category_father.serialize_base : nil
|
16
|
+
|
17
|
+
# add category children informations
|
18
|
+
serialized[:category_children] = serialize_category_children
|
19
|
+
|
20
|
+
# add category parent informations
|
21
|
+
serialized[:other_informations] = serialize_other_informations
|
22
|
+
|
23
|
+
# return serialized post
|
24
|
+
serialized
|
25
|
+
end
|
26
|
+
|
27
|
+
# This function serializes a basic version of the category.
|
28
|
+
def serialize_base
|
29
|
+
serialized = {}
|
30
|
+
|
31
|
+
# set basic info
|
32
|
+
serialized[:id] = id
|
33
|
+
serialized[:title] = title
|
34
|
+
serialized[:meta_language] = meta_language
|
35
|
+
serialized[:meta_permalink] = meta_permalink
|
36
|
+
|
37
|
+
# return serialized category
|
38
|
+
serialized
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def serialize_category_children
|
44
|
+
serialized = {}
|
45
|
+
category_children.each do |category|
|
46
|
+
serialized[category.id] = category.serialize_base
|
47
|
+
end
|
48
|
+
serialized
|
49
|
+
end
|
50
|
+
|
51
|
+
def serialize_other_informations
|
52
|
+
serialized = {}
|
53
|
+
|
54
|
+
# set translations links
|
55
|
+
serialized[:translations] = {}
|
56
|
+
category_parent.categories.each do |category|
|
57
|
+
next if category.id == id
|
58
|
+
serialized[:translations][category.meta_language] = category.serialize_base
|
59
|
+
end
|
60
|
+
|
61
|
+
# return serialzed informations
|
62
|
+
serialized
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module LatoBlog
|
2
|
+
class CategoryPost < ApplicationRecord
|
3
|
+
|
4
|
+
# Validations:
|
5
|
+
|
6
|
+
validates :lato_blog_category_id, presence: true
|
7
|
+
validates :lato_blog_post_id, presence: true
|
8
|
+
|
9
|
+
# Relations:
|
10
|
+
|
11
|
+
belongs_to :category, foreign_key: :lato_blog_category_id, class_name: 'LatoBlog::Category'
|
12
|
+
|
13
|
+
belongs_to :post, foreign_key: :lato_blog_post_id, class_name: 'LatoBlog::Post'
|
14
|
+
|
15
|
+
# Callbacks:
|
16
|
+
|
17
|
+
before_save do
|
18
|
+
check_relation_language
|
19
|
+
end
|
20
|
+
|
21
|
+
after_save do
|
22
|
+
blog__sync_config_post_fields_with_db_post_fields_for_post(post)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def check_relation_language
|
28
|
+
if self.category.meta_language != self.post.meta_language
|
29
|
+
errors.add('Category and Post', 'have not same language')
|
30
|
+
throw :abort
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module LatoBlog
|
2
|
+
class Post < ApplicationRecord
|
3
|
+
|
4
|
+
include Post::EntityHelpers
|
5
|
+
include Post::SerializerHelpers
|
6
|
+
|
7
|
+
# Validations:
|
8
|
+
|
9
|
+
validates :title, presence: true, length: { maximum: 250 }
|
10
|
+
|
11
|
+
validates :meta_permalink, presence: true, uniqueness: true, length: { maximum: 250 }
|
12
|
+
validates :meta_status, presence: true, length: { maximum: 250 }, inclusion: { in: BLOG_POSTS_STATUS.values }
|
13
|
+
validates :meta_language, presence: true, length: { maximum: 250 }, inclusion: { in: ([nil] + BLOG_LANGUAGES_IDENTIFIER) }
|
14
|
+
|
15
|
+
# Relations:
|
16
|
+
|
17
|
+
belongs_to :post_parent, foreign_key: :lato_blog_post_parent_id,
|
18
|
+
class_name: 'LatoBlog::PostParent'
|
19
|
+
|
20
|
+
belongs_to :superuser_creator, foreign_key: :lato_core_superuser_creator_id,
|
21
|
+
class_name: 'LatoCore::Superuser'
|
22
|
+
|
23
|
+
has_many :post_fields, foreign_key: :lato_blog_post_id,
|
24
|
+
class_name: 'LatoBlog::PostField',
|
25
|
+
dependent: :destroy
|
26
|
+
|
27
|
+
has_many :category_relations, foreign_key: :lato_blog_post_id,
|
28
|
+
class_name: 'LatoBlog::CategoryPost',
|
29
|
+
dependent: :destroy
|
30
|
+
has_many :categories, through: :category_relations
|
31
|
+
|
32
|
+
# Scopes:
|
33
|
+
|
34
|
+
scope :published, -> { where(meta_status: BLOG_POSTS_STATUS[:published]) }
|
35
|
+
scope :drafted, -> { where(meta_status: BLOG_POSTS_STATUS[:drafted]) }
|
36
|
+
scope :deleted, -> { where(meta_status: BLOG_POSTS_STATUS[:deleted]) }
|
37
|
+
|
38
|
+
# Callbacks:
|
39
|
+
|
40
|
+
before_validation :check_meta_permalink, on: :create
|
41
|
+
|
42
|
+
before_save do
|
43
|
+
self.meta_permalink = meta_permalink.parameterize
|
44
|
+
meta_status.downcase!
|
45
|
+
meta_language.downcase!
|
46
|
+
|
47
|
+
check_lato_blog_post_parent
|
48
|
+
end
|
49
|
+
|
50
|
+
after_save do
|
51
|
+
blog__sync_config_post_fields_with_db_post_fields_for_post(self)
|
52
|
+
end
|
53
|
+
|
54
|
+
after_create do
|
55
|
+
add_to_default_category
|
56
|
+
end
|
57
|
+
|
58
|
+
after_destroy do
|
59
|
+
blog__clean_post_parents
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
# This function check if current permalink is valid. If it is not valid it
|
65
|
+
# generate a new from the post title.
|
66
|
+
def check_meta_permalink
|
67
|
+
candidate = (meta_permalink ? meta_permalink : title.parameterize)
|
68
|
+
accepted = nil
|
69
|
+
counter = 0
|
70
|
+
|
71
|
+
while accepted.nil?
|
72
|
+
if LatoBlog::Post.find_by(meta_permalink: candidate)
|
73
|
+
counter = counter + 1
|
74
|
+
candidate = "#{candidate}-#{counter}"
|
75
|
+
else
|
76
|
+
accepted = candidate
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
self.meta_permalink = accepted
|
81
|
+
end
|
82
|
+
|
83
|
+
# This function check that the post parent exist and has not others post for the same language.
|
84
|
+
def check_lato_blog_post_parent
|
85
|
+
post_parent = LatoBlog::PostParent.find_by(id: lato_blog_post_parent_id)
|
86
|
+
if !post_parent
|
87
|
+
errors.add('Post parent', 'not exist for the post')
|
88
|
+
throw :abort
|
89
|
+
return
|
90
|
+
end
|
91
|
+
|
92
|
+
same_language_post = post_parent.posts.find_by(meta_language: meta_language)
|
93
|
+
if same_language_post && same_language_post.id != id
|
94
|
+
errors.add('Post parent', 'has another post for the same language')
|
95
|
+
throw :abort
|
96
|
+
return
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# This function add the post to the default category.
|
101
|
+
def add_to_default_category
|
102
|
+
default_category_parent = LatoBlog::CategoryParent.find_by(meta_default: true)
|
103
|
+
return unless default_category_parent
|
104
|
+
|
105
|
+
category = default_category_parent.categories.find_by(meta_language: meta_language)
|
106
|
+
return unless category
|
107
|
+
|
108
|
+
LatoBlog::CategoryPost.create(lato_blog_post_id: id, lato_blog_category_id: category.id)
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module LatoBlog
|
2
|
+
module Post::EntityHelpers
|
3
|
+
|
4
|
+
# This function returns a pretty presentation of the pubblication date for the post.
|
5
|
+
def get_pretty_publication_datetime
|
6
|
+
return self.post_parent.publication_datetime.strftime('%d/%m/%Y - %H:%M')
|
7
|
+
end
|
8
|
+
|
9
|
+
# This function returns a pretty presentation of the creation date for the post.
|
10
|
+
def get_pretty_created_at
|
11
|
+
return self.created_at.strftime('%d/%m/%Y - %H:%M')
|
12
|
+
end
|
13
|
+
|
14
|
+
# This function returns a pretty presentation of the update date for the post.
|
15
|
+
def get_pretty_updated_at
|
16
|
+
return self.updated_at.strftime('%d/%m/%Y - %H:%M')
|
17
|
+
end
|
18
|
+
|
19
|
+
# This function returns a pretty presentation of the post status.
|
20
|
+
def get_pretty_status
|
21
|
+
return LANGUAGES[:lato_blog][:posts_status][self.meta_status]
|
22
|
+
end
|
23
|
+
|
24
|
+
# This function returns a pretty presentation of the post language.
|
25
|
+
def get_pretty_language
|
26
|
+
CONFIGS[:lato_blog][:languages].values.each do |language|
|
27
|
+
return language[:title] if language[:identifier] === self.meta_language
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# This function returns the name of the superuser creator of the post.
|
32
|
+
def get_superuser_creator_name
|
33
|
+
return self.superuser_creator ? self.superuser_creator.get_complete_name : 'Anonymous'
|
34
|
+
end
|
35
|
+
|
36
|
+
# This function the post translation for a specific language.
|
37
|
+
def get_translation_for_language(language_identifier)
|
38
|
+
return self.post_parent.posts.find_by(meta_language: language_identifier)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|