cms9 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/app/assets/images/cms9/cms9_logo.png +0 -0
  4. data/app/assets/images/cms9/favicon-128.png +0 -0
  5. data/app/assets/images/cms9/favicon-16.png +0 -0
  6. data/app/assets/images/cms9/favicon-256.png +0 -0
  7. data/app/assets/images/cms9/favicon-32.png +0 -0
  8. data/app/assets/images/cms9/favicon-48.png +0 -0
  9. data/app/assets/images/cms9/favicon-512.png +0 -0
  10. data/app/controllers/cms9/application_controller.rb +8 -10
  11. data/app/controllers/cms9/fields_controller.rb +1 -0
  12. data/app/controllers/cms9/post_definitions_controller.rb +41 -30
  13. data/app/controllers/cms9/post_fields_controller.rb +58 -48
  14. data/app/controllers/cms9/posts_controller.rb +25 -17
  15. data/app/controllers/cms9/welcome_controller.rb +1 -0
  16. data/app/helpers/cms9/application_helper.rb +43 -36
  17. data/app/helpers/cms9/fields_helper.rb +1 -0
  18. data/app/helpers/cms9/post_definitions_helper.rb +1 -0
  19. data/app/helpers/cms9/post_fields_helper.rb +1 -0
  20. data/app/helpers/cms9/posts_helper.rb +1 -0
  21. data/app/helpers/cms9/welcome_helper.rb +1 -0
  22. data/app/mailers/cms9/application_mailer.rb +1 -0
  23. data/app/models/ckeditor/asset.rb +1 -0
  24. data/app/models/ckeditor/attachment_file.rb +1 -0
  25. data/app/models/ckeditor/picture.rb +8 -2
  26. data/app/models/cms9/application_record.rb +1 -0
  27. data/app/models/cms9/event.rb +1 -0
  28. data/app/models/cms9/field.rb +8 -9
  29. data/app/models/cms9/post.rb +4 -4
  30. data/app/models/cms9/post_definition.rb +6 -5
  31. data/app/models/cms9/post_field.rb +11 -12
  32. data/app/views/cms9/posts/index.html.erb +0 -1
  33. data/app/views/cms9/posts/inputs/_time.html.erb +1 -1
  34. data/app/views/layouts/cms9/application.html.erb +4 -2
  35. data/config/initializers/assets.rb +6 -4
  36. data/config/initializers/ckeditor.rb +9 -5
  37. data/config/initializers/ckeditor_dragonfly.rb +5 -3
  38. data/config/initializers/ckeditor_init.rb +2 -2
  39. data/config/initializers/dragonfly.rb +4 -4
  40. data/lib/cms9.rb +5 -4
  41. data/lib/cms9/engine.rb +2 -2
  42. data/lib/cms9/version.rb +1 -1
  43. data/lib/events/cms9_events.rb +30 -30
  44. data/lib/generators/cms9/install/install_generator.rb +46 -28
  45. data/lib/generators/cms9/install/templates/cms9_configurator.rb +2 -2
  46. metadata +33 -3
  47. data/app/assets/images/cms9/favicon-64.png +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39671969df29f084dc50386b34c30986abd7cf40
4
- data.tar.gz: a5d9ee92ba34f3ddc4b35bf41b815eafad32da36
3
+ metadata.gz: dbd78b3f88753a938d70f3ab5d0617cfcb0e59d7
4
+ data.tar.gz: 38b5b8cdba433909a0e9b9c2efb6ff857829cf4f
5
5
  SHA512:
6
- metadata.gz: ca9af03a530830533930fd948b812300654a9cbadf72334685808353d8e1c1bb19fab4534a9525c4a85b147f7e9d48e06e22ce7cd7ab32da6b5e5bc0b99bd804
7
- data.tar.gz: 11a5d8d5e2dfcdbba45f4468f598f1bffb26c8559595a38b43947ca07043d627a55c19d30fd51c68fddbef66a18e8b8583ab7a7721c293e6424895588303527c
6
+ metadata.gz: cd416f3a1b773d461e2efbf1d8f0247ab7c625fe63839d29db5f599b4c31d7a5c8a8ea6aaf04827a39494deadffc2ff17ded7134cafa271d07ec98b683cabeba
7
+ data.tar.gz: c9d98c9c389007741aaa70d38d8fe1e076858a342dfb44dd69e20e272b7a47fd6679da108728231e5ad53d15af650152c5999c3d8fb5a6fd2fafae8a21fd2302
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  # Cms9
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/cms9.svg)](https://badge.fury.io/rb/cms9)
6
+
5
7
  Small CMS Admin module for developers.
6
8
 
7
9
  [Demo Application](https://github.com/klikaba/cms9-demo) running on Cms9.
@@ -1,4 +1,5 @@
1
1
  module Cms9
2
+ # Main applicaiton contoller
2
3
  class ApplicationController < ActionController::Base
3
4
  protect_from_forgery with: :exception
4
5
  helper_method :current_user, :user_logout
@@ -10,25 +11,22 @@ module Cms9
10
11
  parent = ::ApplicationController.new
11
12
  parent.request = request
12
13
 
13
- if parent.respond_to?(current_user_ident)
14
- parent.send(current_user_ident)
15
- end
14
+ parent.send(current_user_ident) if parent.respond_to?(current_user_ident)
16
15
  end
17
16
 
18
17
  def user_logout
19
- logout_ident = Cms9.configuration.destroy_user_session || :destroy_user_session
18
+ config = Cms9.configuration.destroy_user_session
19
+ logout_ident = config || :destroy_user_session
20
20
  parent = ::ApplicationController.new
21
21
  parent.request = request
22
22
 
23
- if parent.respond_to?(logout_ident)
24
- parent.send(logout_ident)
25
- end
23
+ parent.send(logout_ident) if parent.respond_to?(logout_ident)
26
24
  end
27
25
 
28
26
  def authorize
29
- unless current_user.try(:cms9_admin?)
30
- raise 'Implement cms9_admin? method in current_user context. See https://github.com/klikaba/cms9'
31
- end
27
+ message = 'Implement cms9_admin? method in current_user context.
28
+ See https://github.com/klikaba/cms9'
29
+ raise message unless current_user.try(:cms9_admin?)
32
30
  end
33
31
  end
34
32
  end
@@ -1,4 +1,5 @@
1
1
  module Cms9
2
+ # fields controller
2
3
  class FieldsController < Cms9::ApplicationController
3
4
  end
4
5
  end
@@ -1,7 +1,10 @@
1
1
  module Cms9
2
+ # post definition controller
2
3
  class PostDefinitionsController < Cms9::ApplicationController
3
4
  def index
4
- @posts = PostDefinition.order('created_at desc').page(params[:page]).per(20)
5
+ @posts = PostDefinition.order('created_at desc')
6
+ .page(params[:page])
7
+ .per(20)
5
8
  end
6
9
 
7
10
  def new
@@ -12,74 +15,82 @@ module Cms9
12
15
  @post = PostDefinition.find(params[:id])
13
16
  end
14
17
 
18
+ # rubocop:disable all
15
19
  def create
16
20
  @post = PostDefinition.new(post_definition_params)
17
-
18
21
  @post.user_id = current_user.id
19
22
 
20
23
  if PostDefinition.where(name: @post[:name]).blank?
21
-
22
24
  if @post.save
23
- @field = PostField.new({
24
- 'name': 'Title',
25
- 'field_type': 'text',
26
- 'required': true,
27
- 'post_definition_id': @post.id,
28
- 'user_id': current_user.id
29
- })
25
+ @field = PostField.new(name: 'Title', field_type: 'text',
26
+ required: true, post_definition_id: @post.id,
27
+ user_id: current_user.id)
30
28
  if @field.save
31
- Cms9Events.new.create_event('post_definition', @post.id, params[:action], current_user, nil)
32
-
29
+ create_post_event
33
30
  redirect_to edit_post_definition_path(@post.id)
34
31
  end
35
32
  else
36
33
  render :new
37
34
  end
38
-
39
35
  else
40
- @post.errors.add(:name, " Post Type already exist")
36
+ @post.errors.add(:name, ' Post Type already exist')
41
37
  render :new
42
38
  end
43
-
44
39
  end
45
40
 
46
41
  def update
47
42
  @post = PostDefinition.find(params[:id])
48
43
  @post.user_id = current_user.id
44
+ post_definition_name = params[:post_definition][:name]
49
45
 
50
- field = PostDefinition.where(name: params[:post_definition][:name].downcase)
51
-
52
- if field.blank? || @post.name == params[:post_definition][:name]
46
+ field = PostDefinition.where(name: post_definition_name.downcase)
53
47
 
48
+ if field.blank? || @post.name == post_definition_name
54
49
  if @post.update(post_definition_params)
55
- Cms9Events.new.create_event('post_definition', @post.id, params[:action], current_user, nil)
56
-
50
+ create_post_event
57
51
  redirect_to edit_post_definition_path(@post.id)
58
52
  else
59
53
  render :edit
60
54
  end
61
-
62
55
  else
63
- @post.errors.add(:name, " Post Type already exist")
56
+ @post.errors.add(:name, ' Post Type already exist')
64
57
  render :edit
65
58
  end
66
59
  end
67
60
 
68
61
  def destroy
69
62
  @post_def = PostDefinition.find(params[:id])
70
- @post_def.destroy
71
-
72
- Cms9Events.new.create_event('post_definition', @post_def.id, params[:action], current_user, @post_def.name)
73
-
74
63
  @posts = Post.where(post_definition_id: params[:id])
64
+ @posts.each do |post|
65
+ Cms9Events.new.create_event('post', post[:id], params[:action],
66
+ current_user, post_name(post))
67
+ end
75
68
  @posts.destroy_all
76
-
69
+ @post_def.destroy
70
+ create_post_def_event(@post_def.name)
77
71
  redirect_to post_definitions_path
78
72
  end
79
73
 
80
74
  private
81
- def post_definition_params
82
- params.require(:post_definition).permit(:name)
83
- end
75
+
76
+ def post_name(post)
77
+ Field.where(post_field_id: post.post_definition
78
+ .post_fields[0].id,
79
+ post_id: post.id)[0]['value']
80
+ end
81
+
82
+ def create_post_def_event(name)
83
+ Cms9Events.new.create_event('post_definition', @post_def.id,
84
+ params[:action], current_user, name)
85
+ end
86
+
87
+ def create_post_event
88
+ Cms9Events.new.create_event('post_definition', @post.id,
89
+ params[:action], current_user, nil)
90
+ end
91
+
92
+ def post_definition_params
93
+ params.require(:post_definition).permit(:name)
94
+ end
84
95
  end
85
96
  end
@@ -1,40 +1,42 @@
1
1
  module Cms9
2
+ # post fields controller
2
3
  class PostFieldsController < Cms9::ApplicationController
3
4
  def new
4
5
  @field = PostField.new
5
6
  @field.post_definition_id = params[:post_definition_id]
6
7
  end
7
8
 
9
+ # rubocop:disable all
8
10
  def create
9
11
  @field = PostField.new(post_field_params)
10
12
  @field.user_id = current_user.id
11
13
 
12
- if PostField.where(name: @field[:name], post_definition_id: @field[:post_definition_id]).blank?
13
- if @field[:field_type] == 'select_single' || @field[:field_type] == 'select_multiple'
14
+ if PostField.where(name: @field[:name],
15
+ post_definition_id: @field[:post_definition_id]).blank?
16
+ if %w(select_single select_multiple).include?(@field[:field_type])
14
17
  @field.metadata = ''
15
18
  values = params[:multi_values]
16
19
 
17
20
  values.each_with_index do |value, index|
18
- if value != ''
19
- if index == 0
20
- @field.metadata = value
21
- elsif
22
- @field.metadata = @field.metadata + ',' + value
23
- end
21
+ if value != '' && index.zero?
22
+ @field.metadata = value
23
+ elsif !index.zero?
24
+ @field.metadata = @field.metadata + ',' + value
24
25
  end
25
26
  end
26
- elsif @field[:field_type] != 'select_single' && @field[:field_type] != 'select_multiple' && @field[:field_type] != 'image'
27
+ elsif !%w(select_single select_multiple image)
28
+ .include?(@field[:field_type])
27
29
  @field.metadata = nil
28
30
  end
29
31
 
30
32
  if @field.save
31
- Cms9Events.new.create_event('post_definition', @field[:post_definition_id], 'update', current_user, nil)
33
+ create_post_field_event
32
34
  redirect_to edit_post_definition_path(id: @field.post_definition_id)
33
35
  else
34
36
  render :new
35
37
  end
36
38
  else
37
- @field.errors.add(:name, "of field already exist")
39
+ @field.errors.add(:name, 'of field already exist')
38
40
  render :new
39
41
  end
40
42
  end
@@ -42,51 +44,28 @@ module Cms9
42
44
  def edit
43
45
  @field = PostField.find(params[:id])
44
46
  @post_name = params[:post]
45
-
46
- if PostField.all_types.index(params[:type]) != nil
47
- @field.field_type = params[:type]
48
- end
49
-
50
- if params[:field_name] != nil
51
- @field.name = params[:field_name]
52
- end
47
+ @field.field_type = params[:type] unless PostField.all_types
48
+ .index(params[:type])
49
+ .nil?
50
+ @field.name = params[:field_name] unless params[:field_name].nil?
53
51
  end
54
52
 
55
53
  def update
56
54
  @field = PostField.find(params[:id])
57
55
  @field.user_id = current_user.id
58
-
59
- field = PostField.where(name: post_field_params[:name], post_definition_id: @field[:post_definition_id])
56
+ field = PostField.where(name: post_field_params[:name],
57
+ post_definition_id: @field[:post_definition_id])
60
58
 
61
59
  if field.blank? || field.pluck(:id)[0].to_s == params[:id]
62
- if @field[:field_type] == 'select_single' || @field[:field_type] == 'select_multiple'
63
- @field.metadata = ''
64
- values = params[:multi_values]
65
-
66
- values.each_with_index do |value, index|
67
- if value != ''
68
- if index == 0
69
- @field.metadata = value
70
- elsif
71
- @field.metadata = @field.metadata + ',' + value
72
- end
73
- end
74
- end
75
-
76
- params[:post_field][:metadata] = @field.metadata
77
-
78
- elsif @field[:field_type] != 'select_single' && @field[:field_type] != 'select_multiple' && @field[:field_type] != 'image'
79
- @field.metadata = nil
80
- end
81
-
60
+ check_selectors
82
61
  if @field.update(post_field_params)
83
- Cms9Events.new.create_event('post_definition', @field[:post_definition_id], 'update', current_user, nil)
62
+ create_post_field_event
84
63
  redirect_to edit_post_definition_path(id: @field.post_definition_id)
85
64
  else
86
65
  render :edit
87
66
  end
88
67
  else
89
- @field.errors.add(:name, "of field already exist")
68
+ @field.errors.add(:name, 'of field already exist')
90
69
  render :edit
91
70
  end
92
71
  end
@@ -94,15 +73,46 @@ module Cms9
94
73
  def destroy
95
74
  @field = PostField.find(params[:id])
96
75
  @field.destroy
97
-
98
- Cms9Events.new.create_event('post_definition', @field[:post_definition_id], 'update', current_user, nil)
99
-
76
+ create_post_field_event
100
77
  redirect_to request.referrer
101
78
  end
102
79
 
103
80
  private
104
- def post_field_params
105
- params.require(:post_field).permit(:name, :field_type, :post_definition_id, :required, :metadata)
81
+
82
+ def create_post_field_event
83
+ Cms9Events.new.create_event('post_definition',
84
+ @field[:post_definition_id], 'update',
85
+ current_user, nil)
86
+ end
87
+
88
+ def check_selectors
89
+ if check_single_multiple
90
+ @field.metadata = ''
91
+ params[:multi_values].each_with_index do |value, index|
92
+ if value != '' && index.zero?
93
+ @field.metadata = value
94
+ elsif !index.zero?
95
+ @field.metadata = @field.metadata + ',' + value
96
+ end
97
+ end
98
+ params[:post_field][:metadata] = @field.metadata
99
+ elsif check_select_image
100
+ @field.metadata = nil
106
101
  end
102
+ end
103
+
104
+ def check_single_multiple
105
+ ['select_single', 'select_multiple'].include?(@field[:field_type])
106
+ end
107
+
108
+ def check_select_image
109
+ !['select_single', 'select_multiple', 'image'].include?(@field[:field_type])
110
+ end
111
+
112
+ def post_field_params
113
+ params.require(:post_field).permit(:name, :field_type,
114
+ :post_definition_id,
115
+ :required, :metadata)
116
+ end
107
117
  end
108
118
  end
@@ -1,11 +1,12 @@
1
1
  module Cms9
2
+ # posts controller
2
3
  class PostsController < Cms9::ApplicationController
3
4
  def index
4
5
  @post_definition = Cms9::PostDefinition.find(params[:post_definition_id])
5
6
  @posts = Post.where(post_definition: @post_definition)
6
- .order('created_at desc')
7
- .page(params[:page])
8
- .per(20)
7
+ .order('created_at desc')
8
+ .page(params[:page])
9
+ .per(20)
9
10
  end
10
11
 
11
12
  def new
@@ -19,11 +20,10 @@ module Cms9
19
20
 
20
21
  def create
21
22
  @post = Post.new(post_params)
22
-
23
23
  @post.user_id = current_user.id
24
24
 
25
25
  if @post.save
26
- Cms9Events.new.create_event('post', @post.id, params[:action], current_user, nil)
26
+ create_post_event(@post.id, nil)
27
27
  redirect_to posts_path(post_definition_id: @post.post_definition.id)
28
28
  else
29
29
  render :new
@@ -42,11 +42,10 @@ module Cms9
42
42
 
43
43
  def update
44
44
  @post = Post.find(params[:id])
45
-
46
45
  @post.user_id = current_user.id
47
46
 
48
47
  if @post.update(post_params)
49
- Cms9Events.new.create_event('post', @post.id, params[:action], current_user, nil)
48
+ create_post_event(@post.id, nil)
50
49
  redirect_to posts_path(post_definition_id: @post.post_definition.id)
51
50
  else
52
51
  render :edit
@@ -57,20 +56,29 @@ module Cms9
57
56
  @post = Post.find(params[:id])
58
57
  post_definition_id = @post.post_definition.id
59
58
 
60
- post_name = Field.where(post_field_id: @post.post_definition.post_fields[0].id, post_id: @post.id)[0]
61
- Cms9Events.new.create_event('post', @post.id, params[:action], current_user, post_name)
62
-
63
- @post.destroy
64
-
59
+ create_post_event(@post.id, post_name) && @post.destroy
65
60
  redirect_to posts_path(post_definition_id: post_definition_id)
66
61
  end
67
62
 
68
63
  private
69
- def post_params
70
- params.require(:post).permit(:post_definition_id, fields_attributes:
71
- [:id, :post_id, :post_field_id, :value, { :value => [] },
72
- :image, :image_uid, :image_name, :remove_image, :image_custom_size])
73
- end
74
64
 
65
+ def post_name
66
+ Field.where(post_field_id: @post.post_definition
67
+ .post_fields[0].id,
68
+ post_id: @post.id)[0]['value']
69
+ end
70
+
71
+ def create_post_event(post_id, post_name)
72
+ Cms9Events.new.create_event('post', post_id, params[:action],
73
+ current_user, post_name)
74
+ end
75
+
76
+ def post_params
77
+ params.require(:post).permit(:post_definition_id, fields_attributes:
78
+ [:id, :post_id, :post_field_id, :value,
79
+ { value: [] },
80
+ :image, :image_uid, :image_name,
81
+ :remove_image, :image_custom_size])
82
+ end
75
83
  end
76
84
  end
@@ -1,4 +1,5 @@
1
1
  module Cms9
2
+ # welcome controller
2
3
  class WelcomeController < Cms9::ApplicationController
3
4
  def index
4
5
  limit = params[:limit] ? params[:limit] : 10
@@ -1,58 +1,65 @@
1
1
  module Cms9
2
+ # main application fields displaying helper
2
3
  module ApplicationHelper
4
+ def cms9_field(field, options = {})
5
+ check_type(field, options) if field.present?
6
+ end
3
7
 
4
- def cms9_field(field, options={})
5
- if field.present?
6
- case field.post_field.field_type
7
- when 'text', 'number', 'select_single', 'date', 'time', 'date_time'
8
- return field.value.blank? ? '' : cms9_text_tag(field)
9
- when 'text_area'
10
- return field.value.blank? ? '' : cms9_text_area_tag(field)
11
- when 'select_multiple'
12
- return field.value.blank? ? '' : cms9_multiple_choice(field)
13
- when 'image'
14
- return field.blank? ? '' : cms9_image_tag(field, options)
15
- else
16
- return '<unsupported type>'
17
- end
18
- end
19
- end
20
-
21
8
  def cms9_text_tag(model)
22
- return model.to_s
23
- end
9
+ model.to_s
10
+ end
24
11
 
25
- def cms9_text_area_tag(model)
26
- return raw(model.to_s)
27
- end
12
+ def cms9_text_area_tag(model)
13
+ raw(model.to_s)
14
+ end
28
15
 
29
- def cms9_multiple_choice(model)
30
- @m = model.value.to_s.split("\' ")[0]
31
- return "#{@m}"
32
- end
16
+ def cms9_multiple_choice(model)
17
+ model.value.to_s.split("\' ")[0].to_s
18
+ end
33
19
 
34
- def cms9_image_tag(model, options={})
35
- return image_tag(model.image.url, options)
36
- end
20
+ def cms9_image_tag(model, options = {})
21
+ image_tag(model.image.url, options)
22
+ end
37
23
 
38
24
  def cms9_number_tag(model)
39
- return model.to_s
40
- end
25
+ model.to_s
26
+ end
41
27
 
42
28
  def cms9_select_single_tag(model)
43
- return model.to_s
44
- end
29
+ model.to_s
30
+ end
45
31
 
46
32
  def cms9_date_tag(model)
47
- return model.to_s
33
+ model.to_s
48
34
  end
49
35
 
50
36
  def cms9_time_tag(model)
51
- return model.to_s
37
+ model.to_s
52
38
  end
53
39
 
54
40
  def cms9_date_time_tag(model)
55
- return model.to_s
41
+ model.to_s
42
+ end
43
+
44
+ def check_type(field, options) # rubocop:disable CyclomaticComplexity
45
+ case field.post_field.field_type
46
+ when 'text', 'number', 'select_single', 'date', 'time', 'date_time'
47
+ field_value(field) ? '' : cms9_text_tag(field)
48
+ when 'text_area' then field_value(field) ? '' : cms9_text_area_tag(field)
49
+ when 'select_multiple'
50
+ field_value(field) ? '' : cms9_multiple_choice(field)
51
+ when 'image' then field_blank(field) ? '' : cms9_image_tag(field, options)
52
+ else
53
+ '<unsupported type>'
54
+ end
55
+ end
56
+
57
+ def field_blank(field)
58
+ field.blank?
59
+ end
60
+
61
+ def field_value(field)
62
+ field.value.blank?
56
63
  end
57
64
  end
58
65
  end
@@ -1,4 +1,5 @@
1
1
  module Cms9
2
+ # fields helper
2
3
  module FieldsHelper
3
4
  end
4
5
  end
@@ -1,4 +1,5 @@
1
1
  module Cms9
2
+ # post definition helper
2
3
  module PostDefinitionsHelper
3
4
  end
4
5
  end
@@ -1,4 +1,5 @@
1
1
  module Cms9
2
+ # post field helper
2
3
  module PostFieldsHelper
3
4
  end
4
5
  end
@@ -1,4 +1,5 @@
1
1
  module Cms9
2
+ # posts helper
2
3
  module PostsHelper
3
4
  end
4
5
  end
@@ -1,4 +1,5 @@
1
1
  module Cms9
2
+ # welcome helper
2
3
  module WelcomeHelper
3
4
  end
4
5
  end
@@ -1,4 +1,5 @@
1
1
  module Cms9
2
+ # mailer
2
3
  class ApplicationMailer < ActionMailer::Base
3
4
  default from: 'from@example.com'
4
5
  layout 'mailer'
@@ -1,4 +1,5 @@
1
1
  module Cms9
2
+ # ckeditor main model
2
3
  class Ckeditor::Asset < ActiveRecord::Base
3
4
  include Ckeditor::Orm::ActiveRecord::AssetBase
4
5
  include Ckeditor::Backend::Dragonfly
@@ -1,4 +1,5 @@
1
1
  module Cms9
2
+ # ckeditor attachment model
2
3
  class Ckeditor::AttachmentFile < Ckeditor::Asset
3
4
  validates_property :ext, of: :data, in: attachment_file_types unless attachment_file_types.empty?
4
5
 
@@ -1,7 +1,13 @@
1
1
  module Cms9
2
+ # ckeditor picture model
2
3
  class Ckeditor::Picture < Ckeditor::Asset
3
- validates_property :format, of: :data, in: image_file_types unless image_file_types.empty?
4
- validates_property :image?, of: :data, as: true, message: :invalid
4
+ validates_property :format,
5
+ of: :data,
6
+ in: image_file_types unless image_file_types.empty?
7
+ validates_property :image?,
8
+ of: :data,
9
+ as: true,
10
+ message: :invalid
5
11
 
6
12
  def url_content
7
13
  data.thumb('800x800>').url
@@ -1,4 +1,5 @@
1
1
  module Cms9
2
+ # main application model
2
3
  class ApplicationRecord < ActiveRecord::Base
3
4
  self.abstract_class = true
4
5
  end
@@ -1,4 +1,5 @@
1
1
  module Cms9
2
+ # event model
2
3
  class Event < ApplicationRecord
3
4
  belongs_to :post
4
5
  belongs_to :post_definition
@@ -1,19 +1,18 @@
1
1
  module Cms9
2
+ # field model
2
3
  class Field < ApplicationRecord
3
4
  belongs_to :post_field
4
5
  belongs_to :post, optional: true
5
6
  dragonfly_accessor :image
6
7
 
7
8
  def to_s
8
- case self.post_field.field_type
9
- when 'text', 'text_area', 'number', 'select_single', 'date', 'time', 'date_time'
10
- return self.value
11
- when 'select_multiple'
12
- return self.value.split(',')
13
- when 'image'
14
- return !self.image_uid.blank? ? self.image.url : ''
15
- else
16
- return ''
9
+ case post_field.field_type
10
+ when 'text', 'text_area', 'number',
11
+ 'select_single', 'date', 'time', 'date_time' then value
12
+ when 'select_multiple' then value.split(',')
13
+ when 'image' then !image_uid.blank? ? image.url : ''
14
+ else
15
+ ''
17
16
  end
18
17
  end
19
18
  end
@@ -1,4 +1,5 @@
1
1
  module Cms9
2
+ # post model
2
3
  class Post < ApplicationRecord
3
4
  belongs_to :post_definition
4
5
  has_many :fields, dependent: :destroy
@@ -6,11 +7,10 @@ module Cms9
6
7
  accepts_nested_attributes_for :fields
7
8
 
8
9
  def field(name)
9
- @cache_fields ||= self.fields.joins(:post_field).includes(:post_field)
10
- .map { |field| [field.post_field.name, field] }
11
- .to_h
10
+ @cache_fields ||= fields.joins(:post_field).includes(:post_field)
11
+ .map { |field| [field.post_field.name, field] }
12
+ .to_h
12
13
  @cache_fields[name]
13
14
  end
14
-
15
15
  end
16
16
  end
@@ -1,15 +1,17 @@
1
1
  module Cms9
2
+ # post definition model
2
3
  class PostDefinition < ApplicationRecord
3
- validates :name, presence: true, uniqueness: { case_sensitive: false },
4
+ validates :name,
5
+ presence: true,
6
+ uniqueness: { case_sensitive: false },
4
7
  length: { minimum: 3 }
5
8
 
6
9
  has_many :post_fields, dependent: :destroy
7
10
  has_many :posts, dependent: :destroy
8
11
 
9
-
10
12
  def fields
11
13
  if @cache_fields.nil?
12
- @cache_fields = self.post_fields.map { |field| [field.name, field] }.to_h
14
+ @cache_fields = post_fields.map { |field| [field.name, field] }.to_h
13
15
  end
14
16
 
15
17
  @cache_fields.values
@@ -17,9 +19,8 @@ module Cms9
17
19
 
18
20
  # Get field by name
19
21
  def field(name)
20
- fields()
22
+ fields
21
23
  @cache_fields[name]
22
24
  end
23
-
24
25
  end
25
26
  end
@@ -1,23 +1,22 @@
1
1
  module Cms9
2
+ # post field model
2
3
  class PostField < ApplicationRecord
3
- validates :name, presence: true, length: { minimum:3, maximum: 15 }
4
+ validates :name, presence: true, length: { minimum: 3, maximum: 15 }
4
5
  validates :field_type, presence: true
5
6
 
6
7
  belongs_to :post_definition
7
8
  attr_accessor :multi_values
8
9
 
9
10
  def self.all_types
10
- return [
11
- { key: 'text', display_name: 'Text' },
12
- { key: 'text_area', display_name: 'Text Area' },
13
- { key: 'number', display_name: 'Number'},
14
- { key: 'select_single', display_name: 'Select Single' },
15
- { key: 'select_multiple', display_name: 'Select Multiple' },
16
- { key: 'date', display_name: 'Date' },
17
- { key: 'time', display_name: 'Time' },
18
- { key: 'date_time', display_name: 'Date & Time' },
19
- { key: 'image', display_name: 'Image' }
20
- ]
11
+ [{ key: 'text', display_name: 'Text' },
12
+ { key: 'text_area', display_name: 'Text Area' },
13
+ { key: 'number', display_name: 'Number' },
14
+ { key: 'select_single', display_name: 'Select Single' },
15
+ { key: 'select_multiple', display_name: 'Select Multiple' },
16
+ { key: 'date', display_name: 'Date' },
17
+ { key: 'time', display_name: 'Time' },
18
+ { key: 'date_time', display_name: 'Date & Time' },
19
+ { key: 'image', display_name: 'Image' }]
21
20
  end
22
21
  end
23
22
  end
@@ -1,4 +1,3 @@
1
-
2
1
  <div class="row">
3
2
  <div class="col-md-12">
4
3
  <div class="box box-info">
@@ -1,2 +1,2 @@
1
1
  <%= field.label field.object.post_field.name %>
2
- <%= field.time_field :value, as: :time, value: field.object.value, { class: 'form-control', required: field.object.post_field.required } %>
2
+ <%= field.time_field :value, as: :time, value: field.object.value, class: 'form-control', required: field.object.post_field.required %>
@@ -10,8 +10,10 @@
10
10
  <%= csrf_meta_tags %>
11
11
  <%= favicon_link_tag 'cms9/favicon-16.png', type: 'image/png' %>
12
12
  <%= favicon_link_tag 'cms9/favicon-32.png', type: 'image/png' %>
13
- <%= favicon_link_tag 'cms9/favicon-64.png', type: 'image/png' %>
14
- <%= favicon_link_tag 'cms9/favicon-64.png', type: 'image/png' %>
13
+ <%= favicon_link_tag 'cms9/favicon-48.png', type: 'image/png' %>
14
+ <%= favicon_link_tag 'cms9/favicon-128.png', type: 'image/png' %>
15
+ <%= favicon_link_tag 'cms9/favicon-256.png', type: 'image/png' %>
16
+ <%= favicon_link_tag 'cms9/favicon-512.png', type: 'image/png' %>
15
17
  </head>
16
18
 
17
19
  <body class="skin-blue">
@@ -1,4 +1,6 @@
1
- Rails.application.config.assets.precompile += %w( cms9/favicon-16.png )
2
- Rails.application.config.assets.precompile += %w( cms9/favicon-32.png )
3
- Rails.application.config.assets.precompile += %w( cms9/favicon-64.png )
4
- Rails.application.config.assets.precompile += %w( cms9/favicon-128.png )
1
+ Rails.application.config.assets.precompile += %w(cms9/favicon-16.png)
2
+ Rails.application.config.assets.precompile += %w(cms9/favicon-32.png)
3
+ Rails.application.config.assets.precompile += %w(cms9/favicon-48.png)
4
+ Rails.application.config.assets.precompile += %w(cms9/favicon-128.png)
5
+ Rails.application.config.assets.precompile += %w(cms9/favicon-256.png)
6
+ Rails.application.config.assets.precompile += %w(cms9/favicon-512.png)
@@ -1,15 +1,17 @@
1
+ # ckeditor config file
1
2
  module Cms9
2
3
  Ckeditor.setup do |config|
3
4
  # ==> ORM configuration
4
- # Load and configure the ORM. Supports :active_record (default), :mongo_mapper and
5
+ # Load and configure the ORM. Supports :active_record (default),
6
+ # :mongo_mapper and
5
7
  # :mongoid (bson_ext recommended) by default. Other ORMs may be
6
8
  # available as additional gems.
7
- require "ckeditor/orm/active_record"
9
+ require 'ckeditor/orm/active_record'
8
10
 
9
11
  # Allowed image file types for upload.
10
12
  # Set to nil or [] (empty array) for all file types
11
13
  # By default: %w(jpg jpeg png gif tiff)
12
- # config.image_file_types = %w(jpg jpeg png gif tiff)
14
+ config.image_file_types = %w(jpg jpeg png gif tiff)
13
15
 
14
16
  # Allowed flash file types for upload.
15
17
  # Set to nil or [] (empty array) for all file types
@@ -19,7 +21,8 @@ module Cms9
19
21
  # Allowed attachment file types for upload.
20
22
  # Set to nil or [] (empty array) for all file types
21
23
  # By default: %w(doc docx xls odt ods pdf rar zip tar tar.gz swf)
22
- # config.attachment_file_types = %w(doc docx xls odt ods pdf rar zip tar tar.gz swf)
24
+ # config.attachment_file_types =
25
+ # %w(doc docx xls odt ods pdf rar zip tar tar.gz swf)
23
26
 
24
27
  # Setup authorization to be run as a before filter
25
28
  # By default: there is no authorization.
@@ -41,7 +44,8 @@ module Cms9
41
44
  # By default: nil
42
45
  # config.asset_path = "http://www.example.com/assets/ckeditor/"
43
46
 
44
- # To reduce the asset precompilation time, you can limit plugins and/or languages to those you need:
47
+ # To reduce the asset precompilation time, you can limit plugins and/or
48
+ # languages to those you need:
45
49
  # By default: nil (no limit)
46
50
  # config.assets_languages = ['en', 'uk']
47
51
  # config.assets_plugins = ['image', 'smiley']
@@ -3,13 +3,15 @@ require 'dragonfly'
3
3
 
4
4
  Dragonfly.app(:ckeditor).configure do
5
5
  plugin :imagemagick
6
- secret "761fa77ae747b0b82ddbc54f3ada94d9259690f701852a398130261e117f3798"
6
+ secret '761fa77ae747b0b82ddbc54f3ada94d9259690f701852a398130261e117f3798'
7
7
 
8
8
  # Store files in public/uploads/ckeditor. This is not
9
9
  # mandatory and the files don't even have to be stored under
10
10
  # public. See http://markevans.github.io/dragonfly/data-stores
11
- datastore :file, root_path: Rails.root.join('public/uploads/ckeditor', Rails.env).to_s,
12
- server_root: 'public'
11
+ datastore :file,
12
+ root_path: Rails.root.join('public/uploads/ckeditor',
13
+ Rails.env).to_s,
14
+ server_root: 'public'
13
15
 
14
16
  # Accept asset requests on /ckeditor_assets. Again, this path is
15
17
  # not mandatory. Just be sure to include :job somewhere.
@@ -1,3 +1,3 @@
1
- require "ckeditor/orm/active_record"
1
+ require 'ckeditor/orm/active_record'
2
2
 
3
- Rails.application.config.assets.precompile += %w( ckeditor/* )
3
+ Rails.application.config.assets.precompile += %w(ckeditor/*)
@@ -4,13 +4,13 @@ require 'dragonfly'
4
4
  Dragonfly.app.configure do
5
5
  plugin :imagemagick
6
6
 
7
- secret "0faed7549aa86f0847364e39af20ac099ca03cc542912c1deff473b78bd5700f"
7
+ secret '0faed7549aa86f0847364e39af20ac099ca03cc542912c1deff473b78bd5700f'
8
8
 
9
- url_format "/media/:job/:name"
9
+ url_format '/media/:job/:name'
10
10
 
11
11
  datastore :file,
12
- root_path: Rails.root.join('public/system/dragonfly', Rails.env),
13
- server_root: Rails.root.join('public')
12
+ root_path: Rails.root.join('public/system/dragonfly', Rails.env),
13
+ server_root: Rails.root.join('public')
14
14
  end
15
15
 
16
16
  # Logger
@@ -1,6 +1,7 @@
1
- require "cms9/engine"
2
- require "dragonfly"
1
+ require 'cms9/engine'
2
+ require 'dragonfly'
3
3
 
4
+ # main cms9 module
4
5
  module Cms9
5
6
  class << self
6
7
  attr_accessor :configuration
@@ -10,7 +11,7 @@ module Cms9
10
11
  self.configuration ||= Configuration.new
11
12
  yield(configuration)
12
13
  end
13
-
14
+ # configuration
14
15
  class Configuration
15
16
  attr_accessor :current_user, :destroy_user_session
16
17
 
@@ -21,4 +22,4 @@ module Cms9
21
22
  end
22
23
  end
23
24
 
24
- require "sdk/cms9"
25
+ require 'sdk/cms9'
@@ -8,9 +8,10 @@ require 'rails-assets-tether'
8
8
  require 'font-awesome-rails'
9
9
  require 'ckeditor'
10
10
  require 'cms9'
11
- require "events/cms9_events"
11
+ require 'events/cms9_events'
12
12
 
13
13
  module Cms9
14
+ # main cms9 engine class
14
15
  class Engine < ::Rails::Engine
15
16
  isolate_namespace Cms9
16
17
 
@@ -19,6 +20,5 @@ module Cms9
19
20
  config.to_prepare do
20
21
  ::ApplicationController.helper(Cms9::ApplicationHelper)
21
22
  end
22
-
23
23
  end
24
24
  end
@@ -1,3 +1,3 @@
1
1
  module Cms9
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'.freeze
3
3
  end
@@ -1,42 +1,23 @@
1
1
  module Cms9
2
+ # Events for every action in administration part
2
3
  class Cms9Events
3
-
4
4
  def create_event(event_type, event_id, action, user, del_name)
5
- post_definition_id = nil
6
- post_id = nil
7
-
8
- user_info = [ user.id, user.email ? user.email : nil ]
5
+ @post_definition_id = nil
6
+ @post_id = nil
9
7
 
10
- case event_type
11
- when 'post_definition'
12
- post_definition_id = event_id
13
- when 'post'
14
- post_id = event_id
15
- end
8
+ check_event_type(event_type, event_id)
16
9
 
17
- @event = Event.new({
18
- 'user': user_info,
19
- 'action': action,
20
- 'post_definition_id': post_definition_id,
21
- 'post_id': post_id,
22
- 'deleted_field': del_name
23
- })
10
+ @event = Event.new(
11
+ user: [user.id, user.email ? user.email : nil], action: action,
12
+ post_definition_id: @post_definition_id, post_id: @post_id,
13
+ deleted_field: del_name
14
+ )
24
15
 
25
- if @event.save
26
- if del_name != nil
27
- if event_type == 'post_definition'
28
- Event.where(post_definition_id: post_definition_id).update_all(deleted_field: del_name)
29
- elsif event_type == 'post'
30
- Event.where(post_id: post_id).each do |event|
31
- event.update(deleted_field: del_name)
32
- end
33
- end
34
- end
35
- end
16
+ after_save(event_type) if @event.save && !del_name.nil?
36
17
  end
37
18
 
38
19
  def get_title_value_for_post(post_id)
39
- return @post = Cms9::Field.where(post_id: post_id)[0]
20
+ @post = Cms9::Field.where(post_id: post_id)[0]
40
21
  end
41
22
 
42
23
  def timeline_events(limit)
@@ -46,5 +27,24 @@ module Cms9
46
27
  Event.order('created_at desc')
47
28
  end
48
29
  end
30
+
31
+ def after_save(event_type)
32
+ if event_type == 'post_definition'
33
+ Event.where(post_definition_id: @post_definition_id)
34
+ .update_all(deleted_field: @event.deleted_field)
35
+ elsif event_type == 'post'
36
+ Event.where(post_id: @post_id)
37
+ .update_all(deleted_field: @event.deleted_field)
38
+ end
39
+ end
40
+
41
+ def check_event_type(event_type, event_id)
42
+ case event_type
43
+ when 'post_definition'
44
+ @post_definition_id = event_id
45
+ when 'post'
46
+ @post_id = event_id
47
+ end
48
+ end
49
49
  end
50
50
  end
@@ -1,34 +1,37 @@
1
- require "rails/generators/base"
1
+ require 'rails/generators/base'
2
2
  require 'rails/generators/migration'
3
3
  require 'rails/generators/active_record'
4
4
 
5
5
  module Cms9
6
6
  module Generators
7
+ # Install generator for route mounting and copying necessary files
7
8
  class InstallGenerator < Rails::Generators::Base
8
9
  include Rails::Generators::Migration
9
10
 
10
- argument :def_route, type: :string, default: "cms9"
11
+ argument :def_route, type: :string, default: 'cms9'
11
12
  source_root File.expand_path(File.dirname(__FILE__))
12
13
 
13
14
  def mount_engine_route
14
- puts "\nMounting Cms9::Engine on " + "/" + file_name + " route"
15
- route "mount Cms9::Engine => " + "'/" + file_name + "'"
15
+ puts "\nMounting Cms9::Engine on " + '/' + file_name + ' route'
16
+ route "mount Cms9::Engine => '/#{file_name}'"
16
17
  puts "\n"
17
18
  end
18
19
 
19
20
  def copy_initializer
20
- puts "Copying necessary files..."
21
- copy_file 'templates/cms9_configurator.rb', 'config/initializers/cms9_configurator.rb'
22
- puts ""
21
+ puts 'Copying necessary files...'
22
+ copy_file 'templates/cms9_configurator.rb',
23
+ 'config/initializers/cms9_configurator.rb'
24
+ puts ''
23
25
  end
24
26
 
25
27
  def copy_ckeditor_config
26
- copy_file 'templates/ckeditor_config.js', 'app/assets/javascripts/ckeditor/config.js'
28
+ copy_file 'templates/ckeditor_config.js',
29
+ 'app/assets/javascripts/ckeditor/config.js'
27
30
 
28
- data = File.read("app/assets/javascripts/ckeditor/config.js")
29
- filtered_data = data.gsub("cms9", file_name)
31
+ data = File.read('app/assets/javascripts/ckeditor/config.js')
32
+ filtered_data = data.gsub('cms9', file_name)
30
33
 
31
- File.open("app/assets/javascripts/ckeditor/config.js", "w") do |f|
34
+ File.open('app/assets/javascripts/ckeditor/config.js', 'w') do |f|
32
35
  f.write(filtered_data)
33
36
  end
34
37
  end
@@ -38,28 +41,18 @@ module Cms9
38
41
  end
39
42
 
40
43
  def generate_migration
41
- cms9_file_dir = File.expand_path('../../../../../db/migrate/.', __FILE__)
42
- files = []
43
-
44
- Dir.foreach(cms9_file_dir) do |file|
45
- files << file unless file =~ /^\.\.?$/
46
- end
47
-
48
- files.each do |migration|
49
- destination = File.expand_path('db/migrate/' + migration, self.destination_root)
44
+ migraton_files.each do |migration|
45
+ destination = File.expand_path('db/migrate/' + migration,
46
+ destination_root)
50
47
  migration_dir = File.dirname(destination)
51
48
  only_name = File.basename(migration, File.extname(migration))
52
49
  destination = self.class.migration_exists?(migration_dir, only_name)
53
50
 
54
- if destination
55
- puts "\n\e[0m\e[31mFound existing " + migration + " migration. Remove it if you want to regenerate.\e[0m"
56
- else
57
- puts ""
58
- migration_template '../../../../db/migrate/' + migration, 'db/migrate/' + migration
59
- end
51
+ migration_templating(destination, migration)
60
52
  end
61
53
  end
62
54
 
55
+ # rubocop:disable all
63
56
  def show_info
64
57
  puts "\n *************************************************************************"
65
58
  puts " * *"
@@ -70,12 +63,37 @@ module Cms9
70
63
  puts " * Visit \033[32mhttps://github.com/klikaba/cms9\033[0m for more informations *"
71
64
  puts " * *"
72
65
  puts " *************************************************************************\n\n"
66
+ binding.pry
73
67
  end
74
68
 
75
69
  private
76
- def file_name
77
- def_route.underscore
70
+
71
+ def file_name
72
+ def_route.underscore
73
+ end
74
+
75
+ def migraton_files
76
+ cms9_file_dir = File.expand_path('../../../../../db/migrate/.',
77
+ __FILE__)
78
+ files = []
79
+
80
+ Dir.foreach(cms9_file_dir) do |file|
81
+ files << file unless file =~ /^\.\.?$/
78
82
  end
83
+
84
+ files
85
+ end
86
+
87
+ def migration_templating(destination, migration)
88
+ if destination
89
+ puts "\n\e[0m\e[31mFound existing " + migration +
90
+ " migration. Remove it if you want to regenerate.\e[0m"
91
+ else
92
+ puts ''
93
+ migration_template '../../../../db/migrate/' + migration,
94
+ 'db/migrate/' + migration
95
+ end
96
+ end
79
97
  end
80
98
  end
81
99
  end
@@ -1,4 +1,4 @@
1
1
  Cms9.configure do |config|
2
- config.current_user = :current_user
3
- config.destroy_user_session = :destroy_user_session_path
2
+ config.current_user = :current_user
3
+ config.destroy_user_session = :destroy_user_session_path
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cms9
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Klika.ba
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-24 00:00:00.000000000 Z
11
+ date: 2017-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -296,6 +296,34 @@ dependencies:
296
296
  - - ">="
297
297
  - !ruby/object:Gem::Version
298
298
  version: '0'
299
+ - !ruby/object:Gem::Dependency
300
+ name: rubocop
301
+ requirement: !ruby/object:Gem::Requirement
302
+ requirements:
303
+ - - ">="
304
+ - !ruby/object:Gem::Version
305
+ version: '0'
306
+ type: :development
307
+ prerelease: false
308
+ version_requirements: !ruby/object:Gem::Requirement
309
+ requirements:
310
+ - - ">="
311
+ - !ruby/object:Gem::Version
312
+ version: '0'
313
+ - !ruby/object:Gem::Dependency
314
+ name: brakeman
315
+ requirement: !ruby/object:Gem::Requirement
316
+ requirements:
317
+ - - ">="
318
+ - !ruby/object:Gem::Version
319
+ version: '0'
320
+ type: :development
321
+ prerelease: false
322
+ version_requirements: !ruby/object:Gem::Requirement
323
+ requirements:
324
+ - - ">="
325
+ - !ruby/object:Gem::Version
326
+ version: '0'
299
327
  description: Small CMS Admin module for Rails
300
328
  email:
301
329
  - contact@klika.ba
@@ -311,8 +339,10 @@ files:
311
339
  - app/assets/images/cms9/cms9_logo_readme.png
312
340
  - app/assets/images/cms9/favicon-128.png
313
341
  - app/assets/images/cms9/favicon-16.png
342
+ - app/assets/images/cms9/favicon-256.png
314
343
  - app/assets/images/cms9/favicon-32.png
315
- - app/assets/images/cms9/favicon-64.png
344
+ - app/assets/images/cms9/favicon-48.png
345
+ - app/assets/images/cms9/favicon-512.png
316
346
  - app/assets/images/cms9/iCheck/flat/blue.png
317
347
  - app/assets/images/cms9/iCheck/flat/blue@2x.png
318
348
  - app/assets/javascripts/cms9/admin_lte.js