-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add some more cookbook entries and example apps
- Loading branch information
Showing
12 changed files
with
358 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,46 @@ | ||
use Mojo::Base -signatures; | ||
package MyApp::Controller::Log { | ||
use Mojo::Base 'Yancy::Controller::Yancy', -signatures; | ||
sub list_log( $self ) { | ||
my $levels = $self->every_param( 'log_level' ); | ||
if ( @$levels ) { | ||
# Include only log levels requested | ||
$self->stash( filter => { log_level => $levels } ); | ||
} | ||
return $self->SUPER::list; | ||
} | ||
} | ||
|
||
package MyApp { | ||
use Mojo::Base 'Mojolicious', -signatures; | ||
sub startup( $self ) { | ||
push @{ $self->renderer->classes }, 'main'; | ||
push @{ $self->routes->namespaces }, 'MyApp::Controller'; | ||
|
||
# Download log.db: http://github.com/preaction/Yancy/tree/master/eg/cookbook/log.sqlite3 | ||
$self->plugin( Yancy => { | ||
backend => 'sqlite:log.sqlite3', | ||
read_schema => 1, | ||
} ); | ||
|
||
$self->routes->get( '/' )->to( | ||
controller => 'Log', | ||
action => 'list_log', | ||
schema => 'log', | ||
template => 'log', | ||
); | ||
} | ||
} | ||
|
||
Mojolicious::Commands->new->start_app( 'MyApp' ); | ||
__DATA__ | ||
@@ log.html.ep | ||
%= form_for current_route, begin | ||
% for my $log_level ( qw( debug info warn error ) ) { | ||
%= label_for "log_level_$log_level", begin | ||
%= ucfirst $log_level | ||
%= check_box log_level => $log_level | ||
% end | ||
% } | ||
%= submit_button 'Filter' | ||
% 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,30 @@ | ||
use Mojolicious::Lite -signatures; | ||
# Download log.sqlite3: https://github.com/preaction/Yancy/tree/master/eg/cookbook/log.sqlite3 | ||
plugin Yancy => { backend => 'sqlite:log.sqlite3', read_schema => 1 }; | ||
under sub( $c ) { | ||
my $levels = $c->every_param( 'log_level' ); | ||
if ( @$levels ) { | ||
# Include only log levels requested | ||
$c->stash( filter => { log_level => $levels } ); | ||
} | ||
return 1; | ||
}; | ||
get '/' => { | ||
controller => 'Yancy', | ||
action => 'list', | ||
schema => 'log', | ||
template => 'log', | ||
}; | ||
app->start; | ||
__DATA__ | ||
@@ log.html.ep | ||
%= form_for current_route, begin | ||
% for my $log_level ( qw( debug info warn error ) ) { | ||
%= label_for "log_level_$log_level", begin | ||
%= ucfirst $log_level | ||
%= check_box log_level => $log_level | ||
% end | ||
% } | ||
%= submit_button 'Filter' | ||
% end | ||
%= include 'yancy/table' |
Binary file not shown.
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,42 @@ | ||
|
||
use Mojolicious::Lite -signatures; | ||
use Mojo::JSON qw( true false ); | ||
|
||
# Download this database: https://github.com/preaction/Yancy/tree/master/eg/cookbook/pages.sqlite3 | ||
plugin Yancy => { | ||
backend => 'sqlite:pages.sqlite3', | ||
read_schema => 1, | ||
schema => { | ||
pages => { | ||
title => 'Pages', | ||
description => 'These are the pages in your site.', | ||
'x-id-field' => 'path', | ||
required => [qw( path content )], | ||
properties => { | ||
page_id => { | ||
type => 'integer', | ||
readOnly => true, | ||
}, | ||
path => { | ||
type => 'string', | ||
}, | ||
content => { | ||
type => 'string', | ||
format => 'html', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
app->routes->get( '/*path', { path => 'index' } )->to({ | ||
controller => 'Yancy', | ||
action => 'get', | ||
schema => 'pages', | ||
template => 'page', | ||
}); | ||
|
||
app->start; | ||
__DATA__ | ||
@@ page.html.ep | ||
%== $item->{content} |
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,47 @@ | ||
|
||
use Mojolicious::Lite -signatures; | ||
use Mojo::JSON qw( true false ); | ||
|
||
# Download this database: https://github.com/preaction/Yancy/tree/master/eg/cookbook/pages-markdown.sqlite3 | ||
plugin Yancy => { | ||
backend => 'sqlite:pages-markdown.sqlite3', | ||
read_schema => 1, | ||
schema => { | ||
pages => { | ||
title => 'Pages', | ||
description => 'These are the pages in your site.', | ||
'x-id-field' => 'path', | ||
required => [qw( path content )], | ||
properties => { | ||
page_id => { | ||
type => 'integer', | ||
readOnly => true, | ||
}, | ||
path => { | ||
type => 'string', | ||
}, | ||
markdown => { | ||
type => 'string', | ||
format => 'markdown', | ||
'x-html-field' => 'content', | ||
}, | ||
content => { | ||
type => 'string', | ||
format => 'html', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
app->routes->get( '/*path', { path => 'index' } )->to({ | ||
controller => 'Yancy', | ||
action => 'get', | ||
schema => 'pages', | ||
template => 'page', | ||
}); | ||
|
||
app->start; | ||
__DATA__ | ||
@@ page.html.ep | ||
%== $item->{content} |
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Empty file.
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