enjoy_cms_catalog 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +45 -0
  8. data/Rakefile +1 -0
  9. data/app/assets/javascripts/enjoy_cms_catalog/enjoy_cms_catalog.coffee +0 -0
  10. data/app/assets/stylesheets/enjoy_cms_catalog/enjoy_cms_catalog.sass +0 -0
  11. data/app/controllers/enjoy/catalog/item_categories_controller.rb +5 -0
  12. data/app/controllers/enjoy/catalog/items_controller.rb +5 -0
  13. data/app/models/concerns/enjoy/catalog/decorators/item.rb +5 -0
  14. data/app/models/concerns/enjoy/catalog/decorators/item_category.rb +5 -0
  15. data/app/models/concerns/enjoy/catalog/decorators/item_category_image.rb +5 -0
  16. data/app/models/concerns/enjoy/catalog/decorators/item_image.rb +5 -0
  17. data/app/models/enjoy/catalog/item.rb +11 -0
  18. data/app/models/enjoy/catalog/item_category.rb +9 -0
  19. data/app/models/enjoy/catalog/item_category_image.rb +9 -0
  20. data/app/models/enjoy/catalog/item_image.rb +9 -0
  21. data/app/views/enjoy/catalog/item_categories/index.html.slim +29 -0
  22. data/app/views/enjoy/catalog/item_categories/show.html.slim +84 -0
  23. data/app/views/enjoy/catalog/items/index.html.slim +28 -0
  24. data/app/views/enjoy/catalog/items/show.html.slim +32 -0
  25. data/bin/console +14 -0
  26. data/bin/setup +7 -0
  27. data/config/initializers/rails_admin.rb +8 -0
  28. data/config/routes.rb +18 -0
  29. data/enjoy_cms_catalog.gemspec +42 -0
  30. data/lib/enjoy/catalog/admin.rb +6 -0
  31. data/lib/enjoy/catalog/admin/item.rb +91 -0
  32. data/lib/enjoy/catalog/admin/item_category.rb +141 -0
  33. data/lib/enjoy/catalog/admin/item_category_image.rb +15 -0
  34. data/lib/enjoy/catalog/admin/item_image.rb +15 -0
  35. data/lib/enjoy/catalog/configuration.rb +46 -0
  36. data/lib/enjoy/catalog/controllers/item_categories.rb +76 -0
  37. data/lib/enjoy/catalog/controllers/items.rb +61 -0
  38. data/lib/enjoy/catalog/engine.rb +7 -0
  39. data/lib/enjoy/catalog/models/item.rb +40 -0
  40. data/lib/enjoy/catalog/models/item_category.rb +49 -0
  41. data/lib/enjoy/catalog/models/item_category_image.rb +23 -0
  42. data/lib/enjoy/catalog/models/item_image.rb +23 -0
  43. data/lib/enjoy/catalog/models/mongoid/item.rb +41 -0
  44. data/lib/enjoy/catalog/models/mongoid/item_category.rb +33 -0
  45. data/lib/enjoy/catalog/models/mongoid/item_category_image.rb +25 -0
  46. data/lib/enjoy/catalog/models/mongoid/item_image.rb +26 -0
  47. data/lib/enjoy/catalog/version.rb +5 -0
  48. data/lib/enjoy_cms_catalog.rb +59 -0
  49. data/release.sh +7 -0
  50. metadata +210 -0
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'enjoy/catalog/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "enjoy_cms_catalog"
8
+ spec.version = Enjoy::Catalog::VERSION
9
+ spec.authors = ["Alexander Kiseliev"]
10
+ spec.email = ["dev@enjoycreate.ru"]
11
+
12
+ spec.summary = "Items catalog with EnjoyCMS support."
13
+ spec.description = "Items catalog with EnjoyCMS support."
14
+ spec.homepage = "https://github.com/enjoycreative/enjoy_cms_catalog"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ # spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.10"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+
34
+ spec.add_dependency 'rails', '>= 4.1.0', '< 5.0'
35
+
36
+ spec.add_dependency 'money-rails'
37
+ spec.add_dependency 'mongoid_money_field'
38
+
39
+ spec.add_dependency 'enjoy_cms'
40
+ spec.add_dependency 'rails_admin_sort_embedded'
41
+ spec.add_dependency 'ack_rails_admin_jcrop'
42
+ end
@@ -0,0 +1,6 @@
1
+ module Enjoy::Catalog
2
+ module Admin
3
+ class << self
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,91 @@
1
+ module Enjoy::Catalog
2
+ module Admin
3
+ module Item
4
+ def self.config(fields = {})
5
+ Proc.new {
6
+ list do
7
+ scopes [:sorted, :enabled, nil]
8
+
9
+ field :enabled, :toggle
10
+ field :name
11
+ field :price
12
+ field :item_categories
13
+ field :image
14
+ end
15
+
16
+ edit do
17
+ field :enabled, :toggle
18
+ field :name
19
+ field :slugs, :enum do
20
+ enum_method do
21
+ :slugs
22
+ end
23
+ visible do
24
+ bindings[:view].current_user.admin?
25
+ end
26
+ multiple do
27
+ true
28
+ end
29
+ end
30
+ field :text_slug
31
+ field :image, :jcrop do
32
+ jcrop_options do
33
+ :image_jcrop_options
34
+ end
35
+ end
36
+ field :item_categories
37
+ field :excerpt, :ck_editor
38
+ field :content, :ck_editor
39
+
40
+ field :item_images
41
+
42
+ fields.each_pair do |name, type|
43
+ if type.nil?
44
+ field name
45
+ else
46
+ if type.is_a?(Array)
47
+ field name, type[0], &type[1]
48
+ else
49
+ field name, type
50
+ end
51
+ end
52
+ end
53
+
54
+ group :seo do
55
+ active false
56
+ field :seo do
57
+ active true
58
+ end
59
+ end
60
+ group :sitemap_data do
61
+ active false
62
+ field :sitemap_data do
63
+ active true
64
+ end
65
+ end
66
+ end
67
+
68
+ nested_set({max_depth: 1, scopes: []})
69
+
70
+ sort_embedded(
71
+ {
72
+ fields: [:item_images]
73
+ }
74
+ )
75
+
76
+ if defined?(RailsAdminMultipleFileUpload)
77
+ multiple_file_upload(
78
+ {
79
+ fields: [:item_images]
80
+ }
81
+ )
82
+ end
83
+
84
+ if block_given?
85
+ yield self
86
+ end
87
+ }
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,141 @@
1
+ module Enjoy::Catalog
2
+ module Admin
3
+ module ItemCategory
4
+ def self.config(fields = {})
5
+ Proc.new {
6
+
7
+ list do
8
+ scopes [:sorted, :enabled, nil]
9
+
10
+ field :enabled, :toggle
11
+ field :name
12
+ field :image
13
+
14
+ field :items do
15
+ read_only true
16
+
17
+ pretty_value do
18
+ bindings[:object].items.to_a.map { |h|
19
+ (bindings[:view] || bindings[:controller]).link_to(h.name, (bindings[:view] || bindings[:controller]).rails_admin.show_path(model_name: "item", id: h.id), title: h.name)
20
+ }.join("<br>").html_safe
21
+ end
22
+ end
23
+ end
24
+
25
+ edit do
26
+ field :enabled, :toggle
27
+ field :name
28
+ field :slugs, :enum do
29
+ enum_method do
30
+ :slugs
31
+ end
32
+ visible do
33
+ bindings[:view].current_user.admin?
34
+ end
35
+ multiple do
36
+ true
37
+ end
38
+ end
39
+ field :text_slug
40
+ field :image, :jcrop do
41
+ jcrop_options do
42
+ :image_jcrop_options
43
+ end
44
+ end
45
+ field :excerpt, :ck_editor
46
+ field :content, :ck_editor
47
+
48
+ field :item_category_images
49
+
50
+ fields.each_pair do |name, type|
51
+ if type.nil?
52
+ field name
53
+ else
54
+ if type.is_a?(Array)
55
+ field name, type[0], &type[1]
56
+ else
57
+ field name, type
58
+ end
59
+ end
60
+ end
61
+
62
+ group :seo do
63
+ active false
64
+ field :seo do
65
+ active true
66
+ end
67
+ end
68
+ group :sitemap_data do
69
+ active false
70
+ field :sitemap_data do
71
+ active true
72
+ end
73
+ end
74
+
75
+ field :items do
76
+ read_only true
77
+ help 'Список товаров'
78
+
79
+ pretty_value do
80
+ bindings[:object].items.to_a.map { |h|
81
+ (bindings[:view] || bindings[:controller]).link_to(h.name, (bindings[:view] || bindings[:controller]).rails_admin.edit_path(model_name: "item", id: h.id), title: h.name)
82
+ }.join("<br>").html_safe
83
+ end
84
+ end
85
+ end
86
+
87
+ show do
88
+ field :name
89
+ field :sidebar_title
90
+ field :slugs, :enum do
91
+ enum_method do
92
+ :slugs
93
+ end
94
+ visible do
95
+ bindings[:view].current_user.admin?
96
+ end
97
+ multiple do
98
+ true
99
+ end
100
+ end
101
+ field :text_slug
102
+ field :enabled
103
+ field :image
104
+ field :excerpt
105
+ field :content
106
+
107
+ field :items do
108
+ read_only true
109
+
110
+ pretty_value do
111
+ bindings[:object].items.to_a.map { |h|
112
+ (bindings[:view] || bindings[:controller]).link_to(h.name, (bindings[:view] || bindings[:controller]).rails_admin.show_path(model_name: "item", id: h.id), title: h.name)
113
+ }.join("<br>").html_safe
114
+ end
115
+ end
116
+ end
117
+
118
+ nested_set({max_depth: 2, scopes: []})
119
+
120
+ sort_embedded(
121
+ {
122
+ fields: [:item_category_images]
123
+ }
124
+ )
125
+
126
+ if defined?(RailsAdminMultipleFileUpload)
127
+ multiple_file_upload(
128
+ {
129
+ fields: [:item_category_images]
130
+ }
131
+ )
132
+ end
133
+
134
+ if block_given?
135
+ yield self
136
+ end
137
+ }
138
+ end
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,15 @@
1
+ module Enjoy::Catalog
2
+ module Admin
3
+ module ItemCategoryImage
4
+ def self.config(fields = {})
5
+ if block_given?
6
+ Enjoy::Admin::EmbeddedGalleryImage.config(fields) do |config|
7
+ yield config
8
+ end
9
+ else
10
+ Enjoy::Admin::EmbeddedGalleryImage.config(fields)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Enjoy::Catalog
2
+ module Admin
3
+ module ItemImage
4
+ def self.config(fields = {})
5
+ if block_given?
6
+ Enjoy::Admin::EmbeddedGalleryImage.config(fields) do |config|
7
+ yield config
8
+ end
9
+ else
10
+ Enjoy::Admin::EmbeddedGalleryImage.config(fields)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,46 @@
1
+ module Enjoy
2
+ module Catalog
3
+ def self.configuration
4
+ @configuration ||= Configuration.new
5
+ end
6
+ def self.config
7
+ @configuration ||= Configuration.new
8
+ end
9
+
10
+ def self.configure
11
+ yield configuration
12
+ end
13
+
14
+ class Configuration
15
+ attr_accessor :item_image_styles
16
+ attr_accessor :item_per_page
17
+
18
+ attr_accessor :item_images_image_styles
19
+
20
+ attr_accessor :item_category_image_styles
21
+ attr_accessor :item_category_per_page
22
+
23
+ attr_accessor :item_category_images_image_styles
24
+
25
+ attr_accessor :routes_config
26
+
27
+ def initialize
28
+ @item_image_styles = {}
29
+ @item_per_page = 10
30
+
31
+ @item_images_image_styles = {}
32
+
33
+ @item_category_image_styles = {}
34
+ @item_category_per_page = 10
35
+
36
+ @item_category_images_image_styles = {}
37
+
38
+ @routes_config = {
39
+ use_items_path: true,
40
+ use_item_categories_path: true,
41
+ use_catalog_path: true
42
+ }
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,76 @@
1
+ module Enjoy::Catalog
2
+ module Controllers
3
+ module ItemCategories
4
+ extend ActiveSupport::Concern
5
+
6
+ def index
7
+ @item_categories = item_category_class.enabled.sorted.to_a
8
+ @root_catalog = item_category_class.enabled.roots.sorted.all.to_a
9
+ # index_crumbs
10
+ end
11
+
12
+ def show
13
+ @item_category = item_category_class.enabled.find(params[:id])
14
+ if !@item_category.text_slug.blank? and @item_category.text_slug != params[:id]
15
+ redirect_to @item_category, status_code: 301
16
+ return
17
+ end
18
+ @seo_parent_page = find_seo_page(item_categories_path)
19
+
20
+ @children = @item_category.children.enabled.sorted.all.to_a
21
+ @items = @item_category.items.enabled.sorted.all.to_a
22
+
23
+ # index_crumbs
24
+ # category_crumbs
25
+ end
26
+
27
+ def page_title
28
+ if @item_category
29
+ @item_category.page_title
30
+ else
31
+ super
32
+ end
33
+ end
34
+
35
+ private
36
+ def item_category_class
37
+ Enjoy::Catalog::ItemCategory
38
+ end
39
+ def item_class
40
+ Enjoy::Catalog::Item
41
+ end
42
+
43
+ # def index_crumbs
44
+ # if @seo_parent_page
45
+ # catalog_title = Settings.ns('breadcrumbs').catalog_title(default: "Каталог", label: "'Каталог' в breadcrumbs")
46
+ # _crumb = catalog_title
47
+ # _crumb = @seo_parent_page.name if _crumb.blank?
48
+ # _crumb = @seo_parent_page.title if _crumb.blank?
49
+ # _crumb = @seo_parent_page.h1 if _crumb.blank?
50
+ # add_crumb _crumb, @seo_parent_page.fullpath
51
+ # else
52
+ # catalog_title = Settings.ns('breadcrumbs').catalog_title(default: "Каталог", label: "'Каталог' в breadcrumbs")
53
+ # _crumb = catalog_title
54
+ # add_crumb _crumb, item_categories_path
55
+ # end
56
+ # end
57
+ #
58
+ # def category_crumbs
59
+ # if @item_category
60
+ # _parent = @item_category.parent
61
+ # if _parent
62
+ # _crumb = _parent.name if _crumb.blank?
63
+ # _crumb = _parent.title if _crumb.blank?
64
+ # _crumb = _parent.h1 if _crumb.blank?
65
+ # add_crumb _crumb, item_category_path(_parent)
66
+ # _crumb = nil
67
+ # end
68
+ # _crumb = @item_category.name if _crumb.blank?
69
+ # _crumb = @item_category.title if _crumb.blank?
70
+ # _crumb = @item_category.h1 if _crumb.blank?
71
+ # add_crumb _crumb, item_category_path(@item_category)
72
+ # end
73
+ # end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,61 @@
1
+ module Enjoy::Catalog
2
+ module Controllers
3
+ module Items
4
+ extend ActiveSupport::Concern
5
+
6
+ def index
7
+ @items = item_class.enabled.sorted.to_a
8
+ # index_crumbs
9
+ end
10
+
11
+ def show
12
+ @item = item_class.enabled.find(params[:id])
13
+ if !@item.text_slug.blank? and @item.text_slug != params[:id]
14
+ redirect_to @item, status_code: 301
15
+ return
16
+ end
17
+ @parent_seo_page = find_seo_page(item_categories_path) if @seo_page.blank?
18
+ # item_crumbs
19
+ end
20
+
21
+ def page_title
22
+ if @item
23
+ @item.page_title
24
+ else
25
+ super
26
+ end
27
+ end
28
+
29
+ private
30
+ def item_category_class
31
+ Enjoy::Catalog::ItemCategory
32
+ end
33
+ def item_class
34
+ Enjoy::Catalog::Item
35
+ end
36
+
37
+ # def item_crumbs
38
+ # if @item
39
+ # if @item.item_categories.enabled.count == 1
40
+ # if @parent_seo_page
41
+ # _crumb = @parent_seo_page.name
42
+ # _crumb = @parent_seo_page.title if _crumb.blank?
43
+ # _crumb = @parent_seo_page.h1 if _crumb.blank?
44
+ # add_crumb _crumb, @parent_seo_page.fullpath
45
+ # end
46
+ #
47
+ # @item_category = @item.item_categories.enabled.first
48
+ # _crumb = @item_category.name
49
+ # _crumb = @item_category.title if _crumb.blank?
50
+ # _crumb = @item_category.h1 if _crumb.blank?
51
+ # add_crumb _crumb, item_category_path(@item_category)
52
+ # end
53
+ # _crumb = @item.name
54
+ # _crumb = @item.title if _crumb.blank?
55
+ # _crumb = @item.h1 if _crumb.blank?
56
+ # add_crumb _crumb, item_path(@item)
57
+ # end
58
+ # end
59
+ end
60
+ end
61
+ end