lato_blog 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/MIT-LICENSE +1 -1
  3. data/app/assets/javascripts/lato_blog/modules/BlogPosts.js +8 -0
  4. data/app/assets/stylesheets/lato_blog/pages/_posts.scss +1 -1
  5. data/app/controllers/lato_blog/api/categories_controller.rb +2 -2
  6. data/app/controllers/lato_blog/api/posts_controller.rb +4 -0
  7. data/app/controllers/lato_blog/api/tags_controller.rb +32 -0
  8. data/app/controllers/lato_blog/back/categories_controller.rb +1 -1
  9. data/app/controllers/lato_blog/back/posts_controller.rb +25 -0
  10. data/app/controllers/lato_blog/back/tags_controller.rb +137 -0
  11. data/app/models/lato_blog/post/serializer_helpers.rb +13 -1
  12. data/app/models/lato_blog/post.rb +5 -0
  13. data/app/models/lato_blog/tag/entity_helpers.rb +37 -0
  14. data/app/models/lato_blog/tag/serializer_helpers.rb +52 -0
  15. data/app/models/lato_blog/tag.rb +83 -0
  16. data/app/models/lato_blog/tag_parent.rb +9 -0
  17. data/app/models/lato_blog/tag_post.rb +31 -0
  18. data/app/views/lato_blog/back/categories/edit.html.erb +2 -0
  19. data/app/views/lato_blog/back/categories/index.html.erb +9 -3
  20. data/app/views/lato_blog/back/post_fields/create_relay_field.js.erb +1 -0
  21. data/app/views/lato_blog/back/post_fields/destroy_relay_field.js.erb +1 -0
  22. data/app/views/lato_blog/back/posts/edit.html.erb +4 -0
  23. data/app/views/lato_blog/back/posts/new.html.erb +2 -0
  24. data/app/views/lato_blog/back/posts/shared/edit/_edit_tags.html.erb +28 -0
  25. data/app/views/lato_blog/back/posts/shared/index/_index.html.erb +5 -5
  26. data/app/views/lato_blog/back/tags/edit.html.erb +44 -0
  27. data/app/views/lato_blog/back/tags/index.html.erb +24 -0
  28. data/app/views/lato_blog/back/tags/new.html.erb +40 -0
  29. data/app/views/lato_blog/back/tags/shared/_form.html.erb +34 -0
  30. data/app/views/lato_blog/back/tags/shared/edit/_edit_informations.html.erb +24 -0
  31. data/app/views/lato_blog/back/tags/shared/edit/_edit_languages.html.erb +38 -0
  32. data/app/views/lato_blog/back/tags/shared/new/_new_informations.html.erb +21 -0
  33. data/app/views/lato_blog/doc/doc/index.html.erb +1 -1
  34. data/config/configs.yml +5 -0
  35. data/config/languages/default.yml +11 -1
  36. data/config/languages/it.yml +10 -0
  37. data/config/routes/api.rb +4 -0
  38. data/config/routes/back.rb +5 -1
  39. data/db/migrate/20171020131140_create_lato_blog_tags.rb +15 -0
  40. data/db/migrate/20171021131140_create_lato_blog_tag_parents.rb +8 -0
  41. data/db/migrate/20171022131140_create_lato_blog_tag_posts.rb +10 -0
  42. data/lib/lato_blog/interface.rb +3 -3
  43. data/lib/lato_blog/interfaces/categories.rb +66 -0
  44. data/lib/lato_blog/interfaces/posts.rb +148 -0
  45. data/lib/lato_blog/interfaces/tags.rb +80 -0
  46. data/lib/lato_blog/version.rb +1 -1
  47. metadata +24 -6
  48. data/lib/lato_blog/interfaces/queries.rb +0 -161
@@ -0,0 +1,80 @@
1
+ module LatoBlog
2
+
3
+ # This module contains a list of functions used to manage tags for the blog.
4
+ module Interface::Tags
5
+
6
+ # This function cleans all old tag parents without any child.
7
+ def blog__clean_tag_parents
8
+ tag_parents = LatoBlog::TagParent.all
9
+ tag_parents.map { |tp| tp.destroy if tp.tags.empty? }
10
+ end
11
+
12
+ # This function returns an object with the list of tags with some filters.
13
+ def blog__get_tags(
14
+ order: nil,
15
+ language: nil,
16
+ search: nil,
17
+ page: nil,
18
+ per_page: nil
19
+ )
20
+ tags = LatoBlog::Tag.all
21
+
22
+ # apply filters
23
+ order = order && order == 'ASC' ? 'ASC' : 'DESC'
24
+ tags = _tags_filter_by_order(tags, order)
25
+ tags = _tags_filter_by_language(tags, language)
26
+ tags = _tags_filter_search(tags, search)
27
+
28
+ # take tags uniqueness
29
+ tags = tags.uniq(&:id)
30
+
31
+ # save total tags
32
+ total = tags.length
33
+
34
+ # manage pagination
35
+ page = page&.to_i || 1
36
+ per_page = per_page&.to_i || 20
37
+ tags = core__paginate_array(tags, per_page, page)
38
+
39
+ # return result
40
+ {
41
+ tags: tags && !tags.empty? ? tags.map(&:serialize) : [],
42
+ page: page,
43
+ per_page: per_page,
44
+ order: order,
45
+ total: total
46
+ }
47
+ end
48
+
49
+ # This function returns a single category searched by id or permalink.
50
+ def blog__get_category(id: nil, permalink: nil)
51
+ return {} unless id || permalink
52
+
53
+ if id
54
+ category = LatoBlog::Category.find_by(id: id.to_i)
55
+ else
56
+ category = LatoBlog::Category.find_by(meta_permalink: permalink)
57
+ end
58
+
59
+ category.serialize
60
+ end
61
+
62
+ private
63
+
64
+ def _tags_filter_by_order(tags, order)
65
+ tags.order("title #{order}")
66
+ end
67
+
68
+ def _tags_filter_by_language(tags, language)
69
+ return tags unless language
70
+ tags.where(meta_language: language)
71
+ end
72
+
73
+ def _tags_filter_search(tags, search)
74
+ return tags unless search
75
+ tags.where('title like ?', "%#{search}%")
76
+ end
77
+
78
+ end
79
+ end
80
+
@@ -1,3 +1,3 @@
1
1
  module LatoBlog
2
- VERSION = '2.1.2'
2
+ VERSION = '2.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lato_blog
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ideonetwork
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-27 00:00:00.000000000 Z
11
+ date: 2018-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 2.1.0
47
+ version: 2.1.2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 2.1.0
54
+ version: 2.1.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -101,11 +101,13 @@ files:
101
101
  - app/controllers/lato_blog/api/api_controller.rb
102
102
  - app/controllers/lato_blog/api/categories_controller.rb
103
103
  - app/controllers/lato_blog/api/posts_controller.rb
104
+ - app/controllers/lato_blog/api/tags_controller.rb
104
105
  - app/controllers/lato_blog/application_controller.rb
105
106
  - app/controllers/lato_blog/back/back_controller.rb
106
107
  - app/controllers/lato_blog/back/categories_controller.rb
107
108
  - app/controllers/lato_blog/back/post_fields_controller.rb
108
109
  - app/controllers/lato_blog/back/posts_controller.rb
110
+ - app/controllers/lato_blog/back/tags_controller.rb
109
111
  - app/controllers/lato_blog/doc/doc_controller.rb
110
112
  - app/controllers/lato_blog/doc/fields_controller.rb
111
113
  - app/controllers/lato_blog/doc/general_controller.rb
@@ -126,6 +128,11 @@ files:
126
128
  - app/models/lato_blog/post_field/entity_helpers.rb
127
129
  - app/models/lato_blog/post_field/serializer_helpers.rb
128
130
  - app/models/lato_blog/post_parent.rb
131
+ - app/models/lato_blog/tag.rb
132
+ - app/models/lato_blog/tag/entity_helpers.rb
133
+ - app/models/lato_blog/tag/serializer_helpers.rb
134
+ - app/models/lato_blog/tag_parent.rb
135
+ - app/models/lato_blog/tag_post.rb
129
136
  - app/views/lato_blog/back/back/switch_current_language.js
130
137
  - app/views/lato_blog/back/categories/edit.html.erb
131
138
  - app/views/lato_blog/back/categories/index.html.erb
@@ -159,10 +166,18 @@ files:
159
166
  - app/views/lato_blog/back/posts/shared/edit/_edit_pubblication_datetime.html.erb
160
167
  - app/views/lato_blog/back/posts/shared/edit/_edit_seo_description.html.erb
161
168
  - app/views/lato_blog/back/posts/shared/edit/_edit_status.html.erb
169
+ - app/views/lato_blog/back/posts/shared/edit/_edit_tags.html.erb
162
170
  - app/views/lato_blog/back/posts/shared/index/_index.html.erb
163
171
  - app/views/lato_blog/back/posts/shared/index/_index_informations.html.erb
164
172
  - app/views/lato_blog/back/posts/shared/index/_index_switch_status.html.erb
165
173
  - app/views/lato_blog/back/posts/shared/new/_new_informations.html.erb
174
+ - app/views/lato_blog/back/tags/edit.html.erb
175
+ - app/views/lato_blog/back/tags/index.html.erb
176
+ - app/views/lato_blog/back/tags/new.html.erb
177
+ - app/views/lato_blog/back/tags/shared/_form.html.erb
178
+ - app/views/lato_blog/back/tags/shared/edit/_edit_informations.html.erb
179
+ - app/views/lato_blog/back/tags/shared/edit/_edit_languages.html.erb
180
+ - app/views/lato_blog/back/tags/shared/new/_new_informations.html.erb
166
181
  - app/views/lato_blog/doc/doc/index.html.erb
167
182
  - app/views/lato_blog/doc/fields/composed.html.erb
168
183
  - app/views/lato_blog/doc/fields/datetime.html.erb
@@ -192,6 +207,9 @@ files:
192
207
  - db/migrate/20170516063330_create_lato_blog_category_posts.rb
193
208
  - db/migrate/20170516063330_create_lato_blog_post_fields.rb
194
209
  - db/migrate/20170804131140_add_seo_description_to_lato_blog_posts.rb
210
+ - db/migrate/20171020131140_create_lato_blog_tags.rb
211
+ - db/migrate/20171021131140_create_lato_blog_tag_parents.rb
212
+ - db/migrate/20171022131140_create_lato_blog_tag_posts.rb
195
213
  - lib/lato_blog.rb
196
214
  - lib/lato_blog/engine.rb
197
215
  - lib/lato_blog/interface.rb
@@ -199,7 +217,7 @@ files:
199
217
  - lib/lato_blog/interfaces/fields.rb
200
218
  - lib/lato_blog/interfaces/languages.rb
201
219
  - lib/lato_blog/interfaces/posts.rb
202
- - lib/lato_blog/interfaces/queries.rb
220
+ - lib/lato_blog/interfaces/tags.rb
203
221
  - lib/lato_blog/version.rb
204
222
  - lib/tasks/lato_blog_tasks.rake
205
223
  homepage: http://ideonetwork.it/
@@ -222,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
240
  version: '0'
223
241
  requirements: []
224
242
  rubyforge_project:
225
- rubygems_version: 2.6.12
243
+ rubygems_version: 2.7.3
226
244
  signing_key:
227
245
  specification_version: 4
228
246
  summary: Lato blog module
@@ -1,161 +0,0 @@
1
- module LatoBlog
2
-
3
- # This module contains a list of helpers used on controllers to get posts
4
- # to render the blog elements.
5
- module Interface::Queries
6
-
7
- # This function returns an object with the list of posts with some filters.
8
- def blog__get_posts(order: nil, language: nil, category_permalink: nil, category_permalink_AND: false, category_id: nil, category_id_AND: false, search: nil, page: nil, per_page: nil)
9
- posts = LatoBlog::Post.published.joins(:categories).joins(:post_parent).where('lato_blog_post_parents.publication_datetime <= ?', DateTime.now)
10
-
11
- # apply filters
12
- order = order && order == 'ASC' ? 'ASC' : 'DESC'
13
- posts = _posts_filter_by_order(posts, order)
14
- posts = _posts_filter_by_language(posts, language)
15
- posts = _posts_filter_by_category_permalink(posts, category_permalink, category_permalink_AND)
16
- posts = _posts_filter_category_id(posts, category_id, category_id_AND)
17
- posts = _posts_filter_search(posts, search)
18
-
19
- # take posts uniqueness
20
- posts = posts.uniq(&:id)
21
-
22
- # save total posts
23
- total = posts.length
24
-
25
- # manage pagination
26
- page ||= 1
27
- per_page ||= 20
28
- posts = core__paginate_array(posts, per_page, page)
29
-
30
- # return result
31
- {
32
- posts: posts && !posts.empty? ? posts.map(&:serialize) : [],
33
- page: page,
34
- per_page: per_page,
35
- order: order,
36
- total: total
37
- }
38
- end
39
-
40
- # This function returns a single post searched by id or permalink.
41
- def blog__get_post(id: nil, permalink: nil)
42
- return {} unless id || permalink
43
-
44
- if id
45
- post = LatoBlog::Post.find_by(id: id.to_i, meta_status: 'published')
46
- else
47
- post = LatoBlog::Post.find_by(meta_permalink: permalink, meta_status: 'published')
48
- end
49
-
50
- post.serialize
51
- end
52
-
53
- # This function returns an object with the list of categories with some filters.
54
- def blog__get_categories(order: nil, language: nil, search: nil, page: nil, per_page: nil)
55
- categories = LatoBlog::Category.all
56
-
57
- # apply filters
58
- order = order && order == 'ASC' ? 'ASC' : 'DESC'
59
- categories = _categories_filter_by_order(categories, order)
60
- categories = _categories_filter_by_language(categories, language)
61
- categories = _categories_filter_search(categories, search)
62
-
63
- # take categories uniqueness
64
- categories = categories.uniq(&:id)
65
-
66
- # save total categories
67
- total = categories.length
68
-
69
- # manage pagination
70
- page ||= 1
71
- per_page ||= 20
72
- categories = core__paginate_array(categories, per_page, page)
73
-
74
- # return result
75
- {
76
- categories: categories && !categories.empty? ? categories.map(&:serialize) : [],
77
- page: page,
78
- per_page: per_page,
79
- order: order,
80
- total: total
81
- }
82
- end
83
-
84
- # This function returns a single category searched by id or permalink.
85
- def blog__get_category(id: nil, permalink: nil)
86
- return {} unless id || permalink
87
-
88
- if id
89
- category = LatoBlog::Category.find_by(id: id.to_i)
90
- else
91
- category = LatoBlog::Category.find_by(meta_permalink: permalink)
92
- end
93
-
94
- category.serialize
95
- end
96
-
97
- private
98
-
99
- def _posts_filter_by_order(posts, order)
100
- posts.order("lato_blog_post_parents.publication_datetime #{order}")
101
- end
102
-
103
- def _posts_filter_by_language(posts, language)
104
- return posts unless language
105
- posts.where(meta_language: language)
106
- end
107
-
108
- def _posts_filter_by_category_permalink(posts, category_permalink, category_permalink_AND)
109
- return posts unless category_permalink
110
- category_permalinks = category_permalink.is_a?(Array) ? category_permalink : category_permalink.split(',')
111
- posts = posts.where(lato_blog_categories: { meta_permalink: category_permalinks })
112
- # manage AND clause
113
- if ['true', true].include?(category_permalink_AND)
114
- ids = []
115
- posts.pluck(:id).each do |id|
116
- ids.push(id) if posts.where(id: id).length >= category_permalinks.length
117
- end
118
- posts = posts.where(id: ids)
119
- end
120
- # return posts
121
- posts
122
- end
123
-
124
- def _posts_filter_category_id(posts, category_id, category_id_AND)
125
- return posts unless category_id
126
- category_ids = category_id.is_a?(Array) ? category_id : category_id.split(',')
127
- posts = posts.where(lato_blog_categories: { id: category_ids })
128
- # manage AND clause
129
- if ['true', true].include?(category_id_AND)
130
- ids = []
131
- posts.pluck(:id).each do |id|
132
- ids.push(id) if posts.where(id: id).length >= category_ids.length
133
- end
134
- posts = posts.where(id: ids)
135
- end
136
- # return posts
137
- posts
138
- end
139
-
140
- def _posts_filter_search(posts, search)
141
- return posts unless search
142
- posts.where('lato_blog_posts.title like ?', "%#{params[:search]}%")
143
- end
144
-
145
- def _categories_filter_by_order(categories, order)
146
- categories.order("title #{order}")
147
- end
148
-
149
- def _categories_filter_by_language(categories, language)
150
- return categories unless language
151
- categories.where(meta_language: language)
152
- end
153
-
154
- def _categories_filter_search(categories, search)
155
- return categories unless search
156
- categories.where('title like ?', "%#{search}%")
157
- end
158
-
159
- end
160
-
161
- end