'ey! Markio!

Mark-ee-oh. Whenever I say that out loud, I think of some generic movie from the early 90s in which Markio and his “crew” “hang out” and shoot “ball”. It goes something like this…

Friend: “Ey Markio! Lets go shoot some ball!”
Markio: “Alright…”

...Others disagree.

Anyway. _why wrote a couple times about a language called Io. Those posts turned me on to a great language. In his second post he wrote an incredibly small DSL for generating basic HTML. It did that pretty well. Not long after that I started working on a little web framework in Io, deemed “Iota”. Am I not clever? Because, really, what does the world need more than another web framework?

I wrote the first version of the framework. And it works. It has a tiny little ORM and a tiny little session manager and a tiny little html generator, not much different from _why’s. However, the whole thing was rather fragile, and written is a very Ruby-esque style. Ruby-style is just not a very good fit for Io.

So, I took it all apart, am rewriting parts of it, and have decided to release it bit by bit. The first bit is Markio. If you can’t tell, I blatantly poached the name from Markaby (Markup as Ruby). I prefer to think of Markio as… Markaby in Io. Markio.

It comes in at well under 100 lines of code, but handles most of the basic things that a markup tool should handle. Lets look at how to use it…

builder := Markio Env clone
builder build(
  html(
    head( title( >"My Spiffy Web Page" ) )
    body(
      div_header( >"Some header crap" )
      div_content(
        span.spiffy( >"Spiffy span" )
        span.spiffy( >"Another spiffy span" )
        a({"href":"/there"}, >"Link to there" )
      )
    )
  )
)

Its pretty easy to see the similarity to Markaby. There are a few significant differences to the syntax though.

First of all, in Markaby if you want a div with the class “foo” and the id “bar”, you’d type something: div.foo.bar!. The equivalent in Markio is div.foo_bar. Why the divergence? Honestly, I can’t stand the exclamation point thing. Thats really it. I originally intended to use a hash instead of an underscore, however it appears that Io isn’t a fan of that. CamelCase is the way things are done in the Io world, so the use of an underscore shouldn’t be too confusing.

Markio was designed to be easily dropped into a framework or some other such thing. Which means that there needs to be an easy way to drop paramaters into it. (The code is evaluated in the context of the Markio Env. I suppose that could change…) If we were going to do some such, it might look like this…

params := {"id":1234, "flash":"Victory is mine!"}
builder := Markio makeEnv(params)
builder build(
  div.flash( >flash )
  span.your-id( >("Your id is: " .. id) )
)

In short, Markio makeEnv takes a Map and clones Env. It then sets new members on it using the keys and values of the Map passed to it.

The last major difference is that you cannot simply output strings and expect them to be appended to the output. There is an internal string which is built up. So, all literal output needs to be added to it. That is why the “>” operator is used. It simply appends the argument to the stream.

You can grab Markio right here!

A few notes: First, you may have noticed the strange Map literal syntax I was using. This isn’t built into Io. But its dead easy to add it. I love Io. Grab the code for that here. Secondly, there are a couple known bugs with Markio. First of all, it does not make self-closing tags at the moment. There is a TODO in the code to make that work. Secondly, setting attributes is a bit odd. If you make the first argument to the tag a Map, it will work… as long as there is another argument. If you pass just a Map (a({"href":"blah"})) it will fail. The simple workaround at the moment is just to pass a nil as a second argument.

Have fun. Let me know if you love it… or hate it… or hate me.

blog comments powered by Disqus