enjoy_cms_news 0.4.0.beta3
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/enjoy_cms_news.coffee +0 -0
- data/app/assets/stylesheets/enjoy_cms_news.sass +0 -0
- data/app/controllers/concerns/enjoy/news/decorators/categories.rb +5 -0
- data/app/controllers/concerns/enjoy/news/decorators/news_controller.rb +5 -0
- data/app/controllers/enjoy/news/categories_controller.rb +7 -0
- data/app/controllers/enjoy/news/news_controller.rb +7 -0
- data/app/models/concerns/enjoy/news/decorators/category.rb +5 -0
- data/app/models/concerns/enjoy/news/decorators/image.rb +5 -0
- data/app/models/concerns/enjoy/news/decorators/news.rb +5 -0
- data/app/models/enjoy/news/category.rb +11 -0
- data/app/models/enjoy/news/image.rb +16 -0
- data/app/models/enjoy/news/news.rb +16 -0
- data/app/views/enjoy/news/news/_list.html.slim +6 -0
- data/app/views/enjoy/news/news/index.html.slim +4 -0
- data/app/views/enjoy/news/news/show.html.slim +8 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/config/initializers/enjoy_news.rb +72 -0
- data/config/locales/enjoy.news.ru.yml +13 -0
- data/enjoy_cms_news.gemspec +38 -0
- data/lib/enjoy/news/admin/category.rb +143 -0
- data/lib/enjoy/news/admin/image.rb +31 -0
- data/lib/enjoy/news/admin/news.rb +101 -0
- data/lib/enjoy/news/admin.rb +6 -0
- data/lib/enjoy/news/configuration.rb +61 -0
- data/lib/enjoy/news/controllers/categories.rb +72 -0
- data/lib/enjoy/news/controllers/news.rb +39 -0
- data/lib/enjoy/news/engine.rb +7 -0
- data/lib/enjoy/news/models/active_record/category.rb +25 -0
- data/lib/enjoy/news/models/active_record/image.rb +16 -0
- data/lib/enjoy/news/models/active_record/news.rb +29 -0
- data/lib/enjoy/news/models/category.rb +62 -0
- data/lib/enjoy/news/models/image.rb +20 -0
- data/lib/enjoy/news/models/mongoid/category.rb +28 -0
- data/lib/enjoy/news/models/mongoid/image.rb +22 -0
- data/lib/enjoy/news/models/mongoid/news.rb +39 -0
- data/lib/enjoy/news/models/news.rb +57 -0
- data/lib/enjoy/news/routes.rb +56 -0
- data/lib/enjoy/news/version.rb +5 -0
- data/lib/enjoy_cms_news.rb +69 -0
- data/lib/generators/enjoy/news/all_generator.rb +17 -0
- data/lib/generators/enjoy/news/config/install_generator.rb +13 -0
- data/lib/generators/enjoy/news/config/templates/enjoy_news.erb +28 -0
- data/lib/generators/enjoy/news/controllers/all_generator.rb +28 -0
- data/lib/generators/enjoy/news/controllers/category_generator.rb +43 -0
- data/lib/generators/enjoy/news/controllers/news_generator.rb +43 -0
- data/lib/generators/enjoy/news/controllers/templates/categories_controller.erb +10 -0
- data/lib/generators/enjoy/news/controllers/templates/news_controller.erb +10 -0
- data/lib/generators/enjoy/news/migrations/migration_generator.rb +18 -0
- data/lib/generators/enjoy/news/migrations/templates/news.rb +92 -0
- data/lib/generators/enjoy/news/models/all_generator.rb +33 -0
- data/lib/generators/enjoy/news/models/category_generator.rb +39 -0
- data/lib/generators/enjoy/news/models/image_generator.rb +39 -0
- data/lib/generators/enjoy/news/models/news_generator.rb +34 -0
- data/lib/generators/enjoy/news/models/templates/category.erb +30 -0
- data/lib/generators/enjoy/news/models/templates/image.erb +30 -0
- data/lib/generators/enjoy/news/models/templates/item.erb +38 -0
- data/release.sh +7 -0
- metadata +194 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
module Enjoy
|
2
|
+
module News
|
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 :news_image_styles
|
16
|
+
attr_accessor :category_image_styles
|
17
|
+
attr_accessor :images_image_styles
|
18
|
+
|
19
|
+
attr_accessor :news_per_page
|
20
|
+
attr_accessor :news_excerpt
|
21
|
+
attr_accessor :news_content_required
|
22
|
+
|
23
|
+
attr_accessor :gallery_support
|
24
|
+
attr_accessor :seo_support
|
25
|
+
attr_accessor :pages_support
|
26
|
+
|
27
|
+
attr_accessor :can_connect_news_with_pages
|
28
|
+
attr_accessor :can_connect_category_with_pages
|
29
|
+
|
30
|
+
attr_accessor :localize
|
31
|
+
|
32
|
+
def initialize
|
33
|
+
@news_image_styles = {
|
34
|
+
main: '400x200>',
|
35
|
+
thumb: '200x100>'
|
36
|
+
}
|
37
|
+
@category_image_styles = {
|
38
|
+
main: '400x200>',
|
39
|
+
thumb: '200x100>'
|
40
|
+
}
|
41
|
+
@images_image_styles = {
|
42
|
+
main: '400x200>',
|
43
|
+
thumb: '200x100>'
|
44
|
+
}
|
45
|
+
|
46
|
+
@news_per_page = 10
|
47
|
+
@news_excerpt = 12
|
48
|
+
@news_content_required = true
|
49
|
+
|
50
|
+
@gallery_support = defined? Enjoy::Gallery
|
51
|
+
@seo_support = defined? Enjoy::Seo
|
52
|
+
@pages_support = defined? Enjoy::Pages
|
53
|
+
|
54
|
+
@can_connect_news_with_pages = true
|
55
|
+
@can_connect_category_with_pages = true
|
56
|
+
|
57
|
+
@localize = Enjoy.config.localize
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Enjoy::News
|
2
|
+
module Controllers
|
3
|
+
module Categories
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def index
|
7
|
+
@categories = category_class.enabled.sorted.to_a
|
8
|
+
@root_catalog = category_class.enabled.roots.sorted.all.to_a
|
9
|
+
end
|
10
|
+
|
11
|
+
def show
|
12
|
+
@category = category_class.enabled.find(params[:id])
|
13
|
+
if !@category.text_slug.blank? and @category.text_slug != params[:id]
|
14
|
+
redirect_to @category, status_code: 301
|
15
|
+
return
|
16
|
+
end
|
17
|
+
@seo_parent_page = find_seo_page(url_for(action: :index))
|
18
|
+
|
19
|
+
@children = @category.children.enabled.sorted.all.to_a
|
20
|
+
@news = @category.news.enabled.sorted.all.to_a
|
21
|
+
end
|
22
|
+
|
23
|
+
def page_title
|
24
|
+
if @category
|
25
|
+
@category.page_title
|
26
|
+
else
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def category_class
|
33
|
+
Enjoy::News::Category
|
34
|
+
end
|
35
|
+
def news_class
|
36
|
+
Enjoy::News::News
|
37
|
+
end
|
38
|
+
|
39
|
+
# def index_crumbs
|
40
|
+
# if @seo_parent_page
|
41
|
+
# catalog_title = Settings.ns('breadcrumbs').catalog_title(default: "Каталог", label: "'Каталог' в breadcrumbs")
|
42
|
+
# _crumb = catalog_title
|
43
|
+
# _crumb = @seo_parent_page.name if _crumb.blank?
|
44
|
+
# _crumb = @seo_parent_page.title if _crumb.blank?
|
45
|
+
# _crumb = @seo_parent_page.h1 if _crumb.blank?
|
46
|
+
# add_crumb _crumb, @seo_parent_page.fullpath
|
47
|
+
# else
|
48
|
+
# catalog_title = Settings.ns('breadcrumbs').catalog_title(default: "Каталог", label: "'Каталог' в breadcrumbs")
|
49
|
+
# _crumb = catalog_title
|
50
|
+
# add_crumb _crumb, item_categories_path
|
51
|
+
# end
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# def category_crumbs
|
55
|
+
# if @item_category
|
56
|
+
# _parent = @item_category.parent
|
57
|
+
# if _parent
|
58
|
+
# _crumb = _parent.name if _crumb.blank?
|
59
|
+
# _crumb = _parent.title if _crumb.blank?
|
60
|
+
# _crumb = _parent.h1 if _crumb.blank?
|
61
|
+
# add_crumb _crumb, item_category_path(_parent)
|
62
|
+
# _crumb = nil
|
63
|
+
# end
|
64
|
+
# _crumb = @item_category.name if _crumb.blank?
|
65
|
+
# _crumb = @item_category.title if _crumb.blank?
|
66
|
+
# _crumb = @item_category.h1 if _crumb.blank?
|
67
|
+
# add_crumb _crumb, item_category_path(@item_category)
|
68
|
+
# end
|
69
|
+
# end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Enjoy::News
|
2
|
+
module Controllers
|
3
|
+
module News
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def index
|
7
|
+
@news = news_class.enabled.after_now.by_date
|
8
|
+
|
9
|
+
unless Enjoy::News.config.news_per_page.nil?
|
10
|
+
@news = @news.page(params[:page]).per(Enjoy::News.config.news_per_page)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def show
|
15
|
+
@news = news_class.after_now.find(params[:id])
|
16
|
+
|
17
|
+
if @news and @news.text_slug != params[:id]
|
18
|
+
redirect_to @news, status_code: 301
|
19
|
+
return true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def category_class
|
25
|
+
Enjoy::News::Category
|
26
|
+
end
|
27
|
+
def news_class
|
28
|
+
Enjoy::News::News
|
29
|
+
end
|
30
|
+
def page_title
|
31
|
+
if @news.class.name == model.name
|
32
|
+
@news.page_title
|
33
|
+
else
|
34
|
+
super
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Enjoy::News
|
2
|
+
module Models
|
3
|
+
module Mongoid
|
4
|
+
module Category
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
has_paper_trail
|
9
|
+
|
10
|
+
validates_lengths_from_database only: [:name, :content_html, :excerpt_html]
|
11
|
+
|
12
|
+
scope :sorted, -> { order(lft: :asc) }
|
13
|
+
|
14
|
+
if Enjoy::News.config.localize
|
15
|
+
translates :name, :content_html, :excerpt_html
|
16
|
+
end
|
17
|
+
|
18
|
+
has_and_belongs_to_many :news,
|
19
|
+
class_name: "Enjoy::News::News",
|
20
|
+
join_table: :enjoy_news_news_categories
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Enjoy::News
|
2
|
+
module Models
|
3
|
+
module Mongoid
|
4
|
+
module Image
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
if Enjoy::News.config.gallery_support
|
7
|
+
included do
|
8
|
+
belongs_to :enjoy_gallery_imagable, class_name: 'Enjoy::News::News'
|
9
|
+
|
10
|
+
validates_lengths_from_database only: [:name]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Enjoy::News
|
2
|
+
module Models
|
3
|
+
module ActiveRecord
|
4
|
+
module News
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
included do
|
7
|
+
if Enjoy::News.config.gallery_support
|
8
|
+
has_many :images, as: :enjoy_gallery_imagable, class_name: 'Enjoy::News::Image'
|
9
|
+
end
|
10
|
+
|
11
|
+
has_paper_trail
|
12
|
+
|
13
|
+
validates_lengths_from_database only: [:name, :content_html, :excerpt_html]
|
14
|
+
|
15
|
+
scope :after_now, -> { where("time < ?", Time.now) }
|
16
|
+
scope :by_date, -> { order(time: :desc) }
|
17
|
+
|
18
|
+
if Enjoy::News.config.localize
|
19
|
+
translates :name, :content_html, :excerpt_html
|
20
|
+
end
|
21
|
+
|
22
|
+
has_and_belongs_to_many :categories,
|
23
|
+
class_name: "Enjoy::News::Category",
|
24
|
+
join_table: :enjoy_news_news_categories
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Enjoy::News
|
2
|
+
module Models
|
3
|
+
module Category
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include Enjoy::Model
|
6
|
+
include Enjoy::Enableable
|
7
|
+
include Enjoy::HtmlField
|
8
|
+
include ManualSlug
|
9
|
+
|
10
|
+
if Enjoy::News.config.seo_support
|
11
|
+
include Enjoy::Seo::Seoable
|
12
|
+
include Enjoy::Seo::SitemapDataField
|
13
|
+
end
|
14
|
+
if Enjoy::News.config.pages_support
|
15
|
+
include Enjoy::Pages::Connectable
|
16
|
+
end
|
17
|
+
if Enjoy::News.config.gallery_support
|
18
|
+
include Enjoy::Gallery::Paperclipable
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
include Enjoy::News.orm_specific('Category')
|
23
|
+
|
24
|
+
include ManualSlug
|
25
|
+
|
26
|
+
included do
|
27
|
+
if defined?(RailsAdminComments)
|
28
|
+
include RailsAdminComments::Commentable
|
29
|
+
end
|
30
|
+
manual_slug :name
|
31
|
+
|
32
|
+
if Enjoy::News.config.gallery_support and Enjoy::News.configuration.category_image_styles
|
33
|
+
enjoy_cms_attached_file(:image,
|
34
|
+
styles: lambda { |attachment| attachment.instance.image_styles }
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
acts_as_nested_set
|
39
|
+
|
40
|
+
if Enjoy::News.config.pages_support and Enjoy::News.configuration.can_connect_category_with_pages
|
41
|
+
enjoy_connectable_field :connected_pages
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def news_class
|
46
|
+
Enjoy::News::News
|
47
|
+
end
|
48
|
+
|
49
|
+
def image_styles
|
50
|
+
Enjoy::News.configuration.category_image_styles
|
51
|
+
end
|
52
|
+
|
53
|
+
def image_jcrop_options
|
54
|
+
{}
|
55
|
+
end
|
56
|
+
|
57
|
+
def page_title
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Enjoy::News
|
2
|
+
module Models
|
3
|
+
module Image
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
include Enjoy::News.orm_specific('Image')
|
7
|
+
|
8
|
+
included do
|
9
|
+
end
|
10
|
+
|
11
|
+
def image_styles
|
12
|
+
Enjoy::News.configuration.images_image_styles
|
13
|
+
end
|
14
|
+
|
15
|
+
def image_jcrop_options
|
16
|
+
{}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Enjoy::News
|
2
|
+
module Models
|
3
|
+
module Mongoid
|
4
|
+
module Category
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
include Enjoy::HtmlField
|
8
|
+
|
9
|
+
included do
|
10
|
+
field :name, type: String, localize: Enjoy::News.configuration.localize, default: ""
|
11
|
+
|
12
|
+
scope :sorted, -> { order_by([:lft, :asc]) }
|
13
|
+
|
14
|
+
enjoy_cms_html_field :excerpt, type: String, localize: Enjoy::News.configuration.localize, default: ""
|
15
|
+
enjoy_cms_html_field :content, type: String, localize: Enjoy::News.configuration.localize, default: ""
|
16
|
+
end
|
17
|
+
|
18
|
+
def news
|
19
|
+
news_class.in(category_ids: self.id)
|
20
|
+
end
|
21
|
+
|
22
|
+
def all_news
|
23
|
+
news_class.any_in(category_ids: self.self_and_descendants.map(&:id))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Enjoy::News
|
2
|
+
module Models
|
3
|
+
module Mongoid
|
4
|
+
module Image
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
if Enjoy::News.config.gallery_support
|
7
|
+
|
8
|
+
included do
|
9
|
+
embedded_in :news, class_name: "Enjoy::News::News"
|
10
|
+
end
|
11
|
+
|
12
|
+
include ::Mongoid::EmbeddedFindable
|
13
|
+
module ClassMethods
|
14
|
+
def find(id)
|
15
|
+
find_through(Enjoy::News::News, 'images', id)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Enjoy::News
|
2
|
+
module Models
|
3
|
+
module Mongoid
|
4
|
+
module News
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
include Enjoy::HtmlField
|
8
|
+
|
9
|
+
included do
|
10
|
+
field :name, type: String, localize: Enjoy::News.config.localize, default: ""
|
11
|
+
|
12
|
+
field :time, type: Time
|
13
|
+
index({enabled: 1, time: 1})
|
14
|
+
|
15
|
+
enjoy_cms_html_field :excerpt, type: String, localize: Enjoy::News.configuration.localize, default: ""
|
16
|
+
enjoy_cms_html_field :content, type: String, localize: Enjoy::News.configuration.localize, default: ""
|
17
|
+
|
18
|
+
has_and_belongs_to_many :categories, class_name: "Enjoy::News::Category", inverse_of: nil
|
19
|
+
|
20
|
+
scope :after_now, -> { where(:time.lt => Time.now) }
|
21
|
+
scope :by_date, -> { desc(:time) }
|
22
|
+
|
23
|
+
if Enjoy::News.config.gallery_support
|
24
|
+
embeds_many :images, cascade_callbacks: true, class_name: "Enjoy::News::Image"
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
def image_styles
|
30
|
+
Enjoy::News.configuration.news_image_styles
|
31
|
+
end
|
32
|
+
|
33
|
+
def image_jcrop_options
|
34
|
+
{}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Enjoy::News
|
2
|
+
module Models
|
3
|
+
module News
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include Enjoy::Model
|
6
|
+
include Enjoy::Enableable
|
7
|
+
include Enjoy::HtmlField
|
8
|
+
include ManualSlug
|
9
|
+
|
10
|
+
if Enjoy::News.config.seo_support
|
11
|
+
include Enjoy::Seo::Seoable
|
12
|
+
include Enjoy::Seo::SitemapDataField
|
13
|
+
end
|
14
|
+
if Enjoy::News.config.pages_support
|
15
|
+
include Enjoy::Pages::Connectable
|
16
|
+
end
|
17
|
+
if Enjoy::News.config.gallery_support
|
18
|
+
include Enjoy::Gallery::Paperclipable
|
19
|
+
end
|
20
|
+
|
21
|
+
include SmartExcerpt
|
22
|
+
|
23
|
+
include Enjoy::News.orm_specific('News')
|
24
|
+
|
25
|
+
|
26
|
+
included do
|
27
|
+
|
28
|
+
manual_slug :name
|
29
|
+
|
30
|
+
if Enjoy::News.config.pages_support and Enjoy::News.configuration.can_connect_news_with_pages
|
31
|
+
enjoy_connectable_field :connected_pages
|
32
|
+
end
|
33
|
+
|
34
|
+
if Enjoy::News.config.gallery_support and Enjoy::News.configuration.news_image_styles
|
35
|
+
enjoy_cms_attached_file(:image,
|
36
|
+
styles: lambda { |attachment| attachment.instance.image_styles }
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
alias :news_categories :categories
|
41
|
+
|
42
|
+
if Enjoy::News.config.gallery_support
|
43
|
+
alias :news_images :images
|
44
|
+
accepts_nested_attributes_for :images, allow_destroy: true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def image_styles
|
49
|
+
Enjoy::News.config.news_image_styles
|
50
|
+
end
|
51
|
+
|
52
|
+
def image_jcrop_options
|
53
|
+
{}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module ActionDispatch::Routing
|
2
|
+
class Mapper
|
3
|
+
|
4
|
+
def enjoy_cms_news_routes(config = {})
|
5
|
+
routes_config = {
|
6
|
+
use_news_path: true,
|
7
|
+
use_categories_path: true,
|
8
|
+
classes: {
|
9
|
+
news: :news,
|
10
|
+
categories: :categories
|
11
|
+
},
|
12
|
+
paths: {
|
13
|
+
news: :news,
|
14
|
+
categories: :news_categories
|
15
|
+
}
|
16
|
+
}
|
17
|
+
routes_config.deep_merge!(config)
|
18
|
+
|
19
|
+
generate_enjoy_news_user_routes(routes_config)
|
20
|
+
generate_enjoy_news_cms_routes(routes_config)
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def generate_enjoy_news_user_routes(routes_config)
|
26
|
+
if !routes_config[:use_news_path] and !routes_config[:classes][:news].nil?
|
27
|
+
resources routes_config[:classes][:news].to_sym, only: [:show], path: routes_config[:paths][:news] do
|
28
|
+
get '(/page/:page)', action: :index, on: :collection, as: ""
|
29
|
+
end
|
30
|
+
end
|
31
|
+
if !routes_config[:use_categories_path] and !routes_config[:classes][:categories].nil?
|
32
|
+
resources routes_config[:classes][:categories].to_sym, only: [:show], path: routes_config[:paths][:categories] do
|
33
|
+
get '(/page/:page)', action: :index, on: :collection, as: ""
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def generate_enjoy_news_cms_routes(routes_config)
|
39
|
+
scope module: 'enjoy' do
|
40
|
+
scope module: 'news' do
|
41
|
+
if routes_config[:use_news_path] and !routes_config[:classes][:news].nil?
|
42
|
+
resources routes_config[:classes][:news].to_sym, only: [:show], path: routes_config[:paths][:news], as: :enjoy_news_news do
|
43
|
+
get '(/page/:page)', action: :index, on: :collection, as: ""
|
44
|
+
end
|
45
|
+
end
|
46
|
+
if routes_config[:use_categories_path] and !routes_config[:classes][:categories].nil?
|
47
|
+
resources routes_config[:classes][:categories].to_sym, only: [:show], path: routes_config[:paths][:categories], as: :enjoy_news_categories do
|
48
|
+
get '(/page/:page)', action: :index, on: :collection, as: ""
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +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_news_mongoid or enjoy_cms_news_activerecord and not enjoy_cms_news directly"
|
4
|
+
exit 1
|
5
|
+
end
|
6
|
+
|
7
|
+
require "enjoy/news/version"
|
8
|
+
require 'enjoy/news/engine'
|
9
|
+
require 'enjoy/news/configuration'
|
10
|
+
|
11
|
+
require 'enjoy/news/routes'
|
12
|
+
require 'enjoy/news/admin'
|
13
|
+
|
14
|
+
require 'smart_excerpt'
|
15
|
+
|
16
|
+
# require 'enjoy_cms_pages' if Enjoy::News.config.pages_support
|
17
|
+
# require 'enjoy_cms_seo' if Enjoy::News.config.seo_support
|
18
|
+
# require 'enjoy_cms_gallery' if Enjoy::News.config.gallery_support
|
19
|
+
|
20
|
+
module Enjoy::News
|
21
|
+
class << self
|
22
|
+
def orm
|
23
|
+
Enjoy.orm
|
24
|
+
end
|
25
|
+
def mongoid?
|
26
|
+
Enjoy::News.orm == :mongoid
|
27
|
+
end
|
28
|
+
def active_record?
|
29
|
+
Enjoy::News.orm == :active_record
|
30
|
+
end
|
31
|
+
def model_namespace
|
32
|
+
"Enjoy::News::Models::#{Enjoy::News.orm.to_s.camelize}"
|
33
|
+
end
|
34
|
+
def orm_specific(name)
|
35
|
+
"#{model_namespace}::#{name}".constantize
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
autoload :Admin, 'enjoy/news/admin'
|
40
|
+
module Admin
|
41
|
+
autoload :News, 'enjoy/news/admin/news'
|
42
|
+
autoload :Category, 'enjoy/news/admin/category'
|
43
|
+
autoload :Image, 'enjoy/news/admin/image'
|
44
|
+
end
|
45
|
+
|
46
|
+
module Models
|
47
|
+
autoload :News, 'enjoy/news/models/news'
|
48
|
+
autoload :Category, 'enjoy/news/models/category'
|
49
|
+
autoload :Image, 'enjoy/news/models/image'
|
50
|
+
|
51
|
+
module Mongoid
|
52
|
+
autoload :News, 'enjoy/news/models/mongoid/news'
|
53
|
+
autoload :Category, 'enjoy/news/models/mongoid/category'
|
54
|
+
autoload :Image, 'enjoy/news/models/mongoid/image'
|
55
|
+
end
|
56
|
+
|
57
|
+
module ActiveRecord
|
58
|
+
autoload :News, 'enjoy/news/models/active_record/news'
|
59
|
+
autoload :Category, 'enjoy/news/models/active_record/category'
|
60
|
+
autoload :Image, 'enjoy/news/models/active_record/image'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
module Controllers
|
65
|
+
autoload :Items, 'enjoy/news/controllers/news'
|
66
|
+
autoload :Categories, 'enjoy/news/controllers/categories'
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Enjoy::News
|
4
|
+
class AllGenerator < Rails::Generators::Base
|
5
|
+
argument :class_name, type: :string
|
6
|
+
|
7
|
+
desc 'Enjoy::News generator'
|
8
|
+
def all
|
9
|
+
generate "enjoy:news:config:install"
|
10
|
+
|
11
|
+
generate "enjoy:news:models:all #{class_name}"
|
12
|
+
|
13
|
+
generate "enjoy:news:controllers:all #{class_name}"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Enjoy::News::Config
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
desc 'Enjoy::News Config generator'
|
8
|
+
def install
|
9
|
+
template 'enjoy_news.erb', "config/initializers/enjoy_news.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Enjoy::News.configure do |config|
|
2
|
+
##### defaults #####
|
3
|
+
# config.news_image_styles = {
|
4
|
+
# main: '400x200>',
|
5
|
+
# thumb: '200x100>'
|
6
|
+
# }
|
7
|
+
# config.category_image_styles = {
|
8
|
+
# main: '400x200>',
|
9
|
+
# thumb: '200x100>'
|
10
|
+
# }
|
11
|
+
# config.images_image_styles = {
|
12
|
+
# main: '400x200>',
|
13
|
+
# thumb: '200x100>'
|
14
|
+
# }
|
15
|
+
#
|
16
|
+
# config.news_per_page = 10
|
17
|
+
# config.news_excerpt = 12
|
18
|
+
# config.news_content_required = true
|
19
|
+
#
|
20
|
+
# config.gallery_support = defined? Enjoy::Gallery
|
21
|
+
# config.seo_support = defined? Enjoy::Seo
|
22
|
+
# config.pages_support = defined? Enjoy::Pages
|
23
|
+
#
|
24
|
+
# config.can_connect_news_with_pages = true
|
25
|
+
# config.can_connect_category_with_pages = true
|
26
|
+
#
|
27
|
+
# config.localize = Enjoy.config.localize
|
28
|
+
end
|