summaryrefslogtreecommitdiff
path: root/lib/property_set.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/property_set.rb')
-rw-r--r--lib/property_set.rb23
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/property_set.rb b/lib/property_set.rb
index 64982c9..05aa46a 100644
--- a/lib/property_set.rb
+++ b/lib/property_set.rb
@@ -11,6 +11,7 @@
# getting the property
#
# page.props.title
+# page.props.locale('en').title
#
require 'i18n'
@@ -39,15 +40,17 @@ class PropertySet
def textile(str)
RedCloth.new(str).to_html
end
- def get(var_name)
+ def get(var_name, inheritance=true)
value = instance_variable_get("@#{var_name}")
if value.nil?
if @_locale != DEFAULT_LOCALE
# try value from default locale
@_ps.get_var(var_name)
- else
+ elsif inheritance
# try inherited value
@_ps.get_inherited_var(var_name, @_locale)
+ else
+ nil
end
else
value
@@ -66,7 +69,9 @@ class PropertySet
#
# evaluate the template_string, and load the variables defined into an AttrObject.
#
- def eval(locale, template_string)
+ def eval(template_string, locale)
+ locale ||= DEFAULT_LOCALE
+
# render to the template to get the instance variables
attrs = AttrObject.new(self, locale)
begin
@@ -136,6 +141,18 @@ class PropertySet
end
#
+ # like get_var, but forbits inheritance
+ #
+ def get_var_without_inheritance(var_name, locale=I18n.locale)
+ attrs = locale(locale)
+ if attrs
+ attrs.get(var_name, false)
+ else
+ nil
+ end
+ end
+
+ #
# tries to get the value of an inherited variable
#
def get_inherited_var(var_name, locale=I18n.locale)