Re: mini-languages for MVC view/controller manipulation
by revdiablo (Prior) on Dec 26, 2004 at 20:21 UTC
|
the use of mini-languages within view templates seems to occupy a very small and recent slice in the history of MVC frameworks
Whether I agree with this or not depends on what you consider the definition of a mini-language. If you mean simply an API, as in modules = minilanguages?, then this probably isn't right. I very recently started working on a simple module to generate wx forms for me, and I doubt this is anything new or innovative. But if you mean a mini language as I generally define it -- that is, a language with its own semantics and syntax, rather than just an API on another language -- then you might be right. Either way, interesting Meditation. ++
| [reply] |
Re: mini-languages for MVC view/controller manipulation
by dws (Chancellor) on Dec 27, 2004 at 03:47 UTC
|
Which brings me to my point: the use of mini-languages within view templates seems to occupy a very small and recent slice in the history of MVC frameworks, motivated primarily by the need to dynamically generate HTML.
In the pre-web epoch, several "mini languages" for describing views (and how to hook them up to models) came and went. VisualWorks had one, which served as the basis for reusable visual components. If I recall correctly, NeXT had one, too (on the back end of their visual UI design tool).
| [reply] |
|
| [reply] |
|
I should've been clearer: did said mini-languages exist *in* the view... or did they manipulate the view from outside of the view?
| [reply] |
|
| [reply] |
Re: mini-languages for MVC view/controller manipulation
by hardburn (Abbot) on Dec 27, 2004 at 15:18 UTC
|
HTML::Template . . . A popular, robust, powerful mini-language templating system which also does just fine on normal text files.
IMHO, it's not suitable for normal text files because of the way it handles whitespace:
$ perl -MHTML::Template -e '$in = join "", <>; $tmpl = HTML::Template-
+>new( scalarref => \$in ); print $tmpl->output;'
Hi
<TMPL_IF foo>
<TMPL_INCLUDE foo.txt>
</TMPL_IF>
Hello
Which will output:
Hi
Hello
The extra lines just aren't acceptable for plaintext. It's fine for HTML since whitespace is almost always ignored there.
"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.
| [reply] [d/l] [select] |
|
Hi
<TMPL_IF foo><TMPL_INCLUDE foo.txt>
</TMPL_IF>Hello
Version two looks like this:
Hi
\
<TMPL_IF foo>\
<TMPL_INCLUDE foo.txt>
</TMPL_IF>\
\
Hello
... $in =~ s/\\\n[\t ]*//g; ...
Doesn't this same issue apply to most templating packages, or am I missing something about why this is more of an issue for HTML::Template than the others? | [reply] [d/l] [select] |
|
Doesn't this same issue apply to most templating packages . . . ?
Probably. If there is anything special about H::T, it's that its default tag syntax is a bit lengthy. Compare to Text::BasicTemplate:
Hi
%if foo%include%fi%
Hello
(Note that Text::BasicTemplate doesn't have an equivilent to TMPL_INCLUDE by default, though it can call out to Perl subroutines.)
That's a much more condensed example that, IMHO, works better for plaintext.
"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.
| [reply] [d/l] [select] |
Re: mini-languages for MVC view/controller manipulation
by jdporter (Paladin) on Dec 27, 2004 at 14:55 UTC
|
I, for one, think your HTML::Seamstress module is very cool and elegant.
(So what if the idea originated elsewhere.) But, a couple comments on the html
compilation bit:
- In the line
$name->hello_world(name => $content);
where does that hello_world method come from?
Seems to me that you really want to be saying
$name->replace_with($content);
(And you should probably then call
$name->delete_content(); first.)
- In your look_down call, don't you also want to include criteria
to look for klass=content? I think that would be prudent.
metaperl++ (and all your other egos too, btw ;-)
| [reply] [d/l] [select] |
|
I, for one, think your HTML::Seamstress module is very cool and elegant
Thank you very much jdporter.
In the line $name->hello_world(name => $content);where does that hello_world method come from? Seems to me that you really want to be saying $name->replace_with($content);(And you should probably then call $name->delete_content(); first.)
You are right. I updated the code to what it actually was in the test suite. Actually the content_handler method does what you are talking about.
There is a very nice extension of HTML::TreeBuilder by Matthew Sisk called HTML-Element-Extended. In both of our efforts, we have written a dozen or so convenience methods for common Treebuilder idioms. So, I am developing something called HTML::Element::Library which will have all of our methods in one place.
In your look_down call, don't you also want to include criteria to look for klass=content? I think that would be prudent.
Well, here I rely on the fact that an HTML document must have unique id tags... but your suggestion certainly wouldn't hurt and it would be more precise...
Thanks for the comments.
| [reply] [d/l] [select] |
Re: mini-languages for MVC view/controller manipulation
by metaperl (Curate) on Dec 27, 2004 at 22:32 UTC
|
Also, passing arguments to a component does not use standard Perl syntax
What I mean by this is shown here. Summarily, even though something is typed as an array or hash:
<%args>
@elements
%labels
</%args>
you end up calling it with references like this:
<& /display, elements => \@some_data, labels => \%data_labels &>
a normal Perl subroutine would use $elements and $labels to receive both.
Whether the Mason syntax is more articulate is not the issue at hand. The issue at hand is that knowing Perl is not enough to receive arguments. You must learn a new calling convention. And when things like this happen, I develop paranoia about what else might be a hair different from what I invested great amounts time and money learning: pure Perl.
| [reply] [d/l] [select] |
|
Pshaw.
Your "shown here" link doesn't seem to work, but the example you give above is not very convincing.
You are perfectly free to use standard Perl argument passing conventions with your Mason components:
<& my_component, $foo, $bar, $baz &>
...
my ( $foo, $bar, $baz ) = @_;
...
The <%args> block is an optional extra mechanism for retrieving arguments, which you don't need to use if it makes you paranoid.
The @elements line in an <%args> block is equivalent to something like my %ARGS = @_; my @elements = @{ $ARGS{elements} || croak("Missing required argument: elements" }. That's a useful shortcut, particularly after you factor in the support for default values, but again, it's layered on top of the normal mechanism, not a replacement for it.
I think that in constrained contexts, mini-languages and format strings can be quite useful; the succinctness allows the developer to work at a higher level. I find them particularly non-threatening in cases like HTML::Mason, where all of the mini-language code is translated to pure Perl before execution -- just look at your var/obj directory to see exactly what Perl code was produced for an %args block or other HTML::Mason markup.
If you've made up your mind that you only want to use "pure" Perl syntax, feel free to use heredocs and interpolation tricks to generate your page templates, but I think most developers would agree that this is a case in which an additional layer with a different syntax is justified. | [reply] [d/l] [select] |
|
If you've made up your mind that you only want to use "pure" Perl syntax,
Yes, I have: meta-level (Perl) manipulation of object-level (HTML) is my credo.
feel free to use heredocs and interpolation tricks to generate your page templates,
May I use HTML::Seamstress as part of my heresy? ;-)
| [reply] [d/l] |