Skip to content
This repository has been archived by the owner on Feb 9, 2022. It is now read-only.

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Fitzgerald committed Mar 5, 2012
0 parents commit fdabf22
Show file tree
Hide file tree
Showing 10 changed files with 245 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source 'http://rubygems.org'
gem 'rack'
gem 'wordnik', '4.06.15'
gem 'wordnik_ruby_helpers', '0.1.9'
103 changes: 103 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,103 @@
GEM
remote: http://rubygems.org/
specs:
RedCloth (4.2.9)
actionmailer (3.2.2)
actionpack (= 3.2.2)
mail (~> 2.4.0)
actionpack (3.2.2)
activemodel (= 3.2.2)
activesupport (= 3.2.2)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
rack (~> 1.4.0)
rack-cache (~> 1.1)
rack-test (~> 0.6.1)
sprockets (~> 2.1.2)
activemodel (3.2.2)
activesupport (= 3.2.2)
builder (~> 3.0.0)
activerecord (3.2.2)
activemodel (= 3.2.2)
activesupport (= 3.2.2)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.2)
activemodel (= 3.2.2)
activesupport (= 3.2.2)
activesupport (3.2.2)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.2.7)
arel (3.0.2)
builder (3.0.0)
erubis (2.7.0)
hike (1.2.1)
htmlentities (4.3.1)
i18n (0.6.0)
journey (1.0.3)
json (1.6.5)
mail (2.4.1)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.17.2)
multi_json (1.1.0)
nokogiri (1.5.0)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.1)
rack (>= 0.4)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.2.2)
actionmailer (= 3.2.2)
actionpack (= 3.2.2)
activerecord (= 3.2.2)
activeresource (= 3.2.2)
activesupport (= 3.2.2)
bundler (~> 1.0)
railties (= 3.2.2)
railties (3.2.2)
actionpack (= 3.2.2)
activesupport (= 3.2.2)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
typhoeus (0.3.3)
mime-types
tzinfo (0.3.31)
wordnik (4.06.15)
activemodel (>= 3.0.3)
addressable (>= 2.2.4)
htmlentities (>= 4.2.4)
json (>= 1.4.6)
nokogiri (>= 1.4.4)
typhoeus (>= 0.2.1)
wordnik_ruby_helpers (0.1.9)
RedCloth (>= 4.2.3)
rails

PLATFORMS
ruby

DEPENDENCIES
rack
wordnik (= 4.06.15)
wordnik_ruby_helpers (= 0.1.9)
2 changes: 2 additions & 0 deletions config.ru
@@ -0,0 +1,2 @@
require './ikijibiki'
run Sinatra::Application
13 changes: 13 additions & 0 deletions ikijibiki.rb
@@ -0,0 +1,13 @@
require 'wordnik'
require 'sinatra'
require 'sinatra/static_assets'
require "sinatra/reloader" if development?

Wordnik.configure do |config|
config.api_key = ENV['WORDNIK_API_KEY']
end

get "/" do
@words = Wordnik.word.get_random_words("limit"=>50, "hasDictionaryDef" => true).map{|w| w["word"]}
erb :index
end
Binary file added public/images/wordnik_badge_a3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/wordnik_gearheart.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/wordnik_heart.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions public/javascripts/index.js
@@ -0,0 +1,34 @@
$(document).ready(function () {
function addCommas(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
var sample_size = 50
var kwords = 636.357

$("#according").show();

$(".word").click(function () {
// remove the current definition (if there)
$("#definition").html('')

// highlight it
$(this).toggleClass("highlight");
// calculate size of vocabulary — note magic numbers
var w = kwords * ($('.highlight').length / sample_size);
w = Math.round(w)*1000

$('#wordcount').text(addCommas(w));

// declare intelligence...
(w > 200000) ? $('#ikijibiki').text("You are a walking dictionary! an Ikijibiki!") : $('#ikijibiki').text('')
});
});
59 changes: 59 additions & 0 deletions public/stylesheets/index.css
@@ -0,0 +1,59 @@
body {

font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: black;
word-wrap: break-word;
padding: 3px;
}

p {
margin: 4px;
font-size:16px;
}

h1, h2, h3 {
color: #1980D7;
}
#wordlist {
margin: 20px;
font-size:16px;
font-weight:bolder;
border-style: solid;
border-width: 1px;
border-color: #DDD;
padding: 10px;
}

.word {
color:#1980D7;
cursor: pointer;
}

.expando {
cursor: pointer;
}

.highlight {
background:yellow;
}

#ikijibiki {
font-weight: bold;
}

#wordcount {
font-weight: bold;
}

.wn_small_heart {
height: 15px;
}
#footer {

border-top-width: 1px;
border-top-style: solid;
border-top-color: #DDD;
}
#according {
display: none;
}
30 changes: 30 additions & 0 deletions views/index.erb
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<title>Ikijibiki</title>
<%= stylesheet_link_tag "stylesheets/index.css", :media => "all" %>
<%= javascript_include_tag "http://code.jquery.com/jquery-latest.js" %>
<%= javascript_include_tag "javascripts/index.js" %>
</head>
<body>


<div id="body">
<h1>Wordnik Ikijibiki</h1>
<p>How many words do you know? Are you an <i>Ikijibiki</i>? At our latest count, Wordnik has 636,357 words with definitions.
Scan the words below. Here's a random sample—if you know a word, click on it. You'll see a rough estimate of the
total number of English words you know. (Click on the hearts to see the definitions.)</p>
<div id="wordlist">
<% @words.each do |word| %>
<span><span class="word"> <%= word %> </span> <a target='_new' href='http://wordnik.com/word/<%= word %>'>
<%= image_tag("images/wordnik_heart.png", :class => "wn_small_heart") %></a> </span>
<% end %>
</div>
<p id="according">According to what you've told me so far, you know about <span id="wordcount">0</span> words. <span id="ikijibiki"></p>
<div id="definition" />
</div>
<div id=footer>
<%= image_tag ("images/wordnik_badge_a3.png") %>
</div>
</body>
</html>

0 comments on commit fdabf22

Please sign in to comment.