Skip to content

Instantly share code, notes, and snippets.

@fujimura
Created January 8, 2010 05:32
Show Gist options
  • Save fujimura/271876 to your computer and use it in GitHub Desktop.
Save fujimura/271876 to your computer and use it in GitHub Desktop.
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