class Markababy::Builder
Public Class Methods
const_missing(name)
click to toggle source
# File lib/markababy/builder.rb, line 55 def self.const_missing(name) ::Object.const_get(name) end
new(options, &block)
click to toggle source
# File lib/markababy/builder.rb, line 3 def initialize(options, &block) @options = options @output = @options[:output] @escape = @options[:escape] @context = @options[:context] instance_eval(&block) end
Public Instance Methods
context_responds_to?(name)
click to toggle source
# File lib/markababy/builder.rb, line 15 def context_responds_to?(name) @context.respond_to?(name) end
method_missing(sym, *args, &block)
click to toggle source
# File lib/markababy/builder.rb, line 19 def method_missing(sym, *args, &block) if @context && context_responds_to?(sym) return @context.send(sym, *args, &block) end attributes, content = [], [] args.flatten.each do |arg| if arg.respond_to?(:to_hash) arg.to_hash.each { |k, v| attributes << ' %s="%s"' % [@escape[k.to_s], @escape[v.to_s]] } elsif arg.respond_to?(:id2name) attributes << ' %s' % @escape[arg.to_s] elsif arg.respond_to?(:html_safe?) && arg.html_safe? content << arg.to_s else content << @escape[arg.to_s] end end @output << (attributes.empty? ? "<#{sym}>" : "<#{sym}#{attributes.join}>") @output << content.join unless content.empty? instance_eval(&block) unless block.nil? @output << "</#{sym}>" unless content.empty? && block.nil? end
text(content)
click to toggle source
# File lib/markababy/builder.rb, line 47 def text(content) if content.respond_to?(:html_safe?) && content.html_safe? @output << content.to_s else @output << @escape[content.to_s] end end