lib/markaby/builder.rb in markaby-0.9.3 vs lib/markaby/builder.rb in markaby-0.9.4

- old
+ new

@@ -95,24 +95,13 @@ def helper=(helper) @_helper = helper end - def metaclass(&block) - metaclass = class << self; self; end - metaclass.class_eval(&block) - end - - private :metaclass - def locals=(locals) locals.each do |key, value| - metaclass do - define_method key do - value - end - end + define_singleton_method(key) { value } end end # Returns a string containing the HTML stream. Internally, the stream is stored as an Array. def to_s @@ -243,20 +232,26 @@ # Every tag method in Markaby returns a Fragment. If any method gets called on the Fragment, # the tag is removed from the Markaby stream and given back as a string. Usually the fragment # is never used, though, and the stream stays intact. # # For a more practical explanation, check out the README. - class Fragment < ::Builder::BlankSlate + class Fragment < BasicObject def initialize(*args) @stream, @start, @length = args @transformed_stream = false end [:to_s, :inspect, :==].each do |method| undef_method method if method_defined?(method) end + def to_s + transform_stream unless transformed_stream? + @str.to_s + end + alias_method :to_str, :to_s + private def method_missing(...) transform_stream unless transformed_stream? @str.__send__(...) @@ -269,10 +264,10 @@ def transform_stream @transformed_stream = true # We can't do @stream.slice!(@start, @length), # as it would invalidate the @starts and @lengths of other Fragment instances. - @str = @stream[@start, @length].to_s + @str = @stream[@start, @length].join.to_s @stream[@start, @length] = [nil] * @length end def transformed_stream? @transformed_stream