Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BlankSlate
- instance_methods.each { |m| undef_method m unless m =~ /^__/ or m =~ /send/ }
- end
- class Gestalt < BlankSlate
- def initialize
- @cache = ''
- end
- def method_missing meth, *args, &block
- _gestalt_handle meth, *args, &block
- end
- def p *args, &block
- _gestalt_handle :p, *args, &block
- end
- def _gestalt_handle meth, *args, &block
- _gestalt_build_tag(meth, *args, &block)
- end
- # build a tag for `name`, using `args` and an optional block that
- # will be yielded
- def _gestalt_build_tag(name, args=nil, &block)
- @cache << "<#{name}"
- if block_given?
- @cache << ( args ? args.inject(''){ |s,v| s+%{ #{v[0]}="#{v[1]}"} } : '' )
- @cache << ">"
- tmp = yield
- @cache << tmp unless @cache.include? tmp.to_s
- @cache << "</#{name}>"
- else
- @cache << args.inject(''){ |s,v| s+%{ #{v[0]}="#{v[1]}"} } if args
- @cache << ' />'
- end
- @cache
- end
- end
Add Comment
Please, Sign In to add comment