lib/zafu/markup.rb in zafu-0.6.0 vs lib/zafu/markup.rb in zafu-0.6.1
- old
+ new
@@ -163,10 +163,14 @@
else
@dyn_params[key] = value
end
end
+ def append_attribute(text_to_append)
+ (@append ||= '') << text_to_append
+ end
+
def append_dyn_param(key, value, conditional = false)
spacer = conditional ? '' : ' '
if prev_value = @params.delete(key)
@dyn_params[key] = "#{prev_value}#{spacer}#{value}"
elsif prev_value = @dyn_params[key]
@@ -187,29 +191,38 @@
params[key] || dyn_params[key]
end
# Duplicate markup and make sure params and dyn_params are duplicated as well.
def dup
- markup = Markup.new(@tag)
- markup.params = @params.dup
- markup.dyn_params = @dyn_params.dup
+ markup = super
+ markup.instance_variable_set(:@params, @params.dup)
+ markup.instance_variable_set(:@dyn_params, @dyn_params.dup)
+ markup.instance_variable_set(:@pre_wrap, @pre_wrap.dup) if @pre_wrap
markup
end
+ # Store some text to insert at the beggining of the tag content on wrap. Inserted
+ # elements are indexed in a hash but only values are shown.
+ def pre_wrap
+ @pre_wrap ||= {}
+ end
+
# Wrap the given text with our tag. If 'append' is not empty, append the text
# after the tag parameters: <li class='foo'[APPEND HERE]>text</li>.
- def wrap(text, *append)
+ def wrap(text)
return text if @done
+
+ text = "#{@pre_wrap.values}#{text}" if @pre_wrap
+
if dyn_params[:id]
@tag ||= 'div'
end
- append ||= []
if @tag
if text.blank? && EMPTY_TAGS.include?(@tag)
- res = "<#{@tag}#{params_to_html}#{append.join('')}/>"
+ res = "#{@pre_wrap}<#{@tag}#{params_to_html}#{@append}/>"
else
- res = "<#{@tag}#{params_to_html}#{append.join('')}>#{text}</#{@tag}>"
+ res = "<#{@tag}#{params_to_html}#{@append}>#{text}</#{@tag}>"
end
else
res = text
end
@done = true
\ No newline at end of file