Skip to content

Commit

Permalink
Upgrade Enki to Rails 3.
Browse files Browse the repository at this point in the history
Main changes:
- Upgrade routes.rb (unused routes were not ported).
- ApplicationController#config -> ApplicationController#enki_config (config is used by Rails 3).
- Remove h() from views and helpers, as it is now included by default. Conversely, add raw() where needed.
- Remove posts_path, formatted_posts_path, page_path from UrlHelper and use helpers created by routes instead.
- Use <%= %> instead of deprecated <% %> for block-type helpers in views.
- Change form_for(@object, object) to form_for(@object, :as => object) (former is deprecated).
- Edit tag_list.rb in acts_as_taggable_on_steroids to not use returning (deprecated).
- Pass specs (left with 5 failures).
  • Loading branch information
jasoncheow committed Nov 13, 2010
1 parent 3f111df commit bc0c319
Show file tree
Hide file tree
Showing 84 changed files with 341 additions and 519 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--colour
2 changes: 1 addition & 1 deletion app/controllers/admin/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def preview

respond_to do |format|
format.js {
render :partial => 'pages/page.html.erb'
render :partial => 'pages/page.html.erb', :locals => {:page => @page}
}
end
end
Expand Down
21 changes: 13 additions & 8 deletions app/controllers/admin/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ def new

def create
return successful_login if allow_login_bypass? && params[:bypass_login]
authenticate_with_open_id(params[:openid_url]) do |result, identity_url|
if result.successful?
if config.author_open_ids.include?(URI.parse(identity_url))
return successful_login
if not params[:openid_url].blank?
authenticate_with_open_id(params[:openid_url]) do |result, identity_url|
if result.successful?
if enki_config.author_open_ids.include?(URI.parse(identity_url))
return successful_login
else
flash.now[:error] = "You are not authorized"
end
else
flash.now[:error] = "You are not authorized"
flash.now[:error] = result.message
end
else
flash.now[:error] = result.message
render :action => 'new'
end
else
flash.now[:error] = "Sorry, the OpenID server couldn't be found"
render :action => 'new'
end
end
Expand All @@ -37,7 +42,7 @@ def destroy

def successful_login
session[:logged_in] = true
redirect_to(admin_dashboard_path)
redirect_to(admin_root_path)
end

def allow_login_bypass?
Expand Down
18 changes: 4 additions & 14 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
include ExceptionNotifiable

helper :all # include all helpers, all the time

protect_from_forgery
after_filter :set_content_type

# See ActionController::RequestForgeryProtection for details
# Uncomment the :secret if you're not using the cookie session store
# protect_from_forgery :secret => 'a6a9e417376364b61645d469f04ac8cf'

protected

def set_content_type
headers['Content-Type'] ||= 'application/xhtml+xml; charset=utf-8'
end

def config
@@config = Enki::Config.default
def enki_config
@@enki_config = Enki::Config.default
end
helper_method :config
helper_method :enki_config
end
2 changes: 1 addition & 1 deletion app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def new

respond_to do |format|
format.js do
render :partial => 'comment.html.erb'
render :partial => 'comment.html.erb', :locals => {:comment => @comment}
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/admin/navigation_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Admin::NavigationHelper
def nav_link_to(text, url, options)
options.merge!(:class => 'current') if url == request.request_uri
options.merge!(:class => 'current') if url == request.fullpath
link_to(text, url, options)
end
end
5 changes: 2 additions & 3 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def author
Struct.new(:name, :email).new(config[:author][:name], config[:author][:email])
Struct.new(:name, :email).new(enki_config[:author][:name], enki_config[:author][:email])
end

def open_id_delegation_link_tags(server, delegate)
links = <<-EOS
raw links = <<-EOS
<link rel="openid.server" href="#{server}" />
<link rel="openid.delegate" href="#{delegate}" />
EOS
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/navigation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ def page_links_for_navigation
link = Struct.new(:name, :url)
[link.new("Home", root_path),
link.new("Archives", archives_path)] +
Page.find(:all, :order => 'title').collect {|page| link.new(page.title, page_path(page))}
Page.find(:all, :order => 'title').collect {|page| link.new(page.title, page_path(page.slug))}
end

def category_links_for_navigation
link = Struct.new(:name, :url)
@popular_tags ||= Tag.find(:all).reject {|tag| tag.taggings.empty? }.sort_by {|tag| tag.taggings.size }.reverse
@popular_tags.collect {|tag| link.new(tag.name, posts_path(:tag => tag)) }
@popular_tags.collect {|tag| link.new(tag.name, posts_path(:tag => tag.name)) }
end

def class_for_tab(tab_name, index)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/page_title_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ def page_title(page)
private

def compose_title(*parts)
(parts << config[:title]).reject(&:blank?).join(" - ")
(parts << enki_config[:title]).reject(&:blank?).join(" - ")
end
end
2 changes: 1 addition & 1 deletion app/helpers/tag_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module TagHelper
def linked_tag_list(tags)
tags.collect {|tag| link_to(h(tag.name), posts_path(:tag => tag))}.join(", ")
raw tags.collect {|tag| link_to(tag.name, posts_path(:tag => tag.name))}.join(", ")
end
end
40 changes: 4 additions & 36 deletions app/helpers/url_helper.rb
Original file line number Diff line number Diff line change
@@ -1,52 +1,20 @@
module UrlHelper
def posts_path(options = {})
if options[:tag]
options[:tag] = options[:tag].name if options[:tag].respond_to?(:name)
options[:tag] = options[:tag].downcase
posts_with_tag_path(options)
else
super
end
end

def formatted_posts_path(options = {})
if options[:tag]
options[:tag] = options[:tag].name if options[:tag].respond_to?(:name)
options[:tag] = options[:tag].downcase
formatted_posts_with_tag_path(options)
else
posts_path(options)
end
end

def post_path(post, options = {})
suffix = options[:anchor] ? "##{options[:anchor]}" : ""
path = post.published_at.strftime("/%Y/%m/%d/") + post.slug + suffix
path = URI.join(config[:url], path) if options[:only_path] == false
path.untaint
path = URI.join(enki_config[:url], path) if options[:only_path] == false
path
end

def post_comments_path(post)
post_path(post) + "/comments"
end

def page_path(page)
"/pages/#{page.slug}"
end

def author_link(comment)
if comment.author_url.blank?
h(comment.author)
else
link_to(h(comment.author), h(comment.author_url), :class => 'openid')
end
end

def posts_atom_path(tag)
if tag.blank?
formatted_posts_path(:format => 'atom')
comment.author
else
formatted_posts_with_tag_path(:tag => tag, :format => 'atom')
link_to(comment.author, comment.author_url, :class => 'openid')
end
end
end
5 changes: 2 additions & 3 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ class Comment < ActiveRecord::Base
after_destroy :denormalize

validates_presence_of :author, :body, :post
validate :open_id_error_should_be_blank

# validate :open_id_thing
def validate
super
def open_id_error_should_be_blank
errors.add(:base, openid_error) unless openid_error.blank?
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/tagging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Tagging < ActiveRecord::Base #:nodoc:
belongs_to :tag, :counter_cache => true
belongs_to :taggable, :class_name => 'Post', :foreign_key => 'taggable_id' #:polymorphic => true

def after_destroy
def self.after_destroy
if Tag.destroy_unused and tag.taggings.count.zero?
tag.destroy
end
Expand Down
6 changes: 3 additions & 3 deletions app/views/admin/comments/_comment.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<tr id="comment-<%= comment.id %>" class="<%= cycle('', 'alt') %>">
<td class='created_at'><%= comment.created_at.strftime('%d %b, %Y') %></td>
<td class='author'><%= link_to(h(comment.author), admin_comment_path(comment)) %></td>
<td><%=h truncate(comment.body, :length => 40) %></td>
<td class='author'><%= link_to(comment.author, admin_comment_path(comment)) %></td>
<td><%= truncate(comment.body, :length => 40) %></td>
<td><%= link_to(comment.post_title, admin_post_path(comment.post))%></td>
<td>
<%= link_to(image_tag('silk/pencil.png', :alt => 'edit'), admin_comment_path(comment)) %>
<% form_for(:comment, comment, :url => admin_comment_path(comment), :html => {:class => 'delete-item', :method => :delete}) do |form| -%>
<%= form_for(comment, :as => :comment, :url => admin_comment_path(comment), :html => {:class => 'delete-item', :method => :delete}) do |form| -%>
<%= image_submit_tag("silk/delete.png", :alt => "Delete Comment") %>
<% end -%>
</td>
Expand Down
8 changes: 4 additions & 4 deletions app/views/admin/comments/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<h1>Editing comment by <%=h @comment.author %></h1>
<h1>Editing comment by <%= @comment.author %></h1>

<% semantic_form_for([:admin, @comment]) do |form| -%>
<% form.input_field_set do -%>
<%= semantic_form_for([:admin, @comment]) do |form| -%>
<%= form.input_field_set do -%>
<%= form.input :author %>
<%= form.input :author_url, :required => false %>
<%= form.input :author_email, :required => false %>
<%= form.input :body, :hint => "<a href='http://lesstile.rubyforge.org'>Lesstile enabled</a>." %>
<% end %>
<% form.button_field_set do -%>
<%= form.button_field_set do -%>
<%= form.commit_button("Save") %>
<% end -%>
<% end -%>
20 changes: 10 additions & 10 deletions app/views/admin/dashboard/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<% end -%>

<div id="summary">
<h1><%= link_to(h(config[:title]), '/') %></h1>
<h1><%= link_to(enki_config[:title], '/') %></h1>
<p class="stats"><%= pluralize(@stats.post_count, 'post') %>, <%= pluralize(@stats.comment_count, 'comment') %>, <%= pluralize(@stats.tag_count, 'tag') %></p>
</div>

Expand All @@ -14,9 +14,9 @@
<ul>
<% @posts.each_with_index do |post, i| -%>
<li class="<%= i == 0 ? 'first ' : '' %>item">
<%= link_to("<h3>%s</h3>" % [h(truncate(post.title, :length => 50))], admin_post_path(post)) %>
<span class='date'><%=h post.published_at.strftime("%b %e") %></span>
<span class='count'><%= link_to(h(post.approved_comments.size), post_path(post)) %></span>
<h3><%= link_to(truncate(post.title, :length => 50), admin_post_path(post)) %></h3>
<span class='date'><%= post.published_at.strftime("%b %e") %></span>
<span class='count'><%= link_to(post.approved_comments.size, post_path(post)) %></span>
</li>
<% end -%>
</ul>
Expand All @@ -27,21 +27,21 @@
<ul>
<% @comment_activity.each_with_index do |activity, i| -%>
<li class="<%= i == 0 ? 'first ' : '' %>item">
<%= link_to("<h3>%s</h3>" % [h(truncate(activity.post.title, :length => 50))], post_path(activity.post)) %>
<span class='date'><%=h activity.most_recent_comment.created_at.strftime("%b %e") %></span>
<span class='count'><%=h activity.post.approved_comments.size %></span>
<h3><%= link_to(truncate(activity.post.title, :length => 50), post_path(activity.post)) %></h3>
<span class='date'><%= activity.most_recent_comment.created_at.strftime("%b %e") %></span>
<span class='count'><%= activity.post.approved_comments.size %></span>
<ul>
<% activity.comments.each_with_index do |comment, index| -%>
<% content_tag :li, :class => activity.comments.size == index + 1 ? 'last' : nil do -%>
<%= link_to(h(comment.author), admin_comment_path(comment), {:id => "comment-link-#{comment.id}", :class => 'comment-link'}) -%>
<%= content_tag :li, :class => activity.comments.size == index + 1 ? 'last' : nil do -%>
<%= link_to(comment.author, admin_comment_path(comment), {:id => "comment-link-#{comment.id}", :class => 'comment-link'}) -%>
<% end -%>
<% end -%>
</ul>
<% activity.comments.each do |comment| -%>
<div class='comment-body' id='comment-body-<%= comment.id %>'>
<div class='comment-actions'>
<%= link_to(image_tag('silk/pencil.png', :alt => 'edit'), admin_comment_path(comment)) %>
<% form_for(:comment, comment, :url => admin_comment_path(comment), :html => {:class => 'delete-item', :id => "delete-comment-#{comment.id}", :method => :delete}) do |form| -%>
<%= form_for(comment, :as => :comment, :url => admin_comment_path(comment), :html => {:class => 'delete-item', :id => "delete-comment-#{comment.id}", :method => :delete}) do |form| -%>
<%= image_submit_tag("silk/delete.png") %>
<% end -%>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/pages/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<%= javascript_include_tag 'admin/edit-preview' %>
<% end -%>

<% form.input_field_set do -%>
<%= form.input_field_set do -%>
<%= form.input :title %>
<%= form.input :slug, :hint => "Leave blank for an auto-generated slug based on the title." %>
<%= form.input :body, :hint => "<a href='http://hobix.com/textile/quick.html'>Textile enabled</a>. Use Ctrl+E to switch between preview and edit mode." %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/admin/pages/_page.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<tr class="<%= cycle('', 'alt') %>">
<td><%= page.created_at.strftime('%d %b, %Y') %></td>
<td><%= link_to(h(page.title), admin_page_path(page)) %></td>
<td><%=h truncate(page.body, :length => 50) %></td>
<td><%= link_to(page.title, admin_page_path(page)) %></td>
<td><%= truncate(page.body, :length => 50) %></td>
<td><%= page.slug %></td>
<td>
<%= link_to(image_tag('silk/pencil.png', :alt => 'edit'), admin_page_path(page)) %>
<% form_for(:page, page, :url => admin_page_path(page), :html => {:class => 'delete-item', :method => :delete}) do |form| -%>
<%= form_for(page, :as => :page, :url => admin_page_path(page), :html => {:class => 'delete-item', :method => :delete}) do |form| -%>
<%= image_submit_tag("silk/delete.png") %>
<% end -%>
</td>
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/pages/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<h1>New page</h1>

<% semantic_form_for([:admin, @page]) do |form| -%>
<%= semantic_form_for([:admin, @page]) do |form| -%>
<%= render :partial => 'form', :locals => {:form => form} %>
<% form.button_field_set do -%>
<%= form.button_field_set do -%>
<%= form.commit_button("Save") -%>
<% end -%>
<% end -%>
6 changes: 3 additions & 3 deletions app/views/admin/pages/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<h1>Editing page - <%= link_to(h(@page.title), page_path(@page)) %></h1>
<h1>Editing page - <%= link_to(@page.title, page_path(@page.slug)) %></h1>

<% semantic_form_for([:admin, @page]) do |form| -%>
<%= semantic_form_for([:admin, @page]) do |form| -%>
<%= render :partial => 'form', :locals => {:form => form} %>
<% form.button_field_set do -%>
<%= form.button_field_set do -%>
<%= form.commit_button("Save") -%>
<% end -%>
<% end -%>
4 changes: 2 additions & 2 deletions app/views/admin/posts/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<%= javascript_include_tag 'admin/edit-preview' %>
<% end -%>

<% form.input_field_set do -%>
<%= form.input_field_set do -%>
<%= form.input :title -%>
<%= form.input :body, :hint => "<a href='http://hobix.com/textile/quick.html'>Textile enabled</a>. Use Ctrl+E to switch between preview and edit mode." -%>
<%= form.input :tag_list, :as => 'string', :required => false, :hint => 'Comma separated: ruby, rails&hellip;' -%>
<% end -%>
<% form.input_field_set do -%>
<%= form.input_field_set do -%>
<%= form.input :published_at_natural, :label => 'Published at', :as => 'string', :hint => 'Example: now, yesterday, 1 hour from now, ' + link_to("more&hellip;", "http://chronic.rubyforge.org/") -%>
<%= form.input :slug, :hint => "Leave blank for an auto-generated slug based on the title." -%>
<%= form.input :minor_edit, :as => 'boolean', :hint => 'Minor edits will not show up as refreshed in feed readers. Use this to fix spelling mistakes and the like.' unless @post.new_record? -%>
Expand Down
6 changes: 3 additions & 3 deletions app/views/admin/posts/_post.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<tr class="<%= cycle('', 'alt') %>">
<td><%= post.published_at.strftime('%d %b, %Y') %></td>
<td><%= link_to (post.title == '' ? '[Untitled]' : h(truncate(post.title, :length => 30))), admin_post_path(post) %></td>
<td><% tmpc = h(truncate(post.body, :length => 55)) %><%= (tmpc != '' ? tmpc : '&nbsp;') %></td>
<td><%= link_to (post.title == '' ? '[Untitled]' : truncate(post.title, :length => 30)), admin_post_path(post) %></td>
<td><% tmpc = truncate(post.body, :length => 55) %><%= (tmpc != '' ? tmpc : '&nbsp;') %></td>
<td><%= post.approved_comments.size %></td>
<td>
<%= link_to(image_tag('silk/pencil.png', :alt => 'edit'), admin_post_path(post)) %>
<% form_for(:post, post, :url => admin_post_path(post), :html => {:class => 'delete-item', :method => :delete}) do |form| -%>
<%= form_for(post, :as => :post, :url => admin_post_path(post), :html => {:class => 'delete-item', :method => :delete}) do |form| -%>
<%= image_submit_tag("silk/delete.png") %>
<% end -%>
</td>
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/posts/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<h1>New post</h1>

<% semantic_form_for([:admin, @post]) do |form| -%>
<%= semantic_form_for([:admin, @post]) do |form| -%>
<%= render :partial => 'form', :locals => {:form => form} -%>
<% form.button_field_set do -%>
<%= form.button_field_set do -%>
<%= form.commit_button("Save") -%>
<% end -%>
<% end -%>
Loading

0 comments on commit bc0c319

Please sign in to comment.