forked from zzak/shoes-contrib
-
Notifications
You must be signed in to change notification settings - Fork 5
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
zzak
committed
Dec 13, 2010
1 parent
467301a
commit 6418835
Showing
38 changed files
with
2,644 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'yaml' | ||
|
||
class Book < Shoes | ||
url '/', :index | ||
url '/incidents/(\d+)', :incident | ||
|
||
def index | ||
incident(0) | ||
end | ||
|
||
INCIDENTS = YAML.load_file('class-book.yaml') | ||
|
||
def table_of_contents | ||
toc = [] | ||
INCIDENTS.each_with_index do |(title, story), i| | ||
toc.push "(#{i + 1}) ", | ||
link(title, :click => "/incidents/#{i}"), | ||
" / " | ||
end | ||
toc.pop | ||
span *toc | ||
end | ||
|
||
def incident(num) | ||
num = num.to_i | ||
background white | ||
stack :margin => 10, :margin_left => 190, :margin_top => 20 do | ||
banner "Incident", :margin => 4 | ||
para strong("No. #{num + 1}: #{INCIDENTS[num][0]}"), :margin => 4 | ||
end | ||
flow :width => 180, :margin_left => 10, :margin_top => 0 do | ||
para table_of_contents, :size => 8 | ||
end | ||
stack :width => -190, :margin => 10, :margin_top => 0 do | ||
INCIDENTS[num][1].split(/\n\n+/).each do |p| | ||
para p | ||
end | ||
end | ||
end | ||
end | ||
|
||
Shoes.app :width => 640, :height => 700, | ||
:title => "Incidents, a Book" |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Shoes.app :title => "Dictionary, powered by Definr", :width => 370, :height => 320 do | ||
stack do | ||
background red, :height => 60 | ||
flow :margin => 20 do | ||
caption "Define: ", :stroke => white | ||
@lookup = edit_line | ||
button "Go" do | ||
download "http://definr.com/definr/show/#{@lookup.text}" do |dl| | ||
doc = dl.response.body.gsub(' ', ' '). | ||
gsub(%r!(</a>|<br />|<a href.+?>)!, ''). | ||
gsub(%r!\(http://.+?\)!, '').strip | ||
title, doc = doc.split(/\n+/, 2) | ||
@deft.replace title | ||
@defn.replace doc | ||
end | ||
end | ||
end | ||
stack :margin => 20 do | ||
@deft = subtitle "", :margin => 10 | ||
@defn = para "" | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'hpricot' | ||
|
||
class Comic | ||
attr_reader :rss, :title | ||
|
||
def initialize(body) | ||
@rss = Hpricot.XML(body) | ||
@title = @rss.at("//channel/title").inner_text | ||
end | ||
|
||
def items | ||
@rss.search("//channel/item") | ||
end | ||
|
||
def latest_image | ||
@rss.search("//channel/item").first.inner_html.scan(/src="([^"]+\.\w+)"/).first | ||
end | ||
end | ||
|
||
Shoes.app :width => 800, :height => 600 do | ||
background "#555" | ||
|
||
@title = "Web Funnies" | ||
@feeds = [ | ||
"http://xkcd.com/rss.xml", | ||
"http://feedproxy.google.com/DilbertDailyStrip?format=xml", | ||
"http://www.smbc-comics.com/rss.php", | ||
"http://www.daybydaycartoon.com/index.xml", | ||
"http://www.questionablecontent.net/QCRSS.xml", | ||
"http://indexed.blogspot.com/feeds/posts/default?alt=rss" | ||
] | ||
|
||
stack :margin => 10 do | ||
title strong(@title), :align => "center", :stroke => "#DFA", :margin => 0 | ||
para "(loaded from RSS feeds)", :align => "center", :stroke => "#DFA", | ||
:margin => 0 | ||
|
||
@feeds.each do |feed| | ||
download feed do |dl| | ||
stack :width => "100%", :margin => 10, :border => 1 do | ||
c = Comic.new dl.response.body | ||
stack :margin_right => gutter do | ||
background "#333", :curve => 4 | ||
caption c.title, :stroke => "#CD9", :margin => 4 | ||
end | ||
image c.latest_image.first, :margin => 8 | ||
end | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,112 @@ | ||
require 'irb/ruby-lex' | ||
require 'stringio' | ||
|
||
class MimickIRB < RubyLex | ||
attr_accessor :started | ||
|
||
class Continue < StandardError; end | ||
class Empty < StandardError; end | ||
|
||
def initialize | ||
super | ||
set_input(StringIO.new) | ||
end | ||
|
||
def run(str) | ||
obj = nil | ||
@io << str | ||
@io.rewind | ||
unless l = lex | ||
raise Empty if @line == '' | ||
else | ||
case l.strip | ||
when "reset" | ||
@line = "" | ||
when "time" | ||
@line = "puts %{You started \#{IRBalike.started.since} ago.}" | ||
else | ||
@line << l << "\n" | ||
if @ltype or @continue or @indent > 0 | ||
raise Continue | ||
end | ||
end | ||
end | ||
unless @line.empty? | ||
obj = eval @line, TOPLEVEL_BINDING, "(irb)", @line_no | ||
end | ||
@line_no += @line.scan(/\n/).length | ||
@line = '' | ||
@exp_line_no = @line_no | ||
|
||
@indent = 0 | ||
@indent_stack = [] | ||
|
||
$stdout.rewind | ||
output = $stdout.read | ||
$stdout.truncate(0) | ||
$stdout.rewind | ||
[output, obj] | ||
rescue Object => e | ||
case e when Empty, Continue | ||
else @line = "" | ||
end | ||
raise e | ||
ensure | ||
set_input(StringIO.new) | ||
end | ||
|
||
end | ||
|
||
CURSOR = ">>" | ||
IRBalike = MimickIRB.new | ||
$stdout = StringIO.new | ||
|
||
Shoes.app do | ||
@str, @cmd = [CURSOR + " "], "" | ||
stack :width => 1.0, :height => 1.0 do | ||
background "#555" | ||
stack :width => 1.0, :height => 50 do | ||
para "Interactive Ruby ready.", :fill => white, :stroke => red | ||
end | ||
@scroll = | ||
stack :width => 1.0, :height => -50, :scroll => true do | ||
background "#555" | ||
@console = para @str, :font => "Monospace 12px", :stroke => "#dfa" | ||
@console.cursor = -1 | ||
end | ||
end | ||
keypress do |k| | ||
case k | ||
when "\n" | ||
begin | ||
out, obj = IRBalike.run(@cmd + ';') | ||
@str += ["#@cmd\n", | ||
span("#{out}=> #{obj.inspect}\n", :stroke => "#fda"), | ||
"#{CURSOR} "] | ||
@cmd = "" | ||
rescue MimickIRB::Empty | ||
rescue MimickIRB::Continue | ||
@str += ["#@cmd\n.. "] | ||
@cmd = "" | ||
rescue Object => e | ||
@str += ["#@cmd\n", span("#{e.class}: #{e.message}\n", :stroke => "#fcf"), | ||
"#{CURSOR} "] | ||
@cmd = "" | ||
end | ||
when String | ||
@cmd += k | ||
when :backspace | ||
@cmd.slice!(-1) | ||
when :tab | ||
@cmd += " " | ||
when :alt_q | ||
quit | ||
when :alt_c | ||
self.clipboard = @cmd | ||
when :alt_v | ||
@cmd += self.clipboard | ||
end | ||
@console.replace *(@str + [@cmd]) | ||
@scroll.scroll_top = @scroll.scroll_max | ||
end | ||
end |
Oops, something went wrong.