/
engine.rb
69 lines (58 loc) · 2.45 KB
/
engine.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module Refinery
module Pages
class Engine < ::Rails::Engine
include Refinery::Engine
isolate_namespace Refinery
engine_name :refinery_pages
config.autoload_paths += %W( #{config.root}/lib )
before_inclusion do
::ApplicationController.send :helper, Refinery::Pages::ContentPagesHelper
Refinery::AdminController.send :helper, Refinery::Pages::ContentPagesHelper
end
after_inclusion do
::ApplicationController.send :include, Refinery::Pages::InstanceMethods
Refinery::AdminController.send :include, Refinery::Pages::Admin::InstanceMethods
end
initializer "register refinery_pages plugin" do
Refinery::Plugin.register do |plugin|
plugin.pathname = root
plugin.name = 'refinery_pages'
plugin.version = %q{2.0.0}
plugin.menu_match = %r{refinery/page(_part|s_dialog)?s$}
plugin.activity = {
:class_name => :'refinery/page',
:nested_with => [:uncached_nested_url],
:use_record_in_nesting => false
}
plugin.url = proc { Refinery::Core::Engine.routes.url_helpers.admin_pages_path }
end
end
initializer "append marketable routes", :after => :set_routes_reloader_hook do
append_marketable_routes if Refinery::Pages.marketable_urls
end
initializer "add marketable route parts to reserved words", :after => :set_routes_reloader_hook do
add_route_parts_as_reserved_words if Refinery::Pages.marketable_urls
end
config.after_initialize do
Refinery.register_extension(Refinery::Pages)
end
protected
def append_marketable_routes
Refinery::Core::Engine.routes.append do
get '*path', :to => 'pages#show', :as => :marketable_page
end
Rails.application.routes_reloader.reload!
end
# Add any parts of routes as reserved words.
def add_route_parts_as_reserved_words
ActiveSupport.on_load(:active_record) do
route_paths = Rails.application.routes.named_routes.routes.map { |name, route| route.path.spec }
route_paths.reject! {|path| path.to_s =~ %r{^/(rails|refinery)}}
Refinery::Page.friendly_id_config.reserved_words |= route_paths.map { |path|
path.to_s.gsub(%r{^/}, '').to_s.split('(').first.to_s.split(':').first.to_s.split('/')
}.flatten.reject { |w| w =~ %r{_|\.} }.uniq
end
end
end
end
end