diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 896311d..501e26c 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -27,4 +27,11 @@ def show set_nav_actived(@page.slug) render :file => "pages/show", :layout => "application" end + + def share + set_nav_actived("share") + set_seo_meta("Google Reader 分享") + @api_url = Share.api_url(@setting) + @shares = Share.find_all(@setting) + end end diff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rb deleted file mode 100644 index ada5059..0000000 --- a/app/controllers/shares_controller.rb +++ /dev/null @@ -1,85 +0,0 @@ -class SharesController < ApplicationController - # GET /shares - # GET /shares.xml - def index - @shares = Share.all - - respond_to do |format| - format.html # index.html.erb - format.xml { render :xml => @shares } - end - end - - # GET /shares/1 - # GET /shares/1.xml - def show - @share = Share.find(params[:id]) - - respond_to do |format| - format.html # show.html.erb - format.xml { render :xml => @share } - end - end - - # GET /shares/new - # GET /shares/new.xml - def new - @share = Share.new - - respond_to do |format| - format.html # new.html.erb - format.xml { render :xml => @share } - end - end - - # GET /shares/1/edit - def edit - @share = Share.find(params[:id]) - end - - # POST /shares - # POST /shares.xml - def create - @share = Share.new(params[:share]) - - respond_to do |format| - if @share.save - flash[:notice] = 'Share was successfully created.' - format.html { redirect_to(@share) } - format.xml { render :xml => @share, :status => :created, :location => @share } - else - format.html { render :action => "new" } - format.xml { render :xml => @share.errors, :status => :unprocessable_entity } - end - end - end - - # PUT /shares/1 - # PUT /shares/1.xml - def update - @share = Share.find(params[:id]) - - respond_to do |format| - if @share.update_attributes(params[:share]) - flash[:notice] = 'Share was successfully updated.' - format.html { redirect_to(@share) } - format.xml { head :ok } - else - format.html { render :action => "edit" } - format.xml { render :xml => @share.errors, :status => :unprocessable_entity } - end - end - end - - # DELETE /shares/1 - # DELETE /shares/1.xml - def destroy - @share = Share.find(params[:id]) - @share.destroy - - respond_to do |format| - format.html { redirect_to(shares_url) } - format.xml { head :ok } - end - end -end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4a306f3..6b70874 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -13,4 +13,6 @@ def success_messages '' end end + + end \ No newline at end of file diff --git a/app/helpers/blogs_helper.rb b/app/helpers/blogs_helper.rb deleted file mode 100644 index cc0dbd2..0000000 --- a/app/helpers/blogs_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module BlogsHelper -end diff --git a/app/helpers/shares_helper.rb b/app/helpers/shares_helper.rb deleted file mode 100644 index e51aa8b..0000000 --- a/app/helpers/shares_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module SharesHelper -end diff --git a/app/models/setting.rb b/app/models/setting.rb index 68610cc..9715461 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -9,6 +9,7 @@ def self.find_create :email => "huacnlee@gmail.com", :meta_description => "我是一个Web开发人员,.NET,Python,Ruby,PHP,Javascrip等都有在用,我是做互联网开发的,这是一个用于介绍我自已的网站.", :fanfou_id => "huacn", + :google_reader_id => "08982619185204047523", :home_show => '
diff --git a/app/models/share.rb b/app/models/share.rb index 9fb2c82..8fb6612 100644 --- a/app/models/share.rb +++ b/app/models/share.rb @@ -1,2 +1,34 @@ +require "rubygems" +require 'simple-rss' +require 'open-uri' +require "lib/string" + class Share < ActiveRecord::Base + + def self.api_url(setting) + "http://www.google.com/reader/public/atom/user%2F#{setting.google_reader_id}%2Fstate%2Fcom.google%2Fbroadcast" + end + + def self.find_all(setting) + @expire_minutes = 1.days.minutes + cache_key = "data/shares" + feeds = Rails.cache.read(cache_key) + if not feeds + feeds = [] + feed = SimpleRSS::parse open(api_url(setting)) + if feed != nil + feed.items.each do |item| + feeds << { + "title" => item.title, + "link" => item.link, + "content" => item.content == nil ? item.summary.html_decode.remove_html_tag()[0..500] + '...' : item.content.html_decode.remove_html_tag()[0..500] + '...', + "updated_at" => item.updated, + "author" => item.author, + } + end + end + Rails.cache.write(cache_key,feeds,:expires_in => @expire_minutes) + end + feeds + end end diff --git a/app/views/cpanel/settings/index.html.erb b/app/views/cpanel/settings/index.html.erb index 56f1266..5f33523 100644 --- a/app/views/cpanel/settings/index.html.erb +++ b/app/views/cpanel/settings/index.html.erb @@ -23,6 +23,10 @@ 饭否ID <%= f.text_field :fanfou_id, :class => "text middle" %> + + Google Reader + http://www.google.com/reader/shared/<%= f.text_field :google_reader_id, :class => "text short" %> + Meta Keywords <%= f.text_field :meta_keywords, :class => "text long" %> diff --git a/app/views/shares/edit.html.erb b/app/views/shares/edit.html.erb deleted file mode 100644 index ec9fdbf..0000000 --- a/app/views/shares/edit.html.erb +++ /dev/null @@ -1,32 +0,0 @@ -

Editing share

- -<% form_for(@share) do |f| %> - <%= f.error_messages %> - -

- <%= f.label :title %>
- <%= f.text_field :title %> -

-

- <%= f.label :summary %>
- <%= f.text_field :summary %> -

-

- <%= f.label :from %>
- <%= f.text_field :from %> -

-

- <%= f.label :cover %>
- <%= f.text_field :cover %> -

-

- <%= f.label :url %>
- <%= f.text_field :url %> -

-

- <%= f.submit 'Update' %> -

-<% end %> - -<%= link_to 'Show', @share %> | -<%= link_to 'Back', shares_path %> \ No newline at end of file diff --git a/app/views/shares/index.html.erb b/app/views/shares/index.html.erb deleted file mode 100644 index 0ff1fb3..0000000 --- a/app/views/shares/index.html.erb +++ /dev/null @@ -1,28 +0,0 @@ -

Listing shares

- - - - - - - - - - -<% @shares.each do |share| %> - - - - - - - - - - -<% end %> -
TitleSummaryFromCoverUrl
<%=h share.title %><%=h share.summary %><%=h share.from %><%=h share.cover %><%=h share.url %><%= link_to 'Show', share %><%= link_to 'Edit', edit_share_path(share) %><%= link_to 'Destroy', share, :confirm => 'Are you sure?', :method => :delete %>
- -
- -<%= link_to 'New share', new_share_path %> \ No newline at end of file diff --git a/app/views/shares/new.html.erb b/app/views/shares/new.html.erb deleted file mode 100644 index d148e8b..0000000 --- a/app/views/shares/new.html.erb +++ /dev/null @@ -1,31 +0,0 @@ -

New share

- -<% form_for(@share) do |f| %> - <%= f.error_messages %> - -

- <%= f.label :title %>
- <%= f.text_field :title %> -

-

- <%= f.label :summary %>
- <%= f.text_field :summary %> -

-

- <%= f.label :from %>
- <%= f.text_field :from %> -

-

- <%= f.label :cover %>
- <%= f.text_field :cover %> -

-

- <%= f.label :url %>
- <%= f.text_field :url %> -

-

- <%= f.submit 'Create' %> -

-<% end %> - -<%= link_to 'Back', shares_path %> \ No newline at end of file diff --git a/app/views/shares/show.html.erb b/app/views/shares/show.html.erb deleted file mode 100644 index 98cbc25..0000000 --- a/app/views/shares/show.html.erb +++ /dev/null @@ -1,28 +0,0 @@ -

- Title: - <%=h @share.title %> -

- -

- Summary: - <%=h @share.summary %> -

- -

- From: - <%=h @share.from %> -

- -

- Cover: - <%=h @share.cover %> -

- -

- Url: - <%=h @share.url %> -

- - -<%= link_to 'Edit', edit_share_path(@share) %> | -<%= link_to 'Back', shares_path %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 998bcbb..9dd0f40 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,8 +12,7 @@ end # Share - map.resources :controller => "shares", :as => "share" - + # Blog map.purchase "blog", :controller => "posts" map.purchase "blog", :controller => "posts", :action => "index" @@ -21,6 +20,8 @@ map.purchase "blog/page/:page", :controller => "posts", :action => "index", :requirements => { :page => /[\d]+/ } map.purchase "blog/:slug", :controller => "posts", :action => "show", :requirements => { :slug => /[a-z0-9A-Z\-\_\.]+/ } + map.purchase "share", :controller => "home", :action => "share" + # Pages (This well be stay last line) map.purchase ":slug", :controller => "home", :action => "show", :requirements => { :slug => /[a-z0-9A-Z\-\_\.]+/ } diff --git a/db/development.sqlite3 b/db/development.sqlite3 index 25ba0a9..456536e 100644 Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ diff --git a/db/schema.rb b/db/schema.rb index 1262d65..0decc20 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20090517034648) do +ActiveRecord::Schema.define(:version => 20090517064606) do create_table "comments", :force => true do |t| t.integer "post_id", :null => false @@ -71,16 +71,7 @@ t.datetime "updated_at" t.string "fanfou_id" t.string "blog_feed_html" - end - - create_table "shares", :force => true do |t| - t.string "title", :null => false - t.string "summary", :null => false - t.string "from" - t.string "cover" - t.string "url", :null => false - t.datetime "created_at" - t.datetime "updated_at" + t.string "google_reader_id" end create_table "tags", :force => true do |t| diff --git a/lib/string.rb b/lib/string.rb index 142876f..77c4b86 100644 --- a/lib/string.rb +++ b/lib/string.rb @@ -28,6 +28,15 @@ def truncate_html(len = 30, ellipsis = "...") (results + ellipsis) end + def remove_html_tag() + self.gsub(/<.+?>/, "") + end + + def html_decode + es = {'&' => '&', '>' => '>', '<' => '<', '"' => '"'} + self.gsub(/&|>|<|"/) { |s| es[s] } + end + # clear unsafe char with url slug def safe_slug(spliter = '-') @slug = self diff --git a/personlab.tmproj b/personlab.tmproj index ddb8803..90d1f43 100644 --- a/personlab.tmproj +++ b/personlab.tmproj @@ -2,8 +2,6 @@ - currentDocument - app/controllers/application_controller.rb documents @@ -20,363 +18,10 @@ fileHierarchyDrawerWidth 259 metaData - - app/controllers/application_controller.rb - - caret - - column - 21 - line - 7 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - app/controllers/cpanel/comments_controller.rb - - caret - - column - 0 - line - 9 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - app/controllers/cpanel/posts_controller.rb - - caret - - column - 65 - line - 1 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - app/controllers/posts_controller.rb - - caret - - column - 50 - line - 71 - - firstVisibleColumn - 0 - firstVisibleLine - 60 - - app/models/comment.rb - - caret - - column - 20 - line - 12 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - app/models/comment_observer.rb - - caret - - column - 27 - line - 25 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - app/sweepers/comment_sweeper.rb - - caret - - column - 34 - line - 19 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - app/sweepers/menu_sweeper.rb - - caret - - column - 36 - line - 12 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - app/sweepers/page_sweeper.rb - - caret - - column - 26 - line - 4 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - app/sweepers/post_sweeper.rb - - caret - - column - 25 - line - 11 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - app/views/cpanel/menus/edit.html.erb - - caret - - column - 24 - line - 7 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - app/views/cpanel/menus/index.html.erb - - caret - - column - 23 - line - 5 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - app/views/cpanel/pages/edit.html.erb - - caret - - column - 0 - line - 9 - - columnSelection - - firstVisibleColumn - 0 - firstVisibleLine - 0 - selectFrom - - column - 23 - line - 9 - - selectTo - - column - 0 - line - 9 - - - app/views/cpanel/pages/index.html.erb - - caret - - column - 0 - line - 5 - - columnSelection - - firstVisibleColumn - 0 - firstVisibleLine - 0 - selectFrom - - column - 23 - line - 5 - - selectTo - - column - 0 - line - 5 - - - app/views/cpanel/posts/edit.html.erb - - caret - - column - 25 - line - 16 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - app/views/posts/_posts.html.erb - - caret - - column - 4 - line - 5 - - columnSelection - - firstVisibleColumn - 0 - firstVisibleLine - 0 - selectFrom - - column - 95 - line - 5 - - selectTo - - column - 4 - line - 5 - - - app/views/posts/show.html.erb - - caret - - column - 15 - line - 14 - - firstVisibleColumn - 0 - firstVisibleLine - 14 - - config/environment.rb - - caret - - column - 0 - line - 52 - - firstVisibleColumn - 0 - firstVisibleLine - 25 - - config/environments/development.rb - - caret - - column - 11 - line - 8 - - columnSelection - - firstVisibleColumn - 0 - firstVisibleLine - 0 - selectFrom - - column - 7 - line - 8 - - selectTo - - column - 17 - line - 8 - - - - openDocuments - - app/views/posts/show.html.erb - app/sweepers/comment_sweeper.rb - config/environments/development.rb - app/sweepers/page_sweeper.rb - app/views/cpanel/menus/index.html.erb - app/models/comment.rb - app/models/comment_observer.rb - app/sweepers/post_sweeper.rb - app/controllers/cpanel/posts_controller.rb - app/controllers/cpanel/comments_controller.rb - app/sweepers/menu_sweeper.rb - app/views/cpanel/pages/index.html.erb - app/views/cpanel/menus/edit.html.erb - app/views/cpanel/posts/edit.html.erb - app/views/cpanel/pages/edit.html.erb - app/views/posts/_posts.html.erb - app/controllers/application_controller.rb - app/controllers/posts_controller.rb - config/environment.rb - + showFileHierarchyDrawer windowFrame - {{289, 146}, {871, 595}} + {{590, 92}, {871, 595}} diff --git a/public/about.html b/public/about.html index ee67be1..80f7c23 100644 --- a/public/about.html +++ b/public/about.html @@ -3,22 +3,22 @@ - 关于我 - Jason Lee + 关于我 - 李华顺 - + - +