Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App scaffolding templates #670

Open
wants to merge 7 commits into
base: devel
Choose a base branch
from
Open

App scaffolding templates #670

wants to merge 7 commits into from

Conversation

perlpilot
Copy link
Contributor

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!

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.
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.
@bigpresh
Copy link
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)

* 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
@perlpilot
Copy link
Contributor Author

Where is this Dancer::Script refactoring located?

@bigpresh
Copy link
Member

On Thursday 29 September 2011 19:40:07 Jonathan Scott Duff wrote:

Where is this Dancer::Script refactoring located?

Over on @gnusosa's fork: https://github.com/gnusosa/Dancer

@xsawyerx
Copy link
Member

xsawyerx commented Oct 2, 2011

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

@ambs
Copy link
Member

ambs commented Nov 1, 2011

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

@xsawyerx
Copy link
Member

xsawyerx commented Nov 2, 2011

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

@xsawyerx
Copy link
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. :)

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.
@perlpilot
Copy link
Contributor Author

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
Copy link
Contributor

dams commented Mar 22, 2012

@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
Copy link
Member

sukria commented Mar 23, 2012

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants