[Dancer-users] Minimum code required to get Dancer up and running?
sawyer x
xsawyerx at gmail.com
Sat Feb 26 10:35:48 CET 2011
Hi Brian.
I've written just what Flavio suggest, and it works perfectly. No 404's.
Using relative paths.
My steps:
1. go to ~/tmp
2. mkdir "tmpls"
3. inside "tmpls", create "test.tt" with content "your text: <% text %>"
4. inside ~/tmp, create file "eg.pl" with content:
use Dancer;
set views => 'tmpls';
get '/' => sub {
template test => { text => 'hi' };
};
dance;
--
Run it, go to http://localhost:3000/, et voila! :)
On Sat, Feb 26, 2011 at 2:56 AM, Brian E. Lozier <brian at massassi.com> wrote:
> Thanks for the information, I'm running into some problems, see below.
>
> On Fri, Feb 25, 2011 at 9:10 AM, Flavio Poletti <polettix at gmail.com>
> wrote:
> > 0. You pay only for what you use:
> > perl -MDancer -e 'get "/" => sub {return "Hello, World!"}; dance'
> > 1. There seems to be an undocumented configuration feature that lets you
> > specify the base directory for templates:
> > perl -MDancer -e 'set views => "foo"; get "/" => sub {template "bar"};
> > dance'
> > (this takes foo/bar.tt instead of views/bar.tt), I wonder if this can be
> > made official and documented.
>
> I can't seem to get this to work. When I use this "set views" as you
> suggested or views: in the config file, it sets the "views" config to
> that dir (say, "templates", and I verified this by Dumping the config
> hash), but I always get 404. This is problem #1, when I get a 404 I
> get no detailed information in the logs whatsoever. I get nothing in
> development.log actually. In this case, I know what the problem is
> (will say it in a second), but it would be really nice if Dancer would
> tell me somewhere what the problem is. 404 can mean route not found
> but apparently also view/template not found. There should be some way
> to disambiguate this fact.
>
> The problem is that it's looking in the wrong place for the
> "templates" directory. I don't know where it's looking, but it's not
> looking in appdir/templates. If I set views =>
> '/full/path/to/templates' it works, but if I use what I intend to be a
> relative directory I just get 404 error messages. Setting to app_dir
> . templates works if I set it in the code, but I can't figure out how
> to use "appdir" in config.yml (I'd rather set it in config.yml than in
> code).
>
> This isn't really a big deal. My real problem is that we have a
> function called template which looks in the views directory. This
> terminology mismatch is disconcerting. Since most perl modules call
> everything templates and the function is named template it seems like
> the files should be in "templates." However, if we like the "views"
> terminology we should just name the function "view" instead.
>
> Or figure out what I'm doing wrong with the config :) I realize this
> is undocumented behavior and I can't expect it to work. I'm going to
> follow the convention and use "views" for now.
>
> > 2. No restriction regarding the project directory name, just try it :-)
> The
> > normal startup script is a standard Perl program:
> > #!/usr/bin/env perl
> > use Dancer;
> > use WhateverName::YouLike::ForYour::DancerApplication;
> > dance;
> >
> > Cheers,
> > Flavio.
> >
> >
> > On Fri, Feb 25, 2011 at 5:03 PM, Brian E. Lozier <brian at massassi.com>
> wrote:
> >>
> >> I'm going to do a test implementation of a dancer web app into an
> >> existing project. I would like to know the minimum files I need to
> >> create in order to get it running. My intention is not to use the
> >> scaffolding script to create files as 1) it creates a bunch of files I
> >> don't need [but I don't know which ones are strictly required], 2) it
> >> creates a directory structure designed to house all my code, but I
> >> already have a directory structure [that might not match Dancer's
> >> exactly], and 3) I find scaffolding scripts hide a bunch of
> >> information that it's really better for me to understand instead of
> >> gloss over. I would essentially like to start from scratch. If there
> >> is not already documentation on this and I get some feedback here,
> >> I'll be happy to write a document and submit it back to the list.
> >>
> >> I have a couple other questions as well.
> >>
> >> 1. Is it possible for me to specify the "templates" directory as
> >> something other than "views" (we use "template" function in the code,
> >> it makes more sense to load it from a "templates" directory instead of
> >> a "views" directory)?
> >> 2. Is there an in-code restriction that requires me to have the
> >> directory name of my project (like "myproject") match the name of the
> >> dancer app module (myproject.pm)? I ask because it's not perlish to
> >> have a lower-cased module (like myproject.pm) but I don't want to name
> >> my directory MyProject because it's annoying to type. Generally lower
> >> case module names are reserved for pragmas (like warnings, strict,
> >> feature, etc.).
> >>
> >> Thanks in advance for any help,
> >> Brian
> >> _______________________________________________
> >> Dancer-users mailing list
> >> Dancer-users at perldancer.org
> >> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
> >
> >
> > _______________________________________________
> > Dancer-users mailing list
> > Dancer-users at perldancer.org
> > http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
> >
> >
> _______________________________________________
> Dancer-users mailing list
> Dancer-users at perldancer.org
> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.backup-manager.org/pipermail/dancer-users/attachments/20110226/a3eed666/attachment.htm>
More information about the Dancer-users
mailing list