App scaffolding templates #670

Open
wants to merge 7 commits into
from

6 participants

@perlpilot

Here are some changes to the dancer script to allow for an "application template" directory. It's not well tested yet, but I wanted some feedback.

It adds the --template/-t options such that you can use "application templates" to create new apps. The application templates are subdirectories of ~/.dancer_templates and they should contain everything you'd want in a dancer app.

The use-case is if you're always building dancer apps that use blueprint.css or prototype instead of jquery or come pre-packaged with some other functionality, you build a directory in ~/.dancer_templates that contains all of the necessary files and use "dancer -t my-template -a MyApp" to create new apps.

Anyway, feedback welcome!

perlpilot added some commits Sep 29, 2011
@perlpilot perlpilot Make $name less global
The appname is passed to several subs, but others rely on the globally
scoped $name declared near the top of the program.  So, make those
others take $name as a parameter.
33e04aa
@perlpilot perlpilot Make "meta-template" indicators more obnoxious 997688f
@perlpilot perlpilot Use local $appname rather than global $name e9f7404
@perlpilot perlpilot Add simple templating ability for creating new apps
Allow for a template to be specified on the command line with the -t or
--template option.  These templates are subdirectories within the
$HOME/.dancer_templates directory.

The files in the template dir are copied to the application dir with
some simple substitutions performed: filenames have APPNAME replaced by
the actual application name, within files [[%% appname %%]] and
[[%% appdir %%]] are replaced with the appropriate values for the
Actual application.  (The delimiters there are intentionally "big" so
That they don't conflict with whatever template delimiters may be used
by the templated files themselves (within views for instance))

Also, the file mode of the template files determines the file mode used
for the corresponding file in the application directory.
4a12de1
@bigpresh
PerlDancer member

Looks like a good feature.

The only slight drawback is that this will need to be ported to gnusosa's Dancer::Script refactoring (which reminds me, I need to find out how close we are to merging that in, it looked good)

@perlpilot perlpilot Application templates update
* Change the template dir to be ~/.dancer/templates
* If the argument to -t starts with a /, it's assumed to be the full
  path to a template directory
2ae161a
@perlpilot

Where is this Dancer::Script refactoring located?

@bigpresh
PerlDancer member
@xsawyerx
PerlDancer member

Released a new dev version.
Once I release it as stable, I'm gonna merge @gnusosa's work.

@ambs
PerlDancer member

@xsawyerx, can I poke you to merge @gnusosa's work? Please? With sugar on top?

@xsawyerx
PerlDancer member

@ambs let's see how easy this is...

@xsawyerx
PerlDancer member

@ambs, @bigpresh, @perlpilot - I've put @gnusosa's work on the branch "refactoring/script". If you could resubmit this pull request based on that branch, and adapt it to that code, I would greatly appreciate it. :)

perlpilot added some commits Dec 8, 2011
@perlpilot perlpilot Merge branch 'devel' of https://github.com/sukria/Dancer into devel 90803e4
@perlpilot perlpilot Allow refs to pass through view unscathed
Useful for inline templates so that you don't necessarily need a
directory structure or external files.

Also, the underlying template implementation supports passing a
scalar ref, but without the high-level implementation also supporting
this, there's no way to do inline templates with hooks.
d9ebf53
@perlpilot

I've made it such that

my $template = '<% foo %>';
template \$template, { foo => 42 };

works now.

I was trying to test some simple view code and didn't need or want to generate .tt files. I noticed that the underlying template code supported passing a scalar ref, but then your hooks won't run. The above change allows for the "full stack" template processing to happen and for the templates to be specified inline.

This is useful for extremely simple Dancer apps and, what I want it for, testing plugins that add functionality to templates.

@dams

@ambs, @bigpresh, @perlpilot, @gnusosa @xsawyerx : where are we with this PR ? it seems to me that it can be merged alongside with gnusosa stuff ?

@sukria
PerlDancer member

poking here. Dams++ : can we have a brief on that one?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment