Using IronRuby for making a menu macro, but while it works fine in < 4.6, using with a new site running 4.6.1, I can't determine how to reference the Umbraco library any more (although the DynamicNode additions are nice!).
Used to be able to use HTML Encode method in the Umbraco library by:
puts %Q{ <li><a href="#{library.nice_url(child.id)}" class="#{'first' if i == 0} #{'selected' if child.id == currentPage.id}" title="Go to #{child.name}">#{library.html_encode(child.name)}</a></li> }
...
Now need to modify it for Nice URL via child.nice_url, but I can't determine the new library.html_encode(child.name) variation that will work with 4.6. Anyone know the answer?
I should have mentioned that your blog post is what got me started in the beginning (have used variations of it on several projects since with no issues - love getting away from xslt) ;-) Unfortunately, at least in my one-and-only 4.6.1 installation, it doesn't work (specifically any references to Umbraco.Library - I'm assuming because of the new DynamicNode stuff).
Is it just me or have you used it with a 4.6.1 install? Specifically referencing Umbraco.Library? Again, no problems in versions prior to 4.6.x
This however fails when adding the library.HtmlEncode(child.name) in the following:
def print_link(child, i) puts %Q{ <li><a href="#{child.nice_url}" class="#{'first' if i == 0} #{'selected' if child.id == currentPage.id}" title="Go to #{child.name}">#{library.HtmlEncode(child.name)}</a> } end
Remove library.HtmlEncode(child.name)...replaced with just child.name and works fine (but of course, does not HtmlEncode). Therefore, it appears it's only an issue when within $Q to help with " string delimiters.
Making sure it's nothing else, the following also fails:
def print_link(child, i) puts %Q{ <li>#{library.HtmlEncode(child.name)} } end
Specifically, "Error loading MacroEngine script (file: RubyMenu.rb)" (and yes, I know there's only an opening <li> above - it's a nested menu).
Caveat: this is my only 4.6.1 installation, and it does not allow me to save even an empty Ruby script from the GUI without Skip testing (ignore errors) checked (see http://umbraco.codeplex.com/workitem/29913).
And in case it was a problem with string delimiting and needing the curly brace matching pairs, I tried the following:
def print_link(child, i) encoded_name = child.name #puts %Q{ #<li><a href="#{child.nice_url}" class="#{'first' if i == 0} #{'selected' if child.id == currentPage.id}" title="Go to #{encoded_name}">#{encoded_name}</a> #} end
which works. But the following does not:
def print_link(child, i) encoded_name = library.HtmlEncode(child.name) #puts %Q{ #<li><a href="#{child.nice_url}" class="#{'first' if i == 0} #{'selected' if child.id == currentPage.id}" title="Go to #{encoded_name}">#{encoded_name}</a> #} end
I'm it must be a simple issue that I'm just not seeing.
...further, this works!
parent.children.find_all { |c| c.umbraco_navi_hide && c.umbraco_navi_hide != "1" && c.showInNavigation && c.showInNavigation == "Side"}.each_with_index do |child, i| #print_link(child, i + 1) encoded_name = library.HtmlEncode(child.name) puts %Q{ <li><a href="#{child.nice_url}" class="#{'first' if i == 0} #{'selected' if child.id == currentPage.id}" title="Go to #{encoded_name}">#{encoded_name}</a> } #print_list(child) puts '</li>' end
For some reason, putting the print_link logic in the calling method works. Putting library.HtmlEncode(...) anywhere in print_link and refactoring logic over to it always fails. Is this an IronRuby thing? Or an Umbraco issue? Or mine ;-)
EDIT: editor butchering code so reposted without formatting.
A noob I am, but some times good at guessing and googling ;) - and now much more eager to learn Ruby - Total eyeopener for me this, I thought one had to import at least erb.rb or whatever to create such strings with dictionary lookups and even built in function calls. I'm glad I joined this discussion :-) So thanks Ted, and I hope to see more ruby discussed in the umbraco forums.
One more thing, to make code snippets be formatted nicely I usually start with an empty paragraph and format that to Code, then I paste the code snippet into the formatted empty paragraph.
I started running with the IronRuby implementation in Umbraco before Razor came onto the scene. It apears that Razor is now getting a LOT of development love (especially because it's so central in v5) so it appears that would be the route to take going forward (number of blog posts on IronRuby integration versus Razor is a good indicator ;-)
For IronRuby though, a good place to start (and unfortunately, one of the few blog posts on it...which I would have probably added to if I was planning sticking with IronRuby in Umbraco) is slace's post mentioned above.
Re formatting: good suggestion, although when you go to edit, previous working pastes got mangled upon the second save.
Yeah, not much on Ruby on the forums, I know. There's two things that is really nice with Ruby in Umbraco over Python, one is this %Q which allows for a nice mix with tags and code - might be a way in Python also, but I never found it without importing some lib. And also Ruby has a slightly better implementation in Umbraco than Python - script path can be setup in a config file, so imports are made very nice. Speaking of imports - that is not (yet) possible with Razor (afaik) in Umbraco. Until it is I'd say Ruby is the best overall macro language for Umbraco. For now my only concerns is the class casing rules which requires the
Umbraco=Object.const_get("umbraco")
, and the somewhat strange (in my eyes) syntax in some cases.
IronRuby, Umbraco 4.6.1, and Library methods
Using IronRuby for making a menu macro, but while it works fine in < 4.6, using with a new site running 4.6.1, I can't determine how to reference the Umbraco library any more (although the DynamicNode additions are nice!).
Used to be able to use HTML Encode method in the Umbraco library by:
umbraco = Object.const_get("umbraco")
library = umbraco.const_get("library")
...
puts %Q{
<li><a href="#{library.nice_url(child.id)}" class="#{'first' if i == 0} #{'selected' if child.id == currentPage.id}" title="Go to #{child.name}">#{library.html_encode(child.name)}</a></li>
}
...
Now need to modify it for Nice URL via child.nice_url, but I can't determine the new library.html_encode(child.name) variation that will work with 4.6. Anyone know the answer?
Thanks,
Ted
I did a blog post on how to do a menu in IronRuby - http://www.aaron-powell.com/umbraco-menu-with-ironruby
Hopefully it helps :)
Slace,
I should have mentioned that your blog post is what got me started in the beginning (have used variations of it on several projects since with no issues - love getting away from xslt) ;-) Unfortunately, at least in my one-and-only 4.6.1 installation, it doesn't work (specifically any references to Umbraco.Library - I'm assuming because of the new DynamicNode stuff).
Is it just me or have you used it with a 4.6.1 install? Specifically referencing Umbraco.Library? Again, no problems in versions prior to 4.6.x
Thanks,
Ted
What's the error message you're receiving?
I *think* that there's a url property of the dynamic node that is used so you don't need library for that
Hm, the non-ruby-namestandard way works for me:
umbraco = Object.const_get("umbraco")
library = umbraco.const_get("library")
puts library.HtmlEncode("åäö")
puts library.NiceUrl(1070)
Jonas,
This works:
This however fails when adding the library.HtmlEncode(child.name) in the following:
Remove library.HtmlEncode(child.name)...replaced with just child.name and works fine (but of course, does not HtmlEncode). Therefore, it appears it's only an issue when within $Q to help with " string delimiters.
Making sure it's nothing else, the following also fails:
Specifically, "Error loading MacroEngine script (file: RubyMenu.rb)" (and yes, I know there's only an opening <li> above - it's a nested menu).
Caveat: this is my only 4.6.1 installation, and it does not allow me to save even an empty Ruby script from the GUI without Skip testing (ignore errors) checked (see http://umbraco.codeplex.com/workitem/29913).
And in case it was a problem with string delimiting and needing the curly brace matching pairs, I tried the following:
def print_link(child, i)
encoded_name = child.name
#puts %Q{
#<li><a href="#{child.nice_url}" class="#{'first' if i == 0} #{'selected' if child.id == currentPage.id}" title="Go to #{encoded_name}">#{encoded_name}</a>
#}
end
which works. But the following does not:
def print_link(child, i)
encoded_name = library.HtmlEncode(child.name)
#puts %Q{
#<li><a href="#{child.nice_url}" class="#{'first' if i == 0} #{'selected' if child.id == currentPage.id}" title="Go to #{encoded_name}">#{encoded_name}</a>
#}
end
I'm it must be a simple issue that I'm just not seeing.
...further, this works!
parent.children.find_all { |c| c.umbraco_navi_hide && c.umbraco_navi_hide != "1" && c.showInNavigation && c.showInNavigation == "Side"}.each_with_index do |child, i|
#print_link(child, i + 1)
encoded_name = library.HtmlEncode(child.name)
puts %Q{
<li><a href="#{child.nice_url}" class="#{'first' if i == 0} #{'selected' if child.id == currentPage.id}" title="Go to #{encoded_name}">#{encoded_name}</a>
}
#print_list(child)
puts '</li>'
end
For some reason, putting the print_link logic in the calling method works. Putting library.HtmlEncode(...) anywhere in print_link and refactoring logic over to it always fails. Is this an IronRuby thing? Or an Umbraco issue? Or mine ;-)
EDIT: editor butchering code so reposted without formatting.
Hi,
wow, nice syntax! I didnt think this %Q thing was built in ironruby by default. Seriously cool. (Ruby noob as I am).
To make library work inside functions it's necessary to declare it as global with a $:
Jonas - awesome! Knew it had to be simple...and if you're a Ruby noob, then what does that make me ;-)
A noob I am, but some times good at guessing and googling ;) - and now much more eager to learn Ruby - Total eyeopener for me this, I thought one had to import at least erb.rb or whatever to create such strings with dictionary lookups and even built in function calls. I'm glad I joined this discussion :-) So thanks Ted, and I hope to see more ruby discussed in the umbraco forums.
Cheers!
One more thing, to make code snippets be formatted nicely I usually start with an empty paragraph and format that to Code, then I paste the code snippet into the formatted empty paragraph.
Jonas,
I started running with the IronRuby implementation in Umbraco before Razor came onto the scene. It apears that Razor is now getting a LOT of development love (especially because it's so central in v5) so it appears that would be the route to take going forward (number of blog posts on IronRuby integration versus Razor is a good indicator ;-)
For IronRuby though, a good place to start (and unfortunately, one of the few blog posts on it...which I would have probably added to if I was planning sticking with IronRuby in Umbraco) is slace's post mentioned above.
Re formatting: good suggestion, although when you go to edit, previous working pastes got mangled upon the second save.
Thanks again for the answers above!
You are welcome :)
Yeah, not much on Ruby on the forums, I know. There's two things that is really nice with Ruby in Umbraco over Python, one is this %Q which allows for a nice mix with tags and code - might be a way in Python also, but I never found it without importing some lib. And also Ruby has a slightly better implementation in Umbraco than Python - script path can be setup in a config file, so imports are made very nice. Speaking of imports - that is not (yet) possible with Razor (afaik) in Umbraco. Until it is I'd say Ruby is the best overall macro language for Umbraco. For now my only concerns is the class casing rules which requires the
, and the somewhat strange (in my eyes) syntax in some cases.
Cheers
is working on a reply...