Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2991cc
commit c80b5ff
Showing
1 changed file
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,62 @@ | ||
Raamwerk | ||
======== | ||
|
||
A toy Ruby framework based on continuations. | ||
A toy proof of concept Ruby framework based on continuations. | ||
|
||
Usage: | ||
gem install sinatra | ||
ruby arcchallenge.rb | ||
|
||
The solution to the arc challenge: | ||
|
||
```ruby | ||
page '/' do | ||
form do | ||
msg = input() | ||
submit do | ||
link("Click me"){ puts "You said #{msg}" } | ||
end | ||
end | ||
end | ||
``` | ||
|
||
As you can see you can use normal lexically scoped variables for inputs. This is an improvement over Arc which does not provide an abstraction over form input, you have to use string keys into request parameters to get form input. | ||
|
||
A counter with links to increase and decrease the count: | ||
|
||
```ruby | ||
def counter(i) | ||
puts "the counter is #{i}" | ||
link("increase") { counter(i+1) } | ||
link("decrease") { counter(i-1) } | ||
end | ||
|
||
page '/' do | ||
counter(0) | ||
end | ||
``` | ||
|
||
A todolist application looks like this: | ||
|
||
```ruby | ||
$todo = [] | ||
|
||
def todo | ||
tag(:ul) do | ||
$todo.each do |x| | ||
tag(:li){puts x; link("delete"){ $todo.delete(x); todo }} | ||
end | ||
end | ||
|
||
form do | ||
t = input() | ||
submit { $todo << t; todo } | ||
end | ||
end | ||
|
||
page '/' do | ||
todo | ||
end | ||
``` | ||
|
||
This displays a list of todo items with delete links, and a form to add an item. |