Sha256: 812165249efa6a484a97eebd74fae31d7f4ae3cfa41652b38b820fc74abea120
Contents?: true
Size: 1.71 KB
Versions: 10
Compression:
Stored size: 1.71 KB
Contents
# = htmlbuilder.rb # # == Copyright (c) 2006 Thomas Sawyer # # Ruby License # # This module is free software. You may use, modify, and/or redistribute this # software under the same terms as Ruby. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. # # == Author(s) # # * Thomas Sawyer # Author:: Thomas Sawyer # Copyright:: Copyright (c) 2006 Thomas Sawyer # License:: Ruby License require 'facets/more/xmlbuilder.rb' require 'facets/more/htmlhelper.rb' # = HTMLBuilder # # HTMLBuilder follows the <em>Builder Pattern</em> allowing XML markup to be # constructed via Ruby method calls and block structures. HTMLBuilder is a # subclass of XMLBuilder --see XMLBuilder for more details. class HTMLBuilder < XMLBuilder builder_include HTMLHelper def method_missing( op, *args, &block ) if block_given? @stack << @buffer @buffer = '' body = block.call @buffer = @stack.pop @buffer << builder.element( op, body, *args ) else @buffer << builder.element( op, *args ) end end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test rdoc require 'test/unit' class TCHTMLBuilder < Test::Unit::TestCase def test_01 x = HTMLBuilder.new doc = x.html { x.head { x.title "Test" } x.body { x.p "Hello" x.out.text "Test" } } r = "<html><head><title>Test</title></head><body><p>Hello</p>Test</body></html>" assert_equal( r, doc ) assert_equal( r, x.to_s ) end end =end
Version data entries
10 entries across 10 versions & 1 rubygems