summaryrefslogtreecommitdiff
path: root/lib/property_set.rb
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-02-20 00:39:58 -0800
committerelijah <elijah@riseup.net>2013-02-20 00:39:58 -0800
commit10038e58efe3aa3c1725e2b5b0a0b7b2ce060df7 (patch)
tree53413a9cd679c6d22b405c1035f9c41546677c9a /lib/property_set.rb
parent9c4e765c8fe972a4a9f49c3de7991b3925ddb97c (diff)
added support for pandoc and page properties in static markup.
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)