Created
November 17, 2010 19:19
-
-
Save pol/703884 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'outliner' | |
include Outliner | |
outline "This is my outline" do | |
s "This is a section" do | |
p "This is a paragraph" do | |
t "This is a topic in the paragraph" | |
end | |
p "This is a paragraph without topics" | |
end | |
s "This is another section" | |
p "This is a paragraph, but it (mostly) doesn't matter the method called." | |
todo "I can use this too." | |
end |
This file contains hidden or 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
module Outliner | |
attr_accessor :output | |
attr_accessor :depth | |
def outline(desc, *args, &block) | |
@output = "" | |
@depth = 0 | |
@output = <<-OUTLINE | |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | |
"http://www.w3.org/TR/html4/loose.dtd"> | |
<html> | |
<head> | |
<title>Outline</title> | |
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script> | |
<script src="https://github.com/jzaefferer/jquery-treeview/raw/master/jquery.treeview.js" type="text/javascript" ></script> | |
<script src="https://github.com/carhartl/jquery-cookie/raw/master/jquery.cookie.js" type="text/javascript" ></script> | |
<link rel="stylesheet" href="http://jquery.bassistance.de/treeview/demo/screen.css" type="text/css" /> | |
<link rel="stylesheet" href="http://jquery.bassistance.de/treeview/jquery.treeview.css" type="text/css" /> | |
<script type='text/javascript'> | |
$(document).ready(function() { | |
$(".outline").treeview({ | |
collapsed: true, | |
//persist: "cookie", | |
control: "#outlinecontrol" | |
}); | |
}); | |
</script> | |
<style type="text/css"> | |
ul li{list-style-position: inside;} | |
ul.o2{list-style-type: upper-roman;} | |
ul.o3{list-style-type: upper-alpha; } | |
ul.o4{list-style-type: decimal; } | |
ul.o5{list-style-type: lower-alpha; } | |
ul.o6{list-style-type: disc; } | |
ul.o7{list-style-type: square; } | |
ul.o8{list-style-type: circle; } | |
</style> | |
</head> | |
<body> | |
<div id="outlinecontrol"> | |
<a title="Collapse the entire tree below" href="#"><img src="../images/minus.gif" /> Collapse All</a> | |
<a title="Expand the entire tree below" href="#"><img src="../images/plus.gif" /> Expand All</a> | |
<a title="Toggle the tree below, opening closed branches, closing open branches" href="#">Toggle All</a> | |
</div> | |
OUTLINE | |
_list(:outline) do | |
_line(desc, &block) if block_given? | |
end | |
puts output + <<-FOOT | |
</body></html> | |
FOOT | |
end | |
def _list(kind) | |
@depth += 1 | |
@output += "<ul class='o#{depth} #{kind}'>" | |
yield if block_given? | |
@output += "</ul>\n" | |
@depth -= 1 | |
end | |
def _line(desc, &block) | |
@output += "<li><span class='o#{depth} #{__method__}'>#{desc}</span>" | |
_list(__method__, &block) if block_given? | |
@output += "</li>\n" | |
end | |
alias :o :_line | |
alias :b :_line | |
alias :t :_line | |
alias :p :_line | |
alias :s :_line | |
alias :todo :_line | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment