guide-em-up 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -16,14 +16,6 @@ It's really simple:
16
16
  4. Select your guide and enjoy :-)
17
17
 
18
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
19
  Issues or Suggestions
28
20
  ---------------------
29
21
 
@@ -38,5 +30,8 @@ If you wants to make a pull request, please check the specs before:
38
30
  Credits
39
31
  -------
40
32
 
33
+ The CSS and images for the browser are based on
34
+ [h5ai](http://larsjung.de/h5ai/), a beautified Apache index.
35
+
41
36
  ♡2011 by Bruno Michel. Copying is an act of love. Please copy and share.
42
37
  Released under the MIT license
data/data/browser.erb ADDED
@@ -0,0 +1,47 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Guide'em up - <%= dir %></title>
5
+ <link rel="shortcut icon" type="image/png" href="/g-e-u/images/h5ai-16x16.png">
6
+ <link rel="stylesheet" type="text/css" href="/g-e-u/css/browser.css">
7
+ </head>
8
+ <body>
9
+ <nav>
10
+ <span class="left">
11
+ <a href='/'><img src='/g-e-u/images/home.png' alt='>' /></a>
12
+ </span>
13
+ <span class="center">
14
+ <h1>Guide'em up</h1>
15
+ </span>
16
+ </nav>
17
+
18
+ <aside>
19
+ <h1>Thèmes</h1>
20
+ <ul>
21
+ <% themes.each do |theme| %>
22
+ <li class="theme<%= " selected" if theme.current %>">
23
+ <a href="/g-e-u/theme/<%= theme.name %>">
24
+ <img src="/g-e-u/images/tree.png" />
25
+ <%= theme.name %>
26
+ </a>
27
+ </li>
28
+ <% end %>
29
+ </aside>
30
+
31
+ <section class="clearfix">
32
+ <h1><%= dir %></h1>
33
+ <ul>
34
+ <% files.each do |file| %>
35
+ <li class="entry">
36
+ <a href="<%= "#{file.path}" %>">
37
+ <span class="icon">
38
+ <img src="/g-e-u/icons/<%= file.icon %>.png" />
39
+ </span>
40
+ <span class="label"><%= file.name %></span>
41
+ </a>
42
+ </li>
43
+ <% end %>
44
+ </ul>
45
+ </section>
46
+ </body>
47
+ </html>
@@ -0,0 +1,153 @@
1
+ article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
2
+ display: block;
3
+ }
4
+
5
+ .clearfix:before, .clearfix:after {
6
+ content: "\0020";
7
+ display: block;
8
+ height: 0;
9
+ overflow: hidden;
10
+ }
11
+ .clearfix:after {
12
+ clear: both;
13
+ }
14
+ .clearfix {
15
+ zoom: 1;
16
+ }
17
+
18
+ body {
19
+ font-family: Ubuntu, sans-serif;
20
+ font-size: 16px;
21
+ color: #555;
22
+ margin: 100px 50px;
23
+ }
24
+ h1 {
25
+ font-size: 1.4em;
26
+ margin: 5px;
27
+ }
28
+ a, a:active, a:visited {
29
+ color: #607890;
30
+ }
31
+ a:hover {
32
+ color: #036;
33
+ }
34
+
35
+ nav {
36
+ position: fixed;
37
+ z-index: 1;
38
+ width: 100%;
39
+ left: 0;
40
+ top: 0;
41
+ padding: 6px 0 8px 0;
42
+ background-color: #f1f1f1;
43
+ border-bottom: 2px solid #d2d2d2;
44
+ text-align: center;
45
+ }
46
+ nav a, nav a:active, nav a:visited {
47
+ color: #555;
48
+ text-decoration: none;
49
+ -moz-transition: all .2s ease-in-out;
50
+ -ms-transition: all .2s ease-in-out;
51
+ -o-transition: all .2s ease-in-out;
52
+ -webkit-transition: all .2s ease-in-out;
53
+ transition: all .2s ease-in-out;
54
+ opacity: .7;
55
+ }
56
+ nav a:hover, nav a:active:hover, nav a:visited:hover {
57
+ color: #e80;
58
+ opacity: 1;
59
+ }
60
+ nav .left {
61
+ display: block;
62
+ padding: 0 8px;
63
+ float: left;
64
+ }
65
+ nav .center {
66
+ display: block;
67
+ margin: 0 300px;
68
+ font-size: 1.4em;
69
+ }
70
+ nav .right {
71
+ display: block;
72
+ padding: 0 8px;
73
+ float: right;
74
+ }
75
+
76
+ section {
77
+ margin: 0 auto;
78
+ max-width: 960px;
79
+ border: 1px solid #EEEEEE;
80
+ border-radius: 15px 15px 15px 15px;
81
+ padding: 3px;
82
+ }
83
+ section h1 {
84
+ padding: 5px 15px;
85
+ }
86
+ ul {
87
+ margin: 0;
88
+ padding: 0;
89
+ list-style: none;
90
+ }
91
+ ul li.entry {
92
+ float: left;
93
+ }
94
+ ul li.entry a, ul li.entry a:active, ul li.entry a:visited {
95
+ display: block;
96
+ margin: 8px;
97
+ padding: 8px;
98
+ width: 100px;
99
+ height: 120px;
100
+ float: left;
101
+ text-align: center;
102
+ text-decoration: none;
103
+ overflow: hidden;
104
+ border-radius: 5px;
105
+ color: #555;
106
+ cursor: pointer;
107
+ border: 2px solid rgba(0, 0, 0, 0);
108
+ }
109
+ ul li.entry a:hover, ul li.entry a:active:hover, ul li.entry a:visited:hover, ul li.entry a.hover, ul li.entry a:active.hover, ul li.entry a:visited.hover {
110
+ color: #e80;
111
+ border-color: #eee;
112
+ background-color: #f6f6f6;
113
+ }
114
+ ul li.entry a .icon, ul li.entry a:active .icon, ul li.entry a:visited .icon {
115
+ display: block;
116
+ }
117
+ ul li.entry a .icon img, ul li.entry a:active .icon img, ul li.entry a:visited .icon img {
118
+ min-width: 48px;
119
+ min-height: 48px;
120
+ margin-bottom: 8px;
121
+ }
122
+ ul li.entry a .label, ul li.entry a:active .label, ul li.entry a:visited .label {
123
+ display: block;
124
+ word-wrap: break-word;
125
+ }
126
+
127
+ aside {
128
+ display: block;
129
+ position: fixed;
130
+ left: 0;
131
+ top: 100px;
132
+ z-index: 1;
133
+ overflow: auto;
134
+ padding: 16px 16px 16px 16px;
135
+ background-color: #f1f1f1;
136
+ border: 2px solid #d2d2d2;
137
+ border-left: none;
138
+ -moz-border-radius: 0 15px 15px 0;
139
+ -webkit-border-radius: 0 15px 15px 0;
140
+ border-radius: 0 15px 15px 0;
141
+ }
142
+ aside li {
143
+ padding: 3px;
144
+ }
145
+ aside li.selected {
146
+ font-weight: bold;
147
+ }
148
+ aside li a {
149
+ text-decoration: none;
150
+ }
151
+ aside li img {
152
+ vertical-align: middle;
153
+ }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/data/icons/js.png ADDED
Binary file
Binary file
Binary file
data/data/icons/rb.png ADDED
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
File without changes
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <title><%= title %></title>
6
+ </head>
7
+ <body>
8
+ <%= content %>
9
+ </body>
10
+ </html>
@@ -0,0 +1,43 @@
1
+ <!DOCTYPE html>
2
+ <html xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+
6
+ <link href='http://fonts.googleapis.com/css?family=Ubuntu&v2' rel='stylesheet' type='text/css'>
7
+ <link href='http://fonts.googleapis.com/css?family=Droid+Sans+Mono&v2' rel='stylesheet' type='text/css'>
8
+ <style>
9
+ #container {
10
+ margin: 0 auto;
11
+ max-width: 920px;
12
+ background-color: #f8f8f8;
13
+ padding: .7em;
14
+ line-height: 25px;
15
+ font-size: 18px;
16
+ font-family: "Ubuntu", serif;
17
+ text-align: justify;
18
+ color: #282828;
19
+ border: 1px #E0E0E0 solid;
20
+ }
21
+
22
+ h1 { font-size: 42px; padding: 80px 0 20px; text-align: center; }
23
+ h2 { font-size: 32px; padding: 10px 0 80px; text-align: center; }
24
+ h3 { font-size: 24px; padding-top: 20px; border-top: 4px solid #E0E0E0; }
25
+ h4 { font-size: 18px; padding-top: 10px; }
26
+
27
+ code { font-size: 15px; line-height: 20px; font-family: "Droid Sans Mono", monospace; }
28
+ </style>
29
+
30
+ <title><%= title %></title>
31
+ </head>
32
+ <body>
33
+ <section id="container">
34
+ <header>
35
+ <h1><%= title %></h1>
36
+ <h2><%= Date.today.strftime "%d/%m/%Y" %></h2>
37
+ </header>
38
+ <article>
39
+ <%= content %>
40
+ </article>
41
+ </section>
42
+ </body>
43
+ </html>
@@ -1,4 +1,5 @@
1
1
  require "time"
2
+ require "date"
2
3
  require "rack/utils"
3
4
  require "rack/mime"
4
5
  require "goliath/api"
@@ -7,17 +8,26 @@ require "goliath/api"
7
8
  module GuideEmUp
8
9
  class Browser < Goliath::API
9
10
  def initialize(dir)
10
- @root = dir
11
+ @root = dir
12
+ @data = File.expand_path("../../../data", __FILE__)
13
+ @theme = Theme.new(File.join @data, "themes")
11
14
  end
12
15
 
13
16
  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? ".."
17
+ path_info = Rack::Utils.unescape(env["PATH_INFO"])
18
+ filename = File.join(@root, path_info)
19
+ datafile = File.join(@data, path_info)
20
+ if File.file?(filename)
21
+ serve_guide(filename)
22
+ elsif filename.include? ".."
18
23
  unauthorized_access
19
- elsif File.directory?(path_info)
20
- serve_index(path_info)
24
+ elsif File.directory?(filename)
25
+ serve_index(filename)
26
+ elsif path_info =~ /\/g-e-u\/theme\/(\w+)$/
27
+ @theme.current = $1
28
+ redirect_to env["HTTP_REFERER"] || "http://#{env["HTTP_HOST"]}/"
29
+ elsif path_info =~ /\/g-e-u\/(css|images|icons|js)\//
30
+ serve_data(datafile.sub 'g-e-u', '')
21
31
  else
22
32
  page_not_found(path_info)
23
33
  end
@@ -26,7 +36,7 @@ module GuideEmUp
26
36
  protected
27
37
 
28
38
  def serve_guide(filename)
29
- body = Guide.new(filename).html
39
+ body = Guide.new(filename, @theme.template).html
30
40
  [200, {
31
41
  "Content-Type" => "text/html; charset=utf-8",
32
42
  "Content-Length" => Rack::Utils.bytesize(body).to_s
@@ -34,10 +44,31 @@ module GuideEmUp
34
44
  end
35
45
 
36
46
  def serve_index(path_info)
37
- body = "TODO"
47
+ body = Index.new(@root, path_info, @data, @theme.all).html
38
48
  [200, {
49
+ "Content-Type" => "text/html; charset=utf-8",
39
50
  "Content-Length" => Rack::Utils.bytesize(body).to_s,
51
+ }, [body] ]
52
+ end
53
+
54
+ def serve_data(filename)
55
+ if File.exists?(filename)
56
+ body = File.read(filename)
57
+ [200, {
58
+ "Content-Type" => Rack::Mime.mime_type(File.extname filename),
59
+ "Content-Length" => Rack::Utils.bytesize(body).to_s,
60
+ }, [body] ]
61
+ else
62
+ page_not_found(filename)
63
+ end
64
+ end
65
+
66
+ def redirect_to(location)
67
+ body = "You are being redirected to #{location}"
68
+ [302, {
69
+ "Location" => location,
40
70
  "Content-Type" => "text/html; charset=utf-8",
71
+ "Content-Length" => Rack::Utils.bytesize(body).to_s
41
72
  }, [body] ]
42
73
  end
43
74
 
@@ -6,23 +6,23 @@ require "yajl"
6
6
 
7
7
 
8
8
  module GuideEmUp
9
- class Guide < Struct.new(:filename, :title)
10
- def initialize(filename)
11
- self.filename = self.title = filename
9
+ class Guide < Struct.new(:filename, :title, :template)
10
+ def initialize(filename, template)
11
+ self.filename = filename
12
+ self.title = File.basename(filename)
13
+ self.template = template
12
14
  @codemap = {}
13
15
  end
14
16
 
15
17
  def html
16
- file = File.expand_path("../../../themes/github.erb", __FILE__)
17
- tmpl = File.read(file)
18
+ tmpl = File.read(template)
18
19
  Erubis::Eruby.new(tmpl).result(to_hash)
19
20
  end
20
21
 
21
22
  protected
22
23
 
23
24
  def to_hash
24
- hsh = Hash[members.zip values].merge(:content => content)
25
- hsh
25
+ Hash[members.zip values].merge(:content => content)
26
26
  end
27
27
 
28
28
  def content
@@ -0,0 +1,48 @@
1
+ module GuideEmUp
2
+ class Index < Struct.new(:root, :current_dir, :data_dir, :themes)
3
+ FileEntry = Struct.new(:path, :name, :icon)
4
+
5
+ def html
6
+ file = File.join(data_dir, "/browser.erb")
7
+ tmpl = File.read(file)
8
+ Erubis::Eruby.new(tmpl).result(to_hash)
9
+ end
10
+
11
+ protected
12
+
13
+ def to_hash
14
+ { :themes => themes, :files => files, :dir => current_dir }
15
+ end
16
+
17
+ def files
18
+ results = Dir["#{current_dir}/*"].sort.map do |f|
19
+ path = f.sub(root, '').gsub('//', '/')
20
+ name = File.basename(f)
21
+ icon = File.directory?(f) ? "folder" : icon_for(name)
22
+ FileEntry.new(path, name, icon)
23
+ end
24
+ if current_dir != root + '/'
25
+ path = File.dirname(current_dir).sub(root, '/').gsub('//', '/')
26
+ results.unshift FileEntry.new(path, "..", "parent")
27
+ end
28
+ results
29
+ end
30
+
31
+ def icon_for(filename)
32
+ case filename
33
+ when /\.(css|less|sass|scss)$/ then "css"
34
+ when /\.(js|json)$/ then "js"
35
+ when /\.(bmp|gif|ico|png)$/ then "image"
36
+ when /\.html?$/ then "html"
37
+ when /\.rb$/ then "rb"
38
+ when /readme/i then "readme"
39
+ when /authors/i then "authors"
40
+ when /copying|license/i then "copying"
41
+ when /changelog/i then "log"
42
+ when /\.(md|mkd|markdown|txt)$/ then "text"
43
+ when /\.(gz|bz2|zip|rar|7z|xz)$/ then "archive"
44
+ else "unknown"
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,25 @@
1
+ module GuideEmUp
2
+ class Theme
3
+ ThemeEntry = Struct.new(:name, :current)
4
+
5
+ def initialize(dir)
6
+ @dir = dir
7
+ @templates = Dir["#{@dir}/*.erb"].sort
8
+ @template = @templates.first
9
+ end
10
+
11
+ attr_reader :template
12
+
13
+ def current=(tmpl)
14
+ filename = "#{@dir}/#{tmpl}.erb"
15
+ @template = filename if File.exists?(filename)
16
+ end
17
+
18
+ def all
19
+ @templates.map do |tmpl|
20
+ name = File.basename(tmpl, '.erb')
21
+ ThemeEntry.new(name, tmpl == template)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module GuideEmUp
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/guide-em-up.rb CHANGED
@@ -1,3 +1,5 @@
1
1
  require "guide-em-up/guide"
2
+ require "guide-em-up/index"
3
+ require "guide-em-up/theme"
2
4
  require "guide-em-up/browser"
3
5
  require "guide-em-up/version"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guide-em-up
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-09 00:00:00.000000000Z
12
+ date: 2011-08-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: goliath
16
- requirement: &75214320 !ruby/object:Gem::Requirement
16
+ requirement: &74069870 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.9'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *75214320
24
+ version_requirements: *74069870
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redcarpet
27
- requirement: &75213920 !ruby/object:Gem::Requirement
27
+ requirement: &74069400 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.17'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *75213920
35
+ version_requirements: *74069400
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: erubis
38
- requirement: &75213490 !ruby/object:Gem::Requirement
38
+ requirement: &74068770 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '2.7'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *75213490
46
+ version_requirements: *74068770
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: yajl-ruby
49
- requirement: &75213080 !ruby/object:Gem::Requirement
49
+ requirement: &74068390 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0.8'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *75213080
57
+ version_requirements: *74068390
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: albino
60
- requirement: &75212840 !ruby/object:Gem::Requirement
60
+ requirement: &74068030 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '1.3'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *75212840
68
+ version_requirements: *74068030
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: minitest
71
- requirement: &75212470 !ruby/object:Gem::Requirement
71
+ requirement: &74067710 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '2.3'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *75212470
79
+ version_requirements: *74067710
80
80
  description: Slide'em up is a tool for writing guides in markdown
81
81
  email: bruno.michel@af83.com
82
82
  executables:
@@ -92,8 +92,31 @@ files:
92
92
  - lib/guide-em-up.rb
93
93
  - lib/guide-em-up/guide.rb
94
94
  - lib/guide-em-up/browser.rb
95
+ - lib/guide-em-up/theme.rb
95
96
  - lib/guide-em-up/version.rb
96
- - themes/github.erb
97
+ - lib/guide-em-up/index.rb
98
+ - data/icons/authors.png
99
+ - data/icons/parent.png
100
+ - data/icons/html.png
101
+ - data/icons/text.png
102
+ - data/icons/js.png
103
+ - data/icons/image.png
104
+ - data/icons/archive.png
105
+ - data/icons/css.png
106
+ - data/icons/copying.png
107
+ - data/icons/rb.png
108
+ - data/icons/unknown.png
109
+ - data/icons/folder.png
110
+ - data/icons/log.png
111
+ - data/icons/readme.png
112
+ - data/css/browser.css
113
+ - data/images/h5ai-16x16.png
114
+ - data/images/tree.png
115
+ - data/images/home.png
116
+ - data/browser.erb
117
+ - data/themes/no_style.erb
118
+ - data/themes/pochtron.erb
119
+ - data/themes/github.erb
97
120
  homepage: http://github.com/nono/guide-em-up
98
121
  licenses: []
99
122
  post_install_message: