From 0e971adb4ba67e42942864e04a7fa8bb8eb9c2e4 Mon Sep 17 00:00:00 2001 From: elijah Date: Fri, 7 Dec 2012 12:14:16 -0800 Subject: merge blog features that got deleted when repo was renamed. --- lib/property_set.rb | 57 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 20 deletions(-) (limited to 'lib') diff --git a/lib/property_set.rb b/lib/property_set.rb index c315a13..64982c9 100644 --- a/lib/property_set.rb +++ b/lib/property_set.rb @@ -32,12 +32,6 @@ class PropertySet def initialize(property_set, locale) @_ps = property_set @_locale = locale - #code.gsub!(/^((?!^\-\ \@).)*$/, '') # remove any lines not starting with '- @' - #code.gsub!(/^- /m, '') # remove '-' - #instance_eval(code) - #instance_variables.grep(/_at$/).each do |time_variable| - # instance_variable_set(time_variable, Time.parse(instance_variable_get(time_variable))) - #end end def method_missing(method) get(method) @@ -69,35 +63,58 @@ class PropertySet @locales = {} end - - # - # maybe something like this in the future: - # - #contr = PagesController.new() - #contr.response = ActionController::Response.new() - #scope = ActionView::Base.new(["#{RAILS_ROOT}/app/views/pages","#{RAILS_ROOT}/app/views"], {}, contr) - #scope.template_format = 'html' - #Haml::Engine.new(value, :format => :html5).render(scope) - # - # # evaluate the template_string, and load the variables defined into an AttrObject. # def eval(locale, template_string) + # render to the template to get the instance variables attrs = AttrObject.new(self, locale) - body = nil begin - body = Haml::Engine.new(template_string, :format => :html5).render(attrs) # template is evaluated in scope of attrs + # template is evaluated with binding of attrs object + Haml::Engine.new(template_string, :format => :html5).render(attrs) rescue Exception => exc # eat exceptions end - attrs.instance_variable_set('@body', body) + + # convert date/time variables to objects of class Time attrs.instance_variables.grep(/_at$/).each do |time_variable| attrs.instance_variable_set(time_variable, Time.parse(attrs.instance_variable_get(time_variable))) end + + # save the AttrObject @locales[locale] = attrs end + # + # ALTERNATE EVAL + # + # body = nil + # controller = ApplicationController.new() + # controller.response = ActionController::Response.new() + # view = ActionView::Base.new(["#{Rails.root}/app/views/pages","#{Rails.root}/app/views"], {}, controller) + # view.extend ApplicationHelper # TODO: figure out how to extend all helpers + # view.extend BlogHelper + # view.extend HamlHelper + # view.extend NavigationHelper + # begin + # body = Haml::Engine.new(template_string, :format => :html5).render(view) # template is evaluated with binding of view object + # rescue Exception => exc + # # eat exceptions + # end + # + # this doesn't work because view doesn't get instance variables set + # + # copy new instance variables + # new_variables = view.instance_variables + # new_variables = original_instance_variables - view.instance_variables + # new_variables.each do |variable| + # #attrs.instance_variable_set(variable, view.instance_variable_get(variable)) + # end + # + # clean up attrs + # attrs.instance_variable_set('@body', body) + # + # # allows property_set.propname shortcut, assumes default locale # -- cgit v1.2.3