enjoy_cms_gallery 0.4.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) 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 +41 -0
  9. data/Rakefile +1 -0
  10. data/app/assets/javascripts/enjoy/gallery/init.coffee +2 -0
  11. data/app/assets/javascripts/enjoy/gallery/loaders/gallery_images_loader.coffee +29 -0
  12. data/app/assets/javascripts/enjoy/gallery/loaders/gallery_loader.coffee +29 -0
  13. data/app/assets/javascripts/enjoy/gallery/page_selector.coffee +65 -0
  14. data/app/assets/javascripts/enjoy/gallery.coffee +11 -0
  15. data/app/controllers/concerns/enjoy/gallery/load_gallery.rb +55 -0
  16. data/app/controllers/concerns/enjoy/gallery/load_gallery_images.rb +46 -0
  17. data/app/models/concerns/enjoy/gallery/active_record_paperclip.rb +56 -0
  18. data/app/models/concerns/enjoy/gallery/decorators/embedded_image.rb +5 -0
  19. data/app/models/concerns/enjoy/gallery/decorators/gallery.rb +5 -0
  20. data/app/models/concerns/enjoy/gallery/decorators/image.rb +5 -0
  21. data/app/models/concerns/enjoy/gallery/gallerable.rb +22 -0
  22. data/app/models/concerns/enjoy/gallery/mongoid_paperclip.rb +57 -0
  23. data/app/models/concerns/enjoy/gallery/paperclipable.rb +17 -0
  24. data/app/models/enjoy/gallery/embedded_image.rb +16 -0
  25. data/app/models/enjoy/gallery/gallery.rb +16 -0
  26. data/app/models/enjoy/gallery/image.rb +16 -0
  27. data/bin/console +14 -0
  28. data/bin/setup +7 -0
  29. data/config/initializers/enjoy_rails_admin.rb +51 -0
  30. data/config/initializers/paperclip_fix.rb +4 -0
  31. data/config/locales/enjoy.gallery.ru.yml +16 -0
  32. data/enjoy_cms_gallery.gemspec +41 -0
  33. data/lib/enjoy/gallery/admin/embedded_image.rb +38 -0
  34. data/lib/enjoy/gallery/admin/gallery.rb +56 -0
  35. data/lib/enjoy/gallery/admin/image.rb +33 -0
  36. data/lib/enjoy/gallery/admin.rb +4 -0
  37. data/lib/enjoy/gallery/configuration.rb +21 -0
  38. data/lib/enjoy/gallery/engine.rb +5 -0
  39. data/lib/enjoy/gallery/models/active_record/gallery.rb +19 -0
  40. data/lib/enjoy/gallery/models/active_record/image.rb +21 -0
  41. data/lib/enjoy/gallery/models/embedded_image.rb +26 -0
  42. data/lib/enjoy/gallery/models/gallery.rb +36 -0
  43. data/lib/enjoy/gallery/models/image.rb +30 -0
  44. data/lib/enjoy/gallery/models/mongoid/embedded_image.rb +12 -0
  45. data/lib/enjoy/gallery/models/mongoid/gallery.rb +19 -0
  46. data/lib/enjoy/gallery/models/mongoid/image.rb +18 -0
  47. data/lib/enjoy/gallery/version.rb +5 -0
  48. data/lib/enjoy_cms_gallery.rb +68 -0
  49. data/lib/generators/enjoy/gallery/config/install_generator.rb +13 -0
  50. data/lib/generators/enjoy/gallery/config/templates/enjoy_gallery.erb +4 -0
  51. data/lib/generators/enjoy/gallery/migrations/migration_generator.rb +18 -0
  52. data/lib/generators/enjoy/gallery/migrations/templates/migration_gallery.rb +51 -0
  53. data/lib/generators/enjoy/gallery/models/embedded_image_generator.rb +48 -0
  54. data/lib/generators/enjoy/gallery/models/image_generator.rb +43 -0
  55. data/lib/generators/enjoy/gallery/models/templates/embedded_image.erb +29 -0
  56. data/lib/generators/enjoy/gallery/models/templates/image.erb +22 -0
  57. data/release.sh +7 -0
  58. metadata +212 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1350dc8c6aba1c63e72df3410ae79e7ddc46edf9
4
+ data.tar.gz: 5a03d26e023069e6e43ddf4370fbf04b362513e6
5
+ SHA512:
6
+ metadata.gz: 4ac9f8a99c837139d6ba6a7ad36d51460d4e90029da3fe9c7e06a9bb573fab7ba618991074f2158afccc3e1602ffe5682fb3b7e0b749ae58905c662ba4935b9f
7
+ data.tar.gz: fbf7f448d2c838b8a3c3b4b349416e9e3811e4c49f08c41b560d4b92dad635e01c9500947f642baa8a7df9eb160b53b78f2040b952f10c9ec429782184e9d2e9
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ .idea
2
+ .idea/*
3
+
4
+ *.gem
5
+ *.rbc
6
+
7
+ /.bundle/
8
+ .config
9
+ /.yardoc
10
+ InstalledFiles
11
+ /Gemfile.lock
12
+ /_yardoc/
13
+ /coverage/
14
+ /doc/
15
+ /pkg/
16
+ /spec/reports/
17
+ /tmp/
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ enjoy_cms_gallery
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in enjoy_cms_gallery.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Alexander Kiseliev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # EnjoyCmsGallery
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/enjoy_cms_gallery`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'enjoy_cms_gallery'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install enjoy_cms_gallery
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/enjoy_cms_gallery.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ window.enjoy_cms ||= {}
2
+ window.enjoy_cms.gallery ||= {}
@@ -0,0 +1,29 @@
1
+ window.enjoy_cms.gallery.images_loader = (target = "[data-enjoy-gallery-images-loader]")->
2
+ $(document).delegate target, "click", (e)->
3
+ e.preventDefault()
4
+
5
+ link = $(e.currentTarget)
6
+ url = link.attr('href')
7
+ url = link.data("url") if !url or url == ""
8
+ if url and url != ""
9
+ $.get url, (data)->
10
+ _target_selector = link.data("target-selector")
11
+ if _target_selector and _target_selector != ""
12
+ _target = $(_target_selector)
13
+ if _target.length > 0
14
+ if link.data("target-replace") == "true"
15
+ _target.replaceWith(data)
16
+ else
17
+ _target.html(data)
18
+ if link.data("loader-remove") == "true"
19
+ link.remove()
20
+
21
+ else
22
+ if link.data("loader-insert-data") == "true"
23
+ link.html(data)
24
+ else
25
+ link.replaceWith(data)
26
+
27
+ window.enjoy_cms.gallery.construct_pages_selector()
28
+
29
+ return false
@@ -0,0 +1,29 @@
1
+ window.enjoy_cms.gallery.gallery_loader = (target = "[data-enjoy-gallery-gallery-loader]")->
2
+ $(document).delegate target, "click", (e)->
3
+ e.preventDefault()
4
+
5
+ link = $(e.currentTarget)
6
+ url = link.attr('href')
7
+ url = link.data("url") if !url or url == ""
8
+ if url and url != ""
9
+ $.get url, (data)->
10
+ _target_selector = link.data("target-selector")
11
+ if _target_selector and _target_selector != ""
12
+ _target = $(_target_selector)
13
+ if _target.length > 0
14
+ if link.data("target-replace") == "true"
15
+ _target.replaceWith(data)
16
+ else
17
+ _target.html(data)
18
+ if link.data("loader-remove") == "true"
19
+ link.remove()
20
+
21
+ else
22
+ if link.data("loader-insert-data") == "true"
23
+ link.html(data)
24
+ else
25
+ link.replaceWith(data)
26
+
27
+ window.enjoy_cms.gallery.construct_pages_selector()
28
+
29
+ return false
@@ -0,0 +1,65 @@
1
+ window.enjoy_cms.gallery.construct_pages_selector = (target = "[data-enjoy-gallery-page-selector]")->
2
+ pages_selector = $(target)
3
+ pages_array = []
4
+ pages_selector_html = ""
5
+ $(".enjoy_gallery_page_title_block").each ->
6
+ pages_array.push(parseInt($(this).data('page')))
7
+
8
+ pages_array.sort (a,b)->
9
+ a - b
10
+
11
+ $(pages_array).each ->
12
+ pages_selector_html += "<a href='#page-" + this + "' class='page_selector_block' title='" + this + "'>" + this + "</a>"
13
+ pages_selector.html(pages_selector_html)
14
+ window.enjoy_cms.gallery.format_pages_selector()
15
+
16
+
17
+
18
+ window.enjoy_cms.gallery.format_pages_selector = (target = ".enjoy_gallery_page_selector")->
19
+ pages_selector = $(target)
20
+ pages_array = []
21
+ $(".enjoy_gallery_page_title_block").each ->
22
+ pages_array.push([parseInt($(this).data('page')), $(this), $(this).offset().top])
23
+
24
+ first_window = parseInt(pages_selector.data('first-window')) || 1
25
+ center_window = parseInt(pages_selector.data('window')) || 2
26
+ last_window = parseInt(pages_selector.data('last-window')) || 1
27
+ top_offset = parseInt(pages_selector.data('top-offset')) || 0
28
+ scroll_top = $(window).scrollTop() || 0
29
+
30
+ min_page = 99999999
31
+ max_page = 0
32
+ current_page = null
33
+ min_diff = 99999999
34
+
35
+ $(pages_array).each ->
36
+ if (this[2] - (scroll_top + top_offset) > 0) and min_diff > this[2] - (scroll_top + top_offset)
37
+ current_page = this[0]
38
+ min_diff = this[2] - (scroll_top + top_offset)
39
+ if min_page > this[0]
40
+ min_page = this[0]
41
+ if max_page < this[0]
42
+ max_page = this[0]
43
+
44
+ if current_page
45
+ $(pages_array).each ->
46
+ f_w = this[0] >= min_page and this[0] <= min_page + first_window
47
+ c_w = this[0] >= current_page - center_window and this[0] <= current_page + center_window
48
+ l_w = this[0] >= max_page - last_window and this[0] <= max_page
49
+
50
+ page_selector_block = $(".page_selector_block[href='#page-" + this[0] + "']")
51
+
52
+ if f_w or c_w or l_w
53
+ page_selector_block.addClass("showed").removeClass("hidden")
54
+ else
55
+ page_selector_block.addClass("hidden").removeClass("showed")
56
+
57
+ if this[0] == current_page
58
+ page_selector_block.addClass("current")
59
+ else
60
+ page_selector_block.removeClass("current")
61
+
62
+
63
+
64
+ $(window).scroll ->
65
+ window.enjoy_cms.gallery.format_pages_selector()
@@ -0,0 +1,11 @@
1
+ #= require ./gallery/init
2
+
3
+ #= require ./gallery/page_selector
4
+
5
+ #= require ./gallery/loaders/gallery_loader
6
+ #= require ./gallery/loaders/gallery_images_loader
7
+
8
+ #= require_self
9
+
10
+ window.enjoy_cms.gallery.images_loader()
11
+ window.enjoy_cms.gallery.gallery_loader()
@@ -0,0 +1,55 @@
1
+ module Enjoy::Gallery::LoadGalleryImages
2
+ extend ActiveSupport::Concern
3
+
4
+
5
+ def enjoy_gallery_render_gallery
6
+ @gallery = enjoy_gallery_load_gallery
7
+ @gallery_images = enjoy_gallery_gallery_load_images
8
+
9
+ @next_page = (params[:page] || 1).to_i + 1
10
+
11
+ render_opts = {
12
+ layout: enjoy_gallery_gallery_layout,
13
+ action: enjoy_gallery_gallery_action,
14
+ partial: enjoy_gallery_gallery_partial
15
+ }
16
+ render render_opts.compact
17
+ end
18
+
19
+ private
20
+
21
+
22
+ def enjoy_gallery_gallery_layout
23
+ request.xhr? ? false : 'application'
24
+ end
25
+
26
+ def enjoy_gallery_gallery_action
27
+ 'enjoy_gallery_render_gallery'
28
+ end
29
+
30
+ def enjoy_gallery_gallery_partial
31
+ nil
32
+ end
33
+
34
+ def enjoy_gallery_gallery_class
35
+ Enjoy::Gallery::Gallery
36
+ end
37
+
38
+ def enjoy_gallery_gallery_images_method
39
+ :images
40
+ end
41
+
42
+ def enjoy_gallery_load_gallery
43
+ enjoy_gallery_gallery_class.find(params[:gallery_id])
44
+ end
45
+
46
+ def enjoy_gallery_gallery_load_images
47
+ @gallery.send(enjoy_gallery_gallery_images_method).enabled.sorted.page(params[:page]).per(enjoy_gallery_render_gallery_images_per_page)
48
+ end
49
+
50
+ def enjoy_gallery_gallery_per_page
51
+ 4
52
+ end
53
+
54
+
55
+ end
@@ -0,0 +1,46 @@
1
+ module Enjoy::Gallery::LoadGalleryImages
2
+ extend ActiveSupport::Concern
3
+
4
+
5
+ def enjoy_gallery_render_gallery_images
6
+ @gallery_images = enjoy_gallery_load_gallery_images
7
+
8
+ @next_page = (params[:page] || 1).to_i + 1
9
+
10
+ render_opts = {
11
+ layout: enjoy_gallery_gallery_images_layout,
12
+ action: enjoy_gallery_gallery_images_action,
13
+ partial: enjoy_gallery_gallery_images_partial
14
+ }
15
+ render render_opts.compact
16
+ end
17
+
18
+ private
19
+
20
+ def enjoy_gallery_gallery_images_layout
21
+ request.xhr? ? false : 'application'
22
+ end
23
+
24
+ def enjoy_gallery_gallery_images_action
25
+ 'enjoy_gallery_render_gallery_images'
26
+ end
27
+
28
+ def enjoy_gallery_gallery_images_partial
29
+ nil
30
+ end
31
+
32
+ def enjoy_gallery_gallery_image_class
33
+ Enjoy::Gallery::Image
34
+ end
35
+
36
+ def enjoy_gallery_load_gallery_images
37
+ enjoy_gallery_gallery_image_class.enabled.sorted.page(params[:page]).per(enjoy_gallery_gallery_images_per_page)
38
+ end
39
+
40
+ def enjoy_gallery_gallery_images_per_page
41
+ 4
42
+ end
43
+
44
+
45
+
46
+ end
@@ -0,0 +1,56 @@
1
+ if Enjoy.active_record?
2
+ module Enjoy::Gallery::ActiveRecordPaperclip
3
+ extend ActiveSupport::Concern
4
+
5
+ include ::Paperclip
6
+
7
+ module ClassMethods
8
+ def enjoy_cms_active_record_attached_file(name, opts = {})
9
+ name = name.to_sym
10
+ unless opts.blank?
11
+ content_type = opts.delete(:content_type)
12
+ jcrop_options = opts.delete(:jcrop_options)
13
+ is_image = opts.delete(:is_image)
14
+ is_image = true if is_image.nil?
15
+ end
16
+
17
+ if is_image
18
+ opts[:processors] ||= []
19
+ opts[:processors] << :paperclip_optimizer
20
+ opts[:processors].flatten!
21
+ opts[:processors].uniq!
22
+
23
+ opts[:convert_options] = {all: "-quality 75 -strip"} if opts[:convert_options].blank?
24
+ end
25
+
26
+ has_attached_file name, opts
27
+ # validates_attachment name, content_type: content_type unless content_type.blank?
28
+ validates_attachment_content_type name, content_type: /\Aimage\/.*\Z/ if is_image
29
+ class_eval <<-EVAL
30
+ def #{name}_file_name=(val)
31
+ return self[:#{name}_file_name] = "" if val == ""
32
+ return self[:#{name}_file_name] = nil if val == nil
33
+ val = val.to_s
34
+ extension = File.extname(val)[1..-1]
35
+ file_name = val[0..val.size-extension.size-1]
36
+ self[:#{name}_file_name] = "\#{file_name.filename_to_slug}.\#{extension.filename_to_slug}"
37
+ end
38
+
39
+ before_#{name}_post_process do
40
+ p_o = self.#{name}.processors.delete :paperclip_optimizer
41
+ self.#{name}.processors << p_o if p_o
42
+ true
43
+ end
44
+ EVAL
45
+ jcrop_options ||= {}
46
+ if jcrop_options
47
+ class_eval <<-EVAL
48
+ def #{name}_jcrop_options
49
+ #{jcrop_options}
50
+ end
51
+ EVAL
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,5 @@
1
+ module Enjoy::Gallery::Decorators
2
+ module EmbeddedImage
3
+ extend ActiveSupport::Concern
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Enjoy::Gallery::Decorators
2
+ module Gallery
3
+ extend ActiveSupport::Concern
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Enjoy::Gallery::Decorators
2
+ module Image
3
+ extend ActiveSupport::Concern
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ module Enjoy::Gallery::Gallerable
2
+ extend ActiveSupport::Concern
3
+
4
+ module ClassMethods
5
+ def enjoy_gallerable_field(name = :enjoy_gallerable, opts = {})
6
+ class_name = opts.delete(:class_name)
7
+ class_name ||= "Enjoy::Gallery::Gallery"
8
+
9
+ belongs_to name, polymorphic: true
10
+
11
+ class_eval <<-EVAL
12
+ before_save do
13
+ self.#{name}_id = nil if self.#{name}_type.nil?
14
+ self.#{name}_type = nil if self.#{name}_id.nil?
15
+ self
16
+ end
17
+ EVAL
18
+
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,57 @@
1
+ if Enjoy.mongoid?
2
+ module Enjoy::Gallery::MongoidPaperclip
3
+ extend ActiveSupport::Concern
4
+
5
+ include Mongoid::Paperclip
6
+
7
+ module ClassMethods
8
+ def enjoy_cms_mongoid_attached_file(name, opts = {})
9
+ name = name.to_sym
10
+ is_image = true
11
+ unless opts.blank?
12
+ content_type = opts.delete(:content_type)
13
+ jcrop_options = opts.delete(:jcrop_options)
14
+ is_image = opts.delete(:is_image)
15
+ is_image = true if is_image.nil?
16
+ end
17
+
18
+ if is_image
19
+ opts[:processors] ||= []
20
+ opts[:processors] << :paperclip_optimizer
21
+ opts[:processors].flatten!
22
+ opts[:processors].uniq!
23
+
24
+ opts[:convert_options] = {all: "-quality 75 -strip"} if opts[:convert_options].blank?
25
+ end
26
+
27
+ has_mongoid_attached_file name, opts
28
+ # validates_attachment name, content_type: content_type unless content_type.blank?
29
+ validates_attachment_content_type name, content_type: /\Aimage\/.*\Z/ if is_image
30
+ class_eval <<-EVAL
31
+ def #{name}_file_name=(val)
32
+ return self[:#{name}_file_name] = "" if val == ""
33
+ return self[:#{name}_file_name] = nil if val == nil
34
+ val = val.to_s
35
+ extension = File.extname(val)[1..-1]
36
+ file_name = val[0..val.size-extension.size-1]
37
+ self[:#{name}_file_name] = "\#{file_name.filename_to_slug}.\#{extension.filename_to_slug}"
38
+ end
39
+
40
+ before_#{name}_post_process do
41
+ p_o = self.#{name}.processors.delete :paperclip_optimizer
42
+ self.#{name}.processors << p_o if p_o
43
+ true
44
+ end
45
+ EVAL
46
+ jcrop_options ||= {}
47
+ if jcrop_options
48
+ class_eval <<-EVAL
49
+ def #{name}_jcrop_options
50
+ #{jcrop_options}
51
+ end
52
+ EVAL
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,17 @@
1
+ module Enjoy::Gallery::Paperclipable
2
+ extend ActiveSupport::Concern
3
+
4
+ module ClassMethods
5
+ def enjoy_cms_attached_file(name, opts = {})
6
+ if Enjoy.active_record?
7
+ include Enjoy::Gallery::ActiveRecordPaperclip
8
+ enjoy_cms_active_record_attached_file(name, opts)
9
+
10
+ elsif Enjoy.mongoid?
11
+ include Enjoy::Gallery::MongoidPaperclip
12
+ enjoy_cms_mongoid_attached_file(name, opts)
13
+ end
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,16 @@
1
+ module Enjoy::Gallery
2
+ if Enjoy::Gallery.mongoid?
3
+ class EmbeddedImage < Enjoy::EmbeddedElement
4
+ include Enjoy::Gallery::Models::EmbeddedImage
5
+
6
+ include Enjoy::Gallery::Decorators::EmbeddedImage
7
+
8
+ # use it in inherited model
9
+ # rails_admin &Enjoy::Gallery::Admin::EmbeddedImage.config
10
+
11
+ # use it in rails_admin in parent model for sort
12
+ # sort_embedded({fields: [:embedded_field_1, :embedded_field_2...]})
13
+ # or u need to override rails_admin in inherited model to add sort field
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Enjoy::Gallery
2
+ if Enjoy::Gallery.active_record?
3
+ class Gallery < ActiveRecord::Base
4
+ end
5
+ end
6
+
7
+ class Gallery
8
+ include Enjoy::Gallery::Models::Gallery
9
+
10
+ include Enjoy::Gallery::Decorators::Gallery
11
+
12
+ rails_admin(&Enjoy::Gallery::Admin::Gallery.config(nil, rails_admin_add_fields) { |config|
13
+ rails_admin_add_config(config)
14
+ })
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Enjoy::Gallery
2
+ if Enjoy::Gallery.active_record?
3
+ class Image < ActiveRecord::Base
4
+ end
5
+ end
6
+
7
+ class Image
8
+ include Enjoy::Gallery::Models::Image
9
+
10
+ include Enjoy::Gallery::Decorators::Image
11
+
12
+ rails_admin(&Enjoy::Gallery::Admin::Image.config(nil, false, rails_admin_add_fields) { |config|
13
+ rails_admin_add_config(config)
14
+ })
15
+ end
16
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "enjoy_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,51 @@
1
+ Enjoy.rails_admin_configure do |config|
2
+ config.action_visible_for :nested_set, 'Enjoy::Gallery::Gallery'
3
+ config.action_visible_for :nested_set, 'Enjoy::Gallery::Image'
4
+
5
+ if defined?(RailsAdminComments)
6
+ config.action_visible_for :comments, 'Enjoy::Gallery::Gallery'
7
+ config.action_visible_for :comments, 'Enjoy::Gallery::Image'
8
+
9
+ config.action_visible_for :model_comments, 'Enjoy::Gallery::Gallery'
10
+ config.action_visible_for :model_comments, 'Enjoy::Gallery::Image'
11
+ end
12
+
13
+ if defined?(RailsAdminMultipleFileUpload)
14
+ if true or Enjoy::Catalog.active_record?
15
+ config.action_visible_for :multiple_file_upload, 'Enjoy::Gallery::Gallery'
16
+ end
17
+ end
18
+ end
19
+
20
+ Enjoy.configure do |config|
21
+ config.ability_manager_config << {
22
+ method: :can,
23
+ model: Enjoy::Gallery::Gallery,
24
+ actions: [:edit, :update, :new]
25
+ }
26
+ config.ability_manager_config << {
27
+ method: :can,
28
+ model: Enjoy::Gallery::Image,
29
+ actions: [:edit, :update, :new, :nested_set]
30
+ }
31
+ config.ability_admin_config << {
32
+ method: :can,
33
+ model: Enjoy::Gallery::Gallery,
34
+ actions: :manage
35
+ }
36
+ config.ability_admin_config << {
37
+ method: :can,
38
+ model: Enjoy::Gallery::Image,
39
+ actions: :manage
40
+ }
41
+ end
42
+
43
+ if defined?(RailsAdmin)
44
+ RailsAdmin.config do |config|
45
+ config.excluded_models ||= []
46
+ config.excluded_models << [
47
+ 'Enjoy::Gallery::EmbeddedImage'
48
+ ]
49
+ config.excluded_models.flatten!
50
+ end
51
+ 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