Skip to content

Instantly share code, notes, and snippets.

@tow8ie
Created October 21, 2009 21:39
Show Gist options
  • Save tow8ie/215487 to your computer and use it in GitHub Desktop.
Save tow8ie/215487 to your computer and use it in GitHub Desktop.
A really hacky proof-of-concept of how to model template abstraction by multi-block helper functions.
class Box
def parse(title, &block)
puts "<box>"
puts "<title>#{title}</title>"
block.call(Column.new).parse
puts "<box>"
end
end
class Column
def first(&content)
@first = content
end
def second(&content)
@second = content
end
def third(&content)
@third = content
end
def parse
puts "<col1>#{@first.call}</col1>"
puts "<col2>#{@second.call}</col2>"
puts "<col3>#{@third.call}</col3>"
end
end
Box.new.parse "Neues" do |col|
col.second do
"content of col 2"
end
col.first do
"content of col 1"
end
col.third do
"content of col 3"
end
col
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment