On Fri, Sep 18, 2009 at 6:17 AM, Nathan Weizenbaum <nex...@gmail.com> wrote:
> I've integrated this into Ruby Haml as of
> http://github.com/nex3/haml/commit/7bf25c4e30c88719fa37e9f01f3fcd03429a9d19.
Great - I'm glad you find it useful!
> However, I'd like to make a few suggestions:
>
> Future-proof it. Rather than having the tests be Haml/HTML pairs, make them
> be objects with properties: {"haml": haml_code, "html": html_code}. Then if
> we want to add more attributes later (see below) it's easy.
> Name each of the tests. I like that the groups are named, but I think the
> individual tests should be, too. This helps in debugging, and it helps to
> keep track of exactly what each test is testing (which in turn helps us make
> sure that all the functionality is tested). I know this is a pain, but after
> having generated a lot of Haml tests, many without explanation as to their
> purpose, I find myself pretty befuddled when I go back and look and afraid
> that if I remove any of them I'll stop testing some functionality that's not
> tested anywhere else.
> Make the locals a property of the individual test, rather than an assumed
> global thing. This will make keeping track of the locals easier.
> Test trailing whitespace. Always having exactly one trailing newline is a
> usability issue.
> Test whitespace-only documents. Make sure various documents that produce
> only whitespace produce one and only one trailing newline.
> Minor nitpick: instead of "portable-style attributes", "HTML-style
> attributes". This is what I've been calling them pretty consistently. As a
> side note, we need to decide at some point if this will be the only style of
> attribute mandated for all Haml implementations.
Thanks for the feedback. I think these are all great ideas, and I'll
start implementing them today.
I had actually considered making a more detailed JSON format for the
tests, but honestly I wanted to see if anyone else was going to use it
before putting in the time. Now that I know it's going to be used by
more than just me I'm a lot happier to put in the time necessary to
make it awesome rather than just adequate. :-)
Having the tests be objects rather than simple arrays will also let us
incoroporate tests that are expected to produce errors/failures; we
can add a field to the object that indicates the expected test
outcome. Right now the tests only validate the "happy path," which is
usually significantly less than half the battle. The current set of
Haml error tests is really solid so I can probably incorporate most of
them as-is once I get the new format in place.
Regards,
Norman
Well, Ruby-style attribute hashes are not simply passed through
untouched to Ruby, Haml does a fair bit of processing on them. So
while the syntax is inspired by Ruby, from the precompiler's
standpoint it is part of the Haml language. As a point of comparison,
this is different from script given after "=" and "-" operators which
is sent through to be executed by the renderer untouched, so from the
precompiler's standpoint is an external language hosted by Haml.
So, because Ruby-style attributes are *a part of Haml* and *not just
Ruby,* I think it's reasonable to expect non-Ruby versions of Haml to
support the syntax of Ruby-style attributes. I have already added
support for them to Lua Haml and it was almost exactly as much work as
adding support for HTML-style attributes; if anything it was easier.
-Norman
> That's about it. As an example of what I'm thinking a test should look like,
> see
> http://github.com/nex3/haml/commit/7bf25c4e30c88719fa37e9f01f3fcd03429a9d19.
> Thanks for all your work on this, Norman!
OK, I've committed tests in the new JSON format and updated the Ruby
and Lua test runners. In addition to locals, I added configs in the
JSON in order to test different outputs for xhtml, html4, html5, etc.
I still haven't added the tests for badly formed Haml. Still very much
a work in progress, but getting better!
-Norman
Well, Ruby-style attribute hashes are not simply passed through
untouched to Ruby, Haml does a fair bit of processing on them. So
while the syntax is inspired by Ruby, from the precompiler's
standpoint it is part of the Haml language. As a point of comparison,
this is different from script given after "=" and "-" operators which
is sent through to be executed by the renderer untouched, so from the
precompiler's standpoint is an external language hosted by Haml.
So, because Ruby-style attributes are *a part of Haml* and *not just
Ruby,* I think it's reasonable to expect non-Ruby versions of Haml to
support the syntax of Ruby-style attributes. I have already added
support for them to Lua Haml and it was almost exactly as much work as
adding support for HTML-style attributes; if anything it was easier.
I'm just wondering, why *not* implement them? Is it just because it
"looks like Ruby?" Haml already looks freaking bizarre the first time
you see it anyway, so I don't know if that matters.
If it's *not* required then the tacit recommendation would seem to be,
if you want your Haml to be "as good" as the Ruby one, then implement
HTML-style, and a style that's local to your language:
Ruby: #id{ :hello => "world" }
PHP: #id( "hello" => "world" )
Lua: #id{ hello = "world" }
Python: #id{ "hello": "world" }
My point was, that Ruby Haml doesn't just get the :key => "value"
syntax magically, there's work involved, and it's going to be the same
work for Python Haml to support "key": "value" as :key => "value". So
the question is, is the syntax part of Ruby or part of Haml? Because
if it's part of Haml, then the recommendation should be to implement
it. If we consider it part of Ruby, and say "implement it if you want
to," then people will likely end up doing something like their local
language rather than the "Ruby" style.
I see the syntax as part of Haml and think there's long-term benefit
to the language being uniform across platforms. But I can imagine some
people may also see a beneift to having a syntax more similar to the
host language. So I guess you have to weight the beneifts of
idiomacity vs. the beneifts of uniformity.
-Norman
Yes, I'm going to add that soon - it's a work in progress! I've become a bit busy with some other things at the moment, but I should have the error tests in place in another week or so.
-Norman
On Sep 30, 2009 7:28 AM, "Steve Wagner" <li...@lanwin.de> wrote:
You did a nice work, but shouldn't there be also an spec what no should
work?
In example this could lists something like "%%meta" with position 1 and
length 1.
With this all haml parsers behave similar in error cases.
Steve
Norman Clarke schrieb:
> Hello, > > A few months back we had a discussion on the list about coming up with > a set of gene...
--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subs...
I meant to say, I definitely agree with your suggestion and plan on
getting that in there as soon as I can. :-)
It's the same as above; the order of CSS classes in an HTML "class"
attribute is irrelevant. When I saw this I looked it up because I
expected order to be relevant here to *cascading* style sheets, but
surprisingly, it's not. I assume the alphabetical sort here is also
intended to provide a deterministic output.
> @Norman: Eventually would it be nice to add some notes to the spec how
> about this sorting.
Agreed. I realized once I started working on this that JSON,
surprisingly, does not allow comments. I suppose we could add a
"comment" field to the test objects in order to store the comment as
part of the code. Another possibility it to switch to YAML, (JSON is
actually a proper subset of YAML), but how "weird" is YAML for .NET,
Python or Ruby developers? Would it be worth making the change?
I do see the lack of an explanation for some of the tests as a
usability problem.
-Norman
@Nathan: Should we assume here also alphabetical order? I would suggest
to don use there parsing order since otherwise the attributes could only
be sorted if all dynamics are inferred.
>> @Norman: Eventually would it be nice to add some notes to the spec how
>> about this sorting.
>
> Agreed. I realized once I started working on this that JSON,
> surprisingly, does not allow comments. I suppose we could add a
> "comment" field to the test objects in order to store the comment as
> part of the code. Another possibility it to switch to YAML, (JSON is
> actually a proper subset of YAML), but how "weird" is YAML for .NET,
> Python or Ruby developers? Would it be worth making the change?
-1 As far as i know is there currently no good YAML Parser for .Net and
i think another optional argument would be ok. An alternative would be a
specs.txt where this constrains are described as text.
Steve
>> Agreed. I realized once I started working on this that JSON,
>> surprisingly, does not allow comments. I suppose we could add a
>> "comment" field to the test objects in order to store the comment as
>> part of the code. Another possibility it to switch to YAML, (JSON is
>> actually a proper subset of YAML), but how "weird" is YAML for .NET,
>> Python or Ruby developers? Would it be worth making the change?
>
> -1 As far as i know is there currently no good YAML Parser for .Net and
> i think another optional argument would be ok. An alternative would be a
> specs.txt where this constrains are described as text.
Ok, I think I'd prefer a comment field in the JSON itself, to make it
easier to read things in context. I'll be traveling a bit over the
next 2 weeks but will try to find some time to work on this when I
can.
Hi Norman, i have some more suggestion and one problem.
I would suggest to do the numbering of the tests in the following way.
Give each group a unique number. In example 11 for group interpolation.
Then number each test and prefix it with the group number so that all
tests look like this.
11001: interpolation inside code
If i now want to search or ignore a test, i have to only search for the
number.
In general what is missing are tests with more lines to test the exact
indentation and exact line break.
Whats also missing are tests with multiline |.
Also are tests which answer some special situation like what is the
output of the following haml.
:plain
test
%p
test
Also what is missing is when the } in the interpolation tests is escaped
like this: #{test\}test}.
And then i have a problem the this test:
interpolation: interpolation inside code
%p= "#{var}"
>> Give each group a unique number. In example 11 for group interpolation.
>>
>> Then number each test and prefix it with the group number so that all
>> tests look like this.
>>
>> 11001: interpolation inside code
>
> I'm not sure I like numeric ids... it seems like they'd clutter stuff up.
> What's wrong with just going on the name of the test?
Agreed, I really don't want to do this because it will be a nightmare
to maintain. I also don't really understand what would be gained by
having numbers.
>> Whats also missing are tests with multiline |.
>>
>> Also are tests which answer some special situation like what is the
>> output of the following haml.
>>
>> :plain
>> test
>> %p
>> test
>>
>> Also what is missing is when the } in the interpolation tests is escaped
>> like this: #{test\}test}.
So far I've mostly added tests that match the functionality I have
working in Lua Haml, so there's definitely some stuff missing. Like I
said before, it's a work in progress. I would be happy to accept any
additional tests you might want to add.
>>
>> And then i have a problem the this test:
>>
>> interpolation: interpolation inside code
>>
>> %p= "#{var}"
>
> This is definitely Ruby-specific functionality. The = and - operators
> probably shouldn't be tested at all, because they're heavily
> language-specific.
I included a few simple tests for - and = as a compromise, because on
one hand they are language-specific, but on the other hand it's such a
fundamental part of Haml that it just didn't seem right to leave them
out of the tests completely.
A lot of this comes down to where the dividing line between Haml and
Ruby is. Haml draws upon Ruby for some of its features and syntax, and
it's not always clear where Ruby ends and Haml begins.
I'm OK with leaving this one out if you all think it looks too
Rubyish, but it works in Lua Haml. :-) I had to add support for the
#{} interpolation syntax from scratch because Lua doesn't do string
interpolation at all. I thought it worthwhile because I wanted to err
on the side of completeness.
So is string interpolation going to become another problematic thing
like attributes? Is "#{}" part of Ruby or part of Haml, or both?
-Norman
Only because of the much simple exclusion and it also works when test
names change.
Norman Clarke schrieb:
> I believe the last one is different so that you can easily append
> object id's to a base id, for example:
>
> - posts.each do |post|
> #post(id = post.id)
>
> Would output:
>
> <div id='post_1'></div>
> <div id='post_2'></div>
> etc...
>
> I was surprised by this functionality, as I don't think it's in the
> Haml reference docs. I think it seems pretty useful, though. All the
> same I don't have any strong opinion on how Haml *should* handle this,
> I just implemented what was in Ruby Haml.
Ok right makes sens, but then i would suggest to do this for all ids
also for the 4 first ones.
@Nathen whats your meaning about that?
> Sorry I haven't had much time to work on Haml Spec lately, I'm
> wrapping up a couple of big projects, then I should get back to
> implementing some more tests.
No problem, thats what currently there is still really good.
-Steve
The only reason I see for Haml not barfing when someone does #you#me
is because it's already flexible about invalid CSS. Right now Haml
lets you create technically invalid CSS like #000 or #y^y with no
complaints. I think this is the right approach for a template
language: "if you want to create invalid markup/CSS, go right ahead."
I think it's in the same spirit for Haml to silently "repair"
something silly like a tag with 2 ids; for Haml to be loose about
other things and suddenly strict about that would seem out of
character.
So if we're going to do a repair, I agree the most sensible thing is
to treat the id attribute as a hash with multiple assignments to the
same key, leaving the last assignment in place.
--Norman