enjoy_cms_catalog 0.3.7 → 0.4.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/app/{models/concerns/enjoy/catalog/decorators/item_category.rb → controllers/concerns/enjoy/catalog/decorators/categories.rb} +1 -1
- data/app/controllers/enjoy/catalog/categories_controller.rb +7 -0
- data/app/{controllers/concerns/enjoy/catalog/decorators/item_categories.rb → models/concerns/enjoy/catalog/decorators/category.rb} +1 -1
- data/app/models/concerns/enjoy/catalog/decorators/{item_category_image.rb → category_image.rb} +1 -1
- data/app/models/enjoy/catalog/category.rb +12 -0
- data/app/models/enjoy/catalog/category_image.rb +16 -0
- data/app/models/enjoy/catalog/item_image.rb +12 -7
- data/app/views/enjoy/catalog/{item_categories → categories}/index.html.slim +4 -1
- data/app/views/enjoy/catalog/{item_categories → categories}/show.html.slim +9 -6
- data/app/views/enjoy/catalog/items/index.html.slim +4 -2
- data/app/views/enjoy/catalog/items/show.html.slim +3 -0
- data/config/initializers/enjoy_catalog.rb +88 -0
- data/config/locales/enjoy.catalog.ru.yml +11 -4
- data/config/locales/ru.kaminari.yml +17 -0
- data/enjoy_cms_catalog.gemspec +3 -3
- data/lib/enjoy/catalog/admin/{item_category.rb → category.rb} +22 -10
- data/lib/enjoy/catalog/admin/category_image.rb +31 -0
- data/lib/enjoy/catalog/admin/item.rb +16 -7
- data/lib/enjoy/catalog/admin/item_image.rb +28 -12
- data/lib/enjoy/catalog/admin.rb +0 -2
- data/lib/enjoy/catalog/configuration.rb +46 -26
- data/lib/enjoy/catalog/controllers/{item_categories.rb → categories.rb} +32 -21
- data/lib/enjoy/catalog/controllers/items.rb +25 -36
- data/lib/enjoy/catalog/models/category.rb +50 -0
- data/lib/enjoy/catalog/models/category_image.rb +22 -0
- data/lib/enjoy/catalog/models/item.rb +27 -4
- data/lib/enjoy/catalog/models/item_image.rb +8 -0
- data/lib/enjoy/catalog/models/mongoid/category.rb +32 -0
- data/lib/enjoy/catalog/models/mongoid/category_image.rb +20 -0
- data/lib/enjoy/catalog/models/mongoid/item.rb +5 -24
- data/lib/enjoy/catalog/models/mongoid/item_image.rb +0 -10
- data/lib/enjoy/catalog/routes.rb +57 -13
- data/lib/enjoy/catalog/version.rb +1 -1
- data/lib/enjoy_cms_catalog.rb +55 -48
- data/lib/generators/enjoy/catalog/all_generator.rb +2 -2
- data/lib/generators/enjoy/catalog/config/install_generator.rb +3 -3
- data/lib/generators/enjoy/catalog/config/templates/enjoy_catalog.erb +3 -3
- data/lib/generators/enjoy/catalog/controllers/all_generator.rb +1 -1
- data/lib/generators/enjoy/catalog/controllers/{item_category_generator.rb → category_generator.rb} +4 -4
- data/lib/generators/enjoy/catalog/controllers/item_generator.rb +3 -3
- data/lib/generators/enjoy/catalog/controllers/templates/{item_categories_controller.erb → categories_controller.erb} +2 -2
- data/lib/generators/enjoy/catalog/controllers/templates/items_controller.erb +2 -2
- data/lib/generators/enjoy/catalog/models/all_generator.rb +2 -2
- data/lib/generators/enjoy/catalog/models/{item_category_generator.rb → category_generator.rb} +9 -5
- data/lib/generators/enjoy/catalog/models/{item_category_image_generator.rb → category_image_generator.rb} +11 -7
- data/lib/generators/enjoy/catalog/models/item_image_generator.rb +5 -1
- data/lib/generators/enjoy/catalog/models/templates/category.erb +34 -0
- data/lib/generators/enjoy/catalog/models/templates/category_image.erb +30 -0
- data/lib/generators/enjoy/catalog/models/templates/item.erb +4 -3
- data/lib/generators/enjoy/catalog/models/templates/item_image.erb +3 -3
- metadata +37 -36
- data/app/controllers/enjoy/catalog/item_categories_controller.rb +0 -7
- data/app/models/enjoy/catalog/item_category.rb +0 -11
- data/app/models/enjoy/catalog/item_category_image.rb +0 -11
- data/config/initializers/rails_admin.rb +0 -8
- data/lib/enjoy/catalog/admin/item_category_image.rb +0 -15
- data/lib/enjoy/catalog/models/item_category.rb +0 -27
- data/lib/enjoy/catalog/models/item_category_image.rb +0 -14
- data/lib/enjoy/catalog/models/mongoid/item_category.rb +0 -51
- data/lib/enjoy/catalog/models/mongoid/item_category_image.rb +0 -29
- data/lib/generators/enjoy/catalog/models/templates/item_category.erb +0 -33
- data/lib/generators/enjoy/catalog/models/templates/item_category_image.erb +0 -30
@@ -1,40 +1,51 @@
|
|
1
1
|
module Enjoy::Catalog
|
2
2
|
module Controllers
|
3
|
-
module
|
3
|
+
module Categories
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
+
included do
|
7
|
+
if Enjoy::Catalog.config.breadcrumbs_on_rails_support
|
8
|
+
add_breadcrumb I18n.t('enjoy.breadcrumbs.catalog'), :enjoy_catalog_path
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
6
12
|
def index
|
7
|
-
@
|
8
|
-
@root_catalog =
|
13
|
+
@categories = category_class.enabled.sorted.to_a
|
14
|
+
@root_catalog = category_class.enabled.roots.sorted.all.to_a
|
9
15
|
# index_crumbs
|
10
16
|
end
|
11
17
|
|
12
18
|
def show
|
13
|
-
@
|
14
|
-
if !@
|
15
|
-
redirect_to @
|
19
|
+
@category = category_class.enabled.find(params[:id])
|
20
|
+
if !@category.text_slug.blank? and @category.text_slug != params[:id]
|
21
|
+
redirect_to @category, status_code: 301
|
16
22
|
return
|
17
23
|
end
|
18
|
-
@seo_parent_page = find_seo_page(
|
24
|
+
@seo_parent_page = find_seo_page(url_for(action: :index))
|
25
|
+
|
26
|
+
@children = @category.children.enabled.sorted.all.to_a
|
27
|
+
@items = @category.items.enabled.sorted.all.to_a
|
28
|
+
|
29
|
+
if Enjoy::Catalog.config.breadcrumbs_on_rails_support
|
30
|
+
add_breadcrumb @category.name, url_for(@category)
|
31
|
+
end
|
19
32
|
|
20
|
-
@children = @item_category.children.enabled.sorted.all.to_a
|
21
|
-
@items = @item_category.items.enabled.sorted.all.to_a
|
22
33
|
|
23
34
|
# index_crumbs
|
24
35
|
# category_crumbs
|
25
36
|
end
|
26
37
|
|
27
38
|
def page_title
|
28
|
-
if @
|
29
|
-
@
|
39
|
+
if @category
|
40
|
+
@category.page_title
|
30
41
|
else
|
31
42
|
super
|
32
43
|
end
|
33
44
|
end
|
34
45
|
|
35
46
|
private
|
36
|
-
def
|
37
|
-
Enjoy::Catalog::
|
47
|
+
def category_class
|
48
|
+
Enjoy::Catalog::Category
|
38
49
|
end
|
39
50
|
def item_class
|
40
51
|
Enjoy::Catalog::Item
|
@@ -51,24 +62,24 @@ module Enjoy::Catalog
|
|
51
62
|
# else
|
52
63
|
# catalog_title = Settings.ns('breadcrumbs').catalog_title(default: "Каталог", label: "'Каталог' в breadcrumbs")
|
53
64
|
# _crumb = catalog_title
|
54
|
-
# add_crumb _crumb,
|
65
|
+
# add_crumb _crumb, news_categories_path
|
55
66
|
# end
|
56
67
|
# end
|
57
68
|
#
|
58
69
|
# def category_crumbs
|
59
|
-
# if @
|
60
|
-
# _parent = @
|
70
|
+
# if @news_category
|
71
|
+
# _parent = @news_category.parent
|
61
72
|
# if _parent
|
62
73
|
# _crumb = _parent.name if _crumb.blank?
|
63
74
|
# _crumb = _parent.title if _crumb.blank?
|
64
75
|
# _crumb = _parent.h1 if _crumb.blank?
|
65
|
-
# add_crumb _crumb,
|
76
|
+
# add_crumb _crumb, news_category_path(_parent)
|
66
77
|
# _crumb = nil
|
67
78
|
# end
|
68
|
-
# _crumb = @
|
69
|
-
# _crumb = @
|
70
|
-
# _crumb = @
|
71
|
-
# add_crumb _crumb,
|
79
|
+
# _crumb = @news_category.name if _crumb.blank?
|
80
|
+
# _crumb = @news_category.title if _crumb.blank?
|
81
|
+
# _crumb = @news_category.h1 if _crumb.blank?
|
82
|
+
# add_crumb _crumb, news_category_path(@news_category)
|
72
83
|
# end
|
73
84
|
# end
|
74
85
|
end
|
@@ -3,59 +3,48 @@ module Enjoy::Catalog
|
|
3
3
|
module Items
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
+
included do
|
7
|
+
if Enjoy::Catalog.config.breadcrumbs_on_rails_support
|
8
|
+
add_breadcrumb I18n.t('enjoy.breadcrumbs.items'), :enjoy_items_path
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
6
12
|
def index
|
7
|
-
@
|
8
|
-
|
13
|
+
@item = item_class.enabled.sorted
|
14
|
+
|
15
|
+
unless Enjoy::Catalog.config.items_per_page.nil?
|
16
|
+
@item = @item.page(params[:page])
|
17
|
+
end
|
9
18
|
end
|
10
19
|
|
11
20
|
def show
|
12
21
|
@item = item_class.enabled.find(params[:id])
|
13
|
-
|
22
|
+
|
23
|
+
if @item and @item.text_slug != params[:id]
|
14
24
|
redirect_to @item, status_code: 301
|
15
|
-
return
|
25
|
+
return true
|
16
26
|
end
|
17
|
-
@parent_seo_page = find_seo_page(item_categories_path) if @seo_page.blank?
|
18
|
-
# item_crumbs
|
19
|
-
end
|
20
27
|
|
21
|
-
|
22
|
-
|
23
|
-
@item.page_title
|
24
|
-
else
|
25
|
-
super
|
28
|
+
if Enjoy::Catalog.config.breadcrumbs_on_rails_support
|
29
|
+
add_breadcrumb @item.name, url_for(@item)
|
26
30
|
end
|
27
31
|
end
|
28
32
|
|
29
33
|
private
|
30
|
-
def
|
31
|
-
Enjoy::Catalog::
|
34
|
+
def category_class
|
35
|
+
Enjoy::Catalog::Category
|
32
36
|
end
|
33
37
|
def item_class
|
34
38
|
Enjoy::Catalog::Item
|
35
39
|
end
|
40
|
+
def page_title
|
41
|
+
if @item.class.name == model.name
|
42
|
+
@item.page_title
|
43
|
+
else
|
44
|
+
super
|
45
|
+
end
|
46
|
+
end
|
36
47
|
|
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
48
|
end
|
60
49
|
end
|
61
50
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Enjoy::Catalog
|
2
|
+
module Models
|
3
|
+
module Category
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include Enjoy::Model
|
6
|
+
include Enjoy::Enableable
|
7
|
+
if Enjoy::Catalog.config.seo_support
|
8
|
+
include Enjoy::Seo::Seoable
|
9
|
+
include Enjoy::Seo::SitemapDataField
|
10
|
+
end
|
11
|
+
if Enjoy::Catalog.config.pages_support
|
12
|
+
include Enjoy::Pages::Connectable
|
13
|
+
end
|
14
|
+
if Enjoy::Catalog.config.gallery_support
|
15
|
+
include Enjoy::Gallery::Paperclipable
|
16
|
+
end
|
17
|
+
|
18
|
+
include Enjoy::Catalog.orm_specific('Category')
|
19
|
+
|
20
|
+
include ManualSlug
|
21
|
+
|
22
|
+
included do
|
23
|
+
manual_slug :name
|
24
|
+
|
25
|
+
if Enjoy::Catalog.config.pages_support and Enjoy::Catalog.configuration.can_connect_category_with_pages
|
26
|
+
enjoy_connectable_field :connected_pages
|
27
|
+
end
|
28
|
+
|
29
|
+
if Enjoy::Catalog.config.gallery_support and Enjoy::Catalog.configuration.category_image_styles
|
30
|
+
enjoy_cms_attached_file(:image,
|
31
|
+
styles: lambda { |attachment| attachment.instance.image_styles }
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def item_class
|
37
|
+
Enjoy::Catalog::Item
|
38
|
+
end
|
39
|
+
|
40
|
+
def image_styles
|
41
|
+
Enjoy::Catalog.configuration.category_image_styles
|
42
|
+
end
|
43
|
+
|
44
|
+
def image_jcrop_options
|
45
|
+
{}
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Enjoy::Catalog
|
2
|
+
module Models
|
3
|
+
module CategoryImage
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
# include Enjoy::Model
|
6
|
+
# include Enjoy::Enableable
|
7
|
+
|
8
|
+
include Enjoy::Catalog.orm_specific('CategoryImage')
|
9
|
+
|
10
|
+
included do
|
11
|
+
end
|
12
|
+
|
13
|
+
def image_styles
|
14
|
+
Enjoy::Catalog.configuration.category_images_image_styles
|
15
|
+
end
|
16
|
+
|
17
|
+
def image_jcrop_options
|
18
|
+
{}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -4,9 +4,16 @@ module Enjoy::Catalog
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
include Enjoy::Model
|
6
6
|
include Enjoy::Enableable
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
if Enjoy::Catalog.config.seo_support
|
8
|
+
include Enjoy::Seo::Seoable
|
9
|
+
include Enjoy::Seo::SitemapDataField
|
10
|
+
end
|
11
|
+
if Enjoy::Catalog.config.pages_support
|
12
|
+
include Enjoy::Pages::Connectable
|
13
|
+
end
|
14
|
+
if Enjoy::Catalog.config.gallery_support
|
15
|
+
include Enjoy::Gallery::Paperclipable
|
16
|
+
end
|
10
17
|
|
11
18
|
include Enjoy::Catalog.orm_specific('Item')
|
12
19
|
|
@@ -15,7 +22,23 @@ module Enjoy::Catalog
|
|
15
22
|
included do
|
16
23
|
manual_slug :name
|
17
24
|
|
18
|
-
|
25
|
+
if Enjoy::Catalog.config.pages_support and Enjoy::Catalog.configuration.can_connect_items_with_pages
|
26
|
+
enjoy_connectable_field :connected_pages
|
27
|
+
end
|
28
|
+
|
29
|
+
if Enjoy::Catalog.config.gallery_support and Enjoy::Catalog.configuration.item_image_styles
|
30
|
+
enjoy_cms_attached_file(:image,
|
31
|
+
styles: lambda { |attachment| attachment.instance.image_styles }
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def image_styles
|
37
|
+
Enjoy::Catalog.configuration.item_image_styles
|
38
|
+
end
|
39
|
+
|
40
|
+
def image_jcrop_options
|
41
|
+
{}
|
19
42
|
end
|
20
43
|
end
|
21
44
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Enjoy::Catalog
|
2
|
+
module Models
|
3
|
+
module Mongoid
|
4
|
+
module Category
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
include Enjoy::HtmlField
|
7
|
+
|
8
|
+
included do
|
9
|
+
field :name, type: String, localize: Enjoy::Catalog.configuration.localize, default: ""
|
10
|
+
|
11
|
+
acts_as_nested_set
|
12
|
+
scope :sorted, -> { order_by([:lft, :asc]) }
|
13
|
+
|
14
|
+
enjoy_cms_html_field :excerpt, type: String, localize: Enjoy::Catalog.configuration.localize, default: ""
|
15
|
+
enjoy_cms_html_field :content, type: String, localize: Enjoy::Catalog.configuration.localize, default: ""
|
16
|
+
|
17
|
+
embeds_many :category_images, cascade_callbacks: true, class_name: "Enjoy::Catalog::CategoryImage"
|
18
|
+
alias :images :category_images
|
19
|
+
accepts_nested_attributes_for :category_images, allow_destroy: true
|
20
|
+
end
|
21
|
+
|
22
|
+
def items
|
23
|
+
item_class.in(category_ids: self.id)
|
24
|
+
end
|
25
|
+
|
26
|
+
def all_items
|
27
|
+
item_class.any_in(category_ids: self.self_and_descendants.map(&:id))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Enjoy::Catalog
|
2
|
+
module Models
|
3
|
+
module Mongoid
|
4
|
+
module CategoryImage
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
embedded_in :item, class_name: "Enjoy::Catalog::Category"
|
9
|
+
end
|
10
|
+
|
11
|
+
include ::Mongoid::EmbeddedFindable
|
12
|
+
module ClassMethods
|
13
|
+
def find(id)
|
14
|
+
find_through(Enjoy::Catalog::Category, 'category_images', id)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -3,30 +3,19 @@ module Enjoy::Catalog
|
|
3
3
|
module Mongoid
|
4
4
|
module Item
|
5
5
|
extend ActiveSupport::Concern
|
6
|
-
include Enjoy::MongoidPaperclip
|
7
6
|
|
8
7
|
include Enjoy::HtmlField
|
9
8
|
|
10
9
|
included do
|
11
|
-
|
12
|
-
include RailsAdminComments::Commentable
|
13
|
-
end
|
14
|
-
|
15
|
-
field :name, type: String, localize: Enjoy.configuration.localize, default: ""
|
16
|
-
|
17
|
-
enjoy_cms_mongoid_attached_file(:image,
|
18
|
-
styles: lambda { |attachment| attachment.instance.image_styles },
|
19
|
-
content_type: { content_type: ["image/jpg", "image/jpeg", "image/png"] }
|
20
|
-
)
|
10
|
+
field :name, type: String, localize: Enjoy::Catalog.configuration.localize, default: ""
|
21
11
|
|
22
12
|
acts_as_nested_set
|
23
13
|
scope :sorted, -> { order_by([:lft, :asc]) }
|
24
14
|
|
25
|
-
enjoy_cms_html_field :excerpt, type: String, localize: Enjoy.configuration.localize, default: ""
|
26
|
-
enjoy_cms_html_field :content, type: String, localize: Enjoy.configuration.localize, default: ""
|
15
|
+
enjoy_cms_html_field :excerpt, type: String, localize: Enjoy::Catalog.configuration.localize, default: ""
|
16
|
+
enjoy_cms_html_field :content, type: String, localize: Enjoy::Catalog.configuration.localize, default: ""
|
27
17
|
|
28
|
-
has_and_belongs_to_many :
|
29
|
-
alias :categories :item_categories
|
18
|
+
has_and_belongs_to_many :categories, class_name: "Enjoy::Catalog::Category", inverse_of: nil
|
30
19
|
|
31
20
|
embeds_many :item_images, cascade_callbacks: true, class_name: "Enjoy::Catalog::ItemImage"
|
32
21
|
alias :images :item_images
|
@@ -34,15 +23,7 @@ module Enjoy::Catalog
|
|
34
23
|
|
35
24
|
has_and_belongs_to_many :related_items, :class_name => "Enjoy::Catalog::Item", :inverse_of => :related_items
|
36
25
|
|
37
|
-
field :price, type: Money, default: nil, localize: Enjoy.configuration.localize
|
38
|
-
end
|
39
|
-
|
40
|
-
def image_styles
|
41
|
-
Enjoy::Catalog.configuration.item_image_styles
|
42
|
-
end
|
43
|
-
|
44
|
-
def image_jcrop_options
|
45
|
-
{}
|
26
|
+
field :price, type: Money, default: nil, localize: Enjoy::Catalog.configuration.localize
|
46
27
|
end
|
47
28
|
end
|
48
29
|
end
|
@@ -3,27 +3,17 @@ module Enjoy::Catalog
|
|
3
3
|
module Mongoid
|
4
4
|
module ItemImage
|
5
5
|
extend ActiveSupport::Concern
|
6
|
-
# include Enjoy::MongoidPaperclip
|
7
6
|
|
8
7
|
included do
|
9
8
|
embedded_in :item, class_name: "Enjoy::Catalog::Item"
|
10
9
|
end
|
11
10
|
|
12
|
-
|
13
11
|
include ::Mongoid::EmbeddedFindable
|
14
12
|
module ClassMethods
|
15
13
|
def find(id)
|
16
14
|
find_through(Enjoy::Catalog::Item, 'item_images', id)
|
17
15
|
end
|
18
16
|
end
|
19
|
-
|
20
|
-
def image_styles
|
21
|
-
Enjoy::Catalog.configuration.item_images_image_styles
|
22
|
-
end
|
23
|
-
|
24
|
-
def image_jcrop_options
|
25
|
-
{}
|
26
|
-
end
|
27
17
|
end
|
28
18
|
end
|
29
19
|
end
|
data/lib/enjoy/catalog/routes.rb
CHANGED
@@ -1,33 +1,77 @@
|
|
1
1
|
module ActionDispatch::Routing
|
2
2
|
class Mapper
|
3
|
-
|
4
3
|
def enjoy_cms_catalog_routes(config = {})
|
5
4
|
routes_config = {
|
6
5
|
use_items_path: true,
|
7
|
-
|
8
|
-
use_catalog_path: true
|
6
|
+
use_categories_path: true,
|
7
|
+
use_catalog_path: true,
|
8
|
+
catalog_path: 'catalog',
|
9
|
+
classes: {
|
10
|
+
items: :items,
|
11
|
+
categories: :categories,
|
12
|
+
catalog_controller: :categories
|
13
|
+
},
|
14
|
+
paths: {
|
15
|
+
items: :items,
|
16
|
+
categories: :categories
|
17
|
+
},
|
18
|
+
pagination: {
|
19
|
+
items: true,
|
20
|
+
categories: true,
|
21
|
+
category_items: true
|
22
|
+
},
|
23
|
+
actions: {
|
24
|
+
items: [:show],
|
25
|
+
categories: [:show],
|
26
|
+
}
|
9
27
|
}
|
10
|
-
routes_config.
|
28
|
+
routes_config.deep_merge!(config)
|
29
|
+
|
30
|
+
generate_enjoy_catalog_user_routes(routes_config)
|
31
|
+
generate_enjoy_catalog_cms_routes(routes_config)
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
private
|
36
|
+
def generate_enjoy_catalog_user_routes(routes_config)
|
37
|
+
if !routes_config[:use_items_path] and !routes_config[:classes][:items].nil?
|
38
|
+
resources routes_config[:classes][:items].to_sym, only: routes_config[:actions][:items], path: routes_config[:paths][:items] do
|
39
|
+
get '(/page/:page)', action: :index, on: :collection, as: "" if routes_config[:pagination][:items]
|
40
|
+
end
|
41
|
+
end
|
11
42
|
|
43
|
+
if !routes_config[:use_categories_path] and !routes_config[:classes][:categories].nil?
|
44
|
+
resources routes_config[:classes][:categories].to_sym, only: routes_config[:actions][:categories], path: routes_config[:paths][:categories] do
|
45
|
+
get '(/page/:page)', action: :index, on: :collection, as: "" if routes_config[:pagination][:categories]
|
46
|
+
get 'items(/page/:page)', action: :items, on: :member, as: :items if routes_config[:pagination][:category_items]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
if !routes_config[:use_catalog_path] and !routes_config[:classes][:catalog_controller].nil?
|
51
|
+
get "#{routes_config[:catalog_path]}" => "#{routes_config[:classes][:catalog_controller]}#index"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def generate_enjoy_catalog_cms_routes(routes_config)
|
12
56
|
scope module: 'enjoy' do
|
13
57
|
scope module: 'catalog' do
|
14
|
-
if routes_config[:use_items_path]
|
15
|
-
resources :items, only: [:
|
16
|
-
get '(/page/:page)', action: :index, on: :collection, as: ""
|
58
|
+
if routes_config[:use_items_path] and !routes_config[:classes][:items].nil?
|
59
|
+
resources routes_config[:classes][:items].to_sym, only: routes_config[:actions][:items], path: routes_config[:paths][:items], as: :enjoy_catalog_items do
|
60
|
+
get '(/page/:page)', action: :index, on: :collection, as: "" if routes_config[:pagination][:items]
|
17
61
|
end
|
18
62
|
end
|
19
63
|
|
20
|
-
if routes_config[:
|
21
|
-
resources :
|
22
|
-
get '
|
64
|
+
if routes_config[:use_categories_path] and !routes_config[:classes][:categories].nil?
|
65
|
+
resources routes_config[:classes][:categories].to_sym, only: routes_config[:actions][:categories], path: routes_config[:paths][:categories], as: :enjoy_catalog_categories do
|
66
|
+
get '(/page/:page)', action: :index, on: :collection, as: "" if routes_config[:pagination][:categories]
|
67
|
+
get 'items(/page/:page)', action: :items, on: :member, as: :items if routes_config[:pagination][:category_items]
|
23
68
|
end
|
24
69
|
end
|
25
|
-
if routes_config[:use_catalog_path]
|
26
|
-
get
|
70
|
+
if routes_config[:use_catalog_path] and !routes_config[:classes][:catalog_controller].nil?
|
71
|
+
get "#{routes_config[:catalog_path]}" => "#{routes_config[:classes][:catalog_controller]}#index", as: :enjoy_catalog
|
27
72
|
end
|
28
73
|
end
|
29
74
|
end
|
30
|
-
|
31
75
|
end
|
32
76
|
|
33
77
|
end
|
data/lib/enjoy_cms_catalog.rb
CHANGED
@@ -1,62 +1,69 @@
|
|
1
|
+
unless defined?(Enjoy) && Enjoy.respond_to?(:orm) && [:active_record, :mongoid].include?(Enjoy.orm)
|
2
|
+
puts "please use enjoy_cms_mongoid or enjoy_cms_activerecord"
|
3
|
+
puts "also: please use enjoy_cms_mongoid or enjoy_cms_activerecord and not enjoy_cms directly"
|
4
|
+
exit 1
|
5
|
+
end
|
6
|
+
|
1
7
|
require "enjoy/catalog/version"
|
8
|
+
require 'enjoy/catalog/engine'
|
9
|
+
require 'enjoy/catalog/configuration'
|
2
10
|
|
3
11
|
require 'enjoy/catalog/routes'
|
4
12
|
|
5
13
|
require 'money-rails'
|
14
|
+
# require 'mongoid_money_field'
|
6
15
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
16
|
+
module Enjoy::Catalog
|
17
|
+
class << self
|
18
|
+
def orm
|
19
|
+
Enjoy.orm
|
20
|
+
end
|
21
|
+
def mongoid?
|
22
|
+
Enjoy::Catalog.orm == :mongoid
|
23
|
+
end
|
24
|
+
def active_record?
|
25
|
+
Enjoy::Catalog.orm == :active_record
|
26
|
+
end
|
27
|
+
def model_namespace
|
28
|
+
"Enjoy::Catalog::Models::#{Enjoy::Catalog.orm.to_s.camelize}"
|
29
|
+
end
|
30
|
+
def orm_specific(name)
|
31
|
+
"#{model_namespace}::#{name}".constantize
|
32
|
+
end
|
33
|
+
end
|
11
34
|
|
12
|
-
|
13
|
-
|
35
|
+
autoload :Admin, 'enjoy/catalog/admin'
|
36
|
+
module Admin
|
37
|
+
autoload :Item, 'enjoy/catalog/admin/item'
|
38
|
+
autoload :Category, 'enjoy/catalog/admin/category'
|
39
|
+
autoload :ItemImage, 'enjoy/catalog/admin/item_image'
|
40
|
+
autoload :CategoryImage, 'enjoy/catalog/admin/category_image'
|
41
|
+
end
|
14
42
|
|
15
|
-
module
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
def mongoid?
|
22
|
-
Enjoy::Catalog.orm == :mongoid
|
23
|
-
end
|
24
|
-
def active_record?
|
25
|
-
Enjoy::Catalog.orm == :active_record
|
26
|
-
end
|
27
|
-
def model_namespace
|
28
|
-
"Enjoy::Catalog::Models::#{Enjoy::Catalog.orm.to_s.camelize}"
|
29
|
-
end
|
30
|
-
def orm_specific(name)
|
31
|
-
"#{model_namespace}::#{name}".constantize
|
32
|
-
end
|
33
|
-
end
|
43
|
+
module Models
|
44
|
+
autoload :Item, 'enjoy/catalog/models/item'
|
45
|
+
autoload :Category, 'enjoy/catalog/models/category'
|
46
|
+
autoload :ItemImage, 'enjoy/catalog/models/item_image'
|
47
|
+
autoload :CategoryImage, 'enjoy/catalog/models/category_image'
|
34
48
|
|
35
|
-
|
36
|
-
|
37
|
-
autoload :
|
38
|
-
autoload :
|
39
|
-
autoload :
|
40
|
-
autoload :ItemCategoryImage, 'enjoy/catalog/admin/item_category_image'
|
49
|
+
module Mongoid
|
50
|
+
autoload :Item, 'enjoy/catalog/models/mongoid/item'
|
51
|
+
autoload :Category, 'enjoy/catalog/models/mongoid/category'
|
52
|
+
autoload :ItemImage, 'enjoy/catalog/models/mongoid/item_image'
|
53
|
+
autoload :CategoryImage, 'enjoy/catalog/models/mongoid/category_image'
|
41
54
|
end
|
42
55
|
|
43
|
-
module
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
autoload :Item, 'enjoy/catalog/models/mongoid/item'
|
51
|
-
autoload :ItemCategory, 'enjoy/catalog/models/mongoid/item_category'
|
52
|
-
autoload :ItemImage, 'enjoy/catalog/models/mongoid/item_image'
|
53
|
-
autoload :ItemCategoryImage, 'enjoy/catalog/models/mongoid/item_category_image'
|
54
|
-
end
|
55
|
-
end
|
56
|
+
# module ActiveRecord
|
57
|
+
# autoload :Item, 'enjoy/catalog/models/active_record/item'
|
58
|
+
# autoload :Category, 'enjoy/catalog/models/active_record/category'
|
59
|
+
# autoload :ItemImage, 'enjoy/catalog/models/active_record/item_image'
|
60
|
+
# autoload :CategoryImage, 'enjoy/catalog/models/active_record/category_image'
|
61
|
+
# end
|
62
|
+
end
|
56
63
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
64
|
+
module Controllers
|
65
|
+
autoload :Items, 'enjoy/catalog/controllers/items'
|
66
|
+
autoload :Categories, 'enjoy/catalog/controllers/categories'
|
61
67
|
end
|
68
|
+
|
62
69
|
end
|