enjoy_cms_pages 0.4.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -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 +40 -0
  9. data/Rakefile +1 -0
  10. data/app/assets/javascripts/enjoy/pages/init.coffee +2 -0
  11. data/app/assets/javascripts/enjoy/pages/scrolling.coffee +55 -0
  12. data/app/assets/javascripts/enjoy/pages.coffee +6 -0
  13. data/app/controllers/concerns/enjoy/pages/blocksetable.rb +81 -0
  14. data/app/controllers/concerns/enjoy/pages/decorators/pages_controller.rb +5 -0
  15. data/app/controllers/concerns/enjoy/pages/nav_menu.rb +91 -0
  16. data/app/controllers/concerns/enjoy/pages/seo_pages.rb +90 -0
  17. data/app/controllers/enjoy/pages/pages_controller.rb +7 -0
  18. data/app/helpers/enjoy/pages/canonical_helper.rb +13 -0
  19. data/app/helpers/enjoy/pages/pages_helpers.rb +2 -0
  20. data/app/models/concerns/enjoy/pages/canonicalable.rb +22 -0
  21. data/app/models/concerns/enjoy/pages/connectable.rb +36 -0
  22. data/app/models/concerns/enjoy/pages/decorators/block.rb +5 -0
  23. data/app/models/concerns/enjoy/pages/decorators/blockset.rb +5 -0
  24. data/app/models/concerns/enjoy/pages/decorators/menu.rb +5 -0
  25. data/app/models/concerns/enjoy/pages/decorators/page.rb +5 -0
  26. data/app/models/enjoy/pages/block.rb +13 -0
  27. data/app/models/enjoy/pages/blockset.rb +13 -0
  28. data/app/models/enjoy/pages/menu.rb +16 -0
  29. data/app/models/enjoy/pages/page.rb +16 -0
  30. data/app/views/enjoy/pages/pages/show.html.slim +1 -0
  31. data/app/views/rails_admin/main/_enjoy_connectable.html.slim +56 -0
  32. data/bin/console +14 -0
  33. data/bin/setup +7 -0
  34. data/config/initializers/enjoy_pages.rb +85 -0
  35. data/config/locales/ru.enjoy.pages.yml +44 -0
  36. data/enjoy_cms_pages.gemspec +36 -0
  37. data/lib/enjoy/pages/admin/block.rb +67 -0
  38. data/lib/enjoy/pages/admin/blockset.rb +53 -0
  39. data/lib/enjoy/pages/admin/menu.rb +27 -0
  40. data/lib/enjoy/pages/admin/page.rb +98 -0
  41. data/lib/enjoy/pages/admin.rb +4 -0
  42. data/lib/enjoy/pages/configuration.rb +32 -0
  43. data/lib/enjoy/pages/controllers/pages.rb +26 -0
  44. data/lib/enjoy/pages/engine.rb +5 -0
  45. data/lib/enjoy/pages/models/active_record/block.rb +16 -0
  46. data/lib/enjoy/pages/models/active_record/blockset.rb +19 -0
  47. data/lib/enjoy/pages/models/active_record/menu.rb +20 -0
  48. data/lib/enjoy/pages/models/active_record/page.rb +22 -0
  49. data/lib/enjoy/pages/models/block.rb +89 -0
  50. data/lib/enjoy/pages/models/blockset.rb +17 -0
  51. data/lib/enjoy/pages/models/menu.rb +23 -0
  52. data/lib/enjoy/pages/models/mongoid/block.rb +32 -0
  53. data/lib/enjoy/pages/models/mongoid/blockset.rb +16 -0
  54. data/lib/enjoy/pages/models/mongoid/menu.rb +16 -0
  55. data/lib/enjoy/pages/models/mongoid/page.rb +43 -0
  56. data/lib/enjoy/pages/models/page.rb +106 -0
  57. data/lib/enjoy/pages/rails_admin_ext/enjoy_connectable.rb +33 -0
  58. data/lib/enjoy/pages/rails_admin_ext/menu.rb +147 -0
  59. data/lib/enjoy/pages/routes.rb +46 -0
  60. data/lib/enjoy/pages/version.rb +5 -0
  61. data/lib/enjoy_cms_pages.rb +70 -0
  62. data/lib/generators/enjoy/pages/migration_generator.rb +18 -0
  63. data/lib/generators/enjoy/pages/templates/migration_blocks.rb +42 -0
  64. data/lib/generators/enjoy/pages/templates/migration_pages.rb +48 -0
  65. data/release.sh +7 -0
  66. metadata +164 -0
@@ -0,0 +1,89 @@
1
+ module Enjoy::Pages
2
+ module Models
3
+ module Block
4
+ extend ActiveSupport::Concern
5
+ include Enjoy::Model
6
+ include Enjoy::Enableable
7
+ include ManualSlug
8
+
9
+ include Enjoy::Pages.orm_specific('Block')
10
+
11
+ included do
12
+ manual_slug :name
13
+
14
+ validates :file_path, format: {
15
+ # with: /\A(?!layouts\/).*\Z/,
16
+ without: /\Alayouts\/.*\Z/,
17
+ message: "Недопустимый путь к файлу"
18
+ }
19
+
20
+ attr_accessor :file_pathname
21
+ after_initialize do
22
+ self.file_pathname = Pathname.new(file_path) unless file_path.nil?
23
+ end
24
+ end
25
+
26
+ def file_pathname_as_partial
27
+ self.file_pathname.dirname.join("_#{self.file_pathname.basename}")
28
+ end
29
+
30
+ def file_pathname_for_fs
31
+ self.partial ? self.file_path_as_partial : self.file_pathname
32
+ end
33
+
34
+ def render_or_content_html(view, opts = {})
35
+ ret = ""
36
+ unless self.file_path.blank?
37
+ opts.merge!(partial: self.file_path)
38
+ ret = view.render(opts) rescue self.content_html.html_safe
39
+ else
40
+ ret = self.content_html.html_safe
41
+ end
42
+ ret = content_tag wrapper_tag, ret, class: wrapper_class, id: wrapper_id if use_wrapper
43
+ ret = yield ret if block_given?
44
+ return ret
45
+ end
46
+
47
+ def render_or_content(view, opts = {})
48
+ ret = ""
49
+ unless self.file_path.blank?
50
+ opts.merge!(partial: self.file_path)
51
+ ret = view.render(opts) rescue self.content
52
+ else
53
+ ret = self.content
54
+ end
55
+ ret = yield ret if block_given?
56
+ return ret
57
+ end
58
+
59
+ def file_fullpath(with_ext = false, ext = ".html.slim")
60
+ ret = nil
61
+ unless self.file_path.blank?
62
+ res_filename = self.file_pathname_for_fs.to_s
63
+ res_filename += ext if with_ext
64
+ ret = Rails.root.join("views", res_filename)
65
+ end
66
+ return ret
67
+ end
68
+
69
+ def nav_options
70
+ nav_options_default.merge(nav_options_additions)
71
+ end
72
+
73
+ def nav_options_default
74
+ {
75
+ highlights_on: false,
76
+ link_html: {
77
+ data: {
78
+ pageblock_selector: self.pageblock_selector
79
+ }
80
+ }
81
+ }
82
+ end
83
+
84
+ def nav_options_additions
85
+ {}
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,17 @@
1
+ module Enjoy::Pages
2
+ module Models
3
+ module Blockset
4
+ extend ActiveSupport::Concern
5
+ include Enjoy::Model
6
+ include Enjoy::Enableable
7
+ include ManualSlug
8
+
9
+ include Enjoy::Pages.orm_specific('Blockset')
10
+
11
+ included do
12
+ manual_slug :name
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ module Enjoy::Pages
2
+ module Models
3
+ module Menu
4
+ extend ActiveSupport::Concern
5
+ include Enjoy::Model
6
+ include Enjoy::Enableable
7
+ include ManualSlug
8
+
9
+ include Enjoy::Pages.orm_specific('Menu')
10
+
11
+ included do
12
+ manual_slug :name
13
+
14
+ after_save do
15
+ Rails.cache.delete 'menus'
16
+ end
17
+ after_destroy do
18
+ Rails.cache.delete 'menus'
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,32 @@
1
+ module Enjoy::Pages
2
+ module Models
3
+ module Mongoid
4
+ module Block
5
+ extend ActiveSupport::Concern
6
+
7
+ include Enjoy::HtmlField
8
+
9
+ included do
10
+ field :name, type: String, default: ""
11
+
12
+ field :pageblock_selector, type: String, localize: Enjoy::Pages.config.localize, default: ""
13
+ field :file_path, type: String, localize: Enjoy::Pages.config.localize, default: ""
14
+ field :partial, type: Boolean, default: true
15
+ embedded_in :blockset, inverse_of: :blocks, class_name: "Enjoy::Pages::Blockset"
16
+
17
+ enjoy_cms_html_field :content, type: String, localize: Enjoy::Pages.config.localize, default: ""
18
+
19
+ field :use_wrapper, type: Boolean, default: false
20
+ field :wrapper_tag, type: String, default: ""
21
+ field :wrapper_class, type: String, default: ""
22
+ field :wrapper_id, type: String, default: ""
23
+
24
+ field :menu_link_content, type: String
25
+ field :show_in_menu, type: Boolean, default: true
26
+ scope :show_in_menu, -> { where(show_in_menu: true) }
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,16 @@
1
+ module Enjoy::Pages
2
+ module Models
3
+ module Mongoid
4
+ module Blockset
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ field :name, type: String, default: ""
9
+
10
+ embeds_many :blocks, inverse_of: :blockset, class_name: "Enjoy::Pages::Block"
11
+ accepts_nested_attributes_for :blocks, allow_destroy: true
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Enjoy::Pages
2
+ module Models
3
+ module Mongoid
4
+ module Menu
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ has_and_belongs_to_many :pages, inverse_of: :menus, class_name: "Enjoy::Pages::Page"
9
+ alias_method :items, :pages
10
+
11
+ field :name, type: String, default: ""
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,43 @@
1
+ module Enjoy::Pages
2
+ module Models
3
+ module Mongoid
4
+ module Page
5
+ extend ActiveSupport::Concern
6
+
7
+ include Enjoy::HtmlField
8
+
9
+ included do
10
+ scope :connected, -> {
11
+ where(:connectable_id.ne => nil)
12
+ }
13
+ scope :unconnected, -> (except_this = nil) {
14
+ if except_this
15
+ where({"$or" =>[
16
+ {:connectable_id => nil},
17
+ {"$and" => [
18
+ {connectable_type: except_this.class.to_param},
19
+ {connectable_id: except_this._id}
20
+ ]}
21
+ ]})
22
+ else
23
+ where(:connectable_id => nil)
24
+ end
25
+ }
26
+
27
+ field :name, type: String, localize: Enjoy::Seo.config.localize, default: ""
28
+
29
+ field :regexp, type: String, default: ""
30
+ field :redirect, type: String, default: ""
31
+ enjoy_cms_html_field :excerpt, type: String, localize: Enjoy::Pages.config.localize, default: ""
32
+ enjoy_cms_html_field :content, type: String, localize: Enjoy::Pages.config.localize, default: ""
33
+ field :fullpath, type: String, default: ""
34
+
35
+ has_and_belongs_to_many :menus, inverse_of: :pages, class_name: "Enjoy::Pages::Menu"
36
+
37
+ scope :sorted, -> { order_by([:lft, :asc]) }
38
+ scope :menu, ->(menu_id) { enabled.sorted.where(menu_ids: menu_id) }
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,106 @@
1
+ module Enjoy::Pages
2
+ module Models
3
+ module Page
4
+ extend ActiveSupport::Concern
5
+ include Enjoy::Model
6
+ include Enjoy::Enableable
7
+ include ManualSlug
8
+ if Enjoy::Pages.config.seo_support
9
+ include Enjoy::Seo::Seoable
10
+ include Enjoy::Seo::SitemapDataField
11
+ end
12
+
13
+ include Enjoy::Pages.orm_specific('Page')
14
+
15
+ # if Enjoy.config.search_enabled
16
+ # include Enjoy::ElasticSearch
17
+ # end
18
+
19
+ included do
20
+ acts_as_nested_set
21
+
22
+ validates_uniqueness_of :fullpath
23
+ validates_presence_of :name
24
+ manual_slug :name
25
+ before_validation do
26
+ self.fullpath = "/pages/#{slug}" if self.fullpath.blank?
27
+ end
28
+
29
+ belongs_to :connectable, polymorphic: true
30
+
31
+ before_save do
32
+ self.connectable_id = nil if self.connectable_type.nil?
33
+ self.connectable_type = nil if self.connectable_id.nil?
34
+ self
35
+ end
36
+ end
37
+
38
+ def page_h1
39
+ _ret = seo ? seo.h1 : nil
40
+ _ret = name if _ret.blank?
41
+ _ret = title if _ret.blank?
42
+ _ret
43
+ end
44
+
45
+ def get_fullpath
46
+ redirect.blank? ? fullpath : redirect
47
+ end
48
+
49
+ def has_content?
50
+ @content_used.nil? && !content.blank?
51
+ end
52
+
53
+ def page_content
54
+ if @content_used.nil?
55
+ @content_used = true
56
+ if content.nil?
57
+ ''
58
+ else
59
+ content.gsub(/\{\{(.*?)\}\}/) do
60
+ Settings ? Settings.get($1).val : "" #temp
61
+ end
62
+ end
63
+ else
64
+ ''
65
+ end
66
+ end
67
+
68
+ def is_current?(url)
69
+ if fullpath == '/'
70
+ url == '/'
71
+ else
72
+ url.match(clean_regexp)
73
+ end
74
+ end
75
+
76
+ def regexp_prefix
77
+ Enjoy::Pages.config.localize ? "(?:#{I18n.available_locales.map { |l| "\\/#{l}"}.join("|")})?" : ""
78
+ end
79
+
80
+ def clean_regexp
81
+ if regexp.blank?
82
+ /^#{regexp_prefix}#{Regexp.escape(fullpath)}$/
83
+ else
84
+ begin
85
+ /#{regexp}/
86
+ rescue
87
+ # not a valid regexp - treat as literal search string
88
+ /#{Regexp.escape(regexp)}/
89
+ end
90
+ end
91
+ end
92
+
93
+ def nav_options
94
+ nav_options_default.merge(nav_options_additions)
95
+ end
96
+
97
+ def nav_options_default
98
+ {highlights_on: clean_regexp}
99
+ end
100
+
101
+ def nav_options_additions
102
+ {}
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,33 @@
1
+ require 'rails_admin/config/fields/types/has_many_association'
2
+
3
+ module RailsAdmin
4
+ module Config
5
+ module Fields
6
+ module Types
7
+ class EnjoyConnectable < RailsAdmin::Config::Fields::Types::HasManyAssociation
8
+ RailsAdmin::Config::Fields::Types::register(self)
9
+ include RailsAdmin::Engine.routes.url_helpers
10
+
11
+ register_instance_option :partial do
12
+ :enjoy_connectable
13
+ end
14
+
15
+ register_instance_option :autocreate_page_attr do
16
+ :enjoy_connectable_autocreate_page
17
+ end
18
+
19
+ register_instance_option :allowed_methods do
20
+ [method_name, autocreate_page_attr]
21
+ end
22
+
23
+ register_instance_option :associated_collection_scope do
24
+ me = bindings[:object]
25
+ Proc.new do |scope|
26
+ scope.unconnected(me).enabled.sorted
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,147 @@
1
+ require 'rails_admin/config/fields/base'
2
+
3
+ module RailsAdmin
4
+ module Config
5
+ module Fields
6
+ module Types
7
+ class Menu < RailsAdmin::Config::Fields::Base
8
+ # Register field type for the type loader
9
+ RailsAdmin::Config::Fields::Types::register(self)
10
+ include RailsAdmin::Engine.routes.url_helpers
11
+
12
+ register_instance_option :pretty_value do
13
+ obj = bindings[:object]
14
+ ret = []
15
+ menus = Rails.cache.fetch 'menus', expires_in: 10.minutes do
16
+ if Enjoy.mongoid?
17
+ ::Enjoy::Pages::Menu.all.map { |m| {id: m.id.to_s, name: m.name } }
18
+ else
19
+ ::Enjoy::Pages::Menu.all.map { |m| {id: m.id, name: m.name } }
20
+ end
21
+ end
22
+ menus.each do |m|
23
+ if Enjoy.mongoid?
24
+ on = obj.menu_ids.include?(BSON::ObjectId.from_string(m[:id]))
25
+ else
26
+ on = obj.menu_ids.include?(m[:id].to_i)
27
+ end
28
+ ret << bindings[:view].link_to(
29
+ m[:name],
30
+ bindings[:view].toggle_menu_path(model_name: @abstract_model, id: obj.id, menu: m[:id], on: !on),
31
+ #method: :post,
32
+ title: m[:name],
33
+ class: "btn btn-mini #{on ? "btn-success" : "btn-danger"}",
34
+ style: 'margin-bottom: 5px;',
35
+ onclick: 'var $t = $(this); $.ajax({type: "POST", url: $t.attr("href"), data: {ajax:true}, success: function(r) { $t.attr("href", r.href); $t.attr("class", r.class); }, error: function(e) { alert(e.responseText); }}); return false;'
36
+ )
37
+ end
38
+ ('<div style="white-space: normal;">' + ret.join(' ') + '</div>').html_safe
39
+ end
40
+
41
+ register_instance_option :formatted_value do
42
+ pretty_value
43
+ end
44
+
45
+ register_instance_option :export_value do
46
+ nil
47
+ end
48
+
49
+ register_instance_option :partial do
50
+ :form_raw
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ module RailsAdmin
59
+ module Config
60
+ module Actions
61
+ class ToggleMenu < Base
62
+ RailsAdmin::Config::Actions.register(self)
63
+
64
+ # Is the action acting on the root level (Example: /admin/contact)
65
+ register_instance_option :root? do
66
+ false
67
+ end
68
+
69
+ register_instance_option :collection? do
70
+ false
71
+ end
72
+
73
+ # Is the action on an object scope (Example: /admin/team/1/edit)
74
+ register_instance_option :member? do
75
+ true
76
+ end
77
+
78
+ register_instance_option :controller do
79
+ proc do
80
+ ajax_link = Proc.new do |am, obj, menu, on|
81
+ render json: {
82
+ href: toggle_menu_path(model_name: am, id: obj.id, menu: menu.id, on: !on),
83
+ class: "btn btn-mini #{on ? "btn-success" : "btn-danger"}",
84
+ }
85
+ end
86
+ if params['id'].present?
87
+ begin
88
+ @object = @abstract_model.model.find(params['id'])
89
+ @menu = ::Enjoy::Pages::Menu.find(params[:menu])
90
+ if params[:on] == 'true'
91
+ @object.menus << @menu
92
+ else
93
+ @object.menus.delete(@menu)
94
+ end
95
+
96
+ if @object.save
97
+ if params['ajax'].present?
98
+ if params[:on] == 'true'
99
+ ajax_link.call(@abstract_model, @object, @menu, true)
100
+ else
101
+ ajax_link.call(@abstract_model, @object, @menu, false)
102
+ end
103
+ else
104
+ if params[:on] == 'true'
105
+ flash[:success] = I18n.t('enjoy.menu.enabled', menu: @menu.name)
106
+ else
107
+ flash[:success] = I18n.t('enjoy.menu.disabled', menu: @menu.name)
108
+ end
109
+ end
110
+ else
111
+ if params['ajax'].present?
112
+ render text: @object.errors.full_messages.join(', '), layout: false, status: 422
113
+ else
114
+ flash[:error] = @object.errors.full_messages.join(', ')
115
+ end
116
+ end
117
+ rescue Exception => e
118
+ if params['ajax'].present?
119
+ render text: I18n.t('enjoy.menu.error', err: e.to_s), status: 422
120
+ else
121
+ flash[:error] = I18n.t('enjoy.menu.error', err: e.to_s)
122
+ end
123
+ end
124
+ else
125
+ if params['ajax'].present?
126
+ render text: I18n.t('rs.m.no_id'), status: 422
127
+ else
128
+ flash[:error] = I18n.t('rs.m.no_id')
129
+ end
130
+
131
+ end
132
+
133
+ redirect_to :back unless params['ajax'].present?
134
+ end
135
+ end
136
+
137
+ register_instance_option :link_icon do
138
+ 'icon-move'
139
+ end
140
+
141
+ register_instance_option :http_methods do
142
+ [:post]
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,46 @@
1
+ module ActionDispatch::Routing
2
+ class Mapper
3
+
4
+ def enjoy_cms_pages_routes(config = {})
5
+ routes_config = {
6
+ use_slug_path: true,
7
+ use_pages_path: true,
8
+ classes: {
9
+ pages: :pages
10
+ },
11
+ paths: {
12
+ pages: :pages
13
+ }
14
+ }
15
+ routes_config.deep_merge!(config)
16
+
17
+ generate_enjoy_pages_user_routes(routes_config)
18
+ generate_enjoy_pages_cms_routes(routes_config)
19
+
20
+ end
21
+
22
+
23
+ private
24
+ def generate_enjoy_pages_user_routes(routes_config)
25
+ if !routes_config[:use_pages_path] and !routes_config[:classes][:pages].nil?
26
+ resources routes_config[:classes][:pages].to_sym, only: [:show], path: routes_config[:paths][:pages]
27
+ end
28
+ if !routes_config[:use_slug_path] and !routes_config[:classes][:pages].nil?
29
+ get '*slug' => "#{routes_config[:classes][:pages]}#show"
30
+ end
31
+ end
32
+ def generate_enjoy_pages_cms_routes(routes_config)
33
+ scope module: 'enjoy' do
34
+ scope module: 'pages' do
35
+ if routes_config[:use_pages_path] and !routes_config[:classes][:pages].nil?
36
+ resources routes_config[:classes][:pages].to_sym, only: [:show], path: routes_config[:paths][:pages], as: :enjoy_pages
37
+ end
38
+ if routes_config[:use_slug_path] and !routes_config[:classes][:pages].nil?
39
+ get '*slug' => "#{routes_config[:classes][:pages]}#show"
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ module Enjoy
2
+ module Pages
3
+ VERSION = "0.4.0.beta3"
4
+ end
5
+ end
@@ -0,0 +1,70 @@
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/pages/version"
8
+ require 'enjoy/pages/engine'
9
+ require 'enjoy/pages/configuration'
10
+
11
+ require "enjoy/pages/routes"
12
+
13
+ require 'enjoy/pages/rails_admin_ext/enjoy_connectable'
14
+ require 'enjoy/pages/rails_admin_ext/menu'
15
+
16
+ require 'simple-navigation'
17
+
18
+ module Enjoy::Pages
19
+ class << self
20
+ def orm
21
+ Enjoy.orm
22
+ end
23
+ def mongoid?
24
+ Enjoy::Pages.orm == :mongoid
25
+ end
26
+ def active_record?
27
+ Enjoy::Pages.orm == :active_record
28
+ end
29
+ def model_namespace
30
+ "Enjoy::Pages::Models::#{Enjoy::Pages.orm.to_s.camelize}"
31
+ end
32
+ def orm_specific(name)
33
+ "#{model_namespace}::#{name}".constantize
34
+ end
35
+ end
36
+
37
+ autoload :Admin, 'enjoy/pages/admin'
38
+ module Admin
39
+ autoload :Page, 'enjoy/pages/admin/page'
40
+ autoload :Menu, 'enjoy/pages/admin/menu'
41
+ autoload :Block, 'enjoy/pages/admin/block'
42
+ autoload :Blockset, 'enjoy/pages/admin/blockset'
43
+ end
44
+
45
+ module Models
46
+ autoload :Page, 'enjoy/pages/models/page'
47
+ autoload :Menu, 'enjoy/pages/models/menu'
48
+ autoload :Block, 'enjoy/pages/models/block'
49
+ autoload :Blockset, 'enjoy/pages/models/blockset'
50
+
51
+ module Mongoid
52
+ autoload :Page, 'enjoy/pages/models/mongoid/page'
53
+ autoload :Menu, 'enjoy/pages/models/mongoid/menu'
54
+ autoload :Block, 'enjoy/pages/models/mongoid/block'
55
+ autoload :Blockset, 'enjoy/pages/models/mongoid/blockset'
56
+ end
57
+
58
+ module ActiveRecord
59
+ autoload :Page, 'enjoy/pages/models/active_record/page'
60
+ autoload :Menu, 'enjoy/pages/models/active_record/menu'
61
+ autoload :Block, 'enjoy/pages/models/active_record/block'
62
+ autoload :Blockset, 'enjoy/pages/models/active_record/blockset'
63
+ end
64
+ end
65
+
66
+ module Controllers
67
+ autoload :Pages, 'enjoy/pages/controllers/pages'
68
+ end
69
+
70
+ end
@@ -0,0 +1,18 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/active_record'
3
+
4
+ module Enjoy::Pages
5
+ class MigrationGenerator < Rails::Generators::Base
6
+ include ActiveRecord::Generators::Migration
7
+ source_root File.expand_path('../templates', __FILE__)
8
+
9
+ desc 'Enjoy Pages migration generator'
10
+ def install
11
+ if Enjoy.active_record?
12
+ %w(pages blocks).each do |table_name|
13
+ migration_template "migration_#{table_name}.rb", "db/migrate/enjoy_create_#{table_name}.rb"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end