The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Thoughts on Vooly

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Christian Neukirchen

Posts: 188
Nickname: chris2
Registered: Mar, 2005

Christian Neukirchen is a student from Biberach, Germany playing and hacking with Ruby.
Thoughts on Vooly Posted: Apr 5, 2005 5:01 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Christian Neukirchen.
Original Post: Thoughts on Vooly
Feed Title: chris blogs: Ruby stuff
Feed URL: http://chneukirchen.org/blog/category/ruby.atom
Feed Description: a weblog by christian neukirchen - Ruby stuff
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Christian Neukirchen
Latest Posts From chris blogs: Ruby stuff

Advertisement

I’ve been using Vooly for ten days now, but not completely as I had it in mind: I wrote entries for Anarchaia using it, inbetween ordinary HTML.

Now, how does this work, actually? Anarchaia is, if you look closely, just a list of certain things, just as

  • Links
  • Flickr images
  • Quotes
  • IRC quotes
  • Lyrics

Each of these get their own Vooly tag, for example links are structured like this:

<<link << URL >>
  << INTRO >> DESCRIPTION >>

Or, as a real example:

<<link << http://www.picotux.com/ >>
  << picotux >>, the world's smallest Linux computer.>>

(IRC-)Quotes and Lyrics behave a bit differently, as there is special non-Vooly syntax used. I do that because it’s easier to write and feels more natural too:

<<quote God not only plays dice in physics but also in pure
mathematics. Mathematical truth is sometimes nothing more than a
perfect coin toss.
--- Gregory Chaitin, A Random Walk in Arithmetic>>

Everything after the --- will get converted to the source.

As you (hopefully) can see, writing repetitive HTML with “macros” like this is much easier than doing it manually (or with XML/XSLT, even!).

Now, let’s see how this actually is implemented: Since Anarchaia is powered by Nukumi2, it’s just a matter of another plugin for it, called AugmentedHTML. This plugin is trivial:

class AugmentedHTML
  def initialize(string)
    @string = string
  end

  def to_html
    v = Vooly::Slurp.new(@string, false)
    data = v.slurp.with_mapping! Decorator::MAPPING
    data.to_s
  end
end

AugmentedHTML uses Vooly::Slurp, a tree-like interface (I prefer this term over DOM) to Vooly documents. It provides a nice method with_mapping! that calls constructors given in the mapping.

For example, for the <<link>>, this looks like:

class Link < Decorator
  TEMPLATE = Kashmir.new(<<EOF)
<p class="link">
  <a href="^href">^title</a>^description
</p>
EOF

  def initialize(href, title, description='')
    @href = href
    @title = title
    @description = description
  end

  def to_s
    TEMPLATE.expand { |e|
      e.href @href
      e.title @title
      e.description @description
    }
  end
end

You can see, I’m exercising all the cool technologies I built in the last months. :-) The important part is the initializer, look how the elements of the document get mapped onto parameters.

Then, we simply call to_s recursively on the Slurp, and voilà, there is our HTML!

Now, this works pretty good, but there are some issues with Vooly with respect to using it that way. One, perhaps minor thing, are syntactic constructs like

<<foo <em>cool</em>>>

This will not work as expected, since the parser will (and has to!) match on the first >> to close the tag. Therefore, I decided to make Vooly drop the very last space of tag content, so you simply write

<<foo <em>cool</em> >>

And it’s not ambiguous anymore.

The more difficult thing is that I can’t use (my beloved) BlueCloth anymore, since BlueCloth (and Markdown in general?) will interpret <foo as unclosed HTML, and ignore that block till it finds the matching <.

This is very unfortunate, but I can’t figure a way how to avoid it. Also, AugmentedHTML must run before BlueCloth, since BlueCloth will also try to escape the “superfluous” angle brackets! I wonder if I should maybe change Vooly brackets to {{ and }}, but these are icky to type (at least on German keyboards), and don’t look and feel as near as cool as << and >> do…

NP: Bright Eyes—Easy/Lucky/Free

Read: Thoughts on Vooly

Topic: life.get_update Previous Topic   Next Topic Topic: Rails on Audioscrobbler

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use