hancock_cms_gallery 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +4 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +54 -0
  9. data/Rakefile +1 -0
  10. data/app/assets/javascripts/hancock/gallery/init.coffee +2 -0
  11. data/app/assets/javascripts/hancock/gallery/loaders/gallery_images_loader.coffee +29 -0
  12. data/app/assets/javascripts/hancock/gallery/loaders/gallery_loader.coffee +29 -0
  13. data/app/assets/javascripts/hancock/gallery/page_selector.coffee +65 -0
  14. data/app/assets/javascripts/hancock/gallery.coffee +11 -0
  15. data/app/controllers/concerns/hancock/gallery/load_gallery.rb +74 -0
  16. data/app/controllers/concerns/hancock/gallery/load_gallery_images.rb +58 -0
  17. data/app/controllers/concerns/rails_admin/jcrop_controller.rb +138 -0
  18. data/app/models/concerns/hancock/gallery/active_record_paperclip.rb +95 -0
  19. data/app/models/concerns/hancock/gallery/auto_crop.rb +86 -0
  20. data/app/models/concerns/hancock/gallery/decorators/embedded_image.rb +47 -0
  21. data/app/models/concerns/hancock/gallery/decorators/gallery.rb +47 -0
  22. data/app/models/concerns/hancock/gallery/decorators/image.rb +52 -0
  23. data/app/models/concerns/hancock/gallery/decorators/original_image.rb +35 -0
  24. data/app/models/concerns/hancock/gallery/gallerable.rb +13 -0
  25. data/app/models/concerns/hancock/gallery/mongoid_paperclip.rb +96 -0
  26. data/app/models/concerns/hancock/gallery/paperclipable.rb +19 -0
  27. data/app/models/concerns/hancock/gallery/watermarkable.rb +117 -0
  28. data/app/models/hancock/gallery/embedded_image.rb +17 -0
  29. data/app/models/hancock/gallery/gallery.rb +16 -0
  30. data/app/models/hancock/gallery/image.rb +16 -0
  31. data/app/models/hancock/gallery/original_image.rb +15 -0
  32. data/app/views/rails_admin/jcrop/edit.html.slim +18 -0
  33. data/bin/console +14 -0
  34. data/bin/setup +7 -0
  35. data/config/initializers/hancock_gallery.rb +29 -0
  36. data/config/initializers/paperclip_fix.rb +4 -0
  37. data/config/locales/hancock.gallery.ru.yml +17 -0
  38. data/hancock_cms_gallery.gemspec +37 -0
  39. data/lib/generators/hancock/gallery/config/install_generator.rb +13 -0
  40. data/lib/generators/hancock/gallery/config/templates/hancock_gallery.erb +9 -0
  41. data/lib/generators/hancock/gallery/migrations/migration_generator.rb +18 -0
  42. data/lib/generators/hancock/gallery/migrations/templates/migration_gallery.rb +51 -0
  43. data/lib/generators/hancock/gallery/models/decorators_generator.rb +21 -0
  44. data/lib/generators/hancock/gallery/models/embedded_image_generator.rb +52 -0
  45. data/lib/generators/hancock/gallery/models/gallery_generator.rb +55 -0
  46. data/lib/generators/hancock/gallery/models/image_generator.rb +51 -0
  47. data/lib/generators/hancock/gallery/models/templates/embedded_image.erb +52 -0
  48. data/lib/generators/hancock/gallery/models/templates/gallery.erb +48 -0
  49. data/lib/generators/hancock/gallery/models/templates/image.erb +50 -0
  50. data/lib/generators/hancock/gallery/models/templates/original_image.erb +34 -0
  51. data/lib/hancock/gallery/admin/embedded_image.rb +41 -0
  52. data/lib/hancock/gallery/admin/gallery.rb +52 -0
  53. data/lib/hancock/gallery/admin/image.rb +45 -0
  54. data/lib/hancock/gallery/admin/original_image.rb +33 -0
  55. data/lib/hancock/gallery/admin.rb +26 -0
  56. data/lib/hancock/gallery/configuration.rb +26 -0
  57. data/lib/hancock/gallery/engine.rb +5 -0
  58. data/lib/hancock/gallery/models/active_record/gallery.rb +19 -0
  59. data/lib/hancock/gallery/models/active_record/image.rb +21 -0
  60. data/lib/hancock/gallery/models/embedded_image.rb +28 -0
  61. data/lib/hancock/gallery/models/gallery.rb +62 -0
  62. data/lib/hancock/gallery/models/image.rb +57 -0
  63. data/lib/hancock/gallery/models/mongoid/embedded_image.rb +12 -0
  64. data/lib/hancock/gallery/models/mongoid/gallery.rb +16 -0
  65. data/lib/hancock/gallery/models/mongoid/image.rb +15 -0
  66. data/lib/hancock/gallery/models/mongoid/original_image.rb +14 -0
  67. data/lib/hancock/gallery/models/original_image.rb +30 -0
  68. data/lib/hancock/gallery/rails_admin_ext/hancock_image.rb +32 -0
  69. data/lib/hancock/gallery/version.rb +5 -0
  70. data/lib/hancock_cms_gallery.rb +66 -0
  71. data/release.sh +6 -0
  72. metadata +176 -0
@@ -0,0 +1,86 @@
1
+ module Hancock::Gallery::AutoCrop
2
+ extend ActiveSupport::Concern
3
+ module ClassMethods
4
+
5
+ def set_default_auto_crop_params_for(field = :image, opts = {})
6
+ _width = opts.delete(:width)
7
+ _height = opts.delete(:height)
8
+ crop_area = [_width, _height].compact
9
+ _default_method = opts.delete(:default_method) || :default_crop_params_for_center
10
+
11
+ cattr_accessor "#{field}_default_max_crop_area".to_sym, "#{field}_default_auto_crop_method".to_sym
12
+ self.send("#{field}_default_max_crop_area=".to_sym, crop_area)
13
+ self.send("#{field}_default_auto_crop_method=".to_sym, _default_method.to_sym)
14
+
15
+ class_eval <<-EVAL
16
+ after_save :#{field}_auto_rails_admin_jcrop
17
+ def #{field}_auto_rails_admin_jcrop
18
+ auto_rails_admin_jcrop(:#{field})
19
+ end
20
+
21
+ def #{field}_default_crop_params
22
+ if self.#{field} and !self.#{field}_file_name.blank?
23
+ _default_max_crop_area = self.#{field}_default_max_crop_area
24
+ if _default_max_crop_area or self.respond_to?(:#{field}_styles) and (_#{field}_styles = self.#{field}_styles)
25
+ if _default_max_crop_area.blank?
26
+ _methods = [:big, :main, :standard]
27
+ _#{field}_styles = _#{field}_styles.call(#{field}) if _#{field}_styles.respond_to?(:call)
28
+ _style = nil
29
+ _methods.each do |m|
30
+ _style = _#{field}_styles[m]
31
+ _style = _style[:geometry] if _style and _style.is_a?(Hash)
32
+ break if !_style.blank? and _style
33
+ end
34
+ if _style
35
+ # sizes = _style.match(/^(?<width>[\d\.]+)?(x(?<height>[\d\.]+))?/)
36
+ # need_width = sizes[:width].to_f
37
+ # need_height = sizes[:height].to_f
38
+ sizes = Paperclip::Geometry.parse _style
39
+ need_width = sizes.width.to_f
40
+ need_height = sizes.height.to_f
41
+ end
42
+
43
+ else
44
+ if _default_max_crop_area.is_a?(Hash)
45
+ need_width = _default_max_crop_area[:width].to_f
46
+ need_height = _default_max_crop_area[:height].to_f
47
+ else
48
+ need_width = _default_max_crop_area[0].to_f
49
+ need_height = _default_max_crop_area[1].to_f
50
+ end
51
+ end
52
+ need_width = need_width.to_f
53
+ need_height = need_height.to_f
54
+
55
+ begin
56
+ _file = self.#{field}.queued_for_write.blank? ? self.#{field} : self.#{field}.queued_for_write[:original]
57
+ current_geo = Paperclip::Geometry.from_file(_file)
58
+ current_width = current_geo.width.to_f
59
+ current_height = current_geo.height.to_f
60
+ rescue
61
+ current_width ||= need_width.to_f
62
+ current_height ||= need_height.to_f
63
+ end
64
+
65
+ if need_width != 0 and need_height != 0
66
+ _aspect_ratio = need_width / need_height
67
+ else
68
+ _aspect_ratio = current_width / current_height
69
+ end
70
+
71
+ _width = (need_width > current_width ? current_width : need_width)
72
+ _width = current_width if _width == 0
73
+ _height = _width / _aspect_ratio
74
+ _height = (_height > current_width ? current_width : _height)
75
+ _width = _height * _aspect_ratio
76
+ _width = (_width > current_width ? current_width : _width)
77
+
78
+ self.send(self.#{field}_default_auto_crop_method, :#{field}, _width, _height)
79
+ end
80
+ end
81
+ end
82
+ EVAL
83
+ end
84
+
85
+ end
86
+ end
@@ -0,0 +1,47 @@
1
+ module Hancock::Gallery::Decorators
2
+ module EmbeddedImage
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ # # after_save :image_auto_rails_admin_jcrop
7
+ # def image_auto_rails_admin_jcrop
8
+ # auto_rails_admin_jcrop(:image) # or nil for cancel autocrop
9
+ # end
10
+
11
+ # # hancock_cms_attached_file(:image)
12
+ # def image_styles
13
+ # super
14
+ # end
15
+ # def image_jcrop_options
16
+ # super
17
+ # end
18
+
19
+ ############# rails_admin ##############
20
+ # def self.rails_admin_add_fields
21
+ # [] #super
22
+ # end
23
+ #
24
+ # def self.rails_admin_add_config(config)
25
+ # #super(config)
26
+ # end
27
+ #
28
+ # def self.admin_can_user_defined_actions
29
+ # [].freeze
30
+ # end
31
+ # def self.admin_cannot_user_defined_actions
32
+ # [].freeze
33
+ # end
34
+ # def self.manager_can_user_defined_actions
35
+ # [].freeze
36
+ # end
37
+ # def self.manager_cannot_user_defined_actions
38
+ # [].freeze
39
+ # end
40
+ # def self.rails_admin_user_defined_visible_actions
41
+ # [].freeze
42
+ # end
43
+
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,47 @@
1
+ module Hancock::Gallery::Decorators
2
+ module Gallery
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ # # after_save :image_auto_rails_admin_jcrop
7
+ # def image_auto_rails_admin_jcrop
8
+ # auto_rails_admin_jcrop(:image) # or nil for cancel autocrop
9
+ # end
10
+
11
+ # # hancock_cms_attached_file(:image)
12
+ # def image_styles
13
+ # super
14
+ # end
15
+ # def image_jcrop_options
16
+ # super
17
+ # end
18
+
19
+ ############# rails_admin ##############
20
+ # def self.rails_admin_add_fields
21
+ # [] #super
22
+ # end
23
+ #
24
+ # def self.rails_admin_add_config(config)
25
+ # #super(config)
26
+ # end
27
+ #
28
+ # def self.admin_can_user_defined_actions
29
+ # [].freeze
30
+ # end
31
+ # def self.admin_cannot_user_defined_actions
32
+ # [].freeze
33
+ # end
34
+ # def self.manager_can_user_defined_actions
35
+ # [].freeze
36
+ # end
37
+ # def self.manager_cannot_user_defined_actions
38
+ # [].freeze
39
+ # end
40
+ # def self.rails_admin_user_defined_visible_actions
41
+ # [].freeze
42
+ # end
43
+
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,52 @@
1
+ module Hancock::Gallery::Decorators
2
+ module Image
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+
7
+ # def self.default_cache_keys
8
+ # []
9
+ # end
10
+
11
+ # # after_save :image_auto_rails_admin_jcrop
12
+ # def image_auto_rails_admin_jcrop
13
+ # auto_rails_admin_jcrop(:image) # or nil for cancel autocrop
14
+ # end
15
+
16
+ # # hancock_cms_attached_file(:image)
17
+ # def image_styles
18
+ # super
19
+ # end
20
+ # def image_jcrop_options
21
+ # super
22
+ # end
23
+
24
+ ############# rails_admin ##############
25
+ # def self.rails_admin_add_fields
26
+ # [] #super
27
+ # end
28
+ #
29
+ # def self.rails_admin_add_config(config)
30
+ # #super(config)
31
+ # end
32
+ #
33
+ # def self.admin_can_user_defined_actions
34
+ # [].freeze
35
+ # end
36
+ # def self.admin_cannot_user_defined_actions
37
+ # [].freeze
38
+ # end
39
+ # def self.manager_can_user_defined_actions
40
+ # [].freeze
41
+ # end
42
+ # def self.manager_cannot_user_defined_actions
43
+ # [].freeze
44
+ # end
45
+ # def self.rails_admin_user_defined_visible_actions
46
+ # [].freeze
47
+ # end
48
+
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,35 @@
1
+ module Hancock::Gallery::Decorators
2
+ module OriginalImage
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+
7
+ ############# rails_admin ##############
8
+ # def self.rails_admin_add_fields
9
+ # [] #super
10
+ # end
11
+ #
12
+ # def self.rails_admin_add_config(config)
13
+ # #super(config)
14
+ # end
15
+ #
16
+ # def self.admin_can_user_defined_actions
17
+ # [].freeze
18
+ # end
19
+ # def self.admin_cannot_user_defined_actions
20
+ # [].freeze
21
+ # end
22
+ # def self.manager_can_user_defined_actions
23
+ # [].freeze
24
+ # end
25
+ # def self.manager_cannot_user_defined_actions
26
+ # [].freeze
27
+ # end
28
+ # def self.rails_admin_user_defined_visible_actions
29
+ # [].freeze
30
+ # end
31
+
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,13 @@
1
+ module Hancock::Gallery::Gallerable
2
+ extend ActiveSupport::Concern
3
+
4
+ module ClassMethods
5
+ def hancock_gallerable_field(name = :galleries, opts = {})
6
+ class_name = opts.delete(:class_name)
7
+ class_name ||= "Hancock::Gallery::Gallery"
8
+
9
+ has_many name, as: :hancock_gallerable, class_name: class_name
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,96 @@
1
+ if Hancock.mongoid?
2
+ module Hancock::Gallery::MongoidPaperclip
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ include ::Mongoid::Paperclip
7
+ end
8
+
9
+ module ClassMethods
10
+ def hancock_cms_mongoid_attached_file(name, opts = {})
11
+ name = name.to_sym
12
+ is_image = true
13
+ styles_method_name = nil
14
+ unless opts.blank?
15
+ content_type = opts.delete(:content_type)
16
+ jcrop_options = opts.delete(:jcrop_options)
17
+ is_image = opts.delete(:is_image)
18
+ is_image = true if is_image.nil?
19
+ end
20
+
21
+ if is_image
22
+ opts[:processors] ||= []
23
+ opts[:processors] << :rails_admin_jcropper
24
+ if defined?(::PaperclipOptimizer)
25
+ opts[:processors] << :paperclip_optimizer
26
+ opts[:processors].flatten!
27
+ opts[:processors].uniq!
28
+ end
29
+
30
+ opts[:convert_options] = {all: "-quality 75 -strip"} if opts[:convert_options].blank?
31
+
32
+ if opts[:styles].blank?
33
+ styles_method_name = "#{name}_styles"
34
+ opts[:styles] = lambda { |attachment| attachment.instance.send(styles_method_name) }
35
+ end
36
+
37
+ set_default_auto_crop_params_for name
38
+ end
39
+
40
+ has_mongoid_attached_file name, opts
41
+ # validates_attachment name, content_type: content_type unless content_type.blank?
42
+ validates_attachment_content_type name, content_type: /\Aimage\/.*\Z/ if is_image
43
+
44
+ class_eval <<-EVAL
45
+ def #{name}_file_name=(val)
46
+ return self[:#{name}_file_name] = "" if val == ""
47
+ return self[:#{name}_file_name] = nil if val == nil
48
+ val = val.to_s
49
+ extension = File.extname(val)[1..-1]
50
+ file_name = val[0..val.size-extension.size-1]
51
+ self[:#{name}_file_name] = "\#{file_name.filename_to_slug}.\#{extension.filename_to_slug}"
52
+ end
53
+
54
+ def #{name}_svg?
55
+ #{name}_content_type =~ /svg/
56
+ end
57
+
58
+ def #{name}_url(opts)
59
+ if #{name}_svg?
60
+ #{name}.url
61
+ else
62
+ #{name}.url(opts)
63
+ end
64
+ end
65
+ EVAL
66
+ if defined?(::PaperclipOptimizer)
67
+ class_eval <<-EVAL
68
+ before_#{name}_post_process do
69
+ p_o = self.#{name}.processors.delete :paperclip_optimizer
70
+ self.#{name}.processors << p_o if p_o
71
+ true
72
+ end
73
+ EVAL
74
+ end
75
+ jcrop_options ||= {}
76
+ if jcrop_options
77
+ class_eval <<-EVAL
78
+ def #{name}_jcrop_options
79
+ #{jcrop_options}
80
+ end
81
+ EVAL
82
+ end
83
+ if styles_method_name
84
+ class_eval <<-EVAL
85
+ def #{styles_method_name}
86
+ {
87
+ thumb: '128x128'
88
+ }
89
+ end
90
+ EVAL
91
+ end
92
+
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,19 @@
1
+ module Hancock::Gallery::Paperclipable
2
+ extend ActiveSupport::Concern
3
+
4
+ include Hancock::Gallery::AutoCrop
5
+
6
+ module ClassMethods
7
+ def hancock_cms_attached_file(name, opts = {})
8
+ if Hancock.active_record?
9
+ include Hancock::Gallery::ActiveRecordPaperclip
10
+ hancock_cms_active_record_attached_file(name, opts)
11
+
12
+ elsif Hancock.mongoid?
13
+ include Hancock::Gallery::MongoidPaperclip
14
+ hancock_cms_mongoid_attached_file(name, opts)
15
+ end
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,117 @@
1
+ module Hancock::Gallery::Watermarkable
2
+ extend ActiveSupport::Concern
3
+
4
+ module ClassMethods
5
+ def paperclip_with_watermark(field = :image, original_image_class_name = "Hancock::Gallery::OriginalImage")
6
+
7
+ attr_accessor "#{field}_autocropped".to_sym
8
+
9
+ hancock_cms_attached_file field, processors: [:watermark]
10
+ # field "original_#{field}", type: BSON::Binary
11
+ has_one "original_#{field}_data", as: :originable, class_name: original_image_class_name
12
+
13
+ class_eval %{
14
+ def #{field}_auto_rails_admin_jcrop
15
+ return if self.#{field}.blank? or !self.#{field}_updated_at_changed? or self.#{field}_autocropped
16
+ self.#{field}_autocropped = true
17
+
18
+ if File.exists?(self.#{field}.path)
19
+ auto_rails_admin_jcrop(:#{field})
20
+
21
+ elsif (_data = self.original_#{field})
22
+ _old_filename = self.#{field}_file_name
23
+ if _data
24
+ _data = _data.data
25
+ _temp = Tempfile.new(_old_filename)
26
+ _temp.binmode
27
+ _temp.write _data
28
+ File.unlink(self.#{field}.path) if File.symlink?(self.#{field}.path)
29
+ File.symlink(_temp.path, self.#{field}.path)
30
+ # self.#{field} = _temp
31
+ # self.#{field}.instance_write(:file_name, "\#{SecureRandom.hex}\#{File.extname(_old_filename)}")
32
+ self.class.skip_callback(:save, :after, "original_#{field}_to_db".to_sym)
33
+ auto_rails_admin_jcrop(:#{field})
34
+ self.class.set_callback(:save, :after, "original_#{field}_to_db".to_sym)
35
+ _temp.unlink
36
+ end
37
+ end
38
+ end
39
+
40
+ before_#{field}_post_process do
41
+ p_o = self.#{field}.processors.delete :paperclip_optimizer
42
+ # if p_o
43
+ # _processors = self.#{field}.processors.dup
44
+ # self.#{field}.processors.clear
45
+ # self.#{field}.processors = [:thumbnail, p_o]
46
+ # _processors.each do |p|
47
+ # self.#{field}.processors << p
48
+ # end
49
+ # end
50
+
51
+ p_w = self.#{field}.processors.delete :watermark
52
+ self.#{field}.processors << p_w if p_w
53
+
54
+ true
55
+ end
56
+
57
+ def original_#{field}
58
+ original_#{field}_data.original if original_#{field}_data
59
+ end
60
+ def original_#{field}_base64
61
+ _original = self.original_#{field}
62
+ if _original
63
+ _data = Base64.encode64(_original.data)
64
+ _content_type = self.#{field}_content_type
65
+ else
66
+ _data = ''
67
+ _content_type = 'jpg'
68
+ end
69
+ "data:\#{_content_type};base64,\#{_data}"
70
+ end
71
+
72
+ after_save :original_#{field}_to_db
73
+ def original_#{field}_to_db
74
+ if self.#{field}_file_name
75
+ if File.exists?(self.#{field}.path)
76
+ _original = self.original_#{field}_data
77
+ unless _original
78
+ _original = #{original_image_class_name}.new
79
+ _original.originable = self
80
+ end
81
+ _original.original = BSON::Binary.new(File.binread(self.#{field}.path))
82
+ if _original.save
83
+ File.unlink(self.#{field}.path)
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ def reprocess_#{field}
90
+ return if self.#{field}.blank?
91
+
92
+ if File.exists?(self.#{field}.path)
93
+ self.#{field}.reprocess!
94
+ elsif (_data = self.original_#{field})
95
+ _old_filename = self.#{field}_file_name
96
+ if _data
97
+ _data = _data.data
98
+ _temp = Tempfile.new(_old_filename)
99
+ _temp.binmode
100
+ _temp.write _data
101
+ File.unlink(self.#{field}.path) if File.symlink?(self.#{field}.path)
102
+ File.symlink(_temp.path, self.#{field}.path)
103
+ self.#{field} = _temp
104
+ self.#{field}.instance_write(:file_name, "\#{SecureRandom.hex}\#{File.extname(_old_filename)}")
105
+ self.class.skip_callback(:save, :after, "original_#{field}_to_db".to_sym)
106
+ self.#{field}.reprocess!
107
+ self.class.set_callback(:save, :after, "original_#{field}_to_db".to_sym)
108
+ _temp.unlink
109
+ self.save
110
+ end
111
+ end
112
+ end
113
+ }
114
+ end
115
+ end
116
+
117
+ end
@@ -0,0 +1,17 @@
1
+ module Hancock::Gallery
2
+ if Hancock::Gallery.mongoid?
3
+ class EmbeddedImage < Hancock::EmbeddedElement
4
+ include Hancock::Gallery::Models::EmbeddedImage
5
+
6
+ include Hancock::Gallery::Decorators::EmbeddedImage
7
+
8
+ rails_admin(&Hancock::Gallery::Admin::EmbeddedImage.config(rails_admin_add_fields) { |config|
9
+ rails_admin_add_config(config)
10
+ })
11
+
12
+ # use it in rails_admin in parent model for sort
13
+ # sort_embedded({fields: [:embedded_field_1, :embedded_field_2...]})
14
+ # or u need to override rails_admin in inherited model to add sort field
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ module Hancock::Gallery
2
+ if Hancock::Gallery.active_record?
3
+ class Gallery < ActiveRecord::Base
4
+ end
5
+ end
6
+
7
+ class Gallery
8
+ include Hancock::Gallery::Models::Gallery
9
+
10
+ include Hancock::Gallery::Decorators::Gallery
11
+
12
+ rails_admin(&Hancock::Gallery::Admin::Gallery.config(rails_admin_add_fields) { |config|
13
+ rails_admin_add_config(config)
14
+ })
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Hancock::Gallery
2
+ if Hancock::Gallery.active_record?
3
+ class Image < ActiveRecord::Base
4
+ end
5
+ end
6
+
7
+ class Image
8
+ include Hancock::Gallery::Models::Image
9
+
10
+ include Hancock::Gallery::Decorators::Image
11
+
12
+ rails_admin(&Hancock::Gallery::Admin::Image.config(rails_admin_add_fields) { |config|
13
+ rails_admin_add_config(config)
14
+ })
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ module Hancock::Gallery
2
+ if Hancock::Gallery.mongoid?
3
+
4
+ class OriginalImage
5
+ include Hancock::Gallery::Models::OriginalImage
6
+
7
+ include Hancock::Gallery::Decorators::OriginalImage
8
+
9
+ rails_admin(&Hancock::Gallery::Admin::OriginalImage.config(rails_admin_add_fields) { |config|
10
+ rails_admin_add_config(config)
11
+ })
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ - if params[:img_src]
2
+ = form_tag nil, @form_options.merge({class: "form-horizontal denser"})
3
+ = image_tag params[:img_src], @image_tag_options
4
+ = hidden_field_tag :crop_field, @field
5
+ = hidden_field_tag :crop_model, @object.class.name
6
+ - else
7
+ = form_tag nil, @form_options.merge({class: "form-horizontal denser"}) do
8
+ - if File.exists?(@object.send(@field).path)
9
+ = image_tag @object.send(@field).url, @image_tag_options
10
+ - elsif @object.respond_to?("original_#{@field}_base64".to_sym)
11
+ = image_tag @object.send("original_#{@field}_base64".to_sym), @image_tag_options
12
+
13
+ = hidden_field_tag :crop_x
14
+ = hidden_field_tag :crop_y
15
+ = hidden_field_tag :crop_w
16
+ = hidden_field_tag :crop_h
17
+ = hidden_field_tag :crop_field, @field
18
+ = render partial: 'rails_admin/main/submit_buttons'
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hancock_cms_gallery"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ Hancock.rails_admin_configure do |config|
2
+ config.action_visible_for :nested_set, 'Hancock::Gallery::Gallery'
3
+ config.action_visible_for :nested_set, 'Hancock::Gallery::Image'
4
+
5
+ if defined?(RailsAdminComments)
6
+ config.action_visible_for :comments, 'Hancock::Gallery::Gallery'
7
+ config.action_visible_for :comments, 'Hancock::Gallery::Image'
8
+
9
+ config.action_visible_for :model_comments, 'Hancock::Gallery::Gallery'
10
+ config.action_visible_for :model_comments, 'Hancock::Gallery::Image'
11
+ end
12
+
13
+ if defined?(RailsAdminMultipleFileUpload)
14
+ if true or Hancock::Catalog.active_record?
15
+ config.action_visible_for :multiple_file_upload, 'Hancock::Gallery::Gallery'
16
+ config.action_visible_for :multiple_file_upload_collection, 'Hancock::Gallery::Image'
17
+ end
18
+ end
19
+ end
20
+
21
+ if defined?(RailsAdmin)
22
+ RailsAdmin.config do |config|
23
+ config.excluded_models ||= []
24
+ config.excluded_models << [
25
+ 'Hancock::Gallery::EmbeddedImage'
26
+ ]
27
+ config.excluded_models.flatten!
28
+ end
29
+ end
@@ -0,0 +1,4 @@
1
+ if defined?(Paperclip)
2
+ Paperclip.options[:content_type_mappings] ||= {}
3
+ Paperclip.options[:content_type_mappings].merge!({svg: "image/svg+xml"})
4
+ end
@@ -0,0 +1,17 @@
1
+ ru:
2
+ hancock:
3
+ gallery: "Галерея"
4
+ images: "Галерея"
5
+
6
+ mongoid: &mongoid
7
+ models:
8
+ hancock/gallery/gallery: Фотогалерея
9
+ hancock/gallery/image: Фото в фотогалерее
10
+ hancock/gallery/embedded_image: Фото в фотогалерее
11
+
12
+ attributes:
13
+ hancock/gallery/gallery:
14
+ hancock/gallery/image:
15
+ gallery: Фотогалерея
16
+ gallery_id: Фотогалерея
17
+ hancock/gallery/embedded_image: