sinatra-croon 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,39 +3,58 @@
3
3
  %html
4
4
 
5
5
  %head
6
- %title API Documentation
7
- %link{ :rel => "stylesheet", :href => "docs.css" }
6
+ %title
7
+ API Documentation ::
8
+ = current_section || "General"
9
+
10
+ %link{ :rel => "stylesheet", :href => "#{documentation_base_uri}/docs.css" }
8
11
 
9
12
  %body
10
13
 
14
+ %h1
15
+ %a{ :href => "#{documentation_base_uri}/docs" } API Documentation
16
+
17
+ %ul#sidebar
18
+ - docs.keys.sort_by { |k| k.to_s }.each do |section|
19
+ %li
20
+ %a{ :href => "#{documentation_base_uri}/docs/#{urlify_section(section)}"}
21
+ = section || "General"
22
+ %ul.section
23
+ - docs[section].each do |doc|
24
+ %li
25
+ = doc[:verb].upcase
26
+ = doc[:uri]
27
+
11
28
  #content
12
29
 
13
- %h1
14
- %a{ :href => '/' } API Documentation
30
+ %h2
31
+ = current_section || "General"
32
+
33
+ - docs[current_section].each do |doc|
15
34
 
16
- - docs.each do |doc|
35
+ #doc
17
36
 
18
- .api
37
+ .api
19
38
 
20
- .url
21
- %a
22
- = doc[:verb].upcase
23
- = doc[:uri]
39
+ .url
40
+ %a
41
+ = doc[:verb].upcase
42
+ = doc[:uri]
24
43
 
25
- .description
26
- = doc[:description]
44
+ .description
45
+ = doc[:description]
27
46
 
28
- - if (doc[:params] || []).length > 0
29
- .params
30
- - doc[:params].each do |param|
31
- .param
32
- .type{ :class => (param[:required] && "required") }
33
- = (param[:required]) ? "REQUIRED" : "OPTIONAL"
34
- .name= escape_html(param[:name])
35
- .description= param[:description]
47
+ - if (doc[:params] || []).length > 0
48
+ .params
49
+ - doc[:params].each do |param|
50
+ .param
51
+ .type{ :class => (param[:required] && "required") }
52
+ = (param[:required]) ? "REQUIRED" : "OPTIONAL"
53
+ .name= escape_html(param[:name])
54
+ .description= param[:description]
36
55
 
37
- %code.request
38
- = display_code doc[:request]
56
+ %code.request
57
+ = display_code doc[:request]
39
58
 
40
- %code.response
41
- = display_code doc[:response]
59
+ %code.response
60
+ = display_code doc[:response]
@@ -12,15 +12,43 @@
12
12
  :margin-top -12px
13
13
  :margin-bottom 12px
14
14
 
15
- h2
16
- :background #555
17
- :color #fff
18
- :border 1px #666 solid
19
- :padding 10px
15
+ h1
16
+ :background #ccc
17
+ :width 100%
18
+ :margin 0
19
+ :padding 10px 20px
20
20
  a
21
- :color #fff
21
+ :color #000
22
22
  :text-decoration none
23
23
 
24
+ h2
25
+ :margin 0
26
+ :margin-bottom 20px
27
+ :padding 0
28
+
29
+ ul
30
+ :margin 0
31
+ :padding 0
32
+
33
+ ul#sidebar
34
+ :float left
35
+ :border-right 1px #ccc solid
36
+ :padding-top 10px
37
+ & > li
38
+ :margin 0
39
+ :padding 10px 20px
40
+ :list-style-type none
41
+ :font-weight bold
42
+ a
43
+ :text-decoration none
44
+ ul
45
+ :margin-top 10px
46
+ li
47
+ :list-style-type none
48
+ :padding 6px 10px
49
+ :font-size 0.9em
50
+ :font-family Courier, monospace
51
+
24
52
  .api
25
53
  :margin-bottom 24px
26
54
  :background #eee
@@ -28,10 +56,10 @@ h2
28
56
 
29
57
  .url
30
58
  :padding 6px 10px
31
- :background #aaa
59
+ :background #333
32
60
  :border-bottom 1px #ccc solid
33
61
  a
34
- :color #333
62
+ :color #fff
35
63
  :font-size 1.6em
36
64
  :font-weight bold
37
65
  :font-family monospace
@@ -40,7 +68,7 @@ h2
40
68
  :padding 12px
41
69
 
42
70
  code
43
- :font-family Monaco, monospace
71
+ :font-family Courier, monospace
44
72
  :white-space pre
45
73
  :padding 12px
46
74
  :display block
@@ -73,20 +101,25 @@ h2
73
101
  .request
74
102
  &:before
75
103
  +code_title
76
- :content "Request"
104
+ :content "Example Request"
105
+ :font-family Helvetica, Arial, sans-serif
77
106
 
78
107
  .response
79
108
  &:before
80
109
  +code_title
81
- :content "Response"
110
+ :content "Example Response"
111
+ :font-family Helvetica, Arial, sans-serif
82
112
 
83
113
  body
84
114
  :margin 0
85
115
 
86
116
  #content
87
- :width 800px
88
- :margin-left auto
89
- :margin-right auto
117
+ :float left
118
+ :min-width 800px
119
+ :padding 20px
120
+ :margin-left -1px
121
+ :border-left 1px #ccc solid
122
+ :padding-bottom 0
90
123
 
91
124
  #index
92
125
  .section
data/lib/sinatra/croon.rb CHANGED
@@ -3,7 +3,7 @@ require "sinatra/base"
3
3
 
4
4
  module Sinatra
5
5
  module Croon
6
- VERSION = "0.1.1"
6
+ VERSION = "0.2.0"
7
7
 
8
8
  def self.registered(app)
9
9
  app.helpers Croon::Helpers
@@ -17,10 +17,14 @@ module Sinatra
17
17
  end
18
18
  end
19
19
 
20
- app.get '/docs' do
20
+ app.get %r{^/docs/?([\w]+)?/?$} do |section|
21
21
  pass do
22
22
  template = File.read(File.expand_path("../croon/views/docs.haml", __FILE__))
23
- haml template, :locals => { :docs => documentation }
23
+ sections = documentation.map { |doc| doc[:section] }.sort_by { |s| s.to_s }
24
+ haml template, :locals => {
25
+ :docs => documentation.group_by { |doc| doc[:section] },
26
+ :current_section => sections.detect { |s| urlify_section(s) == section }
27
+ }
24
28
  end
25
29
  end
26
30
  end
@@ -51,6 +55,14 @@ module Sinatra
51
55
  def documentation
52
56
  self.class.documentation
53
57
  end
58
+
59
+ def documentation_base_uri
60
+ env["REQUEST_PATH"].gsub(/#{env["PATH_INFO"]}\/?$/, '')
61
+ end
62
+
63
+ def urlify_section(section)
64
+ section.to_s.downcase.gsub(' ', '_')
65
+ end
54
66
  end
55
67
 
56
68
  module Parser
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-croon
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Dollar
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-27 00:00:00 -04:00
18
+ date: 2010-08-02 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency