summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2012-12-07 12:14:16 -0800
committerelijah <elijah@riseup.net>2012-12-07 12:14:16 -0800
commit0e971adb4ba67e42942864e04a7fa8bb8eb9c2e4 (patch)
tree5f8dfa8b18b36c61fd2a118d668428f23bdcc68f /lib
parentfc7c1b0721afddd321b2906f1a47151c5d11d6a3 (diff)
merge blog features that got deleted when repo was renamed.
Diffstat (limited to 'lib')
-rw-r--r--lib/property_set.rb57
1 files changed, 37 insertions, 20 deletions
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,36 +63,59 @@ 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
#
def method_missing(method)