GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Arrtubates sets meta on meta for objects and adds additional rendering helpers for ActionController::Base in Rails.
Clone URL: git://github.com/bmizerany/attrubates.git
Blake Mizerany (author)
Fri Apr 18 17:03:27 -0700 2008
attrubates / lib / renderer.rb
100644 31 lines (28 sloc) 1.086 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Attrubates
  module Renderer
    ###
    # See README.rdoc
    def render_attrubate(o, *args)
      raise "The object must attrubate!" unless o.respond_to?(:attrubated)
      options, a = extract_options_from_args!(args) || {}, args[0]
      local_name = o.class.name.underscore
      prefix = normalize_prefix(options.delete(:prefix))
      options[:locals] ||= {}
      options[:locals][local_name] = o unless options[:locals].has_key?(local_name)
      parts = [prefix, local_name, "#{a ? a.to_s + '_' : ''}#{options[:force] || o.attrubated[a || :self]}"]
      template_path = File.join(*parts)
      if respond_to?(:partial)
        partial(template_path, options)
      else
        render(options.merge(:partial => template_path))
      end
    end
 
    module Merb
      def normalize_prefix(prefix); prefix || Merb.dir_for(:attrubates) || Merb.dir_for(:view) + '/attrubates'; end
    end
    
    module Rails
      def extract_options_from_args!(args); args.extract_options!; end
      def normalize_prefix(prefix); prefix || 'shared/attrubates'; end
    end
  end
end