Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds an RSS feed via pages/all.rss #225

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ tmp/**/*
config/app_config.yml
config/database.yml
config/initializers/secret_token.rb
config/initializers/rss_token.rb
db/*.sqlite3
nbproject/
config/environments/development.rb
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ PATH
specs:
foodsoft_wiki (0.0.1)
acts_as_versioned
diffy
rails (~> 3.2.15)
wikicloth

Expand Down Expand Up @@ -112,6 +113,7 @@ GEM
database_cleaner (1.2.0)
debug_inspector (0.0.2)
diff-lcs (1.2.5)
diffy (3.0.1)
docile (1.1.1)
erubis (2.7.0)
eventmachine (1.0.3)
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ def deny_access

private

def authenticated_for_rss?
controller_name == "pages" && action_name == "all" && defined?(FoodsoftWiki::Engine) && FoodsoftConfig[:rss_token] && params[:token] == FoodsoftConfig[:rss_token]
end

def authenticate(role = 'any')
# RSS works with a token
return true if authenticated_for_rss?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm wouldn't it be better to use skip_before_filter :authenticate, :only => :whatever and add the authenticated_for_rss filter for the rss feed? I'd find it a bit scary to allow using this token so generally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well it's not so generall. authenticated_for_rss? checks the controller and action but i see your point.


# Attempt to retrieve authenticated user from controller instance or session...
if !current_user
# No user at all: redirect to login page.
Expand Down
4 changes: 3 additions & 1 deletion app/views/layouts/_header.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
= csrf_meta_tags
= stylesheet_link_tag "application", :media => "all"
//%link(href="images/favicon.ico" rel="shortcut icon")

- if respond_to? :rss_meta_tag
= rss_meta_tag

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool!

= yield(:head)

%body
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions lib/foodsoft_wiki/app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ def all
end
@pages.order(order)
end
respond_to do |format|
format.html
format.rss { render :layout => false }
end
end

def version
Expand Down
7 changes: 7 additions & 0 deletions lib/foodsoft_wiki/app/helpers/pages_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
module PagesHelper
include WikiCloth

def rss_meta_tag
if FoodsoftConfig[:rss_token]
url = all_pages_url(:format => :rss, :token => FoodsoftConfig[:rss_token])
tag('link', :rel => "alternate", :type => "application/rss+xml", :title => "RSS", :href => url).html_safe
end
end

def wikified_body(body, title = nil)
render_opts = {:locale => I18n.locale} # workaround for wikicloth 0.8.0 https://github.com/nricciar/wikicloth/pull/59
WikiCloth.new({:data => body+"\n", :link_handler => Wikilink.new, :params => {:referer => title}}).to_html(render_opts).html_safe
Expand Down
18 changes: 18 additions & 0 deletions lib/foodsoft_wiki/app/models/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ def set_permalink
self.permalink = Page.count == 0 ? "Home" : Page.permalink(title)
end
end

def diff
current = versions.order('id DESC').first
old = versions.order('id DESC').second

if old
o = ''
Diffy::Diff.new(old.body, current.body).each do |line|
case line
when /^\+/ then o += "#{line.chomp}<br />" unless line.chomp == "+"
when /^-/ then o += "#{line.chomp}<br />" unless line.chomp == "-"
end
end
o
else
current.body
end
end

protected

Expand Down
1 change: 1 addition & 0 deletions lib/foodsoft_wiki/app/views/pages/all.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
%li= link_to t('.recent_changes'), all_pages_path(:view => 'recent_changes')
%li= link_to t('.title_list'), all_pages_path(:view => 'title_list')
%li= link_to t('.site_map'), all_pages_path(:view => 'site_map')
%li= link_to image_tag('icons/feed-icon-14x14.png', :alt => 'RSS Feed'), all_pages_url(:format => :rss, :token => FoodsoftConfig[:rss_token])
= form_tag all_pages_path, method: :get, class: 'form-search pull-right' do
= text_field_tag :name, params[:name], class: 'input-medium search-query',
placeholder: t('.search.placeholder')
Expand Down
19 changes: 19 additions & 0 deletions lib/foodsoft_wiki/app/views/pages/all.rss.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
xml.instruct! :xml, :version => "1.0"
xml.rss :version => "2.0" do
xml.channel do
xml.title FoodsoftConfig[:name] + " Wiki"
xml.description ""
xml.link FoodsoftConfig[:homepage]

for page in @pages
xml.item do
xml.title page.title
xml.description page.diff, :type => "html"
xml.author User.find(page.updated_by).display
xml.pubDate page.updated_at.to_s(:rfc822)
xml.link wiki_page_path(page.permalink)
xml.guid wiki_page_path(page.permalink)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/foodsoft_wiki/foodsoft_wiki.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ Gem::Specification.new do |s|
s.add_dependency "rails", "~> 3.2.15"
s.add_dependency 'wikicloth'
s.add_dependency 'acts_as_versioned' # need git version, make sure that is included in foodsoft's Gemfile

s.add_dependency 'diffy'
s.add_development_dependency "sqlite3"
end
1 change: 1 addition & 0 deletions lib/foodsoft_wiki/lib/foodsoft_wiki.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'wikicloth'
require 'acts_as_versioned'
require "diffy"
require 'foodsoft_wiki/engine'

module FoodsoftWiki
Expand Down
20 changes: 17 additions & 3 deletions lib/tasks/foodsoft_setup.rake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'stringio'

# put in here all foodsoft tasks
# => :environment loads the environment an gives easy access to the application

Expand All @@ -23,8 +25,6 @@ module Colors
end
include Colors

require 'stringio'

namespace :foodsoft do
desc "Setup foodsoft"
task :setup_development do
Expand All @@ -34,6 +34,7 @@ namespace :foodsoft do
setup_development
setup_database
setup_secret_token
setup_rss_token
start_mailcatcher
puts yellow "All done! Your foodcoft should be running smoothly."
start_server
Expand Down Expand Up @@ -82,10 +83,11 @@ end

def setup_app_config
file = 'config/app_config.yml'
sample = Rails.root.join("#{file}.SAMPLE")
return nil if skip?(file)

puts yellow "Copying #{file}..."
%x( cp #{Rails.root.join("#{file}.SAMPLE")} #{Rails.root.join(file)} )
%x( cp #{sample} #{Rails.root.join(file)} )
reminder(file)
end

Expand All @@ -108,6 +110,15 @@ def setup_secret_token
%x( touch #{Rails.root.join("#{file}")}; echo 'Foodsoft::Application.config.secret_token = "#{secret.chomp}"' > #{Rails.root.join("#{file}")} )
end

def setup_rss_token
file = 'config/initializers/rss_token.rb'
return nil if skip?(file)

puts yellow "Generating rss_token and writing to #{file}..."
secret = SecureRandom.hex
%x( touch #{Rails.root.join("#{file}")}; echo 'FoodsoftConfig.config[:rss_token] = "#{secret.chomp}"' > #{Rails.root.join("#{file}")} )
end

def start_mailcatcher
mailcatcher = ask("Do you want to start mailcatcher?\nOptions:\n(y) Yes\n(n) No", ["y","n"])
if mailcatcher === "y"
Expand All @@ -120,6 +131,8 @@ def start_server
puts blue "Start your server running 'bundle exec rails s' and visit http://localhost:3000"
end

# Helper Methods

def ask(question, answers = false)
puts question
input = STDIN.gets.chomp
Expand Down Expand Up @@ -149,3 +162,4 @@ def capture_stdout
ensure
$stdout = STDOUT
end