# File lib/mab/mixin.rb, line 10 def initialize(name, options, context, instance = nil) @_name = name @_options = options @_context = context @_instance = instance @_done = false @_content = nil @_has_content = nil @_attributes = {} @_pos = @_context.size end
# File lib/mab/mixin.rb, line 104 def _attrs_to_s @_attributes.inject("") do |res, (name, value)| if value value = (value == true) ? name : CGI.escapeHTML(value.to_s) res << " #{name}=\"#{value}\"" end res end end
# File lib/mab/mixin.rb, line 53 def _insert(*args, &blk) raise Error, "This tag is already closed" if @_done if !args.empty? && !args[0].is_a?(Hash) content = args.shift raise Error, "Tag doesn't allow content" if @_has_content == false @_has_content = true end if content @_content = CGI.escapeHTML(content.to_s) @_done = true end if !args.empty? _merge_attributes(*args) @_done = true end if block_given? raise Error, "Tag doesn't allow content" if @_has_content == false @_has_content = true @_block = blk @_done = true end if @_content && @_block raise Error, "Both content and _block is not allowed" end @_instance.mab_done(self) if @_done if @_block before = @_context.children res = @_block.call if before >= @_context.children @_content = res.to_s else # Turn the node into just an opening tag. @_has_content = false @_instance.mab_insert("</#{@_name}>") end end self end
# File lib/mab/mixin.rb, line 31 def _merge_attributes(*args) args.each do |attrs| @_attributes.merge!(attrs) end end
# File lib/mab/mixin.rb, line 37 def method_missing(name, *args, &blk) name = name.to_s if name[-1] == !! @_attributes[:id] = name[0..-2] else if @_attributes.has_key?(:class) @_attributes[:class] += " #{name}" else @_attributes[:class] = name end end _insert(*args, &blk) end
# File lib/mab/mixin.rb, line 114 def to_s if !@_context.joining? && @_context[@_pos] @_context[@_pos] = nil @_context.children -= 1 end res = "<#{@_name}#{_attrs_to_s}" res << (@_options[:xml] && !@_block && !@_has_content ? ' />' : '>') res << "#{@_content}</#{@_name}>" if @_has_content res end
Generated with the Darkfish Rdoc Generator 2.