summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2012-08-29 23:24:16 -0700
committerelijah <elijah@riseup.net>2012-08-29 23:24:16 -0700
commit660b90c785815a7af95f19c5dc8eaf2b85037cce (patch)
tree70b2b184901c1e6e25c5e0a0602ad19950d85fa9
parent3b2f81f707305396e7ab44c928f7da9a77bebe94 (diff)
added support for atom feed.
-rw-r--r--app/controllers/application_controller.rb16
-rw-r--r--app/controllers/pages_controller.rb16
-rw-r--r--app/helpers/blog_helper.rb3
-rw-r--r--app/views/errors/not_found.atom1
-rw-r--r--app/views/layouts/blog/feed.atom.builder12
-rw-r--r--app/views/pages/home/en.haml4
-rw-r--r--lib/property_set.rb63
-rw-r--r--public/img/feed-icon-14x14.pngbin0 -> 689 bytes
-rw-r--r--public/robots.txt0
9 files changed, 93 insertions, 22 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 240df61..da6cf3e 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -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
##
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb
index c86f313..d4fa09a 100644
--- a/app/controllers/pages_controller.rb
+++ b/app/controllers/pages_controller.rb
@@ -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
diff --git a/app/helpers/blog_helper.rb b/app/helpers/blog_helper.rb
index 9e58fc8..42e6f9c 100644
--- a/app/helpers/blog_helper.rb
+++ b/app/helpers/blog_helper.rb
@@ -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
index 0000000..8347208
--- /dev/null
+++ b/app/views/errors/not_found.atom
@@ -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
index 0000000..a9dbf6a
--- /dev/null
+++ b/app/views/layouts/blog/feed.atom.builder
@@ -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
diff --git a/app/views/pages/home/en.haml b/app/views/pages/home/en.haml
index c7bb73b..ff266d0 100644
--- a/app/views/pages/home/en.haml
+++ b/app/views/pages/home/en.haml
@@ -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
diff --git a/lib/property_set.rb b/lib/property_set.rb
index c315a13..e578df1 100644
--- a/lib/property_set.rb
+++ b/lib/property_set.rb
@@ -18,6 +18,8 @@ require 'time'
require 'rubygems'
require 'haml'
require 'RedCloth'
+#require 'action_controller'
+#require 'action_controller/response'
class PropertySet
@@ -32,12 +34,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,32 +65,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)
+ #
+ # I could not figure out how to do this in one render. When I pass in a view, the instance variables don't
+ # get set.
+ #
+
+ #
+ # 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
+ Haml::Engine.new(template_string, :format => :html5).render(attrs) # template is evaluated with binding of attrs object
rescue Exception => exc
# eat exceptions
end
- attrs.instance_variable_set('@body', body)
+
+ #
+ # render the template to get the body
+ #
+ # 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)
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
diff --git a/public/img/feed-icon-14x14.png b/public/img/feed-icon-14x14.png
new file mode 100644
index 0000000..b3c949d
--- /dev/null
+++ b/public/img/feed-icon-14x14.png
Binary files differ
diff --git a/public/robots.txt b/public/robots.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/public/robots.txt