Mislav Marohnić had an interesting idea for extending this. In some
cases, divs are invalid - within a p tag, for example, or an ol. What
if instead of producing a div, an implicit tag would create whatever
makes sense? A span, an li, maybe a tr or td.
When I first started using Haml my brain associated `#foo` and `.foo`
as 'a <div> tag with [id/class] of `foo`'. This change would make the
#/. syntax stand for 'the most appropriate element with the [id/class]
of `foo`'. The switch from being explicitly-implicit to
implicitly-implicit is the source of my uneasiness. One 'implicit' is
pretty magical already.
But! My brain can make this switch in the majority of cases (like the
ones you gave, Mislav) but there are two problem-cases that come to
mind (there might be more or these might be wrong).
Tables:
%table
#foo
thead, tbody and tfoot can go here, right? You might not expect a user
to expect to put an implicit tag here but it's still a syntactical
possibility.
Forms:
%form
#foo
What is supposed to be placed there? There are a number of valid tags
(not span, though, p works) that could be plopped there. Again, this
doesn't make a lot of sense for someone to be doing but it would still
be possible.
Are these really problem-cases or am I missing something? If they are,
would Haml error out or just use the next-best-substitute?
-- Bryce
But! My brain can make this switch in the majority of cases (like the
ones you gave, Mislav) but there are two problem-cases that come to
mind (there might be more or these might be wrong).
Tables:
%table
#foo
thead, tbody and tfoot can go here, right?
Forms:
%form
#foo
What is supposed to be placed there?
Are these really problem-cases or am I missing something? If they are,
would Haml error out or just use the next-best-substitute?
When Haml was originally created, Hampton decided to make it even easier
to create divs than it was to create other sorts of tags by making divs
the default.
Mislav Marohnić had an interesting idea for extending this. In some
cases, divs are invalid - within a p tag, for example, or an ol. What if
instead of producing a div, an implicit tag would create whatever makes
sense? A span, an li, maybe a tr or td.
There are a few potential issues with this. It makes Haml's output more
dependent on the document context than it usually is, and might break a
few templates. On the other hand, you should be thinking about the
context in which you use divs anyway, and any templates it breaks are
invalid anyway.
So I wanted to get the community's opinion on this. Is this something
you'd like? Something you'd dislike? Or does it not really matter to you?
If you want to try it out, grab Mislav's Haml fork at
git://github.com/mislav/haml.git.
- Nathan
I would think...
%ul
.a yo
.b sup
Would translate to...
<ul>
<li class='a'>
yo
<span class='b'>
sup
</span>
</li>
</ul>
Since I don't think a DIV can just be inside a UL.
- Jeff
%ul
.a
yo
.b sup
As far as whether it should have implicit tags, I think it could be a
good thing (time saver), but you should also be able to turn it off.
Sean
As far as whether it should have implicit tags, I think it could be a
good thing (time saver), but you should also be able to turn it off.
Ok, so first off. Fucking A+++++ on unique thoughts. This is probably
the most interesting idea I've heard in a long time. And its a really
interesting extension of what Haml is meant to do and the ways it
makes you think about the documents you are creating. So +100 points
to Mislav for being super-smart.
However, I am pretty solidly against this being default behaviour in
Haml. I shall list the reasons!
* Remembering and figuring out context takes too much brain power.
Having to look up and figure out why something is happening takes too
much time. The programmer should have more power.
* If you are debugging, your first step will have to be View Source
since you will be unaware of what is being created. Your first
instinct is "holy crap it must not be doing the right thing". This
slows you down.
* Nesting partials gets trick, trick, tricky. I can think of many
complex examples where tracking this would be a fucking pain.
* Muddles your assumptions
* Behaviour changing without notice is unnerving.
* Too much "magic" is frightening to programmers.
The only thing I'd consider for "official" syntax is a "GUESS" command.
%table
?
?.name
Data
?.value
Data
I'm just not sure how useful it is. I feel like I want to say "Yeah, I
KNOW what I want there... duh"
Another possibility is building this as an optional pre-parsing.
Install the magic-haml plugin and all templates get put the the ringer
of this magic. That way, core-haml can just focus on what-is-seen....
and the magic can be contained in its own project.
Just my two shits.
-hampton.
PS: I like the line of thought though. I'm still up for convincing.
Yes. +1.
--
Chris Boone, Hypsometry
http://hypsometry.com/
Isn't that a reason to support this idea? Context will be remembered
and figured out for you.
Surprisingly often I find myself wondering "Am I allowed to use a div
here? Or do I need to use a span?" (You'd think I'd have that down by
now.) This enhancement would remove the need to do that.
> * Nesting partials gets trick, trick, tricky. I can think of many
> complex examples where tracking this would be a fucking pain.
I can see that, for sure. But I can also think of cases -- ones I'm
working on right now -- where this smart tag generation would be
helpful, not harmful.
For instance, I'm working on a site with these chunks of content.
(Doesn't really matter what they are.) I've got a standard way of
generating them, using a partial, and I use that partial all over the
place. Sometimes I want the chunks of content to appear in a list,
sometimes just on their own. As it is now, I'm using partial layouts
to wrap the chunks in the appropriate surrounding HTML (li or div, as
needed). It's not difficult or complicated, but it is one extra thing
that I need to keep track of. With these smart tags I wouldn't need to
do that, since Haml would determine the needed tag for me.
> * Too much "magic" is frightening to programmers.
This seems less like magic to me, and more like enforcing best
practices. IMO, it fits in naturally.
* If you are debugging, your first step will have to be View Source
since you will be unaware of what is being created. Your first
instinct is "holy crap it must not be doing the right thing". This
slows you down.
* Nesting partials gets trick, trick, tricky. I can think of many
complex examples where tracking this would be a fucking pain.
The only thing I'd consider for "official" syntax is a "GUESS" command.
%table
?
?.name
Data
?.value
Data
I don't like the idea enough to want to make it the default but I like
it enough to want it as an option.
+1 for 'Guess' Syntax
Fine by me.
I like the concept by itself too, but I'd probably like to either see
it off by default in core or as a separate magic-haml plugin (that
would modify the existing Haml behavior when installed) as Hampton
suggested (I hope he meant that).
The partials... Does the haml in partials normally get compiled and
cached before inclusion into other templates? If that is so, this
magic wouldn't help in generating the correct contextual tag as the
context is non-existent.
If the compilation happens after inclusion, then the magic would
rather aid the programmer, as Chris Boone pointed out.
-- Irfy
2008/3/7, Chris Boone <hypso...@gmail.com>:
* does look nice, but what are we really ~gaining~.
Can someone come up with some examples when the utility of * (or even
the original idea). Like,
"in this situation ____ is easier because _____." But, only examples
that improve both _clarity_ and _efficiency_.
I need these to be compelling problems we run into right now.
-hampton.
>
> Hey folks,
>
> When Haml was originally created, Hampton decided to make it even
> easier to create divs than it was to create other sorts of tags by
> making divs the default.
>
> Mislav Marohnić had an interesting idea for extending this. In some
> cases, divs are invalid - within a p tag, for example, or an ol. What
> if instead of producing a div, an implicit tag would create whatever
> makes sense? A span, an li, maybe a tr or td.
>
> There are a few potential issues with this. It makes Haml's output
> more dependent on the document context than it usually is, and might
> break a few templates. On the other hand, you should be thinking about
> the context in which you use divs anyway, and any templates it breaks
> are invalid anyway.
>
> So I wanted to get the community's opinion on this. Is this something
> you'd like? Something you'd dislike? Or does it not really matter to
> you?
>
> If you want to try it out, grab Mislav's Haml fork at git://
> github.com/mislav/haml.git.
>
> - Nathan
So, to summarize thus far:
- It seems like a good idea, because invalid markup is harder to
create (would it really know the DTDs?)
- It might save typing (or not)
- Surprising things might happen so programmers should be able to
control it
- Maybe an explicit way to invoke it using a "guess" syntax would be
good (or not)
- Partials present a problem because they are compiled first and don't
know about their context
Question: Is Haml likely to succeed at enforcing standards-compliant
(X)HTML or might it just give the illusion of that? If the latter,
then I think this might better be handled in (X)HTML validators that
send you back to your source with your tail tucked between your legs.
Validators can also handle your CSS. Granted, that has to happen on a
per-page basis, but it's pretty darn reliable.
Fair?
It's probably useless to protest, seeing as there is such overwhelming
enthusiasm for this idea, but I'm actually opposed to it.
I don't like the way it takes a piece of syntax and changes what it
means depending on its context. In a markup language, I think any
given token should always mean the same thing, as it makes it easier
to teach, easier to write (because you don't have to think ask
yourself, "What will this syntax produce in this context?") and easier
to read (for exactly the same reason). It just doesn't seem worth it
for the benefit (a few saved keystrokes).
Cheers,
Wincent
-1
Which is a good example of what it would mean to have a guessing
syntax. Is my -1 by you just glancing at it, -1 to not having it or
-1 to having it?
Programming languages and DSLs and markup should provide consistent
behaviour. I don't want to be two partials deep thinking "will this
break something somewhere else?"
besides %li and ? are actually only two keystrokes apart... the time
you would save in typing the two keystrokes you loose overwhelmingly
in having to work out the context you are typing those ? in when you
are looking at it later trying to debug it.
So in this context, my -1 means "no, I do not think this would be an
improvement on HAML"
Mikel
As Irfan Adilovic already pointed out, if you want a <div>, you can
write %div. In some circumstances it would be monumentally useful to
have a context-aware partial that generated the appropriate tag at the
top level -- for rendering a representation of a particular model, for
example, regardless of whether the partial was rendered directly into
the <body>, into a <p>, or into a <ul>.
This behaviour shouldn't be "surprising" if you haven't specified
which tag to output. In many ways it's the least surprising behaviour:
"I haven't given a tag name here, so do whatever is best". Only
familiarity with the meaning of Haml's current syntax would lead you
to expect a <div> where none was specified; if the syntax changed,
future developers wouldn't have the same expectation.
Cheers,
-Tom
Templates are included in a layout, and there we have the same
situation - no context for the outermost tags (right?), but we assume
that div is okay - since that is most common. Should we need anything
else - we'd simply put an explicit tag.
Since we have clarified that we cannot know the context of the partial
while compiling the partial, we could simply make Haml either:
a) fail loudly whenever it encounters a magical tag without context, or
b) generate a div silently, which is simpler, and consistent with
non-partial magic-tag-selection.
If you need a specific tag, you can override it, just as in any other
circumstance.
I'm not sure about this, but it seems the context problem would exist
only for the outermost element(s) in a template/partial (making the
problem that much smaller), correct?
-- Irfan Adilovic
2008/3/11, pangel <pange...@gmail.com>: