Say I have the following tag def:
<def tag="comp" attrs="title">
comp(<%= title %>) {
<header param="hd"/>
<body param="bd"/>
<footer param="ft"/>
}
</def>
And I call it like this:
<comp title="A">
<ft:>
<my-footer/>
</ft>
</comp>
should render: "comp(A) { footer : Myfooter}"
-------------------------------------------
<comp title="B">
<hd:>
<my-header/>
</hd>
<ft:>
<my-footer/>
</ft>
</comp>
should render: "comp(A) { header : MyHeader, footer : Myfooter}"
-------------------------------------------
<comp title="C">
<hd:>
<my-header/>
</hd>
<bd:>
<my-body/>
</bd>
<ft:>
<my-footer/>
</ft>
</comp>
should render: "comp(C) { header : MyHeader, body : MyBody, footer :
Myfooter}"
---
proposed utility function to be used from within DRYML templates:
# params are in runtime really just Proc instances that can be called
def not_empty(param) {
if param
res = param.call
return !param.blank?
end
false
}
Where should you put such a general purpose utility function?
In ApplicationHelper? What about if I want such utility functions for
DRYML to be reused in multiple Hobo apps. Should I put this in a
plugin? How do I make it easily accessible from within DRYML
tamplates?
Should I extend DRYML somehow?
in the Hobo code base I see there is a Hobo::HoboHelper module with a
lot of the utility functions mentioned in various Hobo guides...
"When you extend a module, you are adding the methods of that specific
module into the object instance you call “extend”. So, the methods of
that module will only be available at that specific instance (and not
all objects of that class), other objects of the same class will not
have the methods of the module available. With this, you can add
specific behaviors to just one object of your system, without changing
the other ones."
But I guess I could "extend" it globally like this? :
vendor/plugins/myextensions/lib/customhelper.rb
module Hobo
module HoboHelper
... # custom helper functions
end
end
-------------------------------------------
A proposed solution (in pseudo code) for the problem sketched out
above:
<def tag="comp" attrs="title">
comp(<%= title %>) {
<header param="hd"/>
<% comma1 = not_empty(parameters[:hd]) %>
<%= "," if comma %>
<body param="bd"/>
<% comma2 = not_empty(parameters[:bd]) %>
<%= "," if comma1 || comma2 %>
<footer param="ft"/>
}
</def>
Same as the following? (DRYML pseudo-code)
<def tag="comp" attrs="title">
comp(<%= title %>) {
<if test="¬_empty(parameters[:hd])">
<header param="hd"/>
<set name="comma1">true</set>
</if>
<if test="&comma1">,</if>
<if test="¬_empty(parameters[:bd])">
<body param="bd"/>
<set name="comma2">true</set>
</if>
<if test="&comma1 || comma2">,</if>
<footer param="ft"/>
}
</def>
Looks ugly as hell!!!
Is there a more elegant DRYML approach out there for this sort of
logic?
Kristian
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en
-~----------~----~----~----~------~----~------~--~---