From 10038e58efe3aa3c1725e2b5b0a0b7b2ce060df7 Mon Sep 17 00:00:00 2001 From: elijah Date: Wed, 20 Feb 2013 00:39:58 -0800 Subject: added support for pandoc and page properties in static markup. --- lib/property_set.rb | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'lib/property_set.rb') 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 @@ -135,6 +140,18 @@ class PropertySet end 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 # -- cgit v1.2.3