memowe / contenticious

A simple file based "CMS" on Mojo steroids!
http://memowe.github.com/contenticious
MIT License
68 stars 11 forks source link

Would it be possible to have a form defined in contenticious? #7

Closed mimosinnet closed 12 years ago

mimosinnet commented 12 years ago

I have been trying to get a drop down menu in contenticious. I have written this in contenticious.html.ep:

%= form_for '/traduccio' => (method => 'GET') => begin %= select_field idioma => [[Català => 'ca'], [English => 'en']] %= submit_button 'Translate', id => 'idioma' % end

I get a:

I'm sorry, but I couldn't find what you were looking for:

/traduccio?idioma=ca

Nevertheless, I am unable to find the right place where to write a:

get '/traduccio' => sub { .... }

Any hints appreciated! Thanks!

memowe commented 12 years ago

Defining a form is perfectly fine, the problem is that you didn't add a /traduccio route. Since Contenticious is designed for simplicity, there's no place to put in your own routes for Contenticious.

If you know what you're doing, it is possible to hack around that issue using the mount plugin (see this test), but AFAICS you want multiple languages and that's not what Contenticious is designed for. There may be dragons. :)

memowe commented 12 years ago

However, using multiple languages is possible. You could group all pages inside language directories like pages/en/foo.md. As a next step you would need to change the page's navigation. Use the API docs of Contenticious::Content to find out how to access the path of pages and maybe how to check if a page to a given path (other language!) exists.

Good luck. Looking forward to your wiki page about I18N hacks for Contenticious. :)

mimosinnet commented 12 years ago

Thanks a lot for your tips. I have been able to mount contenticious and have a 'translation' route like this:

#!/usr/bin/env perl
use Mojolicious::Lite;

get '/traduccio' => sub {
    my $self = shift; 
    my $idioma = $self->param('idioma');
    my $onsoc = $self->param('onsoc');
    my $urltrad = qq!&u=http%3A%2F%2Fpsicosocial.uab.cat$onsoc&act=url!;
    my $url = qq!http://translate.google.com/translate?sl=es&tl=$idioma&js=n&prev=_t&hl=en&ie=UTF-8&layout=2&eotf=1$urltrad!;
    $self->redirect_to($url);
    # print "onsoc = $onsoc\n";
    # print "url = $url\n";
} => 'traduccio';

plugin Mount => {'/' => "contenticious/webapp.pl"};

app->start;

It is a starting point, but it works! I will get this into the wiki. Thanks a lot!