diff options
Diffstat (limited to 'lib/property_set.rb')
-rw-r--r-- | lib/property_set.rb | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/property_set.rb b/lib/property_set.rb index 05aa46a..08f408d 100644 --- a/lib/property_set.rb +++ b/lib/property_set.rb @@ -22,7 +22,7 @@ require 'RedCloth' class PropertySet - DEFAULT_LOCALE = 'en' + DEFAULT_LOCALE = :en # # a simple class to pass through all member variables as attributes. @@ -31,8 +31,8 @@ class PropertySet # class AttrObject def initialize(property_set, locale) - @_ps = property_set - @_locale = locale + @_ps = property_set # underscore is important here, because we don't want to + @_locale = locale # accidentally collide with another property that gets set. end def method_missing(method) get(method) @@ -43,9 +43,10 @@ class PropertySet def get(var_name, inheritance=true) value = instance_variable_get("@#{var_name}") if value.nil? + p [var_name, value, @_locale, DEFAULT_LOCALE] if @_locale != DEFAULT_LOCALE # try value from default locale - @_ps.get_var(var_name) + @_ps.get_var(var_name, DEFAULT_LOCALE) elsif inheritance # try inherited value @_ps.get_inherited_var(var_name, @_locale) @@ -71,6 +72,7 @@ class PropertySet # def eval(template_string, locale) locale ||= DEFAULT_LOCALE + locale = locale.to_sym # locales are always symbols # render to the template to get the instance variables attrs = AttrObject.new(self, locale) @@ -128,7 +130,7 @@ class PropertySet end def locale(l) - @locales[l.to_s] || @locales[DEFAULT_LOCALE] + @locales[l.to_sym] || @locales[DEFAULT_LOCALE] end def get_var(var_name, locale=I18n.locale) @@ -141,7 +143,7 @@ class PropertySet end # - # like get_var, but forbits inheritance + # like get_var, but does not allow inheritance # def get_var_without_inheritance(var_name, locale=I18n.locale) attrs = locale(locale) @@ -171,7 +173,7 @@ if ARGV.grep('--test').any? - @author = 'you' - @created_at = 'Sun Aug 12 18:32:20 PDT 2012' - ignored = 1 -this is the body" +" text_es = " - @title = 'hola' @@ -180,13 +182,16 @@ this is the body" " ps = PropertySet.new - ps.eval('en', text_en) - ps.eval('es', text_es) + ps.eval(text_en, 'en') + ps.eval(text_es, 'es') p ps.title == 'hi' p ps.locale(:es).title == 'hola' + p ps.get_var('title', 'es') == 'hola' p ps.locale(:es).created_at == Time.parse('Sun Aug 12 18:32:20 PDT 2012') p ps.ignored == nil + p ps.locale(:es).ignored == nil p ps.locale(:es).heading == "<h1>hi</h1>" - p ps.body == "this is the body\n" + #p ps.body == "this is the body" + #p ps.get_var('body', :es) == "esta es el cuerpo" end |