-
-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add generator to copy default routes to the app
The generator configures clearance to turn off its internal routes and then copies the default routes to the host application's routes file where they can be customized to the developer's content.
- Loading branch information
1 parent
446f41c
commit 2a09afe
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Feature: copy routes to host application | ||
|
||
Background: | ||
Given I have a project with clearance | ||
|
||
Scenario: | ||
When I successfully run `bundle exec rails generate clearance:install` | ||
And I successfully run `bundle exec rails generate clearance:routes` | ||
Then the file "config/initializers/clearance.rb" should contain "config.routes = false" | ||
And the file "config/routes.rb" should contain "get '/sign_in' => 'clearance/sessions#new', as: 'sign_in'" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'rails/generators/base' | ||
|
||
module Clearance | ||
module Generators | ||
class RoutesGenerator < Rails::Generators::Base | ||
source_root File.expand_path('../templates', __FILE__) | ||
|
||
def disable_clearance_routes_in_config | ||
inject_into_file( | ||
'config/initializers/clearance.rb', | ||
' config.routes = false\n', | ||
after: /^Clearance\.configure do |config|\n/ | ||
) | ||
end | ||
|
||
def inject_clearance_routes_into_application_routes | ||
route(clearance_routes) | ||
end | ||
|
||
private | ||
|
||
def clearance_routes | ||
File.read(routes_file_path) | ||
end | ||
|
||
def routes_file_path | ||
File.expand_path(find_in_source_paths('routes.rb')) | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
resources :passwords, controller: 'clearance/passwords', only: [:create, :new] | ||
resource :session, controller: 'clearance/sessions', only: [:create] | ||
|
||
resources :users, controller: 'clearance/users', only: [:create] do | ||
resource :password, | ||
controller: 'clearance/passwords', | ||
only: [:create, :edit, :update] | ||
end | ||
|
||
get '/sign_in' => 'clearance/sessions#new', as: 'sign_in' | ||
delete '/sign_out' => 'clearance/sessions#destroy', as: 'sign_out' | ||
get '/sign_up' => 'clearance/users#new', as: 'sign_up' |