public
Description: View delegate plugin for Rails
Homepage: http://stencil.rubyforge.org
Clone URL: git://github.com/bruce/stencil.git
stencil / lib / stenciling.rb
100644 23 lines (20 sloc) 0.65 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Stenciling
  class << self
    
    def included(base)
      base.send(:include, InstanceMethods)
      base.send(:alias_method_chain, :method_missing, :stenciling)
    end
    
  end
  
  module InstanceMethods
    def method_missing_with_stenciling(meth, *args, &block)
      stencil_candidate = "#{meth.to_s.camelize}Stencil".constantize rescue nil
      if stencil_candidate && stencil_candidate.ancestors.include?(Stencil)
        returning stencil_candidate.new(*args, &block) do |stencil|
          stencil.template = self
        end
      else
        method_missing_without_stenciling(meth, *args, &block)
      end
    end
  end
end