Permalink
Browse files

Fist commit, add 3rd gems and Models

  • Loading branch information...
0 parents commit e2df6ef483f290f6585ce2cf88d416cb36b85eee @huacnlee committed Mar 18, 2011
Showing with 1,498 additions and 0 deletions.
  1. +8 −0 .gitignore
  2. +44 −0 Gemfile
  3. +1 −0 README.textile
  4. +7 −0 Rakefile
  5. +3 −0 app/controllers/application_controller.rb
  6. +4 −0 app/controllers/home_controller.rb
  7. +2 −0 app/helpers/application_helper.rb
  8. +11 −0 app/models/answer.rb
  9. +20 −0 app/models/ask.rb
  10. +21 −0 app/models/authorization.rb
  11. +12 −0 app/models/comment.rb
  12. +4 −0 app/models/setting.rb
  13. +12 −0 app/models/topic.rb
  14. +42 −0 app/models/user.rb
  15. +10 −0 app/uploaders/avatar_uploader.rb
  16. +19 −0 app/uploaders/base_uploader.rb
  17. +10 −0 app/uploaders/cover_uploader.rb
  18. +1 −0 app/views/home/index.html.erb
  19. +14 −0 app/views/layouts/application.html.erb
  20. +4 −0 config.ru
  21. +47 −0 config/application.rb
  22. +6 −0 config/boot.rb
  23. +5 −0 config/environment.rb
  24. +26 −0 config/environments/development.rb
  25. +49 −0 config/environments/production.rb
  26. +35 −0 config/environments/test.rb
  27. +7 −0 config/initializers/backtrace_silencers.rb
  28. +7 −0 config/initializers/carrierwave.rb
  29. +143 −0 config/initializers/devise.rb
  30. +10 −0 config/initializers/inflections.rb
  31. +5 −0 config/initializers/mime_types.rb
  32. +3 −0 config/initializers/omniauth.rb
  33. +7 −0 config/initializers/secret_token.rb
  34. +8 −0 config/initializers/session_store.rb
  35. +53 −0 config/initializers/simple_form.rb
  36. +5 −0 config/locales/en.yml
  37. +24 −0 config/mongoid.yml
  38. +3 −0 config/routes.rb
  39. +24 −0 config/setting.yml
  40. +7 −0 db/seeds.rb
  41. +2 −0 doc/README_FOR_APP
  42. 0 lib/tasks/.gitkeep
  43. +26 −0 public/404.html
  44. +26 −0 public/422.html
  45. +26 −0 public/500.html
  46. 0 public/favicon.ico
  47. BIN public/images/ask_state.png
  48. BIN public/images/best_answer.png
  49. BIN public/images/fang_state.png
  50. BIN public/images/grid/arrow_down.gif
  51. BIN public/images/grid/arrow_up.gif
  52. BIN public/images/grid/calendar_view_month.png
  53. BIN public/images/grid/delete.png
  54. BIN public/images/grid/expand.png
  55. BIN public/images/grid/page_white_excel.png
  56. BIN public/images/grid/page_white_find.png
  57. BIN public/images/grid/table.png
  58. BIN public/images/grid/table_refresh.png
  59. BIN public/images/grid/tick_all.png
  60. BIN public/images/grid/untick_all.png
  61. BIN public/images/nav_menu/admin.png
  62. BIN public/images/nav_menu/admin_current.png
  63. BIN public/images/nav_menu/eats.png
  64. BIN public/images/nav_menu/eats_current.png
  65. BIN public/images/nav_menu/home.png
  66. BIN public/images/nav_menu/home_current.png
  67. BIN public/images/nav_menu/notepad.png
  68. BIN public/images/nav_menu/notepad_current.png
  69. BIN public/images/nav_menu/notices.png
  70. BIN public/images/nav_menu/notices_current.png
  71. BIN public/images/nav_menu/tasks.png
  72. BIN public/images/nav_menu/tasks_current.png
  73. BIN public/images/nav_menu/topics.png
  74. BIN public/images/nav_menu/topics_current.png
  75. BIN public/images/nav_menu/users.png
  76. BIN public/images/nav_menu/users_current.png
  77. BIN public/images/nav_menu/weeklies.png
  78. BIN public/images/nav_menu/weeklies_current.png
  79. BIN public/images/rails.png
  80. BIN public/images/rank1.gif
  81. BIN public/images/rank2.gif
  82. BIN public/images/rank3.gif
  83. BIN public/images/rank4.gif
  84. BIN public/images/rank5.gif
  85. BIN public/images/small/delete.png
  86. +27 −0 public/javascripts/application.js
  87. +188 −0 public/javascripts/jquery.jdialog.js
  88. +154 −0 public/javascripts/jquery.min.js
  89. +132 −0 public/javascripts/rails.js
  90. +161 −0 public/javascripts/wice_grid.js
  91. +5 −0 public/robots.txt
  92. 0 public/stylesheets/.gitkeep
  93. +6 −0 script/rails
  94. +9 −0 test/performance/browsing_test.rb
  95. +13 −0 test/test_helper.rb
  96. 0 vendor/plugins/.gitkeep
@@ -0,0 +1,8 @@
+.bundle
+Gemfile.lock
+db/*.sqlite3
+log/*.log
+tmp/
+config/*.default
+public/javascripts/cached_*
+public/stylesheets/cached_*
44 Gemfile
@@ -0,0 +1,44 @@
+source 'http://rubygems.org'
+gem 'rails', '3.0.5'
+
+# MongoDB
+gem "mongoid", "2.0.0.rc.7"
+gem "bson_ext", "~> 1.2.2"
+gem 'mongo-rails-instrumentation'
+gem "mongoid-eager-loading"
+
+# 用户系统
+gem 'devise', '1.2.rc2'
+
+# 图片上传
+gem 'carrierwave'
+gem 'mini_magick'
+
+# 分页
+gem 'will_paginate', '3.0.pre'
+gem 'memcache-client'
+
+# OAuth
+gem 'omniauth', '0.2.0.beta3'
+gem "oa-openid", '0.2.0.beta3'
+
+# 后台列表
+# gem 'wice_grid', '3.0.0.pre1'
+
+# 设置
+gem 'settingslogic'
+
+# 前端优化
+gem 'smurf-huacnlee'
+
+# 表单
+gem 'simple_form'
+
+# 缓存管理
+gem 'tagged-cache'
+
+# PUT 颜色
+gem 'colorize'
+
+
+
@@ -0,0 +1 @@
+Quora clone write in Ruby on Rails.
@@ -0,0 +1,7 @@
+# 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.expand_path('../config/application', __FILE__)
+require 'rake'
+
+Quora::Application.load_tasks
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
@@ -0,0 +1,4 @@
+class HomeController < ApplicationController
+ def index
+ end
+end
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
@@ -0,0 +1,11 @@
+# coding: utf-8
+class Answer
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field :body
+ belongs_to :ask, :inverse_of => :answers, :counter_cache => true
+ belongs_to :user, :inverse_of => :answers, :counter_cache => true
+
+ embeds_many :comments
+end
@@ -0,0 +1,20 @@
+# coding: utf-8
+class Ask
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field :title
+ field :body
+ field :answered_at, :type => DateTime
+ field :answers_count, :type => Integer, :default => 0
+
+ belongs_to :user, :inverse_of => :asks, :counter_cache => true
+ belongs_to :topic, :inverse_of => :asks, :counter_cache => true
+
+ embeds_many :comments
+
+ attr_protected :user_id
+
+ validates_presence_of :user_id, :title
+
+end
@@ -0,0 +1,21 @@
+class Authorization
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field :provider
+ field :uid
+ embedded_in :user, :inverse_of => :authorizations
+
+ validates_presence_of :uid, :provider
+ validates_uniqueness_of :uid, :scope => :provider
+
+ def self.find_from_hash(hash)
+ find_by_provider_and_uid(hash['provider'], hash['uid'])
+ end
+
+ def self.create_from_hash(hash, user = nil)
+ user ||= User.create_from_hash(hash)
+ Authorization.create(:user_id => user.id, :uid => hash['uid'], :provider => hash['provider'])
+ end
+end
+
@@ -0,0 +1,12 @@
+# coding: utf-8
+class Comment
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field :body
+
+ belongs_to :user
+
+ embedded_in :answer, :inverse_of => :comments
+ embedded_in :ask, :inverse_of => :comments
+end
@@ -0,0 +1,4 @@
+class Setting < Settingslogic
+ source "#{Rails.root}/config/setting.yml"
+ namespace Rails.env
+end
@@ -0,0 +1,12 @@
+# coding: utf-8
+class Topic
+ include Mongoid::Document
+
+ field :name
+ field :summary
+ field :cover
+
+ field :asks_count, :type => Integer, :default => 0
+ has_many :asks
+
+end
@@ -0,0 +1,42 @@
+# coding: utf-8
+class User
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ devise :database_authenticatable, :registerable,
+ :recoverable, :rememberable, :trackable, :validatable
+
+ field :name
+ field :slug
+ field :tagline
+ field :bio
+ field :avatar
+ field :website
+
+ field :asks_count, :type => Integer, :default => 0
+ has_many :asks
+
+ field :answers_count, :type => Integer, :default => 0
+ has_many :answers
+
+ embeds_many :authorizations
+
+ attr_accessor :password_confirmation
+ attr_accessible :name, :slug, :tagline, :bio, :avatar, :website
+
+ def password_required?
+ (authorizations.empty? || !password.blank?) && super
+ end
+
+ mount_uploader :avatar, AvatarUploader
+
+ def self.create_from_hash(auth)
+ user = User.new
+ user.name = auth["user_info"]["name"]
+ user.email = auth['user_info']['email']
+ user.save(false)
+ user.reset_persistence_token! #set persistence_token else sessions will not be created
+ user
+ end
+
+end
@@ -0,0 +1,10 @@
+class AvatarUploader < BaseUploader
+ version :small do
+ process :resize_to_fill => [25, 25]
+ end
+
+ version :normal do
+ process :resize_to_fill => [100, 100]
+ end
+
+end
@@ -0,0 +1,19 @@
+# coding: UTF-8
+require 'carrierwave/processing/mini_magick'
+class BaseUploader < CarrierWave::Uploader::Base
+ include CarrierWave::MiniMagick
+ storage :grid_fs
+
+ def store_dir
+ "#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
+ end
+
+
+ # TODO: 此处要想办法,开启了 open-uri 下载的因为文件名的问题无法通过验证
+ # Allow image file extensions
+ # def extension_white_list
+ # %w(jpg jpeg gif png)
+ # end
+
+end
+
@@ -0,0 +1,10 @@
+class CoverUploader < BaseUploader
+ version :small do
+ process :resize_to_fill => [25, 25]
+ end
+
+ version :normal do
+ process :resize_to_limit => [100, nil]
+ end
+
+end
@@ -0,0 +1 @@
+Well come.
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Quora</title>
+ <%= stylesheet_link_tag :all %>
+ <%= javascript_include_tag :defaults %>
+ <%= csrf_meta_tag %>
+</head>
+<body>
+
+<%= yield %>
+
+</body>
+</html>
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Quora::Application
@@ -0,0 +1,47 @@
+require File.expand_path('../boot', __FILE__)
+
+require "action_controller/railtie"
+require "action_mailer/railtie"
+require "active_resource/railtie"
+require "rails/test_unit/railtie"
+
+# If you have a Gemfile, require the gems listed there, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(:default, Rails.env) if defined?(Bundler)
+
+module Quora
+ class Application < Rails::Application
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Custom directories with classes and modules you want to be autoloadable.
+ config.autoload_paths += %W(#{config.root}/uploaders)
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named.
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Activate observers that should always be running.
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
+ config.time_zone = 'Beijing'
+
+ # 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'
+
+ # JavaScript files you want as :defaults (application.js is always included).
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
+
+ # Configure the default encoding used in templates for Ruby 1.9.
+ config.encoding = "utf-8"
+
+ # Configure sensitive parameters which will be filtered from the log file.
+ config.filter_parameters += [:password]
+ config.mongoid.logger = Logger.new($stdout, :warn)
+ end
+end
+
@@ -0,0 +1,6 @@
+require 'rubygems'
+
+# Set up gems listed in the Gemfile.
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+
+require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Quora::Application.initialize!
@@ -0,0 +1,26 @@
+Quora::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the webserver when you make code changes.
+ config.cache_classes = false
+
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_view.debug_rjs = true
+ config.action_controller.perform_caching = false
+
+ # Don't care if the mailer can't send
+ config.action_mailer.raise_delivery_errors = false
+
+ # Print deprecation notices to the Rails logger
+ config.active_support.deprecation = :log
+
+ # Only use best-standards-support built into browsers
+ config.action_dispatch.best_standards_support = :builtin
+end
+
Oops, something went wrong.

0 comments on commit e2df6ef

Please sign in to comment.