diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..0876f13 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'http://rubygems.org' +gem 'rack' +gem 'wordnik', '4.06.15' +gem 'wordnik_ruby_helpers', '0.1.9' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..f16003e --- /dev/null +++ b/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) diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..b63c573 --- /dev/null +++ b/config.ru @@ -0,0 +1,2 @@ +require './ikijibiki' +run Sinatra::Application \ No newline at end of file diff --git a/ikijibiki.rb b/ikijibiki.rb new file mode 100644 index 0000000..178bf7b --- /dev/null +++ b/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 diff --git a/public/images/wordnik_badge_a3.png b/public/images/wordnik_badge_a3.png new file mode 100644 index 0000000..9161fbc Binary files /dev/null and b/public/images/wordnik_badge_a3.png differ diff --git a/public/images/wordnik_gearheart.png b/public/images/wordnik_gearheart.png new file mode 100644 index 0000000..adf7ada Binary files /dev/null and b/public/images/wordnik_gearheart.png differ diff --git a/public/images/wordnik_heart.png b/public/images/wordnik_heart.png new file mode 100644 index 0000000..621aa16 Binary files /dev/null and b/public/images/wordnik_heart.png differ diff --git a/public/javascripts/index.js b/public/javascripts/index.js new file mode 100644 index 0000000..e7f7d64 --- /dev/null +++ b/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('') + }); +}); diff --git a/public/stylesheets/index.css b/public/stylesheets/index.css new file mode 100644 index 0000000..0f195aa --- /dev/null +++ b/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; +} \ No newline at end of file diff --git a/views/index.erb b/views/index.erb new file mode 100644 index 0000000..fd13616 --- /dev/null +++ b/views/index.erb @@ -0,0 +1,30 @@ + + + + Ikijibiki + <%= stylesheet_link_tag "stylesheets/index.css", :media => "all" %> + <%= javascript_include_tag "http://code.jquery.com/jquery-latest.js" %> + <%= javascript_include_tag "javascripts/index.js" %> + + + + +
+

Wordnik Ikijibiki

+

How many words do you know? Are you an Ikijibiki? 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.)

+
+ <% @words.each do |word| %> + <%= word %> + <%= image_tag("images/wordnik_heart.png", :class => "wn_small_heart") %> + <% end %> +
+

According to what you've told me so far, you know about 0 words.

+
+
+ + + \ No newline at end of file