Skip to content

Instantly share code, notes, and snippets.

@solomon081
Created June 2, 2012 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save solomon081/2859964 to your computer and use it in GitHub Desktop.
Save solomon081/2859964 to your computer and use it in GitHub Desktop.
RBHTML
class String
def strpush! push
newstring = push + self
self.replace(newstring)
end
end
class HTMLDocument
private
def refresh_full
@full_doc = @open_doc + @close_doc
end
public
def initialize
@open_doc = "<html><body>"
@close_doc = "</body></html>"
@full_doc = @open_doc + @close_doc
end
def create_element tag, inner
@open_doc += "<#{tag}>#{inner}"
@close_doc.strpush!("</#{tag}>")
refresh_full
end
def remove_element tag, inner
@open_doc.gsub!("<#{tag}>#{inner}", "")
@close_doc.gsub!("</#{tag}>", "")
refresh_full
end
def remove_char char
@open_doc.gsub!(">#{char}", ">")
refresh_full
end
def to_s
@full_doc
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment