Skip to content

Commit

Permalink
Merge branch 'master' of github.com:defunkt/mustache
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Apr 18, 2010
2 parents 4a3c53d + 61ee5c6 commit 8e04221
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/mustache.rb
Expand Up @@ -116,7 +116,7 @@ def partial(name)
# The template path informs your Mustache subclass where to look for its
# corresponding template. By default it's the current directory (".")
def self.template_path
@template_path ||= '.'
@template_path ||= inheritable_config_for :template_path, '.'
end

def self.template_path=(path)
Expand All @@ -136,7 +136,7 @@ def self.path=(path)

# A Mustache template's default extension is 'mustache'
def self.template_extension
@template_extension ||= 'mustache'
@template_extension ||= inheritable_config_for :template_extension, 'mustache'
end

def self.template_extension=(template_extension)
Expand Down Expand Up @@ -182,7 +182,7 @@ def self.template=(template)
# `Object`, but it might be nice to set it to something like `Hurl::Views` if
# your app's main namespace is `Hurl`.
def self.view_namespace
@view_namespace || Object
@view_namespace ||= inheritable_config_for(:view_namespace, Object)
end

def self.view_namespace=(namespace)
Expand All @@ -192,7 +192,7 @@ def self.view_namespace=(namespace)
# Mustache searches the view path for .rb files to require when asked to find a
# view class. Defaults to "."
def self.view_path
@view_path ||= '.'
@view_path ||= inheritable_config_for(:view_path, '.')
end

def self.view_path=(path)
Expand Down Expand Up @@ -288,6 +288,17 @@ def self.templateify(obj)
end
end

# Return the value of the configuration setting on the superclass, or return
# the default.
#
# attr_name - Symbol name of the attribute. It should match the instance variable.
# default - Default value to use if the superclass does not respond.
#
# Returns the inherited or default configuration setting.
def self.inheritable_config_for(attr_name, default)
superclass.respond_to?(attr_name) ? superclass.send(attr_name) : default
end

def templateify(obj)
self.class.templateify(obj)
end
Expand Down
15 changes: 15 additions & 0 deletions test/mustache_test.rb
Expand Up @@ -442,4 +442,19 @@ def indent
end
template
end

def test_inherited_attributes
Object.const_set :TestNamespace, Module.new
base = Class.new(Mustache)
tmpl = Class.new(base)

{:template_path => File.expand_path('./foo'),
:template_extension => 'stache',
:view_namespace => TestNamespace,
:view_path => './foo'
}.each do |attr, value|
base.send("#{attr}=", value)
assert_equal value, tmpl.send(attr)
end
end
end

0 comments on commit 8e04221

Please sign in to comment.