enjoy_cms 0.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.rspec +1 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +5 -0
  7. data/Gemfile.lock +249 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +137 -0
  10. data/Rakefile +1 -0
  11. data/app/assets/javascripts/enjoy_cms.coffee +6 -0
  12. data/app/assets/javascripts/enjoy_cms/flash.js.coffee +3 -0
  13. data/app/assets/javascripts/enjoy_cms/map.js.coffee +22 -0
  14. data/app/assets/javascripts/head.load.js +707 -0
  15. data/app/assets/javascripts/jquery.placeholder.js +157 -0
  16. data/app/assets/stylesheets/enjoy_cms.sass +5 -0
  17. data/app/assets/stylesheets/enjoy_cms/flash.sass +63 -0
  18. data/app/assets/stylesheets/enjoy_cms/normalize.scss +406 -0
  19. data/app/assets/stylesheets/enjoy_cms/powered.sass +18 -0
  20. data/app/controllers/concerns/enjoy/errors.rb +93 -0
  21. data/app/controllers/concerns/enjoy/fancybox.rb +14 -0
  22. data/app/controllers/concerns/enjoy/localizeable.rb +33 -0
  23. data/app/controllers/concerns/enjoy/nav_menu.rb +64 -0
  24. data/app/controllers/concerns/enjoy/no_cache.rb +12 -0
  25. data/app/controllers/concerns/enjoy/seo_pages.rb +83 -0
  26. data/app/controllers/enjoy/contacts_controller.rb +5 -0
  27. data/app/controllers/enjoy/home_controller.rb +6 -0
  28. data/app/controllers/enjoy/news_controller.rb +5 -0
  29. data/app/controllers/enjoy/pages_controller.rb +5 -0
  30. data/app/controllers/enjoy/search_controller.rb +6 -0
  31. data/app/helpers/enjoy/gzip_helper.rb +27 -0
  32. data/app/helpers/enjoy/powered_helper.rb +12 -0
  33. data/app/mailers/enjoy/contact_mailer.rb +17 -0
  34. data/app/models/concerns/enjoy/boolean_field.rb +17 -0
  35. data/app/models/concerns/enjoy/enableable.rb +8 -0
  36. data/app/models/concerns/enjoy/geocodeable.rb +4 -0
  37. data/app/models/concerns/enjoy/mappable.rb +95 -0
  38. data/app/models/concerns/enjoy/mongoid_paperclip.rb +37 -0
  39. data/app/models/concerns/enjoy/seoable.rb +36 -0
  40. data/app/models/concerns/enjoy/sitemap_data.rb +23 -0
  41. data/app/models/concerns/enjoy/sort_field.rb +20 -0
  42. data/app/models/concerns/enjoy/sortable.rb +8 -0
  43. data/app/models/enjoy/contact_message.rb +12 -0
  44. data/app/models/enjoy/embedded_element.rb +15 -0
  45. data/app/models/enjoy/embedded_gallery_image.rb +15 -0
  46. data/app/models/enjoy/gallery.rb +10 -0
  47. data/app/models/enjoy/gallery_image.rb +10 -0
  48. data/app/models/enjoy/menu.rb +12 -0
  49. data/app/models/enjoy/news.rb +12 -0
  50. data/app/models/enjoy/page.rb +12 -0
  51. data/app/models/enjoy/seo.rb +13 -0
  52. data/app/views/blocks/_favicon.html.slim +21 -0
  53. data/app/views/blocks/_footer.html.slim +1 -0
  54. data/app/views/blocks/_seo_block.html.slim +18 -0
  55. data/app/views/blocks/_seo_block_with_obj.html.slim +27 -0
  56. data/app/views/devise/registrations/edit.html.slim +21 -0
  57. data/app/views/devise/registrations/new.html.slim +21 -0
  58. data/app/views/devise/sessions/new.html.slim +22 -0
  59. data/app/views/devise/shared/_links.html.slim +11 -0
  60. data/app/views/enjoy/contact_mailer/new_message_email.html.slim +15 -0
  61. data/app/views/enjoy/contacts/index.html.slim +10 -0
  62. data/app/views/enjoy/contacts/new.html.slim +10 -0
  63. data/app/views/enjoy/contacts/sent.html.slim +4 -0
  64. data/app/views/enjoy/home/index.html.slim +1 -0
  65. data/app/views/enjoy/news/index.html.slim +9 -0
  66. data/app/views/enjoy/news/show.html.slim +8 -0
  67. data/app/views/enjoy/pages/show.html.slim +1 -0
  68. data/app/views/enjoy/search/index.html.slim +19 -0
  69. data/app/views/errors/_base.html.slim +3 -0
  70. data/app/views/errors/error_403.html.slim +1 -0
  71. data/app/views/errors/error_404.html.slim +1 -0
  72. data/app/views/errors/error_500.html.slim +1 -0
  73. data/app/views/layouts/application.html.slim +25 -0
  74. data/app/views/rails_admin/main/_check_boxes.html.slim +27 -0
  75. data/app/views/rails_admin/main/_enum_check_boxes.html.slim +5 -0
  76. data/app/views/rails_admin/main/_enum_radio_buttons.html.slim +5 -0
  77. data/app/views/rails_admin/main/_form_raw.html.slim +1 -0
  78. data/app/views/shared/_admin_link.html.slim +3 -0
  79. data/app/views/shared/_messages.html.slim +7 -0
  80. data/app/views/shared/_meta.html.slim +19 -0
  81. data/app/views/shared/_obj.html.slim +21 -0
  82. data/app/views/shared/_og.html.slim +4 -0
  83. data/app/views/simple_captcha/_simple_captcha.html.slim +12 -0
  84. data/config/initializers/simple_captcha.rb +29 -0
  85. data/config/locales/en.enjoy.yml +29 -0
  86. data/config/locales/en.enjoy_admin.yml +6 -0
  87. data/config/locales/ru.cancan.yml +4 -0
  88. data/config/locales/ru.devise.yml +65 -0
  89. data/config/locales/ru.enjoy.yml +39 -0
  90. data/config/locales/ru.enjoy_admin.yml +6 -0
  91. data/config/locales/ru.kaminari.yml +17 -0
  92. data/config/locales/ru.models.yml +103 -0
  93. data/config/locales/ru.mongoid.yml +450 -0
  94. data/config/locales/ru.rails_admin.yml +148 -0
  95. data/config/locales/ru.simple_captcha.yml +3 -0
  96. data/config/locales/ru.simple_form.yml +9 -0
  97. data/config/routes.rb +14 -0
  98. data/enjoy_cms.gemspec +53 -0
  99. data/lib/enjoy/admin.rb +350 -0
  100. data/lib/enjoy/admin/contact_message.rb +36 -0
  101. data/lib/enjoy/admin/embedded_element.rb +11 -0
  102. data/lib/enjoy/admin/embedded_gallery_image.rb +15 -0
  103. data/lib/enjoy/admin/gallery.rb +20 -0
  104. data/lib/enjoy/admin/gallery_image.rb +18 -0
  105. data/lib/enjoy/admin/menu.rb +27 -0
  106. data/lib/enjoy/admin/news.rb +57 -0
  107. data/lib/enjoy/admin/page.rb +81 -0
  108. data/lib/enjoy/admin/seo.rb +17 -0
  109. data/lib/enjoy/configuration.rb +73 -0
  110. data/lib/enjoy/controller.rb +31 -0
  111. data/lib/enjoy/controllers/contacts.rb +70 -0
  112. data/lib/enjoy/controllers/news.rb +36 -0
  113. data/lib/enjoy/controllers/pages.rb +22 -0
  114. data/lib/enjoy/controllers/search.rb +62 -0
  115. data/lib/enjoy/elastic_search.rb +31 -0
  116. data/lib/enjoy/engine.rb +46 -0
  117. data/lib/enjoy/migration.rb +34 -0
  118. data/lib/enjoy/model.rb +22 -0
  119. data/lib/enjoy/models/active_record/contact_message.rb +14 -0
  120. data/lib/enjoy/models/active_record/menu.rb +17 -0
  121. data/lib/enjoy/models/active_record/news.rb +26 -0
  122. data/lib/enjoy/models/active_record/page.rb +20 -0
  123. data/lib/enjoy/models/active_record/seo.rb +17 -0
  124. data/lib/enjoy/models/contact_message.rb +37 -0
  125. data/lib/enjoy/models/embedded_element.rb +12 -0
  126. data/lib/enjoy/models/embedded_gallery_image.rb +16 -0
  127. data/lib/enjoy/models/gallery.rb +29 -0
  128. data/lib/enjoy/models/gallery_image.rb +23 -0
  129. data/lib/enjoy/models/menu.rb +28 -0
  130. data/lib/enjoy/models/mongoid/contact_message.rb +20 -0
  131. data/lib/enjoy/models/mongoid/embedded_element.rb +13 -0
  132. data/lib/enjoy/models/mongoid/embedded_gallery_image.rb +19 -0
  133. data/lib/enjoy/models/mongoid/gallery.rb +23 -0
  134. data/lib/enjoy/models/mongoid/gallery_image.rb +21 -0
  135. data/lib/enjoy/models/mongoid/menu.rb +15 -0
  136. data/lib/enjoy/models/mongoid/news.rb +29 -0
  137. data/lib/enjoy/models/mongoid/page.rb +25 -0
  138. data/lib/enjoy/models/mongoid/seo.rb +28 -0
  139. data/lib/enjoy/models/news.rb +58 -0
  140. data/lib/enjoy/models/page.rb +90 -0
  141. data/lib/enjoy/models/seo.rb +22 -0
  142. data/lib/enjoy/patch.rb +58 -0
  143. data/lib/enjoy/rails_admin_menu.rb +145 -0
  144. data/lib/enjoy/simple_form_patch.rb +12 -0
  145. data/lib/enjoy/tasks.rb +13 -0
  146. data/lib/enjoy/version.rb +3 -0
  147. data/lib/enjoy_cms.rb +109 -0
  148. data/lib/filename_to_slug.rb +34 -0
  149. data/lib/generators/enjoy/ability_generator.rb +14 -0
  150. data/lib/generators/enjoy/admin_generator.rb +21 -0
  151. data/lib/generators/enjoy/capify_generator.rb +39 -0
  152. data/lib/generators/enjoy/layout_generator.rb +14 -0
  153. data/lib/generators/enjoy/migration_generator.rb +18 -0
  154. data/lib/generators/enjoy/templates/Capfile +17 -0
  155. data/lib/generators/enjoy/templates/ability.erb +26 -0
  156. data/lib/generators/enjoy/templates/admin.erb +89 -0
  157. data/lib/generators/enjoy/templates/deploy.erb +47 -0
  158. data/lib/generators/enjoy/templates/dl.erb +30 -0
  159. data/lib/generators/enjoy/templates/migration_contact_messages.rb +15 -0
  160. data/lib/generators/enjoy/templates/migration_news.rb +26 -0
  161. data/lib/generators/enjoy/templates/migration_pages.rb +45 -0
  162. data/lib/generators/enjoy/templates/migration_seos.rb +14 -0
  163. data/lib/generators/enjoy/templates/production.erb +8 -0
  164. data/lib/generators/enjoy/templates/unicorn.erb +66 -0
  165. data/lib/generators/enjoy/utils.rb +21 -0
  166. data/lib/manual_slug.rb +10 -0
  167. data/lib/manual_slug/active_record.rb +32 -0
  168. data/lib/manual_slug/mongoid.rb +36 -0
  169. data/lib/rails_admin/custom_show_in_app.rb +43 -0
  170. data/release.sh +13 -0
  171. data/template.rb +824 -0
  172. metadata +579 -0
@@ -0,0 +1,23 @@
1
+ module Enjoy
2
+ module Models
3
+ module GalleryImage
4
+ extend ActiveSupport::Concern
5
+ include Enjoy::Model
6
+ include Enjoy::Enableable
7
+
8
+ include Enjoy.orm_specific('GalleryImage')
9
+
10
+ included do
11
+
12
+ belongs_to :gallery, class_name: gallery_class_name
13
+ field :name, type: String, localize: Enjoy.configuration.localize
14
+
15
+ validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/, if: :image?
16
+ end
17
+
18
+ def gallery_class_name
19
+ "Enjoy::Gallery"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ module Enjoy
2
+ module Models
3
+ module Menu
4
+ extend ActiveSupport::Concern
5
+ include Enjoy::Model
6
+ include ManualSlug
7
+ include Enjoy::Enableable
8
+
9
+ include Enjoy.orm_specific('Menu')
10
+ included do
11
+
12
+ field :name, type: String
13
+ manual_slug :name
14
+
15
+ after_save do
16
+ Rails.cache.delete 'menus'
17
+ end
18
+ after_destroy do
19
+ Rails.cache.delete 'menus'
20
+ end
21
+ end
22
+
23
+ def page_class_name
24
+ "Enjoy::Page"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ module Enjoy
2
+ module Models
3
+ module Mongoid
4
+ module ContactMessage
5
+ extend ActiveSupport::Concern
6
+ included do
7
+
8
+ field :name, type: String
9
+ field :email, type: String
10
+ field :phone, type: String
11
+ field :content, type: String
12
+ Enjoy.config.contacts_fields.each_pair do |fn, ft|
13
+ next if ft.nil?
14
+ field fn, type: ft
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ module Enjoy
2
+ module Models
3
+ module Mongoid
4
+ module EmbeddedElement
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ field :name, type: String, localize: Enjoy.configuration.localize, default: ""
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ module Enjoy
2
+ module Models
3
+ module Mongoid
4
+ module EmbeddedGalleryImage
5
+ extend ActiveSupport::Concern
6
+ include Enjoy::MongoidPaperclip
7
+ include Enjoy::EmbeddedElement
8
+
9
+ included do
10
+
11
+ enjoy_mongoid_attached_file(:image,
12
+ styles: image_styles,
13
+ content_type: { content_type: ["image/jpg", "image/jpeg", "image/png"] }
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ module Enjoy
2
+ module Models
3
+ module Mongoid
4
+ module Gallery
5
+ extend ActiveSupport::Concern
6
+ include Enjoy::MongoidPaperclip
7
+
8
+ included do
9
+
10
+ manual_slug :name
11
+
12
+ acts_as_nested_set
13
+ scope :sorted, -> { order_by([:lft, :asc]) }
14
+
15
+ enjoy_mongoid_attached_file(:image,
16
+ styles: image_styles,
17
+ content_type: { content_type: ["image/jpg", "image/jpeg", "image/png"] }
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ module Enjoy
2
+ module Models
3
+ module Mongoid
4
+ module GalleryImage
5
+ extend ActiveSupport::Concern
6
+ include Enjoy::MongoidPaperclip
7
+
8
+ included do
9
+
10
+ acts_as_nested_set
11
+ scope :sorted, -> { order_by([:lft, :asc]) }
12
+
13
+ enjoy_mongoid_attached_file(:image,
14
+ styles: image_styles,
15
+ content_type: { content_type: ["image/jpg", "image/jpeg", "image/png"] }
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ module Enjoy
2
+ module Models
3
+ module Mongoid
4
+ module Menu
5
+ extend ActiveSupport::Concern
6
+ included do
7
+ has_and_belongs_to_many :pages, inverse_of: :menus, class_name: page_class_name
8
+ alias_method :items, :pages
9
+
10
+ field :name, type: String, default: ""
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ module Enjoy
2
+ module Models
3
+ module Mongoid
4
+ module News
5
+ extend ActiveSupport::Concern
6
+ unless Enjoy.config.news_image_styles.nil?
7
+ include Enjoy::MongoidPaperclip
8
+ end
9
+ included do
10
+
11
+ field :time, type: Time
12
+ index({enabled: 1, time: 1})
13
+ unless Enjoy.config.news_image_styles.nil?
14
+ enjoy_mongoid_attached_file(:image,
15
+ styles: Enjoy.configuration.news_image_styles,
16
+ content_type: { content_type: ["image/jpg", "image/jpeg", "image/png"] }
17
+ )
18
+ end
19
+
20
+ field :excerpt, type: String, localize: Enjoy.configuration.localize, default: ""
21
+ field :content, type: String, localize: Enjoy.configuration.localize, default: ""
22
+
23
+ scope :after_now, -> { where(:time.lt => Time.now) }
24
+ scope :by_date, -> { desc(:time) }
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ module Enjoy
2
+ module Models
3
+ module Mongoid
4
+ module Page
5
+ extend ActiveSupport::Concern
6
+ included do
7
+
8
+ field :regexp, type: String, default: ""
9
+ field :redirect, type: String, default: ""
10
+ field :excerpt, type: String, localize: Enjoy.config.localize, default: ""
11
+ field :content, type: String, localize: Enjoy.config.localize, default: ""
12
+ field :fullpath, type: String, default: ""
13
+
14
+ has_and_belongs_to_many :menus, inverse_of: :pages, class_name: menu_class_name
15
+ acts_as_nested_set
16
+
17
+ manual_slug :name
18
+
19
+ scope :sorted, -> { order_by([:lft, :asc]) }
20
+ scope :menu, ->(menu_id) { enabled.sorted.where(menu_ids: menu_id) }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,28 @@
1
+ module Enjoy
2
+ module Models
3
+ module Mongoid
4
+ module Seo
5
+ extend ActiveSupport::Concern
6
+ include ::Mongoid::Paperclip
7
+ included do
8
+
9
+ field :name, type: String, localize: Enjoy.config.localize
10
+ field :h1, type: String, localize: Enjoy.config.localize
11
+
12
+ field :title, type: String, localize: Enjoy.config.localize
13
+ field :keywords, type: String, localize: Enjoy.config.localize
14
+ field :description, type: String, localize: Enjoy.config.localize
15
+ field :robots, type: String, localize: Enjoy.config.localize
16
+
17
+ field :og_title, type: String, localize: Enjoy.config.localize
18
+ unless Enjoy.config.news_image_styles.nil?
19
+ enjoy_mongoid_attached_file(:image,
20
+ styles: og_image_styles,
21
+ content_type: { content_type: ["image/jpg", "image/jpeg", "image/png"] }
22
+ )
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,58 @@
1
+ module Enjoy
2
+ module Models
3
+ module News
4
+ extend ActiveSupport::Concern
5
+ include Enjoy::Model
6
+ include ManualSlug
7
+ include Enjoy::Seoable
8
+ include Enjoy::Enableable
9
+ include Enjoy::SitemapData
10
+
11
+ include Enjoy.orm_specific('News')
12
+
13
+ # if Enjoy.config.search_enabled
14
+ # include Enjoy::ElasticSearch
15
+ # end
16
+
17
+ included do
18
+
19
+ unless Enjoy.config.news_image_styles.nil?
20
+ validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/, if: :image?
21
+ end
22
+
23
+ validates_presence_of :name
24
+ if Enjoy.config.news_content_required
25
+ validates_presence_of :content
26
+ end
27
+
28
+ before_validation do
29
+ self.time = Time.now if self.time.blank?
30
+ end
31
+ scope :recent, ->(count = 5) { enabled.after_now.by_date.limit(count) }
32
+ unless Enjoy.config.news_per_page.nil?
33
+ paginates_per Enjoy.config.news_per_page
34
+ end
35
+ smart_excerpt :excerpt, :content, Enjoy.config.news_excerpt
36
+ manual_slug :report_slug
37
+
38
+ Enjoy.apply_patches self
39
+ end
40
+
41
+ def report_slug
42
+ if time.blank?
43
+ name
44
+ elsif name.blank?
45
+ time.strftime('%Y-%m-%d')
46
+ else
47
+ time.strftime('%Y-%m-%d') + '-' + name[0..20]
48
+ end
49
+ end
50
+ def html5_date
51
+ time.strftime('%Y-%m-%d')
52
+ end
53
+ def format_date
54
+ time.strftime(I18n.t('Enjoy.format_time'))
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,90 @@
1
+ module Enjoy
2
+ module Models
3
+ module Page
4
+ extend ActiveSupport::Concern
5
+ include Enjoy::Model
6
+ include ManualSlug
7
+ include Enjoy::Enableable
8
+ include Enjoy::Seoable
9
+ include Enjoy::SitemapData
10
+
11
+ include Enjoy.orm_specific('Page')
12
+
13
+ # if Enjoy.config.search_enabled
14
+ # include Enjoy::ElasticSearch
15
+ # end
16
+
17
+ included do
18
+ validates_uniqueness_of :fullpath
19
+ validates_presence_of :name
20
+ manual_slug :name
21
+ before_validation do
22
+ self.fullpath = "/pages/#{slug}" if self.fullpath.blank?
23
+ end
24
+ end
25
+
26
+ def page_h1
27
+ _ret = h1
28
+ _ret = name if _ret.blank?
29
+ _ret = title if _ret.blank?
30
+ _ret
31
+ end
32
+
33
+ def menu_class_name
34
+ "Enjoy::Menu"
35
+ end
36
+
37
+ def get_fullpath
38
+ redirect.blank? ? fullpath : redirect
39
+ end
40
+
41
+ def has_content?
42
+ @content_used.nil? && !content.blank?
43
+ end
44
+
45
+ def page_content
46
+ if @content_used.nil?
47
+ @content_used = true
48
+ if content.nil?
49
+ ''
50
+ else
51
+ content.gsub(/\{\{(.*?)\}\}/) do
52
+ Settings ? Settings.get($1).val : "" #temp
53
+ end
54
+ end
55
+ else
56
+ ''
57
+ end
58
+ end
59
+
60
+ def is_current?(url)
61
+ if fullpath == '/'
62
+ url == '/'
63
+ else
64
+ url.match(clean_regexp)
65
+ end
66
+ end
67
+
68
+ def regexp_prefix
69
+ ""
70
+ end
71
+
72
+ def clean_regexp
73
+ if regexp.blank?
74
+ /^#{regexp_prefix}#{Regexp.escape(fullpath)}$/
75
+ else
76
+ begin
77
+ /#{regexp}/
78
+ rescue
79
+ # not a valid regexp - treat as literal search string
80
+ /#{Regexp.escape(regexp)}/
81
+ end
82
+ end
83
+ end
84
+
85
+ def nav_options
86
+ {highlights_on: clean_regexp}
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,22 @@
1
+ module Enjoy
2
+ module Models
3
+ module Seo
4
+ extend ActiveSupport::Concern
5
+ include Enjoy::Model
6
+ include Enjoy::Enableable
7
+ include Enjoy::Seoable
8
+
9
+ include Enjoy.orm_specific('Seo')
10
+
11
+ included do
12
+
13
+ Enjoy.apply_patches self
14
+ validates_attachment_content_type :og_image, content_type: /\Aimage\/.*\Z/, if: :og_image?
15
+ end
16
+
17
+ def og_image_styles
18
+ {thumb: "800x600>"}
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,58 @@
1
+ module Enjoy
2
+ class PatchDSL
3
+ def self.call(&blk)
4
+ instance = new
5
+ instance.instance_eval(&blk)
6
+ instance.instance_variables.inject({}) { |result_hash, instance_variable|
7
+ result_hash[instance_variable[1..-1].to_sym] = instance.instance_variable_get(instance_variable)
8
+ result_hash
9
+ }
10
+ end
11
+
12
+ def initialize
13
+ @model = Proc.new {}
14
+ @admin = Proc.new {}
15
+ @list = Proc.new {}
16
+ @show = Proc.new {}
17
+ @edit = Proc.new {}
18
+ @export = Proc.new {}
19
+ end
20
+
21
+ def model(&blk); @model = blk; end
22
+ def admin(&blk); @admin = blk; end
23
+ def list(&blk); @list = blk; end
24
+ def show(&blk); @show = blk; end
25
+ def edit(&blk); @edit = blk; end
26
+ def export(&blk); @export = blk; end
27
+ end
28
+
29
+ @@patches = {}
30
+
31
+ def self.only_patches(s, sections)
32
+ s.instance_eval do
33
+ sections.each do |section|
34
+ send section do
35
+ Enjoy.apply_patches self
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ def self.apply_patches(s)
42
+ if s.class.name.index('RailsAdmin::Config::Sections::').nil?
43
+ if s.class.name == 'RailsAdmin::Config::Model'
44
+ s.instance_eval(&@@patches[s.abstract_model.model_name][:admin]) unless @@patches[s.abstract_model.model_name].nil?
45
+ else
46
+ s.instance_eval(&@@patches[s.name][:model]) unless @@patches[s.name].nil?
47
+ end
48
+ else
49
+ model = s.abstract_model.model_name
50
+ action = s.class.name.split('::')[-1].downcase.to_sym
51
+ s.instance_eval(&@@patches[model][action]) unless @@patches[model].nil?
52
+ end
53
+ end
54
+
55
+ def self.patch(model, &blk)
56
+ @@patches[model] = PatchDSL.call(&blk)
57
+ end
58
+ end