To add a collaborator to this project you will need to use the Relish gem to add the collaborator via a terminal command. Soon you'll be able to also add collaborators here!
More about adding a collaboratorControllers
Controller files
The piano
command searches for a controllers
folder in the
working directory.
If it finds the folder, searches recursively in it for files
finished in .controller. Finally, it loads them all, after the Pianofile
but before the default routes.
Configuration
The controllers
folder is configurable both in the Pianofile or via
command line arguments.
Via argument
> piano controllers:app/controllers
In the Pianofile
set :controllers, "app/controllers"
Loading order
piano loads the controllers in the order it finds them. The algorithm
is not yet determined.
Try not to set the same route twice in different .controller
files
because it might lead to erratic behavior.
- Scenarios
-
- There is a controller in the folder
- There is a file not ended in .controller in the folder
- There is a controller inside a subdirectory
- There is more than one controller and a non controller
- Change the controllers folder via command line argument
- There is a controller in the folder
-
- Given
-
the "arena" folder has a "controllers/demo.controller" with:
get "/" do "demo.controller loaded" end
- When
-
the
piano
command is called - And
- I go to "http://localhost:4567/"
- Then
- I should see "demo.controller loaded"
- There is a file not ended in .controller in the folder
-
- Given
-
the "arena" folder has a "controllers/demo.rb" with:
get "/" do "demo.rb loaded" end
- When
-
the
piano
command is called - And
- I go to "http://localhost:4567/"
- Then
- I should not see "demo.rb loaded"
- There is a controller inside a subdirectory
-
- Given
-
the "arena" folder has a "controllers/inside/this.controller" with:
get "/" do "inside/this.controller loaded" end
- When
-
the
piano
command is called - And
- I go to "http://localhost:4567/"
- Then
- I should see "inside/this.controller loaded"
- There is more than one controller and a non controller
-
- Given
-
the "arena" folder has a "controllers/inside/my.controller" with:
get "/my" do "inside/my.controller loaded" end
- And
-
the "arena" folder has a "controllers/index.controller" with:
get "/" do "index.controller loaded" end
- And
-
the "arena" folder has a "controllers/index.rb" with:
get "/rb" do "index.rb loaded" end
- When
-
the
piano
command is called - And
- I go to "http://localhost:4567/my"
- Then
- I should see "inside/my.controller loaded"
- When
- I go to "http://localhost:4567/"
- Then
- I should see "index.controller loaded"
- When
- I go to "http://localhost:4567/rb"
- Then
- I should not see "index.rb loaded"
- Change the controllers folder via command line argument
-
- Given
-
the "arena" folder has a "apps/controllers/index.controller" with:
get "/" do "index.controller loaded" end
- When
-
the
piano controllers:apps/controllers
command is called - And
- I go to "http://localhost:4567/"
- Then
- I should see "index.controller loaded"
Last published almost 7 years ago by xaviervia.