Links
Tags
apache
armenia
books
bsd
c
c++
chips
cinema
concurrency
cooking
database
dragonfly
erlang
filesystem
freebsd
fun
hardware
java
javascript
json
languages
linux
lyric
mac_osx
mail
math
misc
music
personal
poems
presentation
programming
python
references
ruby
rubyjs
scm
software
spiking_neural_net
study
sysadm
sysarch
technology
testing
travel
virtualization
web
wee
windows
For my blogging software I am using Tenjin as template engine. I also tried Kwartz which is also very nice. With Tenjin you embed Ruby into HTML code, in the same way as you’d do in Erb or PHP. This turns out to get pretty ugly. Kwartz completely separates HTML from presentation logic. It is a nice concept, but the presentation logic file can get quite complex for just simple things.
So why not embed HTML in Ruby?
# Example for embedding HTML in Ruby :)
class MyView
def render(posts)
for post in posts
render_post(post)
end
end
def render_post(post)
#<div id="${post.id}">
if post.abstract?
#<p>${post.abstract}</p>
else
#<p>${post.body}</p>
end
#</div>
end
end
I think you got the idea, right? I just misuse comments to embed HTML in Ruby. This is very easy to parse and looks quite nice in an editor and it should be easy to tell vim to colorize the embedded HTML correctly. Note that everything that starts with “#<” would be embedded HTML so that you’d still be able to use regular Ruby comments.