guide-em-up 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/MIT-LICENSE +20 -0
- data/README.md +42 -0
- data/bin/guide-em-up +8 -0
- data/lib/guide-em-up/browser.rb +58 -0
- data/lib/guide-em-up/guide.rb +56 -0
- data/lib/guide-em-up/version.rb +3 -0
- data/lib/guide-em-up.rb +3 -0
- data/themes/github.erb +20 -0
- metadata +122 -0
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Bruno Michel <bruno.michel@af83.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
Guide'em up
|
2
|
+
===========
|
3
|
+
|
4
|
+
Guide'em up is a tool for writing guides in markdown. It generates an HTML
|
5
|
+
document that you can share easily, it's just one file after all!
|
6
|
+
|
7
|
+
|
8
|
+
How to use it?
|
9
|
+
--------------
|
10
|
+
|
11
|
+
It's really simple:
|
12
|
+
|
13
|
+
1. Install it with `gem install guide-em-up`
|
14
|
+
2. Write your guide in markdown
|
15
|
+
3. Launch `guide-em-up` and open http://localhost:9000 in your browser
|
16
|
+
4. Select your guide and enjoy :-)
|
17
|
+
|
18
|
+
|
19
|
+
TODO
|
20
|
+
----
|
21
|
+
|
22
|
+
* Browse files to find the guide
|
23
|
+
* Let us choose between several themes
|
24
|
+
* Complete specs
|
25
|
+
|
26
|
+
|
27
|
+
Issues or Suggestions
|
28
|
+
---------------------
|
29
|
+
|
30
|
+
Found an issue or have a suggestion? Please report it on
|
31
|
+
[Github's issue tracker](http://github.com/nono/guide-em-up/issues).
|
32
|
+
|
33
|
+
If you wants to make a pull request, please check the specs before:
|
34
|
+
|
35
|
+
./spec/guide-em-up_spec.rb
|
36
|
+
|
37
|
+
|
38
|
+
Credits
|
39
|
+
-------
|
40
|
+
|
41
|
+
♡2011 by Bruno Michel. Copying is an act of love. Please copy and share.
|
42
|
+
Released under the MIT license
|
data/bin/guide-em-up
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require "time"
|
2
|
+
require "rack/utils"
|
3
|
+
require "rack/mime"
|
4
|
+
require "goliath/api"
|
5
|
+
|
6
|
+
|
7
|
+
module GuideEmUp
|
8
|
+
class Browser < Goliath::API
|
9
|
+
def initialize(dir)
|
10
|
+
@root = dir
|
11
|
+
end
|
12
|
+
|
13
|
+
def response(env)
|
14
|
+
path_info = File.join(@root, Rack::Utils.unescape(env["PATH_INFO"]))
|
15
|
+
if File.file?(path_info)
|
16
|
+
serve_guide(path_info)
|
17
|
+
elsif path_info.include? ".."
|
18
|
+
unauthorized_access
|
19
|
+
elsif File.directory?(path_info)
|
20
|
+
serve_index(path_info)
|
21
|
+
else
|
22
|
+
page_not_found(path_info)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def serve_guide(filename)
|
29
|
+
body = Guide.new(filename).html
|
30
|
+
[200, {
|
31
|
+
"Content-Type" => "text/html; charset=utf-8",
|
32
|
+
"Content-Length" => Rack::Utils.bytesize(body).to_s
|
33
|
+
}, [body] ]
|
34
|
+
end
|
35
|
+
|
36
|
+
def serve_index(path_info)
|
37
|
+
body = "TODO"
|
38
|
+
[200, {
|
39
|
+
"Content-Length" => Rack::Utils.bytesize(body).to_s,
|
40
|
+
"Content-Type" => "text/html; charset=utf-8",
|
41
|
+
}, [body] ]
|
42
|
+
end
|
43
|
+
|
44
|
+
def page_not_found(path_info)
|
45
|
+
[404, {
|
46
|
+
"Content-Type" => "text/plain",
|
47
|
+
"Content-Length" => "0"
|
48
|
+
}, ["File not found: #{path_info}\n"] ]
|
49
|
+
end
|
50
|
+
|
51
|
+
def unauthorized_access
|
52
|
+
[403, {
|
53
|
+
"Content-Type" => "text/plain",
|
54
|
+
"Content-Length" => "0"
|
55
|
+
}, ["Forbidden\n"] ]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "albino"
|
2
|
+
require "digest/sha1"
|
3
|
+
require "erubis"
|
4
|
+
require "redcarpet"
|
5
|
+
require "yajl"
|
6
|
+
|
7
|
+
|
8
|
+
module GuideEmUp
|
9
|
+
class Guide < Struct.new(:filename, :title)
|
10
|
+
def initialize(filename)
|
11
|
+
self.filename = self.title = filename
|
12
|
+
@codemap = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def html
|
16
|
+
file = File.expand_path("../../../themes/github.erb", __FILE__)
|
17
|
+
tmpl = File.read(file)
|
18
|
+
Erubis::Eruby.new(tmpl).result(to_hash)
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def to_hash
|
24
|
+
hsh = Hash[members.zip values].merge(:content => content)
|
25
|
+
hsh
|
26
|
+
end
|
27
|
+
|
28
|
+
def content
|
29
|
+
raw = File.read(filename)
|
30
|
+
tmp = extract_code(raw)
|
31
|
+
red = Redcarpet.new(tmp, :autolink, :generate_toc, :smart, :strikethrough, :tables)
|
32
|
+
process_code red.to_html
|
33
|
+
end
|
34
|
+
|
35
|
+
# Code taken from gollum (http://github.com/github/gollum)
|
36
|
+
def extract_code(md)
|
37
|
+
md.gsub(/^``` ?(.+?)\r?\n(.+?)\r?\n```\r?$/m) do
|
38
|
+
id = Digest::SHA1.hexdigest($2)
|
39
|
+
@codemap[id] = { :lang => $1, :code => $2 }
|
40
|
+
id
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def process_code(data)
|
45
|
+
@codemap.each do |id, spec|
|
46
|
+
lang, code = spec[:lang], spec[:code]
|
47
|
+
if code.lines.all? { |line| line =~ /\A\r?\n\Z/ || line =~ /^( |\t)/ }
|
48
|
+
code.gsub!(/^( |\t)/m, '')
|
49
|
+
end
|
50
|
+
output = Albino.new(code, lang).colorize(:P => "nowrap")
|
51
|
+
data.gsub!(id, "<pre><code class=\"#{lang}\">#{output}</code></pre>")
|
52
|
+
end
|
53
|
+
data
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/guide-em-up.rb
ADDED
data/themes/github.erb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
5
|
+
<style>
|
6
|
+
#container { margin: 0 auto; max-width: 920px; background-color: #f8f8f8; padding: .7em; font-size: 13.34px; font-family: verdana, sans-serif; border: 1px #E0E0E0 solid; }
|
7
|
+
#container h2, #container h3, #content h4 { padding-top: 10px; border-top: 4px solid #E0E0E0; }
|
8
|
+
#container pre { padding: 5px; border-style: solid; border-width: 1px; border-color: #E0E0E0; background-color: #F8F8FF; }
|
9
|
+
#container pre code { padding: 5px; background-color: #F8F8FF; border: none; }
|
10
|
+
#container code { font-family: courier, fixed; display: inline-block; padding: 0px 2px 0px 2px; background-color: #F8F8FF; border: 1px #E0E0E0 solid; }
|
11
|
+
h4#title { font-family: verdana, sans-serif; display: block; margin: 0 auto; width: 920px; }
|
12
|
+
</style>
|
13
|
+
<title><%= title %></title>
|
14
|
+
</head>
|
15
|
+
<body>
|
16
|
+
<section id="container">
|
17
|
+
<%= content %>
|
18
|
+
</section>
|
19
|
+
</body>
|
20
|
+
</html>
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guide-em-up
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bruno Michel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-07-09 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: goliath
|
16
|
+
requirement: &75214320 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.9'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *75214320
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: redcarpet
|
27
|
+
requirement: &75213920 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.17'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *75213920
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: erubis
|
38
|
+
requirement: &75213490 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '2.7'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *75213490
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: yajl-ruby
|
49
|
+
requirement: &75213080 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.8'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *75213080
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: albino
|
60
|
+
requirement: &75212840 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '1.3'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *75212840
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: &75212470 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '2.3'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *75212470
|
80
|
+
description: Slide'em up is a tool for writing guides in markdown
|
81
|
+
email: bruno.michel@af83.com
|
82
|
+
executables:
|
83
|
+
- guide-em-up
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files:
|
86
|
+
- README.md
|
87
|
+
files:
|
88
|
+
- MIT-LICENSE
|
89
|
+
- README.md
|
90
|
+
- Gemfile
|
91
|
+
- bin/guide-em-up
|
92
|
+
- lib/guide-em-up.rb
|
93
|
+
- lib/guide-em-up/guide.rb
|
94
|
+
- lib/guide-em-up/browser.rb
|
95
|
+
- lib/guide-em-up/version.rb
|
96
|
+
- themes/github.erb
|
97
|
+
homepage: http://github.com/nono/guide-em-up
|
98
|
+
licenses: []
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 1.8.5
|
118
|
+
signing_key:
|
119
|
+
specification_version: 3
|
120
|
+
summary: Slide'em up is a tool for writing guides in markdown and generates one-page
|
121
|
+
HTML document from them
|
122
|
+
test_files: []
|