[PATCH] Default attributes for tags

6 views
Skip to first unread message

botanicus

unread,
Dec 7, 2009, 10:28:31 AM12/7/09
to Haml
Hey guys,

I created a patch which get me the chance to have default attributes
for a tag, so if I specify Haml::Engine.new(template,
default_attributes: {script: {type: "text/javascript"}, form:
{:method: "POST"}}, then all the script tags will have type="text/
javascript" and all the forms will have method="POST".

I sent a pull request, however nex3's opinion is that it might lead to
feature bloat in Haml and he recommend me to ask Haml community. So
I'd like to know your opinion, if you think it is good idea or now and
why.

You can find the commit here: http://github.com/botanicus/haml/commit/b709ace0c881fa4ed43b9c0c4927939fbef51af6
It would be probably better not to have any default attributes, I
know, but I think if I remove them then it might be pretty useful
thing.

Cheers,

Jakub Stastny aka Botanicus
http://twitter.com/botanicus
http://twitter.com/RangoProject

Norman Clarke

unread,
Dec 7, 2009, 10:52:29 AM12/7/09
to ha...@googlegroups.com
On Mon, Dec 7, 2009 at 12:28 PM, botanicus <sta...@101ideas.cz> wrote:

I created a patch which get me the chance to have default attributes
for a tag, so if I specify Haml::Engine.new(template,
default_attributes: {script: {type: "text/javascript"}, form:
{:method: "POST"}}, then all the script tags will have type="text/
javascript" and all the forms will have method="POST".

I sent a pull request, however nex3's opinion is that it might lead to
feature bloat in Haml and he recommend me to ask Haml community. So
I'd like to know your opinion, if you think it is good idea or now and
why.


Perhaps I'm missing something, but can't you accomplish the same thing by defining the script tag as a Haml helper?


--Norman

botanicus

unread,
Dec 8, 2009, 7:38:13 AM12/8/09
to Haml
Well, helper is a Ruby method, so you can't just use
%my_helper#id.class{attr: value}.

Jakub Stastny aka Botanicus
http://twitter.com/botanicus

On Dec 7, 3:52 pm, Norman Clarke <com...@gmail.com> wrote:
> http://haml-lang.com/docs/yardoc/Haml/Helpers.html#haml_tag-instance_...
>
> --Norman

Mislav Marohnić

unread,
Dec 8, 2009, 9:43:21 AM12/8/09
to ha...@googlegroups.com
I can't imagine where I would use this. The "type" attribute in a "script" element is redundant, and as for forms, not all are POST and I seldom write forms tags myself (most frameworks should have helpers for generating them).

This is clearly material for Ruby helpers.


>
> --Norman

--

You received this message because you are subscribed to the Google Groups "Haml" group.
To post to this group, send email to ha...@googlegroups.com.
To unsubscribe from this group, send email to haml+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/haml?hl=en.



botanicus

unread,
Dec 8, 2009, 1:28:46 PM12/8/09
to Haml
Fair enough. So nex3 is right, it doesn't make sense to merge it to
core and so I'm putting it to my Rango framework http://github.com/botanicus/rango.

Mislav: Well you might want to have POST as a (more reasonable?)
default and of course you could overwrite it via %form{method: "GET"}.
And of course using helper means losing the choice of doing .class#id
{attr: value} as I mentioned above, not mention for some things you
don't need to use a framework. But never mind.

Thanks for your opinions,

Jakub Stastny aka botanicus
http://twitter.com/botanicus
> > haml+uns...@googlegroups.com <haml%2Bunsu...@googlegroups.com>.

Chris Eppstein

unread,
Dec 8, 2009, 2:43:44 PM12/8/09
to ha...@googlegroups.com
Why do you think the helper has to emit the tag itself? You can have helper functions like this:

%body{body_attributes}

Where the body_attributes function returns a hash. This allows you to use the haml syntax for what it's good at.

Chris

To unsubscribe from this group, send email to haml+uns...@googlegroups.com.

botanicus

unread,
Dec 9, 2009, 11:41:13 AM12/9/09
to Haml
Cheers, but honestly I don't care, this is not what is my patch about.

On Dec 8, 7:43 pm, Chris Eppstein <ch...@eppsteins.net> wrote:
> Why do you think the helper has to emit the tag itself? You can have helper
> functions like this:
>
> %body{body_attributes}
>
> Where the body_attributes function returns a hash. This allows you to use
> the haml syntax for what it's good at.
>
> > haml%2Bunsu...@googlegroups.com<haml%252Buns...@googlegroups.com>

Widi Harsojo

unread,
Dec 9, 2009, 11:42:19 PM12/9/09
to ha...@googlegroups.com
in my implementation (w2tags), I redefine it like this:

!H!script
<script *all*type="javascript">
<</</script>

%script.myjs
$('#content').text('hellow world!');
return false;

Result will be:
<script class="myjs" type="javascript">
$('#content').text('hellow world!');
return false;
</script>

You can try it your self in: http://w2tags.heroku.com/
> --
>
> You received this message because you are subscribed to the Google Groups "Haml" group.
> To post to this group, send email to ha...@googlegroups.com.
> To unsubscribe from this group, send email to haml+uns...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/haml?hl=en.
>
>
>



--
/wh

e=mc2inhologram
Reply all
Reply to author
Forward
0 new messages