Created
October 21, 2009 21:39
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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