Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add google custom search

  • Loading branch information...
commit cf3356799961e9ce9476f809a64a85516ddcd478 1 parent 1cc9eb6
@chloerei authored
View
1  .gitignore
@@ -6,4 +6,5 @@ tmp/
*.swp
*.swo
config/mongoid.yml
+config/app_config.yml
public/assets
View
136 app/assets/stylesheets/search.scss
@@ -0,0 +1,136 @@
+#search {
+ table th, table td {
+ padding: 13px 0 12px;
+ }
+
+ table th + th, table td + td {
+ border: none;
+ }
+
+ td.gsc-search-button {
+ padding-left: 12px;
+ }
+
+ input.gsc-search-button {
+ height: 28px;
+ cursor: pointer;
+ display: inline-block;
+ background-color: #e6e6e6;
+ background-repeat: no-repeat;
+ background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), color-stop(25%, #ffffff), to(#e6e6e6));
+ background-image: -webkit-linear-gradient(#ffffff, #ffffff 25%, #e6e6e6);
+ background-image: -moz-linear-gradient(top, #ffffff, #ffffff 25%, #e6e6e6);
+ background-image: -ms-linear-gradient(#ffffff, #ffffff 25%, #e6e6e6);
+ background-image: -o-linear-gradient(#ffffff, #ffffff 25%, #e6e6e6);
+ background-image: linear-gradient(#ffffff, #ffffff 25%, #e6e6e6);
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#e6e6e6', GradientType=0);
+ padding: 5px 14px 6px;
+ text-shadow: 0 1px 1px rgba(255, 255, 255, 0.75);
+ color: #333;
+ font-size: 13px;
+ line-height: normal;
+ border: 1px solid #ccc;
+ border-bottom-color: #bbb;
+ -webkit-border-radius: 4px;
+ -moz-border-radius: 4px;
+ border-radius: 4px;
+ -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
+ -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
+ box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
+ -webkit-transition: 0.1s linear all;
+ -moz-transition: 0.1s linear all;
+ -ms-transition: 0.1s linear all;
+ -o-transition: 0.1s linear all;
+ transition: 0.1s linear all;
+
+ &:hover {
+ background-position: 0 -15px;
+ color: #333;
+ text-decoration: none;
+ }
+
+ &:focus {
+ outline: 1px dotted #666;
+ }
+ }
+
+ .gsc-table-result {
+ border: none;
+ }
+
+ .gsc-results {
+ width: 100%;
+ }
+
+ table.gsc-table-result {
+ margin: 0;
+ }
+
+ .gsc-webResult .gsc-result {
+ padding: 0;
+ }
+
+ .gsc-result-info {
+ padding-left: 0;
+ border: none;
+ }
+
+ .gs-result .gs-title, .gs-result .gs-title * {
+ color: #0069D6;
+ text-decoration: none;
+ font-size: 100%;
+ font-weight: bold;
+
+ &:hover {
+ color: #00438A;
+ text-decoration: underline;
+
+ b {
+ color: #00438A;
+ }
+ }
+ }
+
+ .gs-result a.gs-visibleUrl, .gs-result .gs-visibleUrl {
+ display: none;
+ }
+
+ .gsc-cursor-box {
+ height: 34px;
+ display: inline-block;
+ margin: 18px 0;
+ border: 1px solid #DDD;
+ border: 1px solid rgba(0, 0, 0, 0.15);
+ -webkit-border-radius: 3px;
+ -moz-border-radius: 3px;
+ border-radius: 3px;
+ -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
+ -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
+
+ .gsc-cursor-page {
+ color: #0069D6;
+ padding: 0 14px;
+ line-height: 34px;
+ border-right: 1px solid;
+ border-right-color: #DDD;
+ border-right-color: rgba(0, 0, 0, 0.15);
+ text-decoration: none;
+ display: inline-block;
+ margin: 0;
+
+ &:hover {
+ background-color: #c7eefe;
+ }
+
+ &:last-child {
+ border-right: none;
+ }
+ }
+ .gsc-cursor-current-page {
+ background-color: #c7eefe;
+ font-weight: normal;
+ }
+ }
+
+}
View
4 app/controllers/search_controller.rb
@@ -0,0 +1,4 @@
+class SearchController < ApplicationController
+ def show
+ end
+end
View
2  app/views/layouts/_topbar.haml
@@ -10,6 +10,8 @@
= link_to t('.resources'), resources_path
%li{:class => (controller_name == 'topics' ? 'active' : nil)}
= link_to t('.topics'), topics_path
+ %li{:class => (controller_name == 'search' ? 'active' : nil)}
+ = link_to t('.search'), search_path
%ul.nav.secondary-nav
- if logined?
- notification_class = []
View
22 app/views/search/show.haml
@@ -0,0 +1,22 @@
+- content_for :head do
+ = stylesheet_link_tag 'search'
+
+#main
+ .container
+ .row
+ #mainbar.span12
+ %section.box#search
+ #cse= t '.loading'
+ #sidebar.span4
+ - if logined?
+ = render :partial => 'shared/sidebar_profile'
+ - else
+ = render :partial => 'shared/sidebar_login'
+ = javascript_include_tag 'http://www.google.com/jsapi'
+ :javascript
+ google.load('search', '1', {language : '#{I18n.locale}'});
+ google.setOnLoadCallback(function() {
+ var customSearchControl = new google.search.CustomSearchControl('#{APP_CONFIG['google_custom_search_id']}');
+ customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
+ customSearchControl.draw('cse');
+ }, true);
View
11 config/app_config.example.yml
@@ -0,0 +1,11 @@
+production:
+ google_custom_search_id: ""
+
+defaults: &defaults
+ google_custom_search_id: ""
+
+development:
+ <<: *defaults
+
+test:
+ <<: *defaults
View
3  config/application.rb
@@ -55,7 +55,7 @@ class Application < Rails::Application
config.assets.precompile += %w(wmd-buttons.png)
config.assets.precompile += %w(editor.js setttings/favorite_tags.js resources/new.js resources/show.js)
config.assets.precompile += %w(settings/favorite_tags.js topics/show.js)
- config.assets.precompile += %w(editor.css resources.css settings/favorite_tags.css)
+ config.assets.precompile += %w(editor.css resources.css search.css settings/favorite_tags.css)
config.generators do |g|
g.test_framework :test_unit, :fixture_replacement => :factory_girl
@@ -66,3 +66,4 @@ class Application < Rails::Application
end
AllowLocale = %w(zh-CN en)
+APP_CONFIG = YAML.load_file("#{Rails.root}/config/app_config.yml")[Rails.env]
View
4 config/locales/en.yml
@@ -27,6 +27,7 @@ en:
home: "Home"
resources: "Resources"
topics: "Topics"
+ search: "Search"
profiles: "Profile"
settings: "Settings"
shared:
@@ -128,6 +129,9 @@ en:
new:
topics: "Topics"
new_reply: "New Reply"
+ search:
+ show:
+ loading: "Loading..."
mongoid:
attributes:
View
4 config/locales/zh-CN.yml
@@ -27,6 +27,7 @@ zh-CN:
home: "首页"
resources: "资源"
topics: "话题"
+ search: "搜索"
profiles: "个人资料"
settings: "设置"
shared:
@@ -128,6 +129,9 @@ zh-CN:
new:
topics: "话题"
new_reply: "新回复"
+ search:
+ show:
+ loading: "载入中..."
mongoid:
attributes:
View
2  config/routes.rb
@@ -7,6 +7,8 @@
resources :users, :only => [:create]
resources :user_sessions, :only => [:create]
+ resource :search, :controller => 'search', :only => 'show'
+
get '~:name', :controller => 'people', :action => 'show', :as => :person
resources :notifications, :only => [:index, :destroy] do
collection do
View
1  test/functional/homepage_controller_test.rb
@@ -5,5 +5,4 @@ class HomepageControllerTest < ActionController::TestCase
get :index
assert_response :success
end
-
end
View
8 test/functional/search_controller_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class SearchControllerTest < ActionController::TestCase
+ test "should get show page" do
+ get :show
+ assert_response :success, @response.body
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.