Skip to content

Commit

Permalink
Fix options handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lsegal committed Jun 13, 2008
1 parent 541e316 commit e70f560
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/tadpole/template.rb
Expand Up @@ -3,6 +3,7 @@
class OpenHashStruct < OpenStruct
def [](key) send(key.to_s) end
def []=(k,v) send(key.to_s+'=', v) end
def to_hash; @table.dup end
end

module Tadpole
Expand Down Expand Up @@ -31,7 +32,14 @@ def self.included(klass)
attr_accessor :current_section, :subsections

def options; @options ||= OpenHashStruct.new end
def options=(hash) @options = OpenHashStruct.new(hash) end

def options=(hash)
if hash.is_a?(OpenStruct)
@options = hash
else
@options = OpenHashStruct.new(hash)
end
end

def method_missing(meth, *args, &block)
if options.respond_to?(meth)
Expand Down Expand Up @@ -92,10 +100,10 @@ def initialize(opts = {}, &block)
def init; end

def run(opts = {}, &block)
old_opts = options.dup
self.options.update(opts)
old_opts = options
self.options = options.to_hash.update(opts)
out = run_sections(@compiled_sections || sections, &block)
options.replace(old_opts)
self.options = old_opts
out
rescue => e
me = NoMethodError.new("In #{self.inspect}: #{e.message}")
Expand Down

0 comments on commit e70f560

Please sign in to comment.