enjoy_cms 0.2.0.2 → 0.2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +5 -5
  3. data/app/controllers/concerns/enjoy/errors.rb +3 -3
  4. data/app/controllers/concerns/enjoy/localizeable.rb +12 -2
  5. data/app/controllers/concerns/enjoy/seo_pages.rb +11 -4
  6. data/app/models/concerns/enjoy/mappable.rb +0 -4
  7. data/app/models/concerns/enjoy/model_localizeable.rb +30 -0
  8. data/app/models/concerns/enjoy/seoable.rb +1 -18
  9. data/app/models/concerns/enjoy/sitemap_data_field.rb +1 -19
  10. data/app/models/enjoy/contact_message.rb +2 -2
  11. data/app/models/enjoy/embedded_element.rb +2 -2
  12. data/app/models/enjoy/embedded_gallery_image.rb +2 -2
  13. data/app/models/enjoy/gallery.rb +2 -2
  14. data/app/models/enjoy/gallery_image.rb +2 -2
  15. data/app/models/enjoy/menu.rb +2 -2
  16. data/app/models/enjoy/news.rb +2 -2
  17. data/app/models/enjoy/page.rb +2 -2
  18. data/app/models/enjoy/seo.rb +2 -3
  19. data/app/models/enjoy/sitemap_data.rb +2 -3
  20. data/app/views/shared/_obj.html.slim +1 -0
  21. data/app/views/simple_captcha/_simple_captcha.html.slim +1 -1
  22. data/lib/enjoy/admin/contact_message.rb +21 -25
  23. data/lib/enjoy/admin/embedded_element.rb +22 -5
  24. data/lib/enjoy/admin/embedded_gallery_image.rb +12 -7
  25. data/lib/enjoy/admin/gallery.rb +24 -10
  26. data/lib/enjoy/admin/gallery_image.rb +22 -10
  27. data/lib/enjoy/admin/menu.rb +10 -18
  28. data/lib/enjoy/admin/news.rb +62 -45
  29. data/lib/enjoy/admin/page.rb +64 -67
  30. data/lib/enjoy/admin/seo.rb +20 -8
  31. data/lib/enjoy/admin/sitemap_data.rb +27 -0
  32. data/lib/enjoy/admin.rb +3 -340
  33. data/lib/enjoy/controllers/sitemap_data.rb +0 -0
  34. data/lib/enjoy/model.rb +6 -1
  35. data/lib/enjoy/models/gallery.rb +1 -11
  36. data/lib/enjoy/models/gallery_image.rb +1 -11
  37. data/lib/enjoy/models/mongoid/embedded_gallery_image.rb +3 -5
  38. data/lib/enjoy/models/mongoid/gallery.rb +3 -5
  39. data/lib/enjoy/models/mongoid/gallery_image.rb +3 -5
  40. data/lib/enjoy/models/mongoid/menu.rb +1 -11
  41. data/lib/enjoy/models/mongoid/page.rb +1 -11
  42. data/lib/enjoy/models/news.rb +0 -2
  43. data/lib/enjoy/models/seo.rb +2 -0
  44. data/lib/enjoy/models/sitemap_data.rb +4 -0
  45. data/lib/enjoy/rails_admin_menu.rb +3 -3
  46. data/lib/enjoy/version.rb +1 -1
  47. data/lib/enjoy_cms.rb +16 -3
  48. metadata +5 -3
  49. data/lib/enjoy/patch.rb +0 -58
@@ -1,56 +1,73 @@
1
1
  module Enjoy
2
2
  module Admin
3
3
  module News
4
- extend ActiveSupport::Concern
5
- include Enjoy::Model
6
- include Seoable
7
- include Enableable
8
- include ManualSlug
9
- include SitemapData
10
- include Enjoy.orm_specific('News')
4
+ def self.config(fields = {})
5
+ Proc.new {
6
+ # navigation_label I18n.t('enjoy.cms')
7
+ list do
8
+ scopes [:by_date, :enabled, nil]
9
+ end
11
10
 
12
- if Enjoy.config.search_enabled
13
- include Enjoy::ElasticSearch
14
- end
15
-
16
- included do
17
-
18
- unless Enjoy.config.news_image_styles.nil?
19
- validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/, if: :image?
20
- end
11
+ field :enabled, :toggle
12
+ field :time do
13
+ sort_reverse true
14
+ end
15
+ field :name
16
+ unless Enjoy.config.news_image_styles.nil?
17
+ field :image, :jcrop do
18
+ jcrop_options :image_jcrop_options
19
+ end
20
+ end
21
+ field :excerpt, :ck_editor
22
+ field :slugs, :enum do
23
+ enum_method do
24
+ :slugs
25
+ end
26
+ visible do
27
+ bindings[:view].current_user.admin?
28
+ end
29
+ multiple do
30
+ true
31
+ end
32
+ end
33
+ field :text_slug
21
34
 
22
- validates_presence_of :name
23
- if Enjoy.config.news_content_required
24
- validates_presence_of :content
25
- end
35
+ list do
36
+ sort_by :time
37
+ end
26
38
 
27
- before_validation do
28
- self.time = Time.now if self.time.blank?
29
- end
30
- scope :recent, ->(count = 5) { enabled.after_now.by_date.limit(count) }
31
- unless Enjoy.config.news_per_page.nil?
32
- paginates_per Enjoy.config.news_per_page
33
- end
34
- smart_excerpt :excerpt, :content, Enjoy.config.news_excerpt
35
- manual_slug :report_slug
39
+ edit do
40
+ field :content, :ck_editor
41
+ fields.each_pair do |name, type|
42
+ if type.nil?
43
+ field name
44
+ else
45
+ if type.is_a?(Array)
46
+ field name, type[0], &type[1]
47
+ else
48
+ field name, type
49
+ end
50
+ end
51
+ end
36
52
 
37
- Enjoy.apply_patches self
38
- end
53
+ group :seo do
54
+ active false
55
+ field :seo do
56
+ active true
57
+ end
58
+ end
59
+ group :sitemap_data do
60
+ active false
61
+ field :sitemap_data do
62
+ active true
63
+ end
64
+ end
65
+ end
39
66
 
40
- def report_slug
41
- if time.blank?
42
- name
43
- elsif name.blank?
44
- time.strftime('%Y-%m-%d')
45
- else
46
- time.strftime('%Y-%m-%d') + '-' + name[0..20]
47
- end
48
- end
49
- def html5_date
50
- time.strftime('%Y-%m-%d')
51
- end
52
- def format_date
53
- time.strftime(I18n.t('rs.format_time'))
67
+ if block_given?
68
+ yield self
69
+ end
70
+ }
54
71
  end
55
72
  end
56
73
  end
@@ -1,80 +1,77 @@
1
1
  module Enjoy
2
2
  module Admin
3
3
  module Page
4
- extend ActiveSupport::Concern
5
- include Enjoy::Model
6
- include Enableable
7
- include Seoable
8
- include ManualSlug
9
- include SitemapData
4
+ def self.config(fields = {})
5
+ Proc.new {
6
+ # navigation_label I18n.t('enjoy.cms')
7
+ list do
8
+ scopes [:sorted, :enabled, nil]
10
9
 
11
- include Enjoy.orm_specific('Page')
12
-
13
- if Enjoy.config.search_enabled
14
- include Enjoy::ElasticSearch
15
- end
16
-
17
- included do
18
-
19
- has_and_belongs_to_many :menus, inverse_of: :pages, class_name: "Enjoy::Menu"
20
- validates_uniqueness_of :fullpath
21
- validates_presence_of :name
22
- manual_slug :name
23
- before_validation do
24
- self.fullpath = "/pages/#{slug}" if self.fullpath.blank?
25
- end
26
- end
27
-
28
- def get_fullpath
29
- redirect.blank? ? fullpath : redirect
30
- end
31
-
32
- def has_content?
33
- @content_used.nil? && !content.blank?
34
- end
35
-
36
- def page_content
37
- if @content_used.nil?
38
- @content_used = true
39
- if content.nil?
40
- ''
41
- else
42
- content.gsub(/\{\{(.*?)\}\}/) do
43
- Settings ? Settings.get($1).val : "" #temp
10
+ field :enabled, :toggle
11
+ field :menus, :menu
12
+ field :name
13
+ field :fullpath do
14
+ pretty_value do
15
+ bindings[:view].content_tag(:a, bindings[:object].fullpath, href: bindings[:object].fullpath)
16
+ end
44
17
  end
18
+ field :redirect
19
+ field :slug
45
20
  end
46
- else
47
- ''
48
- end
49
- end
21
+
22
+ edit do
23
+ field :name
24
+ field :excerpt, :ck_editor
25
+ field :content, :ck_editor
50
26
 
51
- def is_current?(url)
52
- if fullpath == '/'
53
- url == '/'
54
- else
55
- url.match(clean_regexp)
56
- end
57
- end
27
+ group :menu do
28
+ label I18n.t('enjoy.menu')
29
+ field :menus
30
+ field :fullpath, :string do
31
+ help I18n.t('enjoy.with_final_slash')
32
+ end
33
+ field :regexp, :string do
34
+ help I18n.t('enjoy.page_url_regex')
35
+ end
36
+ field :redirect, :string do
37
+ help I18n.t('enjoy.final_in_menu')
38
+ end
39
+ field :text_slug
40
+ end
41
+ fields.each_pair do |name, type|
42
+ if type.nil?
43
+ field name
44
+ else
45
+ if type.is_a?(Array)
46
+ field name, type[0], &type[1]
47
+ else
48
+ field name, type
49
+ end
50
+ end
51
+ end
52
+ group :seo do
53
+ active false
54
+ field :seo do
55
+ active true
56
+ end
57
+ end
58
+ group :sitemap_data do
59
+ active false
60
+ field :sitemap_data do
61
+ active true
62
+ end
63
+ end
64
+ end
58
65
 
59
- def regexp_prefix
60
- ""
61
- end
66
+ nested_set({
67
+ max_depth: Enjoy.config.menu_max_depth,
68
+ scopes: []
69
+ })
62
70
 
63
- def clean_regexp
64
- if regexp.blank?
65
- /^#{regexp_prefix}#{Regexp.escape(fullpath)}$/
66
- else
67
- begin
68
- /#{regexp}/
69
- rescue
70
- # not a valid regexp - treat as literal search string
71
- /#{Regexp.escape(regexp)}/
71
+ if block_given?
72
+ yield self
72
73
  end
73
- end
74
- end
75
-
76
- def nav_options
77
- {highlights_on: clean_regexp}
74
+ }
78
75
  end
79
76
  end
80
77
  end
@@ -1,16 +1,28 @@
1
1
  module Enjoy
2
2
  module Admin
3
3
  module Seo
4
- extend ActiveSupport::Concern
5
- include Enjoy::Model
6
- include Enableable
7
- include Enjoy.orm_specific('Seo')
8
- include Enjoy::SeoHelpers
4
+ def self.config(is_active = true)
5
+ Proc.new {
6
+ navigation_label 'SEO'
7
+ field :seoable do
8
+ read_only true
9
+ end
10
+ field :h1, :string
11
+ field :title, :string
12
+ field :keywords, :text
13
+ field :description, :text
14
+ field :robots, :string
9
15
 
10
- included do
16
+ field :og_title, :string
11
17
 
12
- Enjoy.apply_patches self
13
- validates_attachment_content_type :og_image, content_type: /\Aimage\/.*\Z/, if: :og_image?
18
+ field :og_image, :jcrop do
19
+ jcrop_options :og_image_jcrop_options
20
+ end
21
+
22
+ if block_given?
23
+ yield self
24
+ end
25
+ }
14
26
  end
15
27
  end
16
28
  end
@@ -0,0 +1,27 @@
1
+ module Enjoy
2
+ module Admin
3
+ module SitemapData
4
+ def self.config(is_active = false)
5
+ Proc.new {
6
+ navigation_label 'SEO'
7
+ label I18n.t('enjoy.sitemap_data')
8
+ field :sitemap_data_field do
9
+ read_only true
10
+ end
11
+ field :sitemap_show, :toggle
12
+ field :sitemap_lastmod
13
+ field :sitemap_changefreq, :enum do
14
+ enum do
15
+ Enjoy::SitemapData::SITEMAP_CHANGEFREQ_ARRAY
16
+ end
17
+ end
18
+ field :sitemap_priority
19
+
20
+ if block_given?
21
+ yield self
22
+ end
23
+ }
24
+ end
25
+ end
26
+ end
27
+ end
data/lib/enjoy/admin.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Enjoy
2
- class << self
3
- def map_config(is_active = true)
2
+ module Admin
3
+ def self.map_config(is_active = true)
4
4
  Proc.new {
5
5
  active is_active
6
6
  label I18n.t('enjoy.map')
@@ -15,344 +15,7 @@ module Enjoy
15
15
  field :lon
16
16
 
17
17
  if block_given?
18
- yield
19
- end
20
- }
21
- end
22
-
23
- def seo_config(is_active = true)
24
- Proc.new {
25
- navigation_label 'SEO'
26
- field :seoable do
27
- read_only true
28
- end
29
- field :h1, :string
30
- field :title, :string
31
- field :keywords, :text
32
- field :description, :text
33
- field :robots, :string
34
-
35
- field :og_title, :string
36
-
37
- field :og_image, :jcrop do
38
- jcrop_options :og_image_jcrop_options
39
- end
40
-
41
- if block_given?
42
- yield
43
- end
44
- }
45
- end
46
-
47
- def page_config(fields = {})
48
- Proc.new {
49
- Enjoy.apply_patches self
50
- # navigation_label I18n.t('enjoy.cms')
51
- list do
52
- scopes [:sorted, :enabled, nil]
53
-
54
- field :enabled, :toggle
55
- field :menus, :menu
56
- field :name
57
- field :fullpath do
58
- pretty_value do
59
- bindings[:view].content_tag(:a, bindings[:object].fullpath, href: bindings[:object].fullpath)
60
- end
61
- end
62
- field :redirect
63
- field :slug
64
- Enjoy.apply_patches self
65
- end
66
- edit do
67
- field :name
68
- field :excerpt, :ck_editor
69
- field :content, :ck_editor
70
- Enjoy.apply_patches self
71
- group :menu do
72
- label I18n.t('enjoy.menu')
73
- field :menus
74
- field :fullpath, :string do
75
- help I18n.t('enjoy.with_final_slash')
76
- end
77
- field :regexp, :string do
78
- help I18n.t('enjoy.page_url_regex')
79
- end
80
- field :redirect, :string do
81
- help I18n.t('enjoy.final_in_menu')
82
- end
83
- field :text_slug
84
- end
85
- fields.each_pair do |name, type|
86
- if type.nil?
87
- field name
88
- else
89
- if type.is_a?(Array)
90
- field name, type[0], &type[1]
91
- else
92
- field name, type
93
- end
94
- end
95
- end
96
- group :seo do
97
- active false
98
- field :seo do
99
- active true
100
- end
101
- end
102
- group :sitemap_data do
103
- active false
104
- field :sitemap_data do
105
- active true
106
- end
107
- end
108
- end
109
- Enjoy.only_patches self, [:show, :export]
110
- nested_set({
111
- max_depth: Enjoy.config.menu_max_depth,
112
- scopes: []
113
- })
114
-
115
- if block_given?
116
- yield
117
- end
118
- }
119
- end
120
-
121
- def menu_config
122
- Proc.new {
123
- # navigation_label 'CMS'
124
-
125
- field :enabled, :toggle
126
- field :text_slug
127
- field :name
128
- Enjoy.apply_patches self
129
- Enjoy.only_patches self, [:show, :list, :edit, :export]
130
-
131
- if block_given?
132
- yield
133
- end
134
- }
135
- end
136
-
137
- def contact_message_config
138
- Proc.new {
139
- # navigation_label I18n.t('enjoy.settings')
140
- field :c_at do
141
- read_only true
142
- end
143
- field :name
144
- field :content, :text
145
- field :email
146
- field :phone
147
-
148
- Enjoy.config.contacts_fields.each_pair do |fn, ft|
149
- next if ft.nil?
150
- if ft.is_a?(Array)
151
- field fn, ft[1].to_sym
152
- else
153
- field fn
154
- end
155
- end
156
-
157
- if block_given?
158
- yield
159
- end
160
-
161
- Enjoy.apply_patches self
162
- Enjoy.only_patches self, [:show, :list, :edit, :export]
163
- }
164
- end
165
-
166
- def news_config(fields = {})
167
- Proc.new {
168
- # navigation_label I18n.t('enjoy.cms')
169
- list do
170
- scopes [:by_date, :enabled, nil]
171
- end
172
-
173
- field :enabled, :toggle
174
- field :time do
175
- sort_reverse true
176
- end
177
- field :name
178
- unless Enjoy.config.news_image_styles.nil?
179
- field :image, :jcrop do
180
- jcrop_options :image_jcrop_options
181
- end
182
- end
183
- field :excerpt, :ck_editor
184
- field :slugs, :enum do
185
- enum_method do
186
- :slugs
187
- end
188
- visible do
189
- bindings[:view].current_user.admin?
190
- end
191
- multiple do
192
- true
193
- end
194
- end
195
- field :text_slug
196
-
197
- Enjoy.apply_patches self
198
-
199
- list do
200
- Enjoy.apply_patches self
201
- sort_by :time
202
- end
203
-
204
- edit do
205
- field :content, :ck_editor
206
- fields.each_pair do |name, type|
207
- if type.nil?
208
- field name
209
- else
210
- if type.is_a?(Array)
211
- field name, type[0], &type[1]
212
- else
213
- field name, type
214
- end
215
- end
216
- end
217
- Enjoy.apply_patches self
218
- group :seo do
219
- active false
220
- field :seo do
221
- active true
222
- end
223
- end
224
- group :sitemap_data do
225
- active false
226
- field :sitemap_data do
227
- active true
228
- end
229
- end
230
- end
231
-
232
- Enjoy.only_patches self, [:show, :list, :export]
233
-
234
- if block_given?
235
- yield(self)
236
- end
237
- }
238
- end
239
-
240
- def sitemap_data_config(is_active = false)
241
- Proc.new {
242
- navigation_label 'SEO'
243
- label I18n.t('enjoy.sitemap_data')
244
- field :sitemap_data_field do
245
- read_only true
246
- end
247
- field :sitemap_show, :toggle
248
- field :sitemap_lastmod
249
- field :sitemap_changefreq, :enum do
250
- enum do
251
- Enjoy::SitemapData::SITEMAP_CHANGEFREQ_ARRAY
252
- end
253
- end
254
- field :sitemap_priority
255
-
256
- if block_given?
257
- yield
258
- end
259
- }
260
- end
261
-
262
-
263
-
264
- def embedded_element_config(_navigation_label = I18n.t('enjoy.cms'), fields = {})
265
- Proc.new {
266
- # navigation_label(_navigation_label) unless _navigation_label.nil?
267
- field :enabled, :toggle
268
- field :name, :string
269
- fields.each_pair do |name, type|
270
- if type.nil?
271
- field name
272
- else
273
- if type.is_a?(Array)
274
- field name, type[0], &type[1]
275
- else
276
- field name, type
277
- end
278
- end
279
- end
280
-
281
- if block_given?
282
- yield
283
- end
284
- }
285
- end
286
-
287
- def embedded_image_config(fields = {})
288
- jcrop_proc = Proc.new do
289
- jcrop_options :image_jcrop_options
290
- end
291
-
292
- if block_given?
293
- Enjoy.embedded_element_config(
294
- nil,
295
- {image: [:jcrop, jcrop_proc]}.merge(fields),
296
- yield
297
- )
298
- else
299
- Enjoy.embedded_element_config(
300
- nil,
301
- {image: [:jcrop, jcrop_proc]}.merge(fields)
302
- )
303
- end
304
- end
305
-
306
- def gallery_config
307
- Proc.new {
308
- # navigation_label I18n.t('enjoy.gallery')
309
- field :enabled, :toggle
310
-
311
- field :name, :string
312
- field :slugs, :enum do
313
- enum_method do
314
- :slugs
315
- end
316
- visible do
317
- bindings[:view].current_user.admin?
318
- end
319
- multiple do
320
- true
321
- end
322
- end
323
- field :text_slug
324
-
325
- field :image, :jcrop do
326
- jcrop_options :image_jcrop_options
327
- end
328
-
329
- if block_given?
330
- yield
331
- end
332
- }
333
- end
334
-
335
- def image_config(without_gallery = false, fields = {})
336
- Proc.new {
337
- # navigation_label I18n.t('enjoy.gallery')
338
- field :enabled, :toggle
339
- unless without_gallery
340
- field :gallery
341
- end
342
- field :name, :string
343
- field :image, :jcrop do
344
- jcrop_options :image_jcrop_options
345
- end
346
- fields.each_pair do |name, type|
347
- if type.nil?
348
- field name
349
- else
350
- field name, type
351
- end
352
- end
353
-
354
- if block_given?
355
- yield
18
+ yield self
356
19
  end
357
20
  }
358
21
  end
File without changes
data/lib/enjoy/model.rb CHANGED
@@ -5,8 +5,12 @@ module Enjoy
5
5
  if Enjoy.mongoid?
6
6
  include Mongoid::Document
7
7
  include Mongoid::Timestamps::Short
8
+
9
+ if Enjoy.config.localize
10
+ include Enjoy::ModelLocalizeable
11
+ end
8
12
  end
9
-
13
+
10
14
  include ActiveModel::ForbiddenAttributesProtection
11
15
  include Enjoy::BooleanField
12
16
  include Enjoy::SortField
@@ -18,5 +22,6 @@ module Enjoy
18
22
  include Trackable
19
23
  end
20
24
  end
25
+
21
26
  end
22
27
  end