Created
January 8, 2010 05:32
-
-
Save fujimura/271876 to your computer and use it in GitHub Desktop.
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
module SMarkUp | |
def markup(&block) | |
yield | |
end | |
TAGS = %w(body h1 h2 p div) | |
TAGS.each do |tag| | |
send(:define_method, tag) do |*args, &block| | |
r = block.call | |
r = case r | |
when Array | |
"\r\n" + r.join | |
when String | |
r | |
end | |
"<#{tag}#{class_id args.first.to_s}>" + r + "</#{tag}>\n\r" | |
end | |
private | |
end | |
def class_id(name = nil) | |
name ? " id=\"" + name + "\"" : nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment