merge blog features that got deleted when repo was renamed.
authorelijah <elijah@riseup.net>
Fri, 7 Dec 2012 20:14:16 +0000 (12:14 -0800)
committerelijah <elijah@riseup.net>
Fri, 7 Dec 2012 20:14:16 +0000 (12:14 -0800)
app/controllers/application_controller.rb
app/controllers/pages_controller.rb
app/helpers/blog_helper.rb
app/views/errors/not_found.atom [new file with mode: 0644]
app/views/layouts/blog/feed.atom.builder [new file with mode: 0644]
app/views/pages/home/en.haml
lib/property_set.rb
public/img/feed-icon-14x14.png [new file with mode: 0644]
public/robots.txt [new file with mode: 0644]

index 240df61..da6cf3e 100644 (file)
@@ -64,6 +64,22 @@ class ApplicationController < ActionController::Base
     end
   end
 
+  #
+  # same as render page, but returns the string
+  #
+  def page_body(page)
+    begin
+      render_to_string :template => page.template_path
+    rescue ActionView::MissingTemplate => exc
+      begin
+        render_to_string :template => page.template_path(DEFAULT_LOCALE)
+      rescue
+        raise exc
+      end
+    end
+  end
+  helper_method :page_body
+
   ##
   ## INITIALIZATION
   ##
index c86f313..d4fa09a 100644 (file)
@@ -9,7 +9,10 @@ class PagesController < ApplicationController
   def show
     @page = StaticPage.find(params[:page])
     if @page
-      render_page(@page)
+      respond_to do |format|
+        format.atom { render_atom_feed(@page) }
+        format.all { render_page(@page) }
+      end
     else
       raise PageNotFound.new
     end
@@ -25,5 +28,16 @@ class PagesController < ApplicationController
     end
   end
 
+  def render_atom_feed(root)
+    if root
+      @pages = root.all_children.order_by(:posted_at, :direction => :desc).limit(PAGINATION_SIZE)
+      if @pages.any?
+        render :file => 'layouts/blog/feed', :layout => false, :content_type => 'application/atom+xml'
+      else
+        render_404
+      end
+    end
+  end
+
 end
 
index 9e58fc8..42e6f9c 100644 (file)
@@ -12,4 +12,7 @@ module BlogHelper
     end
   end
 
+  def news_feed_link
+    link_to(image_tag('/img/feed-icon-14x14.png'), "/#{I18n.locale}/news.atom")
+  end
 end
diff --git a/app/views/errors/not_found.atom b/app/views/errors/not_found.atom
new file mode 100644 (file)
index 0000000..8347208
--- /dev/null
@@ -0,0 +1 @@
+not found
\ No newline at end of file
diff --git a/app/views/layouts/blog/feed.atom.builder b/app/views/layouts/blog/feed.atom.builder
new file mode 100644 (file)
index 0000000..a9dbf6a
--- /dev/null
@@ -0,0 +1,12 @@
+atom_feed(:language => I18n.locale.to_s) do |feed|
+  feed.title "LEAP News"
+  feed.updated @pages.first.props.posted_at
+  @pages.each do |page|
+    feed.entry(page, :url => page_path(page), :updated => page.props.posted_at) do |entry|
+      entry.title page.title
+      entry.summary page.props.preview, :type => 'html'
+      entry.content page_body(page), :type => 'html'
+      entry.author page.props.author
+    end
+  end
+end
index c7bb73b..ff266d0 100644 (file)
@@ -24,7 +24,9 @@
   -#  %h2.invert LEAP Blog
   -#  = recent_blog_summaries('blog')
   .span6
-    %h3.first Recent News
+    %h3.first
+      Recent News
+      = news_feed_link
     = recent_blog_summaries('news')
   .span6
     %h3 LEAP Development Roadmap
index c315a13..64982c9 100644 (file)
@@ -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)
diff --git a/public/img/feed-icon-14x14.png b/public/img/feed-icon-14x14.png
new file mode 100644 (file)
index 0000000..b3c949d
Binary files /dev/null and b/public/img/feed-icon-14x14.png differ
diff --git a/public/robots.txt b/public/robots.txt
new file mode 100644 (file)
index 0000000..e69de29