GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Rubygem
Description: Resource-oriented open source Ruby framework for Web apps.
Homepage: http://rubywaves.com/
Clone URL: git://github.com/dyoder/waves.git
Massive rework of samples/blog
automatthew (author)
Fri Oct 03 23:21:06 -0700 2008
commit  756c237f041676186d43f89dcab43fd24992c53d
tree    3c38289c6ae08fabc2604b9e635df97788126bdd
parent  b8aae01061670d8e1f410c1ba9eb62bc26ab0656
...
1
2
3
4
5
 
 
 
 
 
 
 
 
 
 
 
 
6
7
8
...
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
0
@@ -1,8 +1,18 @@
0
-#!/usr/bin/env ruby
0
-#
0
 # Warning: This file is clobbered when you update your
0
 # application with the waves script. Accordingly, you may
0
 # wish to keep your tasks in .rb or .rake files in lib/tasks
0
+require 'rubygems'
0
+waves = [
0
+ (WAVES if defined? WAVES), ENV[ 'WAVES'], './waves'
0
+].compact.map { |dir| File.join(dir, 'lib') }.find(&File.method(:directory?))
0
+if waves
0
+ $: << waves
0
+ waves = File.join( waves, 'waves' )
0
+else
0
+ waves = 'waves'
0
+end
0
+require waves
0
+
0
 require 'startup'
0
 Waves::Console.load(:mode => ENV['mode'])
0
 
...
9
10
11
 
 
12
13
14
...
20
21
22
23
 
24
25
26
...
9
10
11
12
13
14
15
16
...
22
23
24
 
25
26
27
28
0
@@ -9,6 +9,8 @@ module Blog
0
       reloadable [ Blog ]
0
 
0
       log :level => :debug
0
+
0
+ session :duration => 45.minutes, :path => 'tmp/sessions'
0
 
0
       host '127.0.0.1'
0
 
0
@@ -20,7 +22,7 @@ module Blog
0
 
0
       application do
0
         use ::Rack::ShowExceptions
0
- use ::Rack::Static, :urls => [ '/css', '/javascript', '/favicon.ico' ], :root => 'public'
0
+ use ::Rack::Static, :urls => [ '/images/', '/css/', '/javascript/', '/favicon.ico' ], :root => 'public'
0
         run ::Waves::Dispatchers::Default.new
0
       end
0
 
...
11
12
13
 
 
14
15
16
...
11
12
13
14
15
16
17
18
0
@@ -11,6 +11,8 @@ module Blog
0
       log :level => :info,
0
         :output => ( :log / "waves.production" )
0
 
0
+ session :duration => 45.minutes, :path => 'tmp/sessions'
0
+
0
       host '0.0.0.0'
0
 
0
       port 3000
...
 
1
2
3
 
4
5
...
1
2
3
 
4
5
6
0
@@ -1,5 +1,6 @@
0
+require 'foundations/classic'
0
 require 'layers/orm/sequel'
0
 module Blog
0
- include Waves::Foundations::Default
0
+ include Waves::Foundations::Classic
0
   include Waves::Layers::ORM::Sequel
0
 end
...
7
8
9
 
 
 
 
 
 
 
 
 
10
11
12
...
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
0
@@ -7,6 +7,15 @@ module Blog
0
       before_save do
0
         set_with_params(:updated_on => Time.now) if columns.include? :updated_on
0
       end
0
+
0
+ def time
0
+ updated_on.strftime('%I:%M %p on %b %d, %Y')
0
+ end
0
+
0
+ def attribution
0
+ name.nil? || name.empty? ? 'anonymous coward' : name
0
+ end
0
+
0
     end
0
 
0
   end
...
7
8
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
11
12
...
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
0
@@ -7,6 +7,22 @@ module Blog
0
       before_save do
0
         set_with_params(:updated_on => Time.now) if columns.include? :updated_on
0
       end
0
+
0
+ def date
0
+ updated_on.strftime('%b %d, %Y')
0
+ end
0
+
0
+ def comment_number
0
+ n = comments.size
0
+ case n
0
+ when 0
0
+ "No Comments"
0
+ when 1
0
+ "1 Comment"
0
+ else
0
+ "#{n} Comments"
0
+ end
0
+ end
0
 
0
     end
0
 
...
1
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0
@@ -1,2 +1,14 @@
0
-body { font-family: Verdana, Arial, sans-serif; background-color: white; }
0
-h1, h2, h3, p, label, li { margin-bottom: 20px; }
0
+body { font-size: 16px; line-height: 20px; font-family: Georgia, serif; background: #ddd; }
0
+a { color: #116; text-decoration: none; }
0
+h1, h2, h3, h4, p, hr, div#create { padding: 0px; margin-bottom: 20px; }
0
+h1, h2, h3, h4 { font-family: Optima, "CG Omega", "Zapf Humanist", Helvetica, Arial, sans-serif }
0
+h1 { font-size: 45px; line-height: 45px; padding-bottom: 13px; border-bottom: 2px solid #999;}
0
+h2 { font-size: 20px; line-height: 20px;}
0
+h4 { padding: 0px; margin: 0px; }
0
+a.delete { color: #900;}
0
+div#main { margin: 20px; width: 55%;}
0
+div#create { position: absolute; left: 65%;}
0
+div#entry, div.entry { margin-bottom: 18px; border-bottom: 2px solid #999; }
0
+textarea { width: 100%; }
0
+div.comment { margin-bottom: 19px; border-bottom: 1px solid #999;}
0
+div.comment p.info { font-style: italic;}
...
1
2
3
 
4
5
6
 
7
8
9
10
11
 
12
13
14
15
 
16
17
18
19
20
 
 
 
 
 
 
21
22
23
...
25
26
27
28
29
30
 
 
 
31
32
33
 
 
 
 
 
34
35
36
...
1
2
3
4
5
 
 
6
7
8
9
10
 
11
12
13
14
 
15
16
17
18
 
 
19
20
21
22
23
24
25
26
27
...
29
30
31
 
 
 
32
33
34
35
36
37
38
39
40
41
42
43
44
45
0
@@ -1,23 +1,27 @@
0
 module Blog
0
   module Resources
0
     class Entry < Default
0
+ include Waves::Resources::Mixin
0
       
0
-
0
- on :get, :list => [ 'entry' ] do
0
+ on :get, :list => [ /entry|entries/ ] do
0
         view.list( plural => controller.all )
0
       end
0
       
0
       on :get, :show => [ 'entry', :name ] do
0
- view.show( singular => controller.find( query.name ) )
0
+ view.show( :entry => controller.find( captured.name ) )
0
       end
0
       
0
       on :get, :edit => [ 'entry', :name, 'edit' ] do
0
- view.edit( singular => controller.find( query.name ) )
0
+ view.edit( singular => controller.find( captured.name ) )
0
       end
0
       
0
       on :put, :update => [ 'entry', :name ] do
0
- controller.update( query.name )
0
- redirect "/entry/#{query.name}"
0
+ begin
0
+ controller.update( captured.name )
0
+ rescue Waves::Dispatchers::NotFoundError
0
+ controller.create
0
+ end
0
+ redirect "/entry/#{captured.name}"
0
       end
0
       
0
       on :post, :create => [ 'entry' ] do
0
@@ -25,12 +29,17 @@ module Blog
0
       end
0
       
0
       on :post, :comment => [ 'entry', :name ] do
0
- entry = controller.find( query.name )
0
- comment = Models::Comment.create( query.comment.to_hash )
0
- entry.add_comment( comment )
0
+ entry = controller.find( captured.name )
0
+ entry.add_comment( Models::Comment.create( query.comment.to_hash ) )
0
+ session[:commenter] = query.comment.name
0
         redirect request.path
0
       end
0
       
0
+ on :delete, [ 'entry', :name ] do
0
+ controller.delete( captured.name )
0
+ redirect "/entry"
0
+ end
0
+
0
     end
0
   end
0
 end
...
3
4
5
6
7
 
 
 
 
8
9
10
...
3
4
5
 
 
6
7
8
9
10
11
12
0
@@ -3,8 +3,10 @@ module Blog
0
     class Map
0
       include Waves::Resources::Mixin
0
       
0
- on( :get, [ 'entry' ] ) { to(:entry) }
0
- on( true, [ 'entry', true ] ) { to(:entry) }
0
+ on( :get, [] ) { "This be root." }
0
+
0
+ on( :get, [ /entry|entries/ ] ) { to(:entry) }
0
+ on( true, [ /entry|entries/, true ] ) { to(:entry) }
0
       
0
       
0
       #
...
3
4
5
6
7
8
 
 
9
 
10
11
12
...
3
4
5
 
 
 
6
7
8
9
10
11
12
0
@@ -3,10 +3,10 @@ class InitialSchema < Sequel::Migration
0
   def up
0
     create_table :entries do
0
       primary_key :id
0
- text :name
0
- text :title
0
- text :summary
0
+ string :name
0
+ string :title
0
       text :content
0
+ timestamp :updated_on
0
     end
0
   end
0
 
...
4
5
6
7
8
 
 
9
10
11
...
4
5
6
 
 
7
8
9
10
11
0
@@ -4,8 +4,8 @@ class AddComments < Sequel::Migration
0
     create_table :comments do
0
       primary_key :id
0
       foreign_key :entry_id, :table => :entries
0
- text :name
0
- text :email
0
+ string :name
0
+ string :email
0
       text :content
0
       timestamp :updated_on
0
     end
...
1
2
3
4
 
 
5
6
 
7
8
 
9
10
11
...
1
2
3
 
4
5
6
 
7
8
 
9
10
11
12
0
@@ -1,11 +1,12 @@
0
 form :action => request.path, :method => 'POST' do
0
   input :type => :hidden, :name => 'comment.entry_id', :value => @entry.id
0
   label 'Name'; br
0
- input :type => :text, :name => 'comment.name'; br
0
+ input :type => :text, :name => 'comment.name', :size => 35, :value => session[:commenter]
0
+ br
0
   label 'Email'; br
0
- input :type => :text, :name => 'comment.email'; br
0
+ input :type => :text, :name => 'comment.email', :size => 35; br
0
   label 'Comment'; br
0
- textarea :name => 'comment.content', :rows => 10, :cols => 80; br
0
+ textarea :name => 'comment.content', :rows => 6; br
0
   input :type => :submit, :value => 'Save'
0
 end
0
 
...
1
2
3
4
5
 
 
 
 
6
...
1
 
 
 
 
2
3
4
5
6
0
@@ -1,6 +1,6 @@
0
 @comments.each do |comment|
0
- p "Posted on #{comment.updated_on.strftime('%b %d, %Y') if comment.updated_on} by
0
- #{( ( comment.name.nil? or comment.name.empty? ) ?
0
- 'anonymous coward' : comment.name )}"
0
- textile comment.content
0
+ div.comment do
0
+ textile comment.content
0
+ p.info "#{ comment.attribution }, at #{ comment.time }" if comment.updated_on
0
+ end
0
 end
...
2
3
4
5
6
7
 
 
 
8
9
 
 
10
11
12
13
 
...
2
3
4
 
 
 
5
6
7
8
 
9
10
11
 
12
13
14
0
@@ -2,12 +2,13 @@ layout :default, :title => 'Edit Entry' do
0
   form :action => "/entry/#{@entry.name}", :method => 'POST' do
0
     input :name => '_method', :type => 'hidden', :value => 'put'
0
     label 'Title'; br
0
- input :type => :text, :value => @entry.title, :name => 'entry.title'; br
0
- label 'Summary'; br
0
- textarea @entry.summary, :name => 'entry.summary', :rows => 10, :cols => 80; br
0
+ input :type => :text, :value => @entry.title, :name => 'entry.title', :size => 50; br
0
+ label 'URL name'; br
0
+ input :type => :text, :value => @entry.name, :name => 'entry.name', :size => 50; br
0
     label 'Content'; br
0
- textarea @entry.content, :name => 'entry.content', :rows => 20, :cols => 80; br
0
+ textarea @entry.content, :name => 'entry.content', :rows => 20, :cols => 70; br
0
+ a 'Cancel', :href => "/entry/#{@entry.name}"
0
     input :type => :submit, :value => 'Save'
0
- a.delete 'Delete', :href => "/entry/#{@entry.name}"
0
   end
0
 end
0
+
...
1
2
3
4
5
6
 
 
 
 
 
 
 
 
7
 
8
9
10
 
11
...
1
 
 
 
 
 
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
0
@@ -1,11 +1,16 @@
0
 layout :default, :title => 'Blog Entries' do
0
- h1 'My Blog'
0
- form :action => '/entry', :method => 'post' do
0
- label 'Name'
0
- input :type => :text, :name => 'entry.name'
0
- input :type => :submit, :value => 'Add'
0
+
0
+ div.create! do
0
+ h2 'Create a new entry'
0
+ form :action => '/entry', :method => 'post' do
0
+ label 'URL Name'
0
+ input :type => :text, :name => 'entry.name', :size => 25
0
+ input :type => :submit, :value => 'Add'
0
+ end
0
   end
0
+
0
   @entries.each do |entry|
0
     view :entry, :summary, :entry => entry
0
   end
0
+ p { i "No entries yet. Don't loiter." } if @entries.empty?
0
 end
...
1
2
3
4
5
6
7
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
 
9
...
1
 
 
 
 
 
 
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
0
@@ -1,9 +1,18 @@
0
 layout :default, :title => @entry.title do
0
- a 'Show All Entries', :href => '/entry'
0
- a 'Edit This Entry', :href => "/entry/#{@entry.name}/edit"
0
- h1 @entry.title
0
- textile @entry.content
0
- h1 'Comments'
0
- view :comment, :add, :entry => @entry
0
+
0
+ div.entry! do
0
+ h4 @entry.date if @entry.updated_on
0
+ h2 { a @entry.title }
0
+ textile @entry.content
0
+ p do
0
+ a 'Edit', :href => "/entry/#{@entry.name}/edit"
0
+ text '&nbsp;'
0
+ a.delete 'Delete', :href => "/entry/#{@entry.name}"
0
+ end
0
+ end
0
+
0
+ h3 @entry.comment_number
0
   view :comment, :list, :comments => @entry.comments
0
+ view :comment, :add, :entry => @entry
0
+
0
 end
...
1
2
 
 
 
 
 
 
 
3
4
5
 
...
 
 
1
2
3
4
5
6
7
8
 
 
9
0
@@ -1,5 +1,9 @@
0
-h2 do
0
- a @entry.title, :href => "/entry/#{@entry.name}"
0
+div.entry do
0
+ h4 @entry.date if @entry.updated_on
0
+ h2 { a @entry.title, :href => "/entry/#{@entry.name}" }
0
+ textile @entry.content
0
+ p do
0
+ a @entry.comment_number, :href => "/entry/#{@entry.name}"
0
+ end
0
 end
0
-textile @entry.summary
0
-a 'Read more ...', :href => "/entry/#{@entry.name}"
0
+
...
 
 
 
 
 
1
2
 
...
1
2
3
4
5
6
 
7
0
@@ -1,2 +1,7 @@
0
+style <<-STYLE
0
+ body { background: #933; padding: 20px; font-family: verdana, sans-serif; }
0
+ h1 { font-size: 60px; font-weight: bold; margin: 0px; }
0
+ p { font-size: 24px; margin: 0px; }
0
+STYLE
0
 h1 '404'
0
-p %q( That URL does not exist on this server. )
0
+p { 'That URL does<br> not exist on<br> this server.' }
...
4
5
6
7
8
 
9
10
11
12
13
14
 
 
 
 
15
16
17
...
4
5
6
 
 
7
8
9
10
11
12
 
13
14
15
16
17
18
19
0
@@ -4,14 +4,16 @@ html do
0
 
0
   head do
0
     title @title
0
- script :src => '/javascript/jquery-1.2.6.min.js',
0
- :type => 'text/javascript'
0
+ script :src => '/javascript/jquery-1.2.6.min.js', :type => 'text/javascript'
0
     script :src => '/javascript/site.js', :type => 'text/javascript'
0
     link :href => '/css/site.css', :rel => 'stylesheet', :type => 'text/css'
0
   end
0
 
0
   body do
0
- layout_content
0
+ h1 { a 'I Blog Here', :href => '/entries' }
0
+ div.main! do
0
+ layout_content
0
+ end
0
   end
0
 
0
 end

Comments

    No one has commented yet.