Markaby

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


Caylan

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 :slight_smile:

\ Dean

Before:

  • Continue Reading…

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

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 :slight_smile:

\ Dean

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

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

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

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

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

On 26/07/06, Caylan Van L. [email protected] 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/”)

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs