Created
November 15, 2012 23:28
-
-
Save flash-gordon/4082345 to your computer and use it in GitHub Desktop.
clients_stuff/hupo.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ClientsStuff | |
class Hupo < ::Rails::Engine | |
delegate :application, to: :Rails | |
initializer 'clients_stuff.hupo.append_assets' do | |
append_paths('assets') | |
end | |
initializer 'clients_stuff.hupo.append_widgets_paths', before: 'hupo_widget.load_all_widgets' do | |
append_paths('widgets') | |
end | |
initializer 'clients_stuff.hupo.append_client_locales' do | |
append_paths('locales') | |
end | |
initializer 'clients_stuff.hupo.append_client_views' do | |
append_paths('views') | |
end | |
private | |
def append_paths(dirname, chain = %w(default client shared)) | |
chain.each do |node| | |
path = send("%s_path" % node, dirname) # ex. default_path | |
send("append_#{dirname}_path", path) # ex. append_assets_path | |
end | |
end | |
def append_assets_path(path) | |
paths.add path, glob: '*', eager_load: true | |
application.config.assets.paths.unshift(*paths[path].existent_directories) | |
end | |
def append_widgets_path(path) | |
application.config.paths['config/widgets'] << path | |
end | |
def append_locales_path(path) | |
paths.add path, glob: '*.{rb,yml}' | |
config.i18n.railties_load_path.concat(paths[path].existent) | |
end | |
def append_views_path(path) | |
paths.add path | |
views = paths[path].existent | |
unless views.empty? | |
ActiveSupport.on_load(:action_controller){ prepend_view_path(views) } | |
ActiveSupport.on_load(:action_mailer){ prepend_view_path(views) } | |
end | |
end | |
def base_path | |
@base_path ||= File.dirname(__FILE__) | |
end | |
def client_path(path, client = application.client) | |
'%s/hupo/%s/%s' % [base_path, client, path] | |
end | |
def default_path(path) | |
client_path(path, 'default') | |
end | |
def shared_path(path) | |
[application.shared_path, application.client, path].join('/') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment