Skip to content

Commit

Permalink
Add frontend and backend routes method
Browse files Browse the repository at this point in the history
  • Loading branch information
bricesanchez authored and Brice Sanchez committed Aug 18, 2015
1 parent 3623baa commit ead992c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/config/routes.rb
Expand Up @@ -9,3 +9,5 @@

get '/sitemap.xml' => 'sitemap#index', :defaults => { :format => 'xml' }
end

Refinery::Core::Engine.draw_routes
29 changes: 29 additions & 0 deletions core/lib/refinery/core/engine.rb
Expand Up @@ -28,6 +28,35 @@ def refinery_inclusion!
end
end

def self.frontend_routes(&block)
@@frontend_routes ||= []
if @@frontend_routes.exclude?(block)
@@frontend_routes << block
end
end

def self.backend_routes(&block)
@@backend_routes ||= []
if @@backend_routes.exclude?(block)
@@backend_routes << block
end
end

def self.draw_routes(&block)
@@frontend_routes ||= []
@@backend_routes ||= []
eval_block(block) if block_given?
@@frontend_routes.each { |r| eval_block(&r) }
@@backend_routes.each { |r| eval_block(&r) }
# # Clear out routes so that they aren't drawn twice.
@@frontend_routes = []
@@backend_routes = []
end

def eval_block(&block)
Refinery::Core::Engine.routes.send :eval_block, block
end

config.autoload_paths += %W( #{config.root}/lib )

# Include the refinery controllers and helpers dynamically
Expand Down

0 comments on commit ead992c

Please sign in to comment.