Clarification on use of "param" in tags

21 views
Skip to first unread message

Raklet

unread,
Sep 11, 2011, 8:40:33 PM9/11/11
to hobo...@googlegroups.com
I'm working my way through the "Rapid Rails 3 with Hobo" guide and am starting to dive into DRYML.

If I understand it correctly, I believe that saying

<span param>  is the same as  <span param="span">

Is that correct?


Second question is a little more difficult to explain.  Let me post some code from the examples in the book and then ask my question.

<def tag="messages">
<br/><br/>
<ul>
<li param="msg1">Message 1</li>
<li param="msg2">Message 2</li>
<li param="msg3">Message 3</li>
</ul>
</def>

<def tag="more-messages">
<messages merge>
<msg2: param>Message 2 Changed</msg2:>
</messages>
</def>

In the new tag "more-messages", is it necessary to state that msg2 is a param "<msg2: param>"?  Because through trying different combinations of things, I've found that it doesn't make any difference whether param is stated or not.  DRYML still knows that msg2 is a param and displays whatever value is passed to it.



<def tag="more-messages">
<messages merge>
<msg2:>Message 2 Changed</msg2:>
</messages>
</def>

This code (without "param" stated) works the exact same as the snippet above.  If "param" is needed, why does it work without it?  And if it is not needed, why is it stated in the code?  Is it for clarity?  Doesn't the proceeding ":" indicated the same thing?


Thanks for any help you can give,

Tyler

 




kevinpfromnm

unread,
Sep 12, 2011, 3:31:11 PM9/12/11
to hobo...@googlegroups.com
param is needed only when defining a new parameter and by default, it adds a parameter with the same name as the tag.  As you're using the existing one to modify code, it still exists in this new tag.  A caveat is needed there, if you use the replace keyword when calling a parameter, it will replace the whole tag, including the spot for the parameter.  If however, you had a parameter inside that parameter, you would need to redefine it as you're replacing the contents of the parent.

For example you had a message-link2 param inside, by calling the parent, that tag would no longer exist.


<def tag="messages">
<br/><br/>
<ul>
<li param="msg1">Message 1</li>
<li param="msg2">Message 2 <a param="message-link2" /></li>
<li param="msg3">Message 3</li>
</ul>
</def>

<def tag="more-messages">
<messages merge>
<msg2:>Message 2 Changed <a param="message-link2" /></msg2:>
</messages>
</def>

Make sense?

Raklet

unread,
Sep 13, 2011, 9:24:48 AM9/13/11
to hobo...@googlegroups.com
Yes, I can see that "message-link2" is no longer available in a new tag that is merged from an old.  It must be recreated in the new tag in order to still be available.

Now that I've had time to think about it and you introduced the topic of nested tags, I understand and can answer my question if someone were to ask me about it, but I'm still also thinking in terms of clarity for the book and a beginner that is reading it.  The book presents itself as a step-by-step guide for beginners that have no knowledge of Hobo / DRYML / Ruby.

One sees the use of param from the start of the book

<header: param>
<body: param>
etc

Ok, no problem.  The book even states that it won't give all the details immediately.  Read along to chapter 4 and start the discussion of DRYML.  The topic of tag parameters is brought up on page 150 "Parameterize the tag".  Several pages follow, describing how to use parameters in tags.  Everything is great so far.  Clearly written and well explained.  Arrive at page 155.  Move on to a new topic "Define a tag based on another tag".  I say to myself "Great, a new topic.  My knowledge of parameters must be complete".  But then, in the first block of code given I see this:

<msg2: param>.....

Whoa, wait a minute!  What does that mean?  They didn't discuss the word "param" all by itself and what it might mean....and here are introduced doubts or confusion to the uninformed but perceptive reader.

At least that was my experience.  So, I started playing with code examples to see what it might do or not do.  I don't really know what it does, except I can discover from the code that it seems to work fine with or without the word "param" being stated.  There is no mention whatsoever of the word "param" by itself creating a parameter with the same name as the tag until almost 100 pages later on page 246.  I think that is too long to go before explaining it.  It ought to be covered under the topic of "Parameterize a tag".  It doesn't have to be complex - just explain the basics of the thing.  A note could even be added that more advanced topics (such as the nested tag example you gave above) will be covered later.


Tyler




 


Reply all
Reply to author
Forward
0 new messages