doco 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +15 -0
- data/Rakefile +22 -0
- data/lib/doco.rb +82 -0
- metadata +99 -0
data/README.textile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
h1. Doco
|
2
|
+
|
3
|
+
Is a simple piece of rack middleware[1] which allows me to write stuff in textile, give it structure with mustache, and deploy it easily. It was designed for documentation, hence the name.
|
4
|
+
|
5
|
+
h2. Usage
|
6
|
+
|
7
|
+
It's pretty simple to use, just clone this repository, and edit your layout in the layouts directory, write your content in the pages directory, and put anything else you want available in the public directory.
|
8
|
+
|
9
|
+
h2. Patches & Feedback
|
10
|
+
|
11
|
+
Patches are welcome, as is feedback, feel free to send either as a "message on github":http://github.com/inbox/new/miksago
|
12
|
+
|
13
|
+
---
|
14
|
+
|
15
|
+
fn1. -Maybe it's a rack application, not middleware? I'm still learning this stuff!- Hopefully it's actually middleware now.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "doco"
|
8
|
+
gem.summary = %Q{Renders textile documents within mustache templates}
|
9
|
+
gem.description = %Q{Renders textile documents within mustache templates}
|
10
|
+
gem.email = "micheil@brandedcode.com"
|
11
|
+
gem.homepage = "http://github.com/miksago/doco"
|
12
|
+
gem.authors = ["Micheil Smith"]
|
13
|
+
gem.add_dependency "rack"
|
14
|
+
gem.add_dependency "mustache"
|
15
|
+
gem.add_dependency "RedCloth"
|
16
|
+
gem.require_path = 'lib'
|
17
|
+
gem.files = %w(LICENSE README.textile Rakefile) + Dir.glob("{lib,bin}/**/{*,.[a-z]*}")
|
18
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
|
+
end
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
22
|
+
end
|
data/lib/doco.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
|
2
|
+
require 'rack/utils'
|
3
|
+
require 'yaml'
|
4
|
+
require 'mustache'
|
5
|
+
require 'RedCloth'
|
6
|
+
|
7
|
+
require 'digest'
|
8
|
+
|
9
|
+
module Rack
|
10
|
+
class Doco
|
11
|
+
def initialize(app, options={})
|
12
|
+
@app = app
|
13
|
+
@url = options[:url].chomp("/") || "/"
|
14
|
+
@root = options[:root] || Dir.pwd
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
dup._call(env)
|
19
|
+
end
|
20
|
+
|
21
|
+
F = ::File
|
22
|
+
|
23
|
+
def _call(env)
|
24
|
+
path = Utils.unescape(F.expand_path(env['PATH_INFO']))
|
25
|
+
|
26
|
+
result = if path.index(@url) == 0 && env["REQUEST_METHOD"] == "GET"
|
27
|
+
route = path[@url.length..-1].split('/').reject {|i| i.empty? }
|
28
|
+
route << "index" if route.empty?
|
29
|
+
|
30
|
+
handle(route)
|
31
|
+
end
|
32
|
+
|
33
|
+
result.first == 404 ? @app.call(env) : result
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def respond status, body
|
38
|
+
headers = {
|
39
|
+
"Content-Type" => "text/html",
|
40
|
+
"Content-Length" => Utils.bytesize(body).to_s,
|
41
|
+
"Etag" => Digest::SHA1.hexdigest(body)
|
42
|
+
}
|
43
|
+
|
44
|
+
return [status, headers, body]
|
45
|
+
end
|
46
|
+
|
47
|
+
def handle(route)
|
48
|
+
page = F.join(@root, "pages", route) + ".textile"
|
49
|
+
|
50
|
+
if F.exists?(page)
|
51
|
+
content = F.read(page)
|
52
|
+
data = {"title" => "untitled", "layout" => "default"}
|
53
|
+
|
54
|
+
if content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
|
55
|
+
content = content[($1.size + $2.size)..-1]
|
56
|
+
data = data.merge(YAML.load($1))
|
57
|
+
end
|
58
|
+
|
59
|
+
respond 200, mustache(load_layout(data["layout"]), data.merge({
|
60
|
+
:body => textile(content),
|
61
|
+
:base_url => @url
|
62
|
+
}))
|
63
|
+
else
|
64
|
+
[404, {}, ""]
|
65
|
+
end
|
66
|
+
rescue Errno::ENOENT => e
|
67
|
+
[404, {}, ""]
|
68
|
+
end
|
69
|
+
|
70
|
+
def load_layout(layout)
|
71
|
+
F.read(F.join(@root, "layouts", layout + ".mustache"))
|
72
|
+
end
|
73
|
+
|
74
|
+
def textile(content)
|
75
|
+
RedCloth.new(content).to_html
|
76
|
+
end
|
77
|
+
|
78
|
+
def mustache(template, data)
|
79
|
+
Mustache.render(template, data)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: doco
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Micheil Smith
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-08 00:00:00 +11:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rack
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: mustache
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :runtime
|
43
|
+
version_requirements: *id002
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: RedCloth
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
type: :runtime
|
55
|
+
version_requirements: *id003
|
56
|
+
description: Renders textile documents within mustache templates
|
57
|
+
email: micheil@brandedcode.com
|
58
|
+
executables: []
|
59
|
+
|
60
|
+
extensions: []
|
61
|
+
|
62
|
+
extra_rdoc_files:
|
63
|
+
- README.textile
|
64
|
+
files:
|
65
|
+
- README.textile
|
66
|
+
- Rakefile
|
67
|
+
- lib/doco.rb
|
68
|
+
has_rdoc: true
|
69
|
+
homepage: http://github.com/miksago/doco
|
70
|
+
licenses: []
|
71
|
+
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options:
|
74
|
+
- --charset=UTF-8
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.3.6
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Renders textile documents within mustache templates
|
98
|
+
test_files: []
|
99
|
+
|