Permalink
Browse files

Twitter gem upgrade.

use I18n gem to instill zh_cn.yml;
fix posts list draft not hidde bug.
  • Loading branch information...
1 parent d537118 commit e94d370b8ab6c4e1192f6c30c20cad22d0b32d54 @huacnlee committed Nov 7, 2011
View
@@ -5,9 +5,10 @@ gem 'mysql2', "0.2.7"
gem 'simple-rss', '1.2.3'
gem 'will_paginate', '3.0.pre'
gem 'acts-as-taggable-on','2.0.6'
-gem 'twitter', '1.2.0'
+gem 'twitter', '1.7.2'
gem 'dalli', '1.0.4'
gem 'tagged-cache', '1.1.1'
gem "heroku"
gem "taps", '0.3.23'
-gem "bluecloth","2.1.0"
+gem "bluecloth","2.1.0"
+gem 'rails-i18n', '0.1.8'
View
@@ -36,13 +36,13 @@ GEM
dalli (1.0.4)
erubis (2.6.6)
abstract (>= 1.0.0)
- faraday (0.5.7)
- addressable (~> 2.2.4)
- multipart-post (~> 1.1.0)
+ faraday (0.7.5)
+ addressable (~> 2.2.6)
+ multipart-post (~> 1.1.3)
rack (>= 1.1.0, < 2)
- faraday_middleware (0.3.2)
- faraday (~> 0.5.4)
- hashie (1.0.0)
+ faraday_middleware (0.7.0)
+ faraday (~> 0.7.3)
+ hashie (1.1.0)
heroku (2.9.0)
launchy (>= 0.3.2)
rest-client (~> 1.6.1)
@@ -58,9 +58,9 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.17.1)
- multi_json (0.0.5)
- multi_xml (0.2.2)
- multipart-post (1.1.2)
+ multi_json (1.0.3)
+ multi_xml (0.4.1)
+ multipart-post (1.1.3)
mysql2 (0.2.7)
polyglot (0.3.2)
rack (1.2.4)
@@ -76,6 +76,8 @@ GEM
activesupport (= 3.0.9)
bundler (~> 1.0)
railties (= 3.0.9)
+ rails-i18n (0.1.8)
+ i18n (~> 0.5)
railties (3.0.9)
actionpack (= 3.0.9)
activesupport (= 3.0.9)
@@ -109,13 +111,13 @@ GEM
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
- twitter (1.2.0)
- faraday (~> 0.5.4)
- faraday_middleware (~> 0.3.2)
- hashie (~> 1.0.0)
- multi_json (~> 0.0.5)
- multi_xml (~> 0.2.0)
- simple_oauth (~> 0.1.4)
+ twitter (1.7.2)
+ faraday (~> 0.7.4)
+ faraday_middleware (~> 0.7.0)
+ hashie (~> 1.1.0)
+ multi_json (~> 1.0.0)
+ multi_xml (~> 0.4.0)
+ simple_oauth (~> 0.1.5)
tzinfo (0.3.30)
will_paginate (3.0.pre)
@@ -129,8 +131,9 @@ DEPENDENCIES
heroku
mysql2 (= 0.2.7)
rails (= 3.0.9)
+ rails-i18n (= 0.1.8)
simple-rss (= 1.2.3)
tagged-cache (= 1.1.1)
taps (= 0.3.23)
- twitter (= 1.2.0)
+ twitter (= 1.7.2)
will_paginate (= 3.0.pre)
@@ -13,7 +13,7 @@ class Cpanel::PagesController < Cpanel::ApplicationController
# 页面列表
def index
- @pages = Page.find_list(1)
+ @pages = Page.paginate :page => params[:page], :per_page => 20, :order => 'id desc'
end
# 创建页面
@@ -18,7 +18,7 @@ def index
end
if !fragment_exist? "home/index/recent_posts"
- @recent_posts = Post.limit(13).where(:status => 1)
+ @recent_posts = Post.publish.limit(13).where(:status => 1)
end
end
@@ -21,13 +21,13 @@ def index
return
end
- @posts = @category.posts.paginate :include => [:category],:page => page, :per_page => 5
+ @posts = @category.posts.publish.paginate :include => [:category],:page => page, :per_page => 5
set_seo_meta("博客 &raquo; 分类:#{@category.name}")
elsif params[:tag]
- @posts = Post.tagged_with(params[:tag]).paginate :include => [:category],:page => page, :per_page => 5
+ @posts = Post.tagged_with(params[:tag]).publish.paginate :include => [:category],:page => page, :per_page => 5
set_seo_meta("博客 &raquo; Tag:#{params[:tag]}")
else
- @posts = Post.paginate :include => [:category], :page => page, :per_page => 5
+ @posts = Post.publish.paginate :include => [:category], :page => page, :per_page => 5
set_seo_meta("博客")
end
end
@@ -36,7 +36,7 @@ def index
def rss
# Get the 10 most recent photos
- @posts = Post.paginate :include => [:category], :page => 1, :per_page => 20
+ @posts = Post.publish.paginate :include => [:category], :page => 1, :per_page => 20
# Title for the RSS feed
@feed_title = "10 most recent photos"
# Get the absolute URL which produces the feed
@@ -1,68 +0,0 @@
-# XML-RPC protocol support clone with Wordpress
-# API interface: http://codex.wordpress.org/XML-RPC_wp
-require 'xmlrpc/server'
-class XmlrpcController < ActionController::Base
-
- def initialize
- @server = XMLRPC::BasicServer.new
- # loop through all the methods, adding them as handlers
- self.class.instance_methods(false).each do |method|
- if not ['index','rsd'].index(method.to_s)
- logger.debug "------ in #{method}"
- @server.add_handler("wp.#{method.to_s}") do |*args|
- self.send(method.to_sym, *args)
- end
- end
- end
- @setting = Setting.find_create
- end
-
-
- def index
- if !params[:rsd].blank?
- return rsd
- end
-
- result = @server.process(request.body)
- logger.info "\n\n----- BEGIN RESULT -----\n#{result}\n----- END RESULT -----\n"
- render :text => result, :content_type => 'text/xml'
- end
-
- private
- def rsd
- render "rsd", :layout => false
- end
-
- public
- def getUsersBlogs(username,password)
- logger.debug "------ in getUsersBlogs"
- if user = User.check_login(username,User.encode(password))
- array = [{
- 'isAdmin' => true,
- 'url' => root_url,
- 'blogid' => 1,
- 'blogName' => @setting.site_name,
- 'xmlrpc' => xmlrpc_url
- }]
- return array
- else
- render :status => 403
- end
- end
-
- def getTags(blog_id,username,password)
- tags = Tag.all
- result = []
- tags.each do |tag|
- result << {
- 'tag_id' => tag.id,
- 'name' => tag.name,
- 'count' => 0,
- 'slug' => tag.name,
- 'html_url' =>tag_blogs_url(tag.name),
- 'rss_url' => ''
- }
- end
- return result
- end
-end
View
@@ -6,7 +6,6 @@ class Category < ActiveRecord::Base
has_many :posts
before_update :recount_posts_count
-
def recount_posts_count
self.posts_count = self.posts.count
end
View
@@ -1,30 +1,24 @@
# coding: utf-8
class Page < ActiveRecord::Base
validates_uniqueness_of :title, :slug, :case_sensitive => false , :message => "已经有同名的存在,请检查是否重发了."
- before_validation :safe_slug_for_validation
# status
STATUS = [
["请选择状态",-1],
["发布",1],
["草稿",2],
].freeze
+
+ scope :publish, where(:status => 1)
- private
# before validation
+ before_validation :safe_slug_for_validation
def safe_slug_for_validation
self.slug = self.slug.safe_slug
end
# custom methods
public
- # find list
- def self.find_list(page = 1, per_page = 20,options = {})
- with_scope :find => options do
- paginate :page => page,:per_page => per_page, :order => 'created_at desc'
- end
- end
-
def self.find_show(slug)
find_by_slug_and_status(slug,1)
end
View
@@ -1,16 +1,17 @@
# coding: utf-8
require "string_extensions"
class Post < ActiveRecord::Base
- validates_uniqueness_of :title, :slug, :case_sensitive => false , :message => "已经有同名的存在,请检查是否重发了."
- validates_presence_of :title,:body,:status
- belongs_to :category, :counter_cache => true
acts_as_taggable_on :tags
- default_scope :order => 'posts.id desc'
+ belongs_to :category, :counter_cache => true
+ validates_uniqueness_of :title, :slug, :case_sensitive => false , :message => "已经有同名的存在,请检查是否重发了."
+ validates_presence_of :title,:body,:status
+
# callback events
before_validation :safe_slug_validation
-
- # enum sets
+ def safe_slug_validation
+ self.slug = self.slug.safe_slug
+ end
# status
STATUS = [
@@ -19,7 +20,9 @@ class Post < ActiveRecord::Base
["草稿",2],
].freeze
- # custome field
+ # scope
+ default_scope :order => 'posts.id desc'
+ scope :publish, where(:status => 1)
# string formated created_at
def created_at_s
@@ -42,21 +45,8 @@ def delay_view_count
Rails.cache.read(cache_key).to_i || 0
end
-
- # before validation
- def safe_slug_validation
- self.slug = self.slug.safe_slug
- end
-
-
# custom method
public
- def self.find_list_with_front_by_tag(page = 1, per_page = 5,tag = '', options = {})
- tagged_with(tag,:on => :tags).paginate(:page => page,:per_page => per_page,
- :include => [:tags,:category],
- :conditions => ["status =1"])
- end
-
# show
def self.find_slug(slug)
p = Rails.cache.read("models/posts/#{slug}")
@@ -86,12 +76,4 @@ def self.update_view_count(slug)
Rails.cache.write(cache_key,count)
count
end
-
-
-
- def self.destroy_all
- all.each do |p|
- p.destroy
- end
- end
end
View
@@ -10,7 +10,7 @@ def self.api_url(setting)
end
def self.find_all(setting,force = false)
- cache_key = "data/shares"
+ cache_key = "data/share_items"
feeds = Rails.cache.read(cache_key)
if not feeds or force
feeds = []
@@ -26,7 +26,7 @@ def self.find_all(setting,force = false)
}
end
end
- Rails.cache.write(cache_key,feeds)
+ Rails.cache.write(cache_key,feeds, :expires_in => 1.days)
end
feeds
end
View
@@ -8,7 +8,7 @@ def self.gets(uid = 'huacnlee',count = 5,force = false)
msgs = Rails.cache.read("data/tweet/#{uid}")
if not msgs or force
msgs = Twitter.user_timeline(uid, :count => count)
- Rails.cache.write("data/tweet/#{uid}",msgs, :expires_in => 20.minutes)
+ Rails.cache.write("data/tweet/#{uid}",msgs, :expires_in => 15.minutes)
end
msgs
View
@@ -32,7 +32,7 @@ class Application < Rails::Application
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
- config.i18n.default_locale = :zh_cn
+ config.i18n.default_locale = "zh-CN"
# JavaScript files you want as :defaults (application.js is always included).
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
View
@@ -1,5 +0,0 @@
-# Sample localization file for English. Add more files in this directory for other locales.
-# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
-
-en:
- hello: "Hello world"
Oops, something went wrong.

0 comments on commit e94d370

Please sign in to comment.