slippers 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README +56 -0
- data/Rakefile +27 -0
- data/VERSION.yml +4 -0
- data/examples/blog/README +3 -0
- data/examples/blog/blog.db +0 -0
- data/examples/blog/controller/main.rb +30 -0
- data/examples/blog/model/entry.rb +31 -0
- data/examples/blog/public/styles/blog.css +132 -0
- data/examples/blog/spec/blog.rb +87 -0
- data/examples/blog/start.rb +7 -0
- data/examples/blog/view/edit.st +19 -0
- data/examples/blog/view/edit.xhtml +17 -0
- data/examples/blog/view/entry.st +12 -0
- data/examples/blog/view/index.st +4 -0
- data/examples/blog/view/index.xhtml +17 -0
- data/examples/blog/view/layout.st +11 -0
- data/examples/blog/view/layout.xhtml +11 -0
- data/examples/blog/view/new.st +16 -0
- data/examples/blog/view/new.xhtml +16 -0
- data/examples/forms/Rakefile +22 -0
- data/examples/forms/controller/init.rb +12 -0
- data/examples/forms/controller/main.rb +20 -0
- data/examples/forms/controller/registration.rb +24 -0
- data/examples/forms/forms.db +0 -0
- data/examples/forms/model/core_extensions/string_extensions.rb +5 -0
- data/examples/forms/model/field.rb +33 -0
- data/examples/forms/model/form.rb +33 -0
- data/examples/forms/model/init.rb +18 -0
- data/examples/forms/model/orm/registration.rb +12 -0
- data/examples/forms/model/registration_form_builder.rb +7 -0
- data/examples/forms/model/registration_repository.rb +39 -0
- data/examples/forms/model/registration_rules/incorrect_email_format.rb +11 -0
- data/examples/forms/model/registration_rules/number_field.rb +10 -0
- data/examples/forms/model/registration_rules/required_field.rb +9 -0
- data/examples/forms/model/registration_validator.rb +17 -0
- data/examples/forms/public/css/ramaze_error.css +90 -0
- data/examples/forms/public/dispatch.fcgi +11 -0
- data/examples/forms/public/favicon.ico +0 -0
- data/examples/forms/public/js/jquery.js +3549 -0
- data/examples/forms/public/ramaze.png +0 -0
- data/examples/forms/public/web-application.js +0 -0
- data/examples/forms/spec/form_spec.rb +16 -0
- data/examples/forms/spec/main.rb +25 -0
- data/examples/forms/spec/registration_controller_spec.rb +0 -0
- data/examples/forms/spec/registration_repository_spec.rb +38 -0
- data/examples/forms/spec/registration_validator_spec.rb +53 -0
- data/examples/forms/spec/spec_helper.rb +3 -0
- data/examples/forms/start.rb +12 -0
- data/examples/forms/start.ru +16 -0
- data/examples/forms/view/error.xhtml +64 -0
- data/examples/forms/view/index.xhtml +34 -0
- data/examples/forms/view/page.xhtml +27 -0
- data/examples/forms/view/registration/index.st +26 -0
- data/examples/main_controller.rb +40 -0
- data/examples/start.rb +7 -0
- data/examples/todolist/README +1 -0
- data/examples/todolist/controller/main.rb +71 -0
- data/examples/todolist/layout/page.rb +31 -0
- data/examples/todolist/model/tasks.rb +14 -0
- data/examples/todolist/public/favicon.ico +0 -0
- data/examples/todolist/public/js/jquery.js +1923 -0
- data/examples/todolist/public/ramaze.png +0 -0
- data/examples/todolist/start.rb +11 -0
- data/examples/todolist/todolist.db +11 -0
- data/examples/todolist/view/index.st +39 -0
- data/examples/todolist/view/index.xhtml +17 -0
- data/examples/todolist/view/new.st +41 -0
- data/examples/todolist/view/new.xhtml +7 -0
- data/examples/todolist/view/tasks.st +6 -0
- data/examples/todolist.db +5 -0
- data/examples/view/index.st +11 -0
- data/examples/view/person/age.st +1 -0
- data/examples/view/person/age_renderer.rb +6 -0
- data/examples/view/person/index.st +2 -0
- data/lib/engine/binding_wrapper.rb +10 -0
- data/lib/engine/engine.rb +28 -0
- data/lib/engine/file_template.rb +12 -0
- data/lib/engine/slippers.treetop +169 -0
- data/lib/engine/slippers_nodes.rb +119 -0
- data/lib/engine/template.rb +17 -0
- data/lib/engine/template_group.rb +40 -0
- data/lib/engine/template_group_directory.rb +57 -0
- data/lib/ramazeTemplates/0001-Adding-slippers-as-a-new-template.patch +138 -0
- data/lib/ramazeTemplates/0002-Fixing-problem-with-using-other-renderers.patch +27 -0
- data/lib/ramazeTemplates/slippers.rb +22 -0
- data/lib/slippers.rb +14 -0
- data/spec/binding_wrapper.rb +19 -0
- data/spec/engine.rb +89 -0
- data/spec/file_template.rb +9 -0
- data/spec/parse_attributes.rb +98 -0
- data/spec/parse_renderers.rb +35 -0
- data/spec/parse_templates.rb +73 -0
- data/spec/person_template.st +1 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/template_group.rb +52 -0
- data/spec/template_group_directory.rb +43 -0
- data/spec/views/index.st +1 -0
- data/spec/views/money.rb +2 -0
- data/spec/views/person/age.st +1 -0
- data/spec/views/person/date_renderer.rb +5 -0
- data/spec/views/person/name.st +1 -0
- metadata +218 -0
Binary file
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../model/form'
|
2
|
+
require File.dirname(__FILE__) + '/../model/field'
|
3
|
+
|
4
|
+
describe Form do
|
5
|
+
it 'should update the value of a field on the form' do
|
6
|
+
form = Form.new(:blah => "")
|
7
|
+
form.update(:blah => "foo")
|
8
|
+
form[:blah].should eql("foo")
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should find the value of a field in the form' do
|
12
|
+
form = Form.new(:blah => "foo")
|
13
|
+
form[:blah].should eql("foo")
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'ramaze'
|
2
|
+
require 'ramaze/spec/helper'
|
3
|
+
|
4
|
+
require __DIR__('../start')
|
5
|
+
|
6
|
+
describe MainController do
|
7
|
+
behaves_like 'http', 'xpath'
|
8
|
+
ramaze :view_root => __DIR__('../view'),
|
9
|
+
:public_root => __DIR__('../public')
|
10
|
+
|
11
|
+
it 'should show start page' do
|
12
|
+
got = get('/')
|
13
|
+
got.status.should == 200
|
14
|
+
puts got.body
|
15
|
+
got.at('//title').text.strip.should ==
|
16
|
+
MainController.new.index
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should show /notemplate' do
|
20
|
+
got = get('/notemplate')
|
21
|
+
got.status.should == 200
|
22
|
+
got.at('//div').text.strip.should ==
|
23
|
+
MainController.new.notemplate
|
24
|
+
end
|
25
|
+
end
|
File without changes
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe RegistrationRepository do
|
4
|
+
|
5
|
+
it 'should create a new registration form when the key is unknown' do
|
6
|
+
form = RegistrationRepository.new.find()
|
7
|
+
form[:name].should eql("")
|
8
|
+
form[:address].should eql("")
|
9
|
+
form[:email].should eql("")
|
10
|
+
#form[:key].should eql(3)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should save a regsistration form' do
|
14
|
+
form = RegistrationFormBuilder.new.build(1)
|
15
|
+
form.update(:name => "Sarah")
|
16
|
+
RegistrationRepository.new.save(form)
|
17
|
+
|
18
|
+
registration = Registration[:id => form[:key]]
|
19
|
+
registration.should_not be_nil
|
20
|
+
registration.name.should eql("Sarah")
|
21
|
+
|
22
|
+
registration.delete
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should find a registration form' do
|
26
|
+
registration = Registration.create(:name => "sarah", :email => "sarah@me", :address => "Hi")
|
27
|
+
registration.save
|
28
|
+
|
29
|
+
form = RegistrationRepository.new.find(registration.id)
|
30
|
+
form[:name].should eql("sarah")
|
31
|
+
form[:address].should eql("Hi")
|
32
|
+
form[:email].should eql("sarah@me")
|
33
|
+
form[:key].should eql(registration.id)
|
34
|
+
|
35
|
+
registration.delete
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe RegistrationValidator do
|
4
|
+
|
5
|
+
it 'should not be valid if name is missing' do
|
6
|
+
form = RegistrationFormBuilder.new.build()
|
7
|
+
form.update(:address => "123 blah st", :email => "sarah@me.com")
|
8
|
+
|
9
|
+
RegistrationValidator.new.validate(form)
|
10
|
+
|
11
|
+
form.is_valid?.should be_false
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should not be valid if email is missing' do
|
15
|
+
form = RegistrationFormBuilder.new.build()
|
16
|
+
form.update(:address => "123 blah st", :name => "sarah@me.com")
|
17
|
+
|
18
|
+
RegistrationValidator.new.validate(form)
|
19
|
+
|
20
|
+
form.is_valid?.should be_false
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should not be valid if the provided phone number is not in the correct format' do
|
24
|
+
form = RegistrationFormBuilder.new.build()
|
25
|
+
form.update(:name => "123 blah st", :email => "sarah@me.com", :phone => "not valid")
|
26
|
+
|
27
|
+
RegistrationValidator.new.validate(form)
|
28
|
+
|
29
|
+
form.is_valid?.should be_false
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should not be valid if the email is in the incorrect format' do
|
33
|
+
form = RegistrationFormBuilder.new.build()
|
34
|
+
form.update(:name => "123 blah st", :email => "sarah without the at me.com")
|
35
|
+
|
36
|
+
RegistrationValidator.new.validate(form)
|
37
|
+
|
38
|
+
form.is_valid?.should be_false
|
39
|
+
form.errors_for(:email).should be_a_kind_of(Enumerable)
|
40
|
+
form.errors_for(:email).size.should eql(1)
|
41
|
+
form.errors_for(:email).first.should be_a_kind_of(IncorrectEmailFormatError)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should be valid if all fields correctly filled in' do
|
45
|
+
form = RegistrationFormBuilder.new.build()
|
46
|
+
form.update(:name => "sarah", :address => "123 blah st", :email => "sarah@me.com")
|
47
|
+
|
48
|
+
RegistrationValidator.new.validate(form)
|
49
|
+
|
50
|
+
form.is_valid?.should be_true
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'ramaze'
|
3
|
+
|
4
|
+
# Add directory start.rb is in to the load path, so you can run the app from
|
5
|
+
# any other working path
|
6
|
+
$LOAD_PATH.unshift(__DIR__)
|
7
|
+
|
8
|
+
# Initialize controllers and models
|
9
|
+
require 'controller/init'
|
10
|
+
require 'model/init'
|
11
|
+
|
12
|
+
Ramaze.start :adapter => :webrick, :port => 7000
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env rackup
|
2
|
+
# start.ru for ramaze apps
|
3
|
+
# use thin>=0.6.3
|
4
|
+
# thin start -r start.ru
|
5
|
+
#
|
6
|
+
# rackup is a useful tool for running Rack applications, which uses the
|
7
|
+
# Rack::Builder DSL to configure middleware and build up applications easily.
|
8
|
+
#
|
9
|
+
# rackup automatically figures out the environment it is run in, and runs your
|
10
|
+
# application as FastCGI, CGI, or standalone with Mongrel or WEBrick—all from
|
11
|
+
# the same configuration.
|
12
|
+
|
13
|
+
require 'start'
|
14
|
+
Ramaze.trait[:essentials].delete Ramaze::Adapter
|
15
|
+
Ramaze.start!
|
16
|
+
run Ramaze::Adapter::Base
|
@@ -0,0 +1,64 @@
|
|
1
|
+
<link rel="stylesheet" href="/css/ramaze_error.css" />
|
2
|
+
<script type="text/javascript" src="/js/jquery.js"></script>
|
3
|
+
|
4
|
+
<p>The backtrace gives filenames and line numbers for all parts of the call stack.<br />
|
5
|
+
Click on any of them to view the surrounding source code.</p>
|
6
|
+
|
7
|
+
<h3>#@title</h3>
|
8
|
+
|
9
|
+
<table class="main">
|
10
|
+
<tr class="head">
|
11
|
+
<td>File</td><td>Line</td><td>Method</td>
|
12
|
+
</tr>
|
13
|
+
<?r @backtrace.each do |lines, hash, file, lineno, meth| ?>
|
14
|
+
<tr class="line" id="#{hash}">
|
15
|
+
<td>#{file}</td><td class="lineno">#{lineno}</td><td><pre>#{meth}</pre></td>
|
16
|
+
</tr>
|
17
|
+
<tr id="source_#{hash}" style="display:none;">
|
18
|
+
<td colspan="3">
|
19
|
+
<div class="source">
|
20
|
+
<table style="width:100%;">
|
21
|
+
<tr>
|
22
|
+
<td class="editor" colspan="2">
|
23
|
+
#{@editor} #{file} +#{lineno}
|
24
|
+
<div style="float: right">
|
25
|
+
<a href="txmt://open?url=file://#{file}&line=#{lineno}">open in textmate</a>
|
26
|
+
</div>
|
27
|
+
</td>
|
28
|
+
</tr>
|
29
|
+
<?r lines.each do |llineno, lcode, lcurrent| ?>
|
30
|
+
<tr class="source" #{'style="background:#faa;"' if lcurrent}>
|
31
|
+
<td class="lineno">#{llineno}</td>
|
32
|
+
<td class="code"><pre>#{lcode.to_s.rstrip}</pre></td>
|
33
|
+
</tr>
|
34
|
+
<?r end ?>
|
35
|
+
</table>
|
36
|
+
</div>
|
37
|
+
</td>
|
38
|
+
</tr>
|
39
|
+
<?r end ?>
|
40
|
+
</table>
|
41
|
+
|
42
|
+
<?r
|
43
|
+
{ 'Session' => Ramaze::STATE[:session],
|
44
|
+
'Request' => Ramaze::STATE[:request],
|
45
|
+
'Response' => Ramaze::STATE[:response],
|
46
|
+
'Global' => Global,
|
47
|
+
}.each do |title, content|
|
48
|
+
hash = [title, content].object_id.abs
|
49
|
+
?>
|
50
|
+
<div class="additional">
|
51
|
+
<h3 id="#{hash}">#{title}</h3>
|
52
|
+
<pre style="display:none" id="is_#{hash}">#{Rack::Utils.escape_html(content.pretty_inspect)}</pre>
|
53
|
+
</div>
|
54
|
+
<?r end ?>
|
55
|
+
|
56
|
+
<script type="text/javascript">
|
57
|
+
$("tr.line").click(function(){
|
58
|
+
$("tr#source_"+this.id).toggle()
|
59
|
+
});
|
60
|
+
|
61
|
+
$("div.additional > h3").click(function(){
|
62
|
+
$("pre#is_"+this.id).toggle()
|
63
|
+
});
|
64
|
+
</script>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<p>Ramaze is working correctly with this application, now you can start
|
2
|
+
working.</p>
|
3
|
+
|
4
|
+
<p>To start you can modify:
|
5
|
+
<ol>
|
6
|
+
<li>
|
7
|
+
<code>view/index.xhtml</code>, this page.
|
8
|
+
</li>
|
9
|
+
<li>
|
10
|
+
<code>view/page.xhtml</code>, the layout for this page.
|
11
|
+
</li>
|
12
|
+
<li>
|
13
|
+
<code>controller/main.rb</code>, where you can change the header of this
|
14
|
+
page and the <a href="/notemplate">notemplate</a> action
|
15
|
+
</li>
|
16
|
+
</ol>
|
17
|
+
</p>
|
18
|
+
|
19
|
+
<p>For more documentation, check out <a href="http://ramaze.net">ramaze.net</a>, which includes:
|
20
|
+
<ul>
|
21
|
+
<li>a <a href="http://ramaze.net/getting-started">getting started</a> guide</li>
|
22
|
+
<li>some <a href="http://ramaze.net/screencasts">screencasts</a></li>
|
23
|
+
<li>and <a href="http://wiki.ramaze.net/Tutorials">tutorials</a></li>
|
24
|
+
</ul>
|
25
|
+
</p>
|
26
|
+
|
27
|
+
<p>You can also read the
|
28
|
+
<a href="http://ramaze.rubyforge.org/rdoc/files/doc/README.html">rdocs</a> or browse
|
29
|
+
around the <a href="http://source.ramaze.net">Ramaze source code</a>.
|
30
|
+
</p>
|
31
|
+
|
32
|
+
<p>For help with Ramaze, visit the <a href="irc://chat.freenode.net/ramaze">#ramaze on irc.freenode.net</a> (you can use <a href="http://java.freenode.net/?channel=ramaze">this browser-based frontend</a>),
|
33
|
+
or post on the <a href="http://groups.google.com/group/ramaze">Ramaze Google Group</a>.
|
34
|
+
</p>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<?xml version="1.0" ?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
5
|
+
<head>
|
6
|
+
<title>#{@title}</title>
|
7
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
8
|
+
<meta http-equiv="Content-Style-Type" content="text/css" />
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
10
|
+
<meta http-equiv="expires" content="0" />
|
11
|
+
<meta name="description" content="Description for search engines" />
|
12
|
+
<meta name="generator" content="Ramaze #{Ramaze::VERSION}" />
|
13
|
+
<meta name="keywords" content="Ramaze, Your own keywords" />
|
14
|
+
<meta name="author" content="Max Mustermann" />
|
15
|
+
<meta name="date" content="#{Time.now.iso8601}" />
|
16
|
+
<style type="text/css">
|
17
|
+
body { margin: 2em; }
|
18
|
+
#content { margin-left: 2em; }
|
19
|
+
</style>
|
20
|
+
</head>
|
21
|
+
<body>
|
22
|
+
<h1>#{@title}</h1>
|
23
|
+
<div id="content">
|
24
|
+
#@content
|
25
|
+
</div>
|
26
|
+
</body>
|
27
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
4
|
+
<title>Registration</title>
|
5
|
+
</head>
|
6
|
+
<body>
|
7
|
+
<h3>Registration</h3>
|
8
|
+
<div class="form" id="regirationForm">
|
9
|
+
<span>$message$</span>
|
10
|
+
<form action="/registration/save" method="post" accept-charset="utf-8">
|
11
|
+
$form:{
|
12
|
+
<input type="hidden" name="key" value="$key$">
|
13
|
+
<label for="name">Name</label>
|
14
|
+
<input type="text" name="name" value="$name$">
|
15
|
+
<label for="name">Address</label>
|
16
|
+
<input type="text" name="address" value="$address$">
|
17
|
+
<label for="name">Email</label>
|
18
|
+
<input type="text" name="email" value="$email$">
|
19
|
+
<label for="name">Phone</label>
|
20
|
+
<input type="text" name="phone" value="$phone$">
|
21
|
+
<input type="submit" name="save" value="Save Me!">
|
22
|
+
}$
|
23
|
+
</form>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
class Role
|
4
|
+
def initialize(name, level)
|
5
|
+
@name, @level = name, level
|
6
|
+
end
|
7
|
+
attr_reader :name, :level
|
8
|
+
end
|
9
|
+
|
10
|
+
class Person
|
11
|
+
def initialize(name, date_of_birth, role)
|
12
|
+
@name, @dob, @role = name, date_of_birth, role
|
13
|
+
end
|
14
|
+
attr_reader :name, :dob, :role
|
15
|
+
end
|
16
|
+
|
17
|
+
class RoleRenderer
|
18
|
+
def render(role)
|
19
|
+
role.level + ' : ' + role.name
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class AuthorRenderer
|
24
|
+
def render(author)
|
25
|
+
"the awesome " + author.name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class MainController < Ramaze::Controller
|
30
|
+
engine :Slippers
|
31
|
+
trait :slippers_options => {:author => AuthorRenderer.new, Role => RoleRenderer.new}
|
32
|
+
|
33
|
+
def index
|
34
|
+
@person = Person.new('Sarah', Date.new(1999, 1, 1), Role.new('developer', 'senior'))
|
35
|
+
@author = Person.new('Paul', Date.new(1880,3,5), Role.new('author', 'junior'))
|
36
|
+
@role = Role.new("sd", "sdffs")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
data/examples/start.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
A simple ToDo list example that uses Ramaze::Store as the persistence layer.
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
3
|
+
|
4
|
+
# Default url mappings are:
|
5
|
+
# a controller called Main is mapped on the root of the site: /
|
6
|
+
# a controller called Something is mapped on: /something
|
7
|
+
# If you want to override this, add a line like this inside the class
|
8
|
+
# map '/otherurl'
|
9
|
+
# this will force the controller to be mounted on: /otherurl
|
10
|
+
|
11
|
+
class MainController < Ramaze::Controller
|
12
|
+
engine :Slippers
|
13
|
+
def index
|
14
|
+
@tasks = []
|
15
|
+
TodoList.original.each do |title, value|
|
16
|
+
if value[:done]
|
17
|
+
status = 'done'
|
18
|
+
toggle = 'open'
|
19
|
+
else
|
20
|
+
status = 'not done'
|
21
|
+
toggle = 'close'
|
22
|
+
end
|
23
|
+
@tasks << {:title => title, :status => status, :resource => title, :toggle => toggle}
|
24
|
+
end
|
25
|
+
@heading = "TodoList"
|
26
|
+
#@tasks.sort!
|
27
|
+
end
|
28
|
+
|
29
|
+
def create
|
30
|
+
if title = request['title']
|
31
|
+
title.strip!
|
32
|
+
if title.empty?
|
33
|
+
failed("Please enter a title")
|
34
|
+
redirect '/new'
|
35
|
+
end
|
36
|
+
TodoList[title] = {:done => false}
|
37
|
+
redirect route('/', :title => title)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def open title
|
42
|
+
task_status title, false
|
43
|
+
end
|
44
|
+
|
45
|
+
def close title
|
46
|
+
task_status title, true
|
47
|
+
end
|
48
|
+
|
49
|
+
def delete title
|
50
|
+
TodoList.delete title
|
51
|
+
end
|
52
|
+
|
53
|
+
helper :aspect
|
54
|
+
after(:create, :open, :close, :delete){ redirect_referrer }
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def failed(message)
|
59
|
+
flash[:error] = message
|
60
|
+
end
|
61
|
+
|
62
|
+
def task_status title, status
|
63
|
+
unless task = TodoList[title]
|
64
|
+
failed "No such Task: `#{title}'"
|
65
|
+
redirect_referer
|
66
|
+
end
|
67
|
+
|
68
|
+
task[:done] = status
|
69
|
+
TodoList[title] = task
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
3
|
+
|
4
|
+
class Page < Ezamar::Element
|
5
|
+
def render
|
6
|
+
%{
|
7
|
+
<html>
|
8
|
+
<head>
|
9
|
+
<title>TodoList</title>
|
10
|
+
<style>
|
11
|
+
table { width: 100%; }
|
12
|
+
tr { background: #efe; width: 100%; }
|
13
|
+
tr:hover { background: #dfd; }
|
14
|
+
td.title { font-weight: bold; width: 60%; }
|
15
|
+
td.status { margin: 1em; }
|
16
|
+
a { color: #3a3; }
|
17
|
+
</style>
|
18
|
+
</head>
|
19
|
+
<body>
|
20
|
+
<h1>#{@title}</h1>
|
21
|
+
<?r if flash[:error] ?>
|
22
|
+
<div class="error">
|
23
|
+
\#{flash[:error]}
|
24
|
+
</div>
|
25
|
+
<?r end ?>
|
26
|
+
#{content}
|
27
|
+
</body>
|
28
|
+
</html>
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
3
|
+
|
4
|
+
require 'ramaze/store/default'
|
5
|
+
|
6
|
+
TodoList = Ramaze::Store::Default.new('todolist.db')
|
7
|
+
|
8
|
+
{
|
9
|
+
'Laundry' => {:done => false},
|
10
|
+
'Wash dishes' => {:done => false},
|
11
|
+
|
12
|
+
}.each do |title, value|
|
13
|
+
TodoList[title] = value
|
14
|
+
end
|
Binary file
|