[Mojolicious] Is it possible to avoid repetitive validation code?

2018-02-26 Thread Michael Fung
Hi All,

I am trying out Mojolicious::Validator. It is very elegant. But, if many 
actions take a optional "page" parameter, then I need to include something 
like the following for all these actions.

sub action1 {
  ...

  $validation->optional('page')->num(1,100);


Is there a way to avoid this repetition while using Mojolicious::Validator?


Thanks,
Michael



-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


[Mojolicious] Yancy first attempts

2018-02-26 Thread Luc Larochelle
Hi everyone,

I took the Yancy app example from the Mojolicious Advent calendar and made 
some minor modifications to use an SQLite backend instead of Postgres.

Thing is, the page won't render at all , but there is no error message.

>From my understanding of the purpose of this plugin, it should render blank 
at least ? (no posts, for instance) 

Any idea what I'm doing wrong ? Below is the full code.

Best regards,



use Mojolicious::Lite;
use Mojo::SQLite;

my $sql = Mojo::SQLite->new('sqlite:config.db');

# Use migrations to create a table
$sql->migrations->name('my_config_app')->from_string(migrations->migrate(0)->migrate;

plugin Yancy => {
backend => 'sqlite:config.db',
collections => {
hosts => {
required => [ 'title', 'markdown', 'html' ],
properties => {
id => {
type => 'integer',
readOnly => 1,
},
title => {
type => 'string',
},
markdown => {
type => 'string',
format => 'markdown',
'x-html-field' => 'html',
},
html => {
type => 'string',
},
},
},
},
};

get '/' => sub {
my ( $c ) = @_;
return $c->render(
'index',
posts => [ $c->yancy->list(
'hosts',
) ],
);
};

app->start;

__DATA__
@@ index.html.ep


  
Hello, world!





https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css";
 
integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb"
 
crossorigin="anonymous">
  
  

% for my $post ( @{ stash 'posts' } ) {
  <%== $post->{html} %>
% }




https://code.jquery.com/jquery-3.2.1.slim.min.js"; 
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
 
crossorigin="anonymous">
https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"; 
integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh"
 
crossorigin="anonymous">
https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js";
 
integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ"
 
crossorigin="anonymous">
  


-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.