Skip to content

Commit

Permalink
Adding memory search controller, which will perform the ajax searches
Browse files Browse the repository at this point in the history
  • Loading branch information
perryqh committed Mar 5, 2011
1 parent 3eb0e97 commit 5e8e8b8
Show file tree
Hide file tree
Showing 15 changed files with 224 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -7,6 +7,7 @@ gem 'simple-navigation', '~>3.1.0'
gem 'hoptoad_notifier', '>=2.3.12'
gem 'nokogiri', '>= 1.4.4'
gem 'high_voltage', '>= 0.9.3'
gem 'jammit', '>= 0.6.0'

group :production do
end
Expand Down Expand Up @@ -45,6 +46,7 @@ group :test do
gem 'guard-rspec', '>= 0.2.0'
gem 'guard-cucumber', '>= 0.2.3'
gem 'guard-spork', '>= 0.1.4'
gem 'guard-jammit', '>= 0.1.0'
gem 'rb-fsevent', '>= 0.3.10'
gem 'growl', '>= 1.0.3'
gem "spork", '>= 0.9.0.rc3'
Expand Down
10 changes: 10 additions & 0 deletions Gemfile.lock
Expand Up @@ -53,6 +53,7 @@ GEM
main
ruby_parser (~> 2.0.4)
sexp_processor (~> 3.0.3)
closure-compiler (1.0.0)
colored (1.2)
configuration (1.2.0)
cucumber (0.10.0)
Expand Down Expand Up @@ -87,6 +88,9 @@ GEM
guard-cucumber (0.2.3)
cucumber (~> 0.10.0)
guard (~> 0.3.0)
guard-jammit (0.1.0)
guard
jammit
guard-rspec (0.2.0)
guard (>= 0.2.2)
guard-spork (0.1.4)
Expand All @@ -103,6 +107,9 @@ GEM
activesupport
builder
i18n (0.5.0)
jammit (0.6.0)
closure-compiler (>= 0.1.0)
yui-compressor (>= 0.9.1)
jquery-rails (0.2.7)
rails (~> 3.0)
thor (~> 0.14.4)
Expand Down Expand Up @@ -225,6 +232,7 @@ GEM
tzinfo (0.3.24)
xpath (0.1.3)
nokogiri (~> 1.3)
yui-compressor (0.9.4)

PLATFORMS
ruby
Expand All @@ -237,12 +245,14 @@ DEPENDENCIES
growl (>= 1.0.3)
guard (>= 0.3.0)
guard-cucumber (>= 0.2.3)
guard-jammit (>= 0.1.0)
guard-rspec (>= 0.2.0)
guard-spork (>= 0.1.4)
haml (~> 3.0.25)
heroku
high_voltage (>= 0.9.3)
hoptoad_notifier (>= 2.3.12)
jammit (>= 0.6.0)
jquery-rails (>= 0.2.7)
launchy (>= 0.3.7)
machinist (>= 2.0.0.beta2)
Expand Down
5 changes: 5 additions & 0 deletions Guardfile
Expand Up @@ -27,3 +27,8 @@ guard 'cucumber', :cli => "--drb --profile autotest" do
watch(%r{features/support/.+}) { 'features' }
watch(%r{features/step_definitions/.+}) { 'features' }
end

guard 'jammit' do
watch('^public/javascripts/(.*)\.js')
watch('^public/stylesheets/(.*)\.css')
end
7 changes: 7 additions & 0 deletions app/controllers/memory_search_controller.rb
@@ -0,0 +1,7 @@
class MemorySearchController < ApplicationController

def new
render :partial => :search_results
end

end
2 changes: 1 addition & 1 deletion app/views/home/index.html.haml
Expand Up @@ -2,4 +2,4 @@
.search-form
%label{:for => 'search-mem-txt'} Search for Text to Memorize
%input{:type => :text, :id => 'search-mem-txt'}
%button{:id => :go} Go
%button{:id => :go, 'data-url' => new_memory_search_url} Go
4 changes: 2 additions & 2 deletions app/views/layouts/application.html.haml
Expand Up @@ -5,8 +5,8 @@
%title
= yield(:title) || "Sticky Memory"
%meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/
= stylesheet_link_tag "application"
= javascript_include_tag :defaults
= include_stylesheets :common, :workspace, :media => 'all'
= include_javascripts :workspace
= csrf_meta_tag
= yield(:head)
Expand Down
1 change: 1 addition & 0 deletions app/views/memory_search/_search_results.html.haml
@@ -0,0 +1 @@
james result
15 changes: 15 additions & 0 deletions config/assets.yml
@@ -0,0 +1,15 @@
embed_assets: on

javascripts:
workspace:
- public/javascripts/jquery.min.js
- public/javascripts/jquery-ui.min.js
- public/javascripts/jquery.timers-1.2.js
- public/javascripts/rails.js
- public/javascripts/application.js


stylesheets:
common:
workspace:
- public/stylesheets/application.css
1 change: 1 addition & 0 deletions config/routes.rb
@@ -1,4 +1,5 @@
Stickymemory::Application.routes.draw do
resources :home, :only => [:index]
resources :memory_search, :only => [:new]
root :to => "home#index"
end
10 changes: 8 additions & 2 deletions features/landing.feature
Expand Up @@ -3,5 +3,11 @@ Feature: Landing Page

Scenario: load the home page
Given I am on the home page
Then I should see "Sticky Memory"
And I should see "Search for Text to Memorize"
Then I should see "Search for Text to Memorize"
And I should see "Go"

Scenario: search for text to memorize
Given I am on the home page
When I fill in "Search for Text to Memorize" with "James"
And I press "Go"
Then I should see "James"
24 changes: 22 additions & 2 deletions public/javascripts/application.js
@@ -1,2 +1,22 @@
// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
(function($) {
$(document).ready(function() {
$.initSearch();
});

$.search = function() {
//ajax search
};

$.initSearch = function() {
$('.search-form #go').click(function() {
$.search();
});
$('.search-form #search-mem-txt').everyTime(500, function(i) {
$.search();
});
};

$.fn.memorySearch = function() {

};
}(jQuery));
138 changes: 138 additions & 0 deletions public/javascripts/jquery.timers-1.2.js
@@ -0,0 +1,138 @@
/**
* jQuery.timers - Timer abstractions for jQuery
* Written by Blair Mitchelmore (blair DOT mitchelmore AT gmail DOT com)
* Licensed under the WTFPL (http://sam.zoy.org/wtfpl/).
* Date: 2009/10/16
*
* @author Blair Mitchelmore
* @version 1.2
*
**/

jQuery.fn.extend({
everyTime: function(interval, label, fn, times) {
return this.each(function() {
jQuery.timer.add(this, interval, label, fn, times);
});
},
oneTime: function(interval, label, fn) {
return this.each(function() {
jQuery.timer.add(this, interval, label, fn, 1);
});
},
stopTime: function(label, fn) {
return this.each(function() {
jQuery.timer.remove(this, label, fn);
});
}
});

jQuery.extend({
timer: {
global: [],
guid: 1,
dataKey: "jQuery.timer",
regex: /^([0-9]+(?:\.[0-9]*)?)\s*(.*s)?$/,
powers: {
// Yeah this is major overkill...
'ms': 1,
'cs': 10,
'ds': 100,
's': 1000,
'das': 10000,
'hs': 100000,
'ks': 1000000
},
timeParse: function(value) {
if (value == undefined || value == null)
return null;
var result = this.regex.exec(jQuery.trim(value.toString()));
if (result[2]) {
var num = parseFloat(result[1]);
var mult = this.powers[result[2]] || 1;
return num * mult;
} else {
return value;
}
},
add: function(element, interval, label, fn, times) {
var counter = 0;

if (jQuery.isFunction(label)) {
if (!times)
times = fn;
fn = label;
label = interval;
}

interval = jQuery.timer.timeParse(interval);

if (typeof interval != 'number' || isNaN(interval) || interval < 0)
return;

if (typeof times != 'number' || isNaN(times) || times < 0)
times = 0;

times = times || 0;

var timers = jQuery.data(element, this.dataKey) || jQuery.data(element, this.dataKey, {});

if (!timers[label])
timers[label] = {};

fn.timerID = fn.timerID || this.guid++;

var handler = function() {
if ((++counter > times && times !== 0) || fn.call(element, counter) === false)
jQuery.timer.remove(element, label, fn);
};

handler.timerID = fn.timerID;

if (!timers[label][fn.timerID])
timers[label][fn.timerID] = window.setInterval(handler,interval);

this.global.push( element );

},
remove: function(element, label, fn) {
var timers = jQuery.data(element, this.dataKey), ret;

if ( timers ) {

if (!label) {
for ( label in timers )
this.remove(element, label, fn);
} else if ( timers[label] ) {
if ( fn ) {
if ( fn.timerID ) {
window.clearInterval(timers[label][fn.timerID]);
delete timers[label][fn.timerID];
}
} else {
for ( var fn in timers[label] ) {
window.clearInterval(timers[label][fn]);
delete timers[label][fn];
}
}

for ( ret in timers[label] ) break;
if ( !ret ) {
ret = null;
delete timers[label];
}
}

for ( ret in timers ) break;
if ( !ret )
jQuery.removeData(element, this.dataKey);
}
}
}
});

jQuery(window).bind("unload", function() {
jQuery.each(jQuery.timer.global, function(index, item) {
jQuery.timer.remove(item);
});
});
2 changes: 1 addition & 1 deletion public/stylesheets/application.css
Expand Up @@ -102,7 +102,7 @@ a {
border-bottom: 2px solid #fff8e8; }
.search-form:focus {
outline: none; }
.search-form button {
.search-form input[type=submit], .search-form button {
-moz-background-clip: border;
-moz-background-inline-policy: continuous;
-moz-background-origin: padding;
Expand Down
2 changes: 1 addition & 1 deletion public/stylesheets/sass/application.sass
Expand Up @@ -108,7 +108,7 @@ a
&:focus
outline: none

button
input[type=submit], button
-moz-background-clip: border
-moz-background-inline-policy: continuous
-moz-background-origin: padding
Expand Down
10 changes: 10 additions & 0 deletions spec/controllers/memory_search_controller_spec.rb
@@ -0,0 +1,10 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe MemorySearchController do
describe "GET new" do
it "should render search results in a partial"
get :new, :search => 'james'
response.should render_template(:new)
end
end
end

0 comments on commit 5e8e8b8

Please sign in to comment.