diff options
author | elijah <elijah@riseup.net> | 2012-12-07 12:14:16 -0800 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2012-12-07 12:14:16 -0800 |
commit | 0e971adb4ba67e42942864e04a7fa8bb8eb9c2e4 (patch) | |
tree | 5f8dfa8b18b36c61fd2a118d668428f23bdcc68f | |
parent | fc7c1b0721afddd321b2906f1a47151c5d11d6a3 (diff) |
merge blog features that got deleted when repo was renamed.
-rw-r--r-- | app/controllers/application_controller.rb | 16 | ||||
-rw-r--r-- | app/controllers/pages_controller.rb | 16 | ||||
-rw-r--r-- | app/helpers/blog_helper.rb | 3 | ||||
-rw-r--r-- | app/views/errors/not_found.atom | 1 | ||||
-rw-r--r-- | app/views/layouts/blog/feed.atom.builder | 12 | ||||
-rw-r--r-- | app/views/pages/home/en.haml | 4 | ||||
-rw-r--r-- | lib/property_set.rb | 57 | ||||
-rw-r--r-- | public/img/feed-icon-14x14.png | bin | 0 -> 689 bytes | |||
-rw-r--r-- | public/robots.txt | 0 |
9 files changed, 87 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..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) diff --git a/public/img/feed-icon-14x14.png b/public/img/feed-icon-14x14.png Binary files differnew file mode 100644 index 0000000..b3c949d --- /dev/null +++ b/public/img/feed-icon-14x14.png diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/public/robots.txt |