Skip to content
This repository has been archived by the owner on Mar 6, 2018. It is now read-only.

Commit

Permalink
Update to Rails3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Aug 27, 2010
1 parent daaae12 commit 9c93e79
Show file tree
Hide file tree
Showing 139 changed files with 1,146 additions and 3,601 deletions.
2 changes: 2 additions & 0 deletions .bundle/config
@@ -0,0 +1,2 @@
---
BUNDLE_DISABLE_SHARED_GEMS: "1"
19 changes: 19 additions & 0 deletions Gemfile
@@ -0,0 +1,19 @@
source 'http://rubygems.org'

gem 'rails', '3.0.0.rc2'
gem 'mysql2'
gem 'RedCloth'
gem 'simple-rss'
gem 'will_paginate', '3.0.pre'
gem 'twitter4r'
gem 'acts-as-taggable-on'
gem 'rmagick'
gem 'jquery-ujs'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
87 changes: 87 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,87 @@
GEM
remote: http://rubygems.org/
specs:
RedCloth (4.2.3)
abstract (1.0.0)
actionmailer (3.0.0.rc2)
actionpack (= 3.0.0.rc2)
mail (~> 2.2.5)
actionpack (3.0.0.rc2)
activemodel (= 3.0.0.rc2)
activesupport (= 3.0.0.rc2)
builder (~> 2.1.2)
erubis (~> 2.6.6)
i18n (~> 0.4.1)
rack (~> 1.2.1)
rack-mount (~> 0.6.12)
rack-test (~> 0.5.4)
tzinfo (~> 0.3.23)
activemodel (3.0.0.rc2)
activesupport (= 3.0.0.rc2)
builder (~> 2.1.2)
i18n (~> 0.4.1)
activerecord (3.0.0.rc2)
activemodel (= 3.0.0.rc2)
activesupport (= 3.0.0.rc2)
arel (~> 1.0.0.rc1)
tzinfo (~> 0.3.23)
activeresource (3.0.0.rc2)
activemodel (= 3.0.0.rc2)
activesupport (= 3.0.0.rc2)
activesupport (3.0.0.rc2)
acts-as-taggable-on (2.0.6)
arel (1.0.0.rc1)
activesupport (>= 3.0.0.beta)
builder (2.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
i18n (0.4.1)
json (1.4.6)
mail (2.2.5)
activesupport (>= 2.3.6)
mime-types
treetop (>= 1.4.5)
mime-types (1.16)
mysql2 (0.2.3)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.12)
rack (>= 1.0.0)
rack-test (0.5.4)
rack (>= 1.0)
rails (3.0.0.rc2)
actionmailer (= 3.0.0.rc2)
actionpack (= 3.0.0.rc2)
activerecord (= 3.0.0.rc2)
activeresource (= 3.0.0.rc2)
activesupport (= 3.0.0.rc2)
bundler (>= 1.0.0.rc.6)
railties (= 3.0.0.rc2)
railties (3.0.0.rc2)
actionpack (= 3.0.0.rc2)
activesupport (= 3.0.0.rc2)
rake (>= 0.8.3)
thor (~> 0.14.0)
rake (0.8.7)
rmagick (2.13.1)
simple-rss (1.2.3)
thor (0.14.0)
treetop (1.4.8)
polyglot (>= 0.3.1)
twitter4r (0.3.2)
json (>= 1.1.1)
tzinfo (0.3.23)
will_paginate (3.0.pre)

PLATFORMS
ruby

DEPENDENCIES
RedCloth
acts-as-taggable-on
mysql2
rails (= 3.0.0.rc2)
rmagick
simple-rss
twitter4r
will_paginate (= 3.0.pre)
16 changes: 7 additions & 9 deletions Rakefile
@@ -1,17 +1,15 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require(File.join(File.dirname(__FILE__), 'config', 'boot'))

require File.expand_path('../config/application', __FILE__)
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'

Personlab::Application.load_tasks

# Twitter
namespace :tweet do
namespace :tweet do
desc "Twitter reload."
task :update => :environment do
task :update => :environment do
require 'app/models/setting'
require 'app/models/tweet'
setting = Setting.find_create
Expand All @@ -25,9 +23,9 @@ namespace :tweet do
end

# Google Reader
namespace :reader_share do
namespace :reader_share do
desc "Google Reader reload shere items."
task :update => :environment do
task :update => :environment do
require 'app/models/setting'
require 'app/models/share'
setting = Setting.find_create
Expand Down
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
@@ -1,3 +1,4 @@
# coding: utf-8
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

Expand Down
1 change: 1 addition & 0 deletions app/controllers/cpanel/application_controller.rb
@@ -1,3 +1,4 @@
# coding: utf-8
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

Expand Down
1 change: 1 addition & 0 deletions app/controllers/cpanel/categories_controller.rb
@@ -1,3 +1,4 @@
# coding: utf-8
# ----------------------------------------------------
# name: menus_controller.rb
# authors: Jason Lee<huacnlee@gmail.com>,
Expand Down
1 change: 1 addition & 0 deletions app/controllers/cpanel/comments_controller.rb
@@ -1,3 +1,4 @@
# coding: utf-8
# ----------------------------------------------------
# name: comments_controller.rb
# authors: Jason Lee<huacnlee@gmail.com>,
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/cpanel/home_controller.rb
@@ -1,3 +1,4 @@
# coding: utf-8
# admin home controller
class Cpanel::HomeController < Cpanel::ApplicationController
before_filter :require_login,:only => [:index,:logout]
Expand Down Expand Up @@ -38,4 +39,4 @@ def login
render :action => "login", :layout => false
end

end
end
1 change: 1 addition & 0 deletions app/controllers/cpanel/menus_controller.rb
@@ -1,3 +1,4 @@
# coding: utf-8
# ----------------------------------------------------
# name: menus_controller.rb
# authors: Jason Lee<huacnlee@gmail.com>,
Expand Down
1 change: 1 addition & 0 deletions app/controllers/cpanel/pages_controller.rb
@@ -1,3 +1,4 @@
# coding: utf-8
# ----------------------------------------------------
# name: pages_controller.rb
# authors: Jason Lee<huacnlee@gmail.com>,
Expand Down
1 change: 1 addition & 0 deletions app/controllers/cpanel/posts_controller.rb
@@ -1,3 +1,4 @@
# coding: utf-8
class Cpanel::PostsController < Cpanel::ApplicationController
cache_sweeper :post_sweeper,:only => [:create,:update,:destroy]
# GET /posts
Expand Down
1 change: 1 addition & 0 deletions app/controllers/cpanel/settings_controller.rb
@@ -1,3 +1,4 @@
# coding: utf-8
class Cpanel::SettingsController < Cpanel::ApplicationController
cache_sweeper :setting_sweeper,:page_sweeper, :only => [:update]

Expand Down
1 change: 1 addition & 0 deletions app/controllers/home_controller.rb
@@ -1,3 +1,4 @@
# coding: utf-8
class HomeController < ApplicationController
caches_action :show

Expand Down
7 changes: 2 additions & 5 deletions app/controllers/posts_controller.rb
@@ -1,3 +1,4 @@
# coding: utf-8
class PostsController < ApplicationController
cache_sweeper :comment_sweeper,:only => [:show]
validates_captcha
Expand Down Expand Up @@ -107,23 +108,19 @@ def show

@view_count = Post.update_view_count(params[:slug])

@post = Rails.cache.read(@post_key)
if (not @post) or (@view_count == 0)
@post = Post.find_slug(params[:slug])
if not @post
return render_404
end

Rails.cache.write(@post_key,@post)
end

if request.post?
@pcomment = params[:comment]
@comment = Comment.new(params[:comment])
@comment = @post.comments.build(params[:comment])

set_guest(@comment.author,@comment.url,@comment.email)
if captcha_validated?
@comment.post_id = @post.id
if @comment.save
NoticeMailer.new_comment_notice(@post,@comment)
if @comment.status == 2
Expand Down
19 changes: 10 additions & 9 deletions app/helpers/application_helper.rb
@@ -1,30 +1,31 @@
require "md5"
# coding: utf-8
require "digest/md5"
require "encoder"
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper

# return the formatted flash[:notice] html
def success_messages
msg = ''
if flash[:notice]
'
msg = '
<div id="successMessage" class="successMessage">
'+flash[:notice]+'
</div>
'
else
''
end
raw msg
end

# form auth token
def auth_token
"<input name=\"authenticity_token\" type=\"hidden\" value=\"#{form_authenticity_token}\" />"
raw "<input name=\"authenticity_token\" type=\"hidden\" value=\"#{form_authenticity_token}\" />"
end

# return the Gravatar face by Email
def face_url(email)
hash = MD5::md5(email)
"http://www.gravatar.com/avatar/#{hash}?s=32"
hash = Digest::MD5.hexdigest(email)
raw "http://www.gravatar.com/avatar/#{hash}?s=32"
end

# close html tag when truncated
Expand All @@ -33,7 +34,7 @@ def close_tags(text)
text.scan(/\<([^\>\s\/]+)[^\>\/]*?\>/).each { |t| open_tags.unshift(t) }
text.scan(/\<\/([^\>\s\/]+)[^\>]*?\>/).each { |t| open_tags.slice!(open_tags.index(t)) }
open_tags.each {|t| text += "</#{t}>" }
return text
return raw text
end

def truncate_html(html, options={})
Expand Down Expand Up @@ -62,7 +63,7 @@ def truncate_html(html, options={})
end
end
end
return result.join(" ") + options[:omission].to_s
return raw(result.join(" ") + options[:omission].to_s)
end

# 退定连接
Expand Down
1 change: 1 addition & 0 deletions app/helpers/comments_helper.rb
@@ -1,2 +1,3 @@
# coding: utf-8
module CommentsHelper
end
1 change: 1 addition & 0 deletions app/helpers/home_helper.rb
@@ -1,2 +1,3 @@
# coding: utf-8
module HomeHelper
end
1 change: 1 addition & 0 deletions app/helpers/menus_helper.rb
@@ -1,2 +1,3 @@
# coding: utf-8
module MenusHelper
end
1 change: 1 addition & 0 deletions app/helpers/pages_helper.rb
@@ -1,3 +1,4 @@
# coding: utf-8
require "RedCloth"
module PagesHelper
def textile(body)
Expand Down
1 change: 1 addition & 0 deletions app/helpers/posts_helper.rb
@@ -1,2 +1,3 @@
# coding: utf-8
module PostsHelper
end
1 change: 1 addition & 0 deletions app/helpers/settings_helper.rb
@@ -1,2 +1,3 @@
# coding: utf-8
module SettingsHelper
end
@@ -1,3 +1,4 @@
# coding: utf-8
class NoticeMailer < ActionMailer::Base
helper :application
layout "mailer"
Expand Down
8 changes: 5 additions & 3 deletions app/models/category.rb
@@ -1,11 +1,13 @@
# coding: utf-8
require "string_extensions"
class Category < ActiveRecord::Base
validates_presence_of :name

has_many :posts

before_update :before_update
before_update :recount_posts_count

def before_update
def recount_posts_count
self.posts_count = self.posts.count
end
end
end
11 changes: 6 additions & 5 deletions app/models/comment.rb
@@ -1,16 +1,17 @@
# coding: utf-8
class Comment < ActiveRecord::Base
belongs_to :post
belongs_to :post,:counter_cache => "comment_count"

validates_presence_of :author,:email,:body, :message => "还未填写."
validates_presence_of :author,:email,:body
default_scope :order => 'id ASC'
before_create :before_create

def before_create
before_create :default_value
def default_value
self.status = 1 if self.status.blank?
end

def created_at_s
created_at.to_s(:short_time_string)
I18n.l created_at
end

def self.find_list(page = 1, per_page = 20,options = {})
Expand Down
30 changes: 0 additions & 30 deletions app/models/comment_observer.rb

This file was deleted.

0 comments on commit 9c93e79

Please sign in to comment.