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,340 @@
|
|
1
|
+
module LatoBlog
|
2
|
+
class Back::PostsController < Back::BackController
|
3
|
+
|
4
|
+
before_action do
|
5
|
+
core__set_menu_active_item('blog_articles')
|
6
|
+
end
|
7
|
+
|
8
|
+
# This function shows the list of published posts.
|
9
|
+
def index
|
10
|
+
core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:posts])
|
11
|
+
# find correct status to show
|
12
|
+
@posts_status = 'published'
|
13
|
+
@posts_status = 'drafted' if params[:status] && params[:status] === 'drafted'
|
14
|
+
@posts_status = 'deleted' if params[:status] && params[:status] === 'deleted'
|
15
|
+
# find informations data
|
16
|
+
@posts_informations = {
|
17
|
+
published_length: LatoBlog::Post.published.where(meta_language: cookies[:lato_blog__current_language]).length,
|
18
|
+
drafted_length: LatoBlog::Post.drafted.where(meta_language: cookies[:lato_blog__current_language]).length,
|
19
|
+
deleted_length: LatoBlog::Post.deleted.where(meta_language: cookies[:lato_blog__current_language]).length
|
20
|
+
}
|
21
|
+
# find posts to show
|
22
|
+
@posts = LatoBlog::Post.where(meta_status: @posts_status,
|
23
|
+
meta_language: cookies[:lato_blog__current_language]).joins(:post_parent).order('lato_blog_post_parents.publication_datetime DESC')
|
24
|
+
|
25
|
+
@widget_index_posts = core__widgets_index(@posts, search: 'title', pagination: 10)
|
26
|
+
end
|
27
|
+
|
28
|
+
# This function shows a single post. It create a redirect to the edit path.
|
29
|
+
def show
|
30
|
+
# use edit as default post show page
|
31
|
+
redirect_to lato_blog.edit_post_path(params[:id])
|
32
|
+
end
|
33
|
+
|
34
|
+
# This function shows the view to create a new post.
|
35
|
+
def new
|
36
|
+
core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:posts_new])
|
37
|
+
@post = LatoBlog::Post.new
|
38
|
+
|
39
|
+
set_current_language params[:language] if params[:language]
|
40
|
+
|
41
|
+
if params[:parent]
|
42
|
+
@post_parent = LatoBlog::PostParent.find_by(id: params[:parent])
|
43
|
+
end
|
44
|
+
|
45
|
+
fetch_external_objects
|
46
|
+
end
|
47
|
+
|
48
|
+
# This function creates a new post.
|
49
|
+
def create
|
50
|
+
@post = LatoBlog::Post.new(new_post_params)
|
51
|
+
|
52
|
+
unless @post.save
|
53
|
+
flash[:danger] = @post.errors.full_messages.to_sentence
|
54
|
+
redirect_to lato_blog.new_post_path
|
55
|
+
return
|
56
|
+
end
|
57
|
+
|
58
|
+
flash[:success] = LANGUAGES[:lato_blog][:flashes][:post_create_success]
|
59
|
+
redirect_to lato_blog.post_path(@post.id)
|
60
|
+
end
|
61
|
+
|
62
|
+
# This function show the view to edit a post.
|
63
|
+
def edit
|
64
|
+
core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:posts_edit])
|
65
|
+
@post = LatoBlog::Post.find_by(id: params[:id])
|
66
|
+
return unless check_post_presence
|
67
|
+
|
68
|
+
if @post.meta_language != cookies[:lato_blog__current_language]
|
69
|
+
set_current_language @post.meta_language
|
70
|
+
end
|
71
|
+
|
72
|
+
fetch_external_objects
|
73
|
+
end
|
74
|
+
|
75
|
+
# This function updates a post.
|
76
|
+
def update
|
77
|
+
@post = LatoBlog::Post.find_by(id: params[:id])
|
78
|
+
return unless check_post_presence
|
79
|
+
|
80
|
+
# update for autosaving
|
81
|
+
autosaving = params[:autosave] && params[:autosave] == 'true'
|
82
|
+
if autosaving
|
83
|
+
@post.update(edit_post_params)
|
84
|
+
update_fields
|
85
|
+
render status: 200, json: {} # render something positive :)
|
86
|
+
return
|
87
|
+
end
|
88
|
+
|
89
|
+
# check post data update
|
90
|
+
unless @post.update(edit_post_params)
|
91
|
+
flash[:danger] = @post.errors.full_messages.to_sentence
|
92
|
+
redirect_to lato_blog.edit_post_path(@post.id)
|
93
|
+
return
|
94
|
+
end
|
95
|
+
|
96
|
+
# update single fields
|
97
|
+
unless update_fields
|
98
|
+
flash[:warning] = LANGUAGES[:lato_blog][:flashes][:post_update_fields_warning]
|
99
|
+
redirect_to lato_blog.edit_post_path(@post.id)
|
100
|
+
return
|
101
|
+
end
|
102
|
+
|
103
|
+
# render positive response
|
104
|
+
flash[:success] = LANGUAGES[:lato_blog][:flashes][:post_update_success]
|
105
|
+
redirect_to lato_blog.post_path(@post.id)
|
106
|
+
end
|
107
|
+
|
108
|
+
# This function updates the status of a post.
|
109
|
+
def update_status
|
110
|
+
@post = LatoBlog::Post.find_by(id: params[:id])
|
111
|
+
return unless check_post_presence
|
112
|
+
|
113
|
+
@post.update(meta_status: params[:status])
|
114
|
+
end
|
115
|
+
|
116
|
+
# This function updates the publication datetime of a post (update the post parent).
|
117
|
+
def update_publication_datetime
|
118
|
+
@post = LatoBlog::Post.find_by(id: params[:id])
|
119
|
+
return unless check_post_presence
|
120
|
+
|
121
|
+
@post.post_parent.update(publication_datetime: params[:publication_datetime])
|
122
|
+
end
|
123
|
+
|
124
|
+
# This function updates the categories of a post.
|
125
|
+
def update_categories
|
126
|
+
@post = LatoBlog::Post.find_by(id: params[:id])
|
127
|
+
return unless check_post_presence
|
128
|
+
|
129
|
+
params[:categories].each do |category_id, value|
|
130
|
+
category = LatoBlog::Category.find_by(id: category_id)
|
131
|
+
next if !category || category.meta_language != @post.meta_language
|
132
|
+
|
133
|
+
category_post = LatoBlog::CategoryPost.find_by(lato_blog_post_id: @post.id, lato_blog_category_id: category.id)
|
134
|
+
if value == 'true'
|
135
|
+
LatoBlog::CategoryPost.create(lato_blog_post_id: @post.id, lato_blog_category_id: category.id) unless category_post
|
136
|
+
else
|
137
|
+
category_post.destroy if category_post
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# This function destroyes a post.
|
143
|
+
def destroy
|
144
|
+
@post = LatoBlog::Post.find_by(id: params[:id])
|
145
|
+
return unless check_post_presence
|
146
|
+
|
147
|
+
unless @post.destroy
|
148
|
+
flash[:danger] = @post.post_parent.errors.full_messages.to_sentence
|
149
|
+
redirect_to lato_blog.edit_post_path(@post.id)
|
150
|
+
return
|
151
|
+
end
|
152
|
+
|
153
|
+
flash[:success] = LANGUAGES[:lato_blog][:flashes][:post_destroy_success]
|
154
|
+
redirect_to lato_blog.posts_path(status: 'deleted')
|
155
|
+
end
|
156
|
+
|
157
|
+
# Tis function destroyes all posts with status deleted.
|
158
|
+
def destroy_all_deleted
|
159
|
+
@posts = LatoBlog::Post.deleted
|
160
|
+
|
161
|
+
if !@posts || @posts.empty?
|
162
|
+
flash[:warning] = LANGUAGES[:lato_blog][:flashes][:deleted_posts_not_found]
|
163
|
+
redirect_to lato_blog.posts_path(status: 'deleted')
|
164
|
+
return
|
165
|
+
end
|
166
|
+
|
167
|
+
@posts.each do |post|
|
168
|
+
unless post.destroy
|
169
|
+
flash[:danger] = post.errors.full_messages.to_sentence
|
170
|
+
redirect_to lato_blog.edit_post_path(post.id)
|
171
|
+
return
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
flash[:success] = LANGUAGES[:lato_blog][:flashes][:deleted_posts_destroy_success]
|
176
|
+
redirect_to lato_blog.posts_path(status: 'deleted')
|
177
|
+
end
|
178
|
+
|
179
|
+
# Private functions:
|
180
|
+
# **************************************************************************
|
181
|
+
|
182
|
+
private
|
183
|
+
|
184
|
+
def fetch_external_objects
|
185
|
+
@categories = LatoBlog::Category.all.where(meta_language: cookies[:lato_blog__current_language])
|
186
|
+
@medias = LatoMedia::Media.all
|
187
|
+
end
|
188
|
+
|
189
|
+
# This function checks the @post variable is present and redirect to index if it not exist.
|
190
|
+
def check_post_presence
|
191
|
+
if !@post
|
192
|
+
flash[:warning] = LANGUAGES[:lato_blog][:flashes][:post_not_found]
|
193
|
+
redirect_to lato_blog.posts_path
|
194
|
+
return false
|
195
|
+
end
|
196
|
+
|
197
|
+
true
|
198
|
+
end
|
199
|
+
|
200
|
+
# Update fields helpers:
|
201
|
+
# **************************************************************************
|
202
|
+
|
203
|
+
# This function checks all fields params and update the value
|
204
|
+
# on the database for the field.
|
205
|
+
def update_fields
|
206
|
+
return true unless params[:fields]
|
207
|
+
params[:fields].each do |id, value|
|
208
|
+
field = @post.post_fields.find_by(id: id)
|
209
|
+
return false unless field
|
210
|
+
return false unless update_field(field, value)
|
211
|
+
end
|
212
|
+
true
|
213
|
+
end
|
214
|
+
|
215
|
+
# This function updates a single field from its key and value.
|
216
|
+
def update_field(field, value)
|
217
|
+
case field.typology
|
218
|
+
when 'text'
|
219
|
+
update_field_text(field, value)
|
220
|
+
when 'datetime'
|
221
|
+
update_field_datetime(field, value)
|
222
|
+
when 'editor'
|
223
|
+
update_field_editor(field, value)
|
224
|
+
when 'geolocalization'
|
225
|
+
update_field_geolocalization(field, value)
|
226
|
+
when 'image'
|
227
|
+
update_field_image(field, value)
|
228
|
+
when 'composed'
|
229
|
+
update_field_composed(field, value)
|
230
|
+
when 'relay'
|
231
|
+
update_field_relay(field, value)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
# Update specific fields helpers:
|
236
|
+
# **************************************************************************
|
237
|
+
|
238
|
+
# Text.
|
239
|
+
def update_field_text(field, value)
|
240
|
+
field.update(value: value)
|
241
|
+
end
|
242
|
+
|
243
|
+
# Datetime.
|
244
|
+
def update_field_datetime(field, value)
|
245
|
+
field.update(value: value)
|
246
|
+
end
|
247
|
+
|
248
|
+
# Editor.
|
249
|
+
def update_field_editor(field, value)
|
250
|
+
field.update(value: value)
|
251
|
+
end
|
252
|
+
|
253
|
+
# Geolocalization.
|
254
|
+
def update_field_geolocalization(field, value)
|
255
|
+
final_value = {
|
256
|
+
lat: value[:lat],
|
257
|
+
lng: value[:lng],
|
258
|
+
address: value[:address]
|
259
|
+
}
|
260
|
+
field.update(value: final_value)
|
261
|
+
end
|
262
|
+
|
263
|
+
# Image.
|
264
|
+
def update_field_image(field, value)
|
265
|
+
field.update(value: value)
|
266
|
+
end
|
267
|
+
|
268
|
+
# Composed.
|
269
|
+
def update_field_composed(field, value)
|
270
|
+
# find composed children
|
271
|
+
child_fields = field.post_fields.visibles
|
272
|
+
# loop values and update single children
|
273
|
+
value.each do |child_id, child_value|
|
274
|
+
child_field = child_fields.find_by(id: child_id)
|
275
|
+
return false unless child_field
|
276
|
+
return false unless update_field(child_field, child_value)
|
277
|
+
end
|
278
|
+
true
|
279
|
+
end
|
280
|
+
|
281
|
+
# Relay.
|
282
|
+
def update_field_relay(field, value)
|
283
|
+
# find composed children
|
284
|
+
child_fields = field.post_fields.visibles
|
285
|
+
# loop values and update single children
|
286
|
+
value.each do |child_id, child_value|
|
287
|
+
if child_id.include?('position')
|
288
|
+
child_id = child_id.dup
|
289
|
+
child_id.slice! 'position'
|
290
|
+
return false unless update_field_relay_single_position(child_id, child_value, child_fields)
|
291
|
+
else
|
292
|
+
return false unless update_field_relay_single_value(child_id, child_value, child_fields)
|
293
|
+
end
|
294
|
+
end
|
295
|
+
true
|
296
|
+
end
|
297
|
+
|
298
|
+
def update_field_relay_single_value(id, value, child_fields)
|
299
|
+
child_field = child_fields.find_by(id: id)
|
300
|
+
return false unless child_field
|
301
|
+
update_field(child_field, value)
|
302
|
+
end
|
303
|
+
|
304
|
+
def update_field_relay_single_position(id, value, child_fields)
|
305
|
+
child_field = child_fields.find_by(id: id)
|
306
|
+
return false unless child_field
|
307
|
+
child_field.update(position: value)
|
308
|
+
end
|
309
|
+
|
310
|
+
# Params helpers:
|
311
|
+
# **************************************************************************
|
312
|
+
|
313
|
+
# This function generate params for a new post.
|
314
|
+
def new_post_params
|
315
|
+
# take params from front-end request
|
316
|
+
post_params = params.require(:post).permit(:title, :subtitle).to_h
|
317
|
+
# add current superuser id
|
318
|
+
post_params[:lato_core_superuser_creator_id] = @core__current_superuser.id
|
319
|
+
# add post parent id
|
320
|
+
post_params[:lato_blog_post_parent_id] = (params[:parent] && !params[:parent].blank? ? params[:parent] : generate_post_parent)
|
321
|
+
# add metadata
|
322
|
+
post_params[:meta_language] = cookies[:lato_blog__current_language]
|
323
|
+
post_params[:meta_status] = BLOG_POSTS_STATUS[:drafted]
|
324
|
+
# return final post object
|
325
|
+
post_params
|
326
|
+
end
|
327
|
+
|
328
|
+
# This function generate params for a edit post.
|
329
|
+
def edit_post_params
|
330
|
+
params.require(:post).permit(:meta_permalink, :title, :subtitle, :content, :excerpt)
|
331
|
+
end
|
332
|
+
|
333
|
+
# This function generate and save a new post parent and return the id.
|
334
|
+
def generate_post_parent
|
335
|
+
post_parent = LatoBlog::PostParent.create
|
336
|
+
post_parent.id
|
337
|
+
end
|
338
|
+
|
339
|
+
end
|
340
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module LatoBlog
|
2
|
+
class Doc::DocController < ApplicationController
|
3
|
+
|
4
|
+
layout 'lato_core/admin'
|
5
|
+
|
6
|
+
before_action :core__manage_superuser_session
|
7
|
+
|
8
|
+
before_action do
|
9
|
+
core__set_menu_active_item('blog_documentation')
|
10
|
+
core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:documentation])
|
11
|
+
end
|
12
|
+
|
13
|
+
def index; end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module LatoBlog
|
2
|
+
module ApplicationHelper
|
3
|
+
|
4
|
+
# This function returns the title of the current language used by the system.
|
5
|
+
def get_current_language_title
|
6
|
+
return unless cookies[:lato_blog__current_language]
|
7
|
+
CONFIGS[:lato_blog][:languages].values.each do |language|
|
8
|
+
return language[:title] if language[:identifier] === cookies[:lato_blog__current_language]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module LatoBlog
|
2
|
+
module FieldsHelper
|
3
|
+
|
4
|
+
# This function render the partial used to render post fields for a
|
5
|
+
# specific post.
|
6
|
+
def render_post_fields(post)
|
7
|
+
post_fields = post.post_fields.visibles.roots.order('position ASC')
|
8
|
+
render 'lato_blog/back/posts/shared/fields', post_fields: post_fields
|
9
|
+
end
|
10
|
+
|
11
|
+
# This function render a single post field.
|
12
|
+
def render_post_field(post_field, key_parent = 'fields')
|
13
|
+
# define key
|
14
|
+
key = "#{key_parent}[#{post_field.id}]"
|
15
|
+
# render correct field
|
16
|
+
case post_field.typology
|
17
|
+
when 'text'
|
18
|
+
render_post_field_text(post_field, key)
|
19
|
+
when 'datetime'
|
20
|
+
render_post_field_datetime(post_field, key)
|
21
|
+
when 'editor'
|
22
|
+
render_post_field_editor(post_field, key)
|
23
|
+
when 'geolocalization'
|
24
|
+
render_post_field_geolocalization(post_field, key)
|
25
|
+
when 'image'
|
26
|
+
render_post_field_image(post_field, key)
|
27
|
+
when 'composed'
|
28
|
+
render_post_field_composed(post_field, key)
|
29
|
+
when 'relay'
|
30
|
+
render_post_field_relay(post_field, key)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Specific field render functions:
|
35
|
+
# **************************************************************************
|
36
|
+
|
37
|
+
# Text.
|
38
|
+
def render_post_field_text(post_field, key)
|
39
|
+
render 'lato_blog/back/post_fields/fields/text', post_field: post_field, key: key
|
40
|
+
end
|
41
|
+
|
42
|
+
# Datetime.
|
43
|
+
def render_post_field_datetime(post_field, key)
|
44
|
+
render 'lato_blog/back/post_fields/fields/datetime', post_field: post_field, key: key
|
45
|
+
end
|
46
|
+
|
47
|
+
# Editor.
|
48
|
+
def render_post_field_editor(post_field, key)
|
49
|
+
render 'lato_blog/back/post_fields/fields/editor', post_field: post_field, key: key
|
50
|
+
end
|
51
|
+
|
52
|
+
# Geolocalization.
|
53
|
+
def render_post_field_geolocalization(post_field, key)
|
54
|
+
value_object = post_field.value ? eval(post_field.value) : nil
|
55
|
+
render(
|
56
|
+
'lato_blog/back/post_fields/fields/geolocalization',
|
57
|
+
post_field: post_field,
|
58
|
+
key: key,
|
59
|
+
lat: value_object ? value_object[:lat] : nil,
|
60
|
+
lng: value_object ? value_object[:lng] : nil,
|
61
|
+
address: value_object ? value_object[:address] : nil
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Image.
|
66
|
+
def render_post_field_image(post_field, key)
|
67
|
+
render 'lato_blog/back/post_fields/fields/image', post_field: post_field, key: key
|
68
|
+
end
|
69
|
+
|
70
|
+
# Composed.
|
71
|
+
def render_post_field_composed(post_field, key)
|
72
|
+
render 'lato_blog/back/post_fields/fields/composed', post_field: post_field, key: key
|
73
|
+
end
|
74
|
+
|
75
|
+
# Relay.
|
76
|
+
def render_post_field_relay(post_field, key)
|
77
|
+
render 'lato_blog/back/post_fields/fields/relay', post_field: post_field, key: key
|
78
|
+
end
|
79
|
+
|
80
|
+
# Single field helpers functions:
|
81
|
+
# **************************************************************************
|
82
|
+
|
83
|
+
def field_general_get_default_class
|
84
|
+
'xs-12 sm-12 md-12 lg-12'
|
85
|
+
end
|
86
|
+
|
87
|
+
def field_relay_generate_components(post_field)
|
88
|
+
components = []
|
89
|
+
post_field.post_fields.visibles.order('position ASC').each do |child_post_field|
|
90
|
+
components.push({
|
91
|
+
id: "position#{child_post_field.id}",
|
92
|
+
position: child_post_field.position,
|
93
|
+
render: render_post_field(child_post_field, "fields[#{post_field.id}]")
|
94
|
+
})
|
95
|
+
end
|
96
|
+
components
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|