lib/livetext/html.rb in livetext-0.9.33 vs lib/livetext/html.rb in livetext-0.9.35

- old
+ new

@@ -1,45 +1,50 @@ -module HTMLHelper +# module HTMLHelper +# +# def wrapped(str, *tags) # helper +# open, close = open_close_tags(*tags) +# open + str + close +# end +# +# def wrapped!(str, tag, **extras) # helper +# open, close = open_close_tags(tag) +# extras.each_pair do |name, value| +# open.sub!(">", " #{name}='#{value}'>") +# end +# open + str + close +# end +# +# def wrap(*tags) # helper +# open, close = open_close_tags(*tags) +# api.out open +# yield +# api.out close +# end +# +# def open_close_tags(*tags) +# open, close = "", "" +# tags.each do |tag| +# open << "<#{tag}>" +# close.prepend("</#{tag}>") +# end +# [open, close] +# end +# end - def wrapped(str, *tags) # helper - open, close = open_close_tags(*tags) - open + str + close - end - - def wrapped!(str, tag, **extras) # helper - open, close = open_close_tags(tag) - extras.each_pair do |name, value| - open.sub!(">", " #{name}='#{value}'>") - end - open + str + close - end - - def wrap(*tags) # helper - open, close = open_close_tags(*tags) - api.out open - yield - api.out close - end - - def open_close_tags(*tags) - open, close = "", "" - tags.each do |tag| - open << "<#{tag}>" - close.prepend("</#{tag}>") - end - [open, close] - end -end - class HTML def initialize(api) + raise "API is nil!" unless api @api = api @indent = 0 end + def api + @api + end + def indented " "*@indent end def indent(which) @@ -67,14 +72,10 @@ def li(**details, &block) wrap(:li, **details, &block) end - def api - @api - end - def open_close_tags(*tags) open, close = "", "" tags.each do |tag| open << "<#{tag}>" close.prepend("</#{tag}>") @@ -85,9 +86,10 @@ def wrap(*tags, **extras) # helper open, close = open_close_tags(*tags) extras.each_pair do |name, value| open.sub!(">", " #{name}='#{value}'>") end +# STDERR.puts "#wrap - @api = #{@api.inspect}\n-----------" api.out indented + open indent(:in) yield indent(:out) api.out indented + close