Skip to content

Commit

Permalink
template and route work
Browse files Browse the repository at this point in the history
  • Loading branch information
gnugeek committed Dec 25, 2008
1 parent 55d031d commit cde1508
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 24 deletions.
3 changes: 3 additions & 0 deletions helpers.rb
@@ -0,0 +1,3 @@
def link_to(label,url)
%{<a href="http://#{url}">#{label}</a>}
end
10 changes: 8 additions & 2 deletions main.rb
Expand Up @@ -5,6 +5,7 @@
require 'sass'
require 'logger'
require 'yaml'
require 'helpers'

Dir.glob(File.join(File.dirname(__FILE__), 'models/*.rb')).each {|f| require f }
DBCONFIG = YAML.load_file('database.yml') unless defined?(DBCONFIG)
Expand Down Expand Up @@ -40,16 +41,21 @@
end

get '/' do
@word ||= Word.first(:lemma => 'hello')
haml :index
end

post '/' do
redirect "word/#{params[:lemma]}"
@word = Word.first(:lemma => params[:lemma])
haml :index
end

get '/word/:lemma' do
@word = Word.first(:lemma => params[:lemma])
haml :word
end

get '/stylesheets/style.css' do
header 'Content-Type' => 'text/css; charset=utf-8'
sass :style
end
end
42 changes: 21 additions & 21 deletions views/index.haml
@@ -1,23 +1,23 @@
#wordnet-search
%form{:method => 'post'}
%input{:type=>'text', :size=>40, :name=>'lemma', :id=>'lemma_search'}
%input{:type =>'submit', :value=>'search'}

#content

%table.display
- @word.attributes.each_pair do |k,v|
%tr
%td{:class=>'title'}= k
%td= v
%p

%table.display
-@word.synsets.each do |synset|
%tr
%td{:class=>'title'}= synset.categorydef.name
%td= synset.definition

%script
:plain
document.getElementById('wordnet-search').focus();
#wordnatra-info
Welcome to Wordnatra.
%br
Wordnatra is an interface to Princeton's "Wordnet" lexical dictionary.
%br
To get started, search for a word.
%p
For information on this project and the technologies used, see the following links:
%p

=link_to 'Wordnatra', 'http://github.com/gnugeek/wordnatra/tree/master'
%br
=link_to 'Wordnet', 'http://wordnet.princeton.edu/'
%br
=link_to 'Ruby', 'http://www.ruby-lang.org/en/'
%br
=link_to 'MySQL', 'http://www.mysql.com/'
%br
=link_to 'Sinatra', 'http://sinatra.rubyforge.org/'
%br
=link_to 'DataMapper', 'http://datamapper.org/doku.php'
14 changes: 13 additions & 1 deletion views/layout.haml
Expand Up @@ -6,4 +6,16 @@
%body
#banner Wordnatra
%br
= yield

#wordnet-search
%form{:method => 'post', :action => '/'}
%input{:type=>'text', :size=>40, :name=>'lemma', :id=>'lemma_search'}
%input{:type =>'submit', :value=>'search'}

%p

= yield

%script
:plain
document.getElementById('wordnet-search').focus();
12 changes: 12 additions & 0 deletions views/word.haml
@@ -0,0 +1,12 @@
%table.display
- @word.attributes.each_pair do |k,v|
%tr
%td{:class=>'title'}= k
%td= v
%p

%table.display
-@word.synsets.each do |synset|
%tr
%td{:class=>'title'}= synset.categorydef.name
%td= synset.definition

0 comments on commit cde1508

Please sign in to comment.