# Markaby

**URL:** <https://www.ruby-forum.com/t/markaby/100047>\
**Category:** Radiant CMS\
**Created:** [July 26, 2006, 8:39pm UTC](https://www.ruby-forum.com/t/markaby/100047 "2006-07-26T20:39:03Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Caylan\_Van\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Caylan\_Van\_L](https://www.ruby-forum.com/u/Caylan_Van_L)\
**Post date:** [July 26, 2006, 8:39pm UTC](https://www.ruby-forum.com/t/markaby/100047/1 "2006-07-26T20:39:03Z")

</div>

What’s the possibility of having a markaby filter, or markaby in the  
layouts?

* * *

Caylan

---

<div class="post-metadata">

**Author:** ![Caylan\_Van\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Caylan\_Van\_L](https://www.ruby-forum.com/u/Caylan_Van_L)\
**Post date:** [July 26, 2006, 8:42pm UTC](https://www.ruby-forum.com/t/markaby/100047/2 "2006-07-26T20:42:15Z")

</div>

What an excellent idea! I’ve yet to hack around with the filters, but  
now I  
definitely want to. Anyone have any thoughts on how easy / ridiculous  
this  
would be to implement?

The only problem I can see is that as pretty as Markaby is in pure Ruby,  
the  
Radius tags sort of ruin the effect with their \<\> nonsense 🙂

\ Dean

---

<div class="post-metadata">

**Author:** ![Caylan\_Van\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Caylan\_Van\_L](https://www.ruby-forum.com/u/Caylan_Van_L)\
**Post date:** [July 26, 2006, 9:11pm UTC](https://www.ruby-forum.com/t/markaby/100047/3 "2006-07-26T21:11:35Z")

</div>

Before:

- 

After:

ul.blog\_archive do  
r.find :url =\> ‘/articles’ do  
r.children.each :order =\> :desc do  
li do  
p.date { span.highlight date.format("%b %d, %Y") }  
h5 r.link  
end  
end  
end  
end

Rough and full of typos, logic errors, and cyanide.

* * *

Caylan

---

<div class="post-metadata">

**Author:** ![Caylan\_Van\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Caylan\_Van\_L](https://www.ruby-forum.com/u/Caylan_Van_L)\
**Post date:** [July 26, 2006, 10:22pm UTC](https://www.ruby-forum.com/t/markaby/100047/4 "2006-07-26T22:22:16Z")

</div>

Okay, I just looked into the code & I still see a problem here. . .  
unfortunately. Radiant’s filters run after any \<r: /\> tags have been  
processed, and Radiant uses the Radius system to do all its custom tags.  
As  
I see it, you’d have to rewrite quite a bit of Radius to make this work  
like  
you’ve written it. I don’t see any other way to turn things like \<r:find  
/\>  
into r.find.

Disclaimer: I could be completely wrong about this 🙂

\ Dean

---

<div class="post-metadata">

**Author:** ![Caylan\_Van\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Caylan\_Van\_L](https://www.ruby-forum.com/u/Caylan_Van_L)\
**Post date:** [July 28, 2006, 10:02pm UTC](https://www.ruby-forum.com/t/markaby/100047/5 "2006-07-28T22:02:44Z")

</div>

On Jul 26, 2006, at 5:11 PM, John W. Long wrote:

> Caylan Van L. wrote:
> 
> > What’s the possibility of having a markaby filter, or markaby in the  
> > layouts?
> 
> This would make a great plugin. Probably the thing to do would be to  
> override Behavior::Base#render\_page, but you might be able to override  
> Behavior::Base#parse\_object (which is the method that actually parses  
> the layouts).

Not to be naive, but where are these defined? I’m using locomotive.

Is there an easy ruby way to figure that out? For instance…  
starting IRB and loading the class, then asking it where it’s defined?

* * *

Caylan

---

<div class="post-metadata">

**Author:** ![Caylan\_Van\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Caylan\_Van\_L](https://www.ruby-forum.com/u/Caylan_Van_L)\
**Post date:** [July 27, 2006, 12:13am UTC](https://www.ruby-forum.com/t/markaby/100047/6 "2006-07-27T00:13:56Z")

</div>

Caylan Van L. wrote:

> What’s the possibility of having a markaby filter, or markaby in the  
> layouts?

This would make a great plugin. Probably the thing to do would be to  
override Behavior::Base#render\_page, but you might be able to override  
Behavior::Base#parse\_object (which is the method that actually parses  
the layouts).

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<div class="post-metadata">

**Author:** ![Caylan\_Van\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Caylan\_Van\_L](https://www.ruby-forum.com/u/Caylan_Van_L)\
**Post date:** [July 29, 2006, 6:45am UTC](https://www.ruby-forum.com/t/markaby/100047/7 "2006-07-29T06:45:15Z")

</div>

On 28-Jul-06, at 3:59 PM | Jul 28, Caylan Van L. wrote:

> Not to be naive, but where are these defined? I’m using locomotive.

Whenever I’m stumped about where a method definition is, I just do a  
search for “def method\_name.” If you happen to use TextMate, you can  
easily do a project-wide search with command-shift-f and you usually  
have the answer in a few short seconds. Otherwise, you could just  
keep a terminal window open in the root of your radiant app for using  
grep, or something similar.

James

---

<div class="post-metadata">

**Author:** ![Caylan\_Van\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Caylan\_Van\_L](https://www.ruby-forum.com/u/Caylan_Van_L)\
**Post date:** [July 28, 2006, 10:56pm UTC](https://www.ruby-forum.com/t/markaby/100047/8 "2006-07-28T22:56:52Z")

</div>

Caylan Van L. wrote:

> Not to be naive, but where are these defined? I’m using locomotive.

Behavior::Base is defined in app/models/behavior.rb:

[http://dev.radiantcms.org/radiant/browser/trunk/radiant/app/models/behavior.rb](http://dev.radiantcms.org/radiant/browser/trunk/radiant/app/models/behavior.rb)

> Is there an easy ruby way to figure that out? For instance…  
> starting IRB and loading the class, then asking it where it’s defined?

No. Ruby doesn’t makes it easy for you to get at that information.

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<div class="post-metadata">

**Author:** ![Caylan\_Van\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Caylan\_Van\_L](https://www.ruby-forum.com/u/Caylan_Van_L)\
**Post date:** [July 30, 2006, 3:01pm UTC](https://www.ruby-forum.com/t/markaby/100047/9 "2006-07-30T15:01:38Z")

</div>

On 26/07/06, Caylan Van L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> What’s the possibility of having a markaby filter, or markaby in the  
> layouts?

I’ve been experimenting around today trying to get markaby working as  
a filter. I’ve run into a number of problems though so I’m putting it  
out to the mailing list to see if someone can improve it.

Firstly it seems Ruby syntax can only handle simple radius tags  
without parameters. So a simple tag like

h2{r:date}

works but a tag like

r:link(:url=\>“[http://localhost/](http://localhost/)”)

does not, although  
r:link do  
test(“link”)  
end

does work. Also it doesn’t seem to like the {} block delimeters so

r:random {  
r:option {text(“random1”)}  
r:oprion {text(“random2”)}  
}

won’t parse but

r:random do  
r:option do;text(“random1”);end  
r:option do;text(“random2”);end  
end

works.

Anyway here’s the code for the filter I was using. I had to redefine  
parse\_object and change the order of filtering and parsing by radius,  
hopefully that doesn’t cause problems with other filters.

require ‘markaby’

class Behavior::Base  
def parse\_object(object)  
text = object.content  
text = object.filter.filter(text) if object.respond\_to? :filter\_id  
text = parse(text)  
text  
end  
end

class MarkabyFilter \< TextFilter::Base  
register ‘Markaby’

def filter(text)  
Markaby::Template.new(text).render+  
end  
end

Farrel

---

<div class="post-metadata">

**Author:** ![Caylan\_Van\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Caylan\_Van\_L](https://www.ruby-forum.com/u/Caylan_Van_L)\
**Post date:** [July 30, 2006, 5:08pm UTC](https://www.ruby-forum.com/t/markaby/100047/10 "2006-07-30T17:08:26Z")

</div>

Have you guys considered Jim W.'s Builder? Although a bit more  
wordy than Markaby in terms of code, it allows curly braces and you can  
output unescaped text (i.e. Radius tags, if necessary) using the \<\<  
operator. Unlike Markaby, however, it would have to be eval’d in the  
filter method. Here’s an example of how you might do it.

require ‘builder’  
class BuilderFilter \< TextFilter::Base  
register ‘Builder::XmlMarkup’  
def filter(text)  
x = Builder::XmlMarkup.new :indent =\> 2  
eval(text)  
x.target!  
end  
end

Documentation for this filter would obviously have to include what the  
local variable name is for the XmlMarkup object since Builder 2.0  
requires a target for all of its markup calls.

Cheers,

Sean C.  
[seancribbs.com](http://seancribbs.com)
