Jeff-Lewis / nhaml

Automatically exported from code.google.com/p/nhaml
0 stars 0 forks source link

Empty attributes omitted from output #43

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Create a template containing the following:
%img{src="data:image/gif;base64,R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs=
",
alt=""}
2. Render it and view the source
3. Note the lack of an alt="" attribute in the output

What is the expected output? What do you see instead?

There should be an empty alt attribute, but instead nothing is there.

What version of the product are you using? On what operating system?

trunk/Vista

Please provide any additional information below.

Empty attributes are crucial - empty alt attributes are recommended
practice for icons with separate labels and empty value attributes are
necessary for default <select> options.

Original issue reported on code.google.com by epicbiz...@gmail.com on 2 Mar 2009 at 4:44

GoogleCodeExporter commented 9 years ago
I just stepped through the attribute-writing process in the debugger and it 
looks
like the root of the problem is localised at src\NHaml\Utils\Utility.cs:81 
(which
suppresses the attribute if the value is null or empty). Nuking that if 
statement
should clear things up.

Original comment by epicbiz...@gmail.com on 2 Mar 2009 at 4:58

GoogleCodeExporter commented 9 years ago
Here's a patch that should resolve the problem: http://pastie.org/404374

Original comment by epicbiz...@gmail.com on 2 Mar 2009 at 5:07

GoogleCodeExporter commented 9 years ago
Ok i am writing a test for this first before i apply the patch.

Original comment by lanwin...@gmail.com on 2 Mar 2009 at 10:38

GoogleCodeExporter commented 9 years ago
Hmm it is not so simple as it looks like. 

The removing of null attributes is a feature because you can do this: Checked= 
true ?
"true" : null 

I have to think about it. It should be possible to allow nhaml to output empty
attributes.

The best solution would be if the atttribute value is null, then the attribute 
get
removed. If the attribute is String.Emtpy, the the attribute stayes. I will 
test it.

Original comment by lanwin...@gmail.com on 2 Mar 2009 at 11:06

GoogleCodeExporter commented 9 years ago
Yeah, I forgot about that. Your solution sounds good - I think that's how Haml 
does
it (it also omits attributes with a value of (bool)false).

Original comment by epicbiz...@gmail.com on 4 Mar 2009 at 5:33

GoogleCodeExporter commented 9 years ago
Currently i am not sure if it dose the bool false evaluation for all 
attributes. I
think there was an list of attributes in the haml settings for which is dose 
this
evaluation (like checked and selected).

Original comment by lanwin...@gmail.com on 5 Mar 2009 at 10:23

GoogleCodeExporter commented 9 years ago
Ok this is now changed in trunk. The attributes is now only removed if the 
value is
null and not if it is empty.

For the Checked=true case we have another issue:
http://code.google.com/p/nhaml/issues/detail?id=23

Original comment by lanwin...@gmail.com on 16 Mar 2009 at 2:42