lib/boson/view.rb in boson-0.0.1 vs lib/boson/view.rb in boson-0.1.0

- old
+ new

@@ -1,19 +1,31 @@ module Boson + # Handles {Hirb}[http://tagaholic.me/hirb/]-based views. module View extend self + # Enables hirb and reads a config file from the main repo's config/hirb.yml. def enable Hirb::View.enable(:config_file=>File.join(Boson.repo.config_dir, 'hirb.yml')) unless @enabled @enabled = true end + # Renders any object via Hirb. Options are passed directly to + # {Hirb::Console.render_output}[http://tagaholic.me/hirb/doc/classes/Hirb/Console.html#M000011]. def render(object, options={}) - [nil,false,true].include?(object) ? puts(object.inspect) : render_object(object, options) + if silent_object?(object) + puts(object.inspect) unless options[:silence_booleans] + else + render_object(object, options) + end end - def render_object(object, options={}) - options[:class] = options.delete(:as) || :auto_table + def silent_object?(obj) + [nil,false,true].include?(obj) + end + + def render_object(object, options={}) #:nodoc: + options[:class] ||= :auto_table if object.is_a?(Array) && object.size > 0 && (sort = options.delete(:sort)) begin sort_lambda = object[0].is_a?(Hash) ? (object[0][sort].respond_to?(:<=>) ? lambda {|e| e[sort] } : lambda {|e| e[sort].to_s }) : (object[0].send(sort).respond_to?(:<=>) ? lambda {|e| e.send(sort)} : \ No newline at end of file