arnaud-lb / MtHamlBundle

Symfony2 HAML bundle
38 stars 13 forks source link

Documentation with examples #9

Open gentisaliu opened 10 years ago

gentisaliu commented 10 years ago

Some example HAML templates would be in order for devs who are interested in using this bundle in their Symfony projects, focusing on Twig <-> Haml interoperation, e.g.

... and the list goes on. The current documentation/examples are very scarce.

I could help with some use cases with which I had difficulties or I am stuck at, if you like.

arnaud-lb commented 10 years ago

I agree MtHaml needs some examples.

Basically, the rules are as follows:

We could write some examples in the wiki: https://github.com/arnaud-lb/MtHaml/wiki

gentisaliu commented 10 years ago

Thanks for getting back to me... I was wondering whether it is possible to define attribute methods, as per the HAML reference: http://haml.info/docs/yardoc/file.REFERENCE.html#attribute_methods

arnaud-lb commented 10 years ago

Yes, this syntax is supported. The function has to return an array of name=>value.

arnaud-lb commented 10 years ago

Also works with interpolations:

%p(attrs()) // attrs() should return an array
%p(#{attrs}) // attrs() should return a string (e.g. symfony's form_enctype() heper)
gentisaliu commented 10 years ago

Great, though the part I am having difficulties with is in defining the attribute method.

I tried both

def attrs()
     ...
end

- def attrs()
     ...

An illegal nesting exception is thrown in the first case, whereas in the second I get an "Unknown tag name "def"" error.

arnaud-lb commented 10 years ago

def attrs() is how you define a method in ruby. You should use twig syntax ;)

- macro attrs()
    foo="bar" bar="baz"

Since macros in Twig return strings, you should use the #{...} syntax, too:

%p(#{attrs()})
gentisaliu commented 10 years ago

Wonderful, thank you for your timely responses! I'll try and add something to the wiki later.