optionsful 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,9 +18,13 @@ module Baurets
18
18
  end
19
19
  end
20
20
  end
21
-
21
+
22
22
  private
23
23
 
24
+ require 'rubygems'
25
+ require 'yaml'
26
+ require 'RedCloth'
27
+
24
28
  def extract_documentation(env)
25
29
  path = env["PATH_INFO"]
26
30
  path = path.gsub(@config.base_path, '')
@@ -44,19 +48,38 @@ module Baurets
44
48
  file = File.join(RAILS_ROOT, "app", "controllers", controller_name + ".rb")
45
49
  controller_class = controller_name.camelize
46
50
 
47
- service_doc = extract_comments_above(file, find_line_for(file, controller_class, :class)).join("\n")
51
+ service_doc = extract_comments_above(file, find_line_for(file, controller_class, :class))
48
52
 
49
53
  methods_docs = []
50
54
  controller_actions.each do |info|
51
55
  methods_docs << [info, extract_comments_above(file, find_line_for(file, info[1], :method)).join("\n")]
52
56
  end
53
57
 
54
- body = "\n\nService: \n" + service_doc + "\n"
55
- methods_docs.each do |md|
56
- body += "\n\nMethod: #{md[0][0]} \n Action: #{md[0][1]} \n Metadata: \n #{md[1]}\n\n-- end ---\n"
57
- end
58
+ body = build_html(service_doc, methods_docs)
59
+
60
+ [200, {"Content-Type" => "text/html"}, body]
61
+ end
58
62
 
59
- [200, {}, "Under development!!! \n #{body}"]
63
+
64
+ def build_html(comment, methods)
65
+ comments = comment.join("\n").gsub(/^#+\s/, '')
66
+ resource = YAML::parse(comments)
67
+ html = "<html><head></head><body>"
68
+ resource_title = resource["resource"]["title"].value
69
+
70
+ title = "h1. " + resource_title.to_s if resource_title
71
+
72
+ html += RedCloth.new(title).to_html
73
+
74
+ html += RedCloth.new("#{resource["resource"]["description"].value}").to_html
75
+
76
+ methods.each do |meth|
77
+ meth_verb = meth[0][0]
78
+ #TODO
79
+ html += RedCloth.new("*" + meth_verb).to_html
80
+ end
81
+ html += "</body></html>"
82
+ html
60
83
  end
61
84
 
62
85
  def relate_action_to_method(path, verb)
@@ -100,7 +123,7 @@ module Baurets
100
123
  line_number = 0
101
124
  end
102
125
  end
103
- doc.reverse
126
+ doc = doc.reverse
104
127
  doc
105
128
  end
106
129
 
@@ -4,7 +4,7 @@ module Baurets
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 1
7
- TINY = 6
7
+ TINY = 7
8
8
 
9
9
  def self.to_s
10
10
  "#{MAJOR}.#{MINOR}.#{TINY}"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optionsful
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 6
10
- version: 0.1.6
9
+ - 7
10
+ version: 0.1.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marco Antonio Gonzalez Junior
@@ -17,8 +17,23 @@ cert_chain: []
17
17
 
18
18
  date: 2010-07-22 00:00:00 -03:00
19
19
  default_executable:
20
- dependencies: []
21
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: RedCloth
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 51
30
+ segments:
31
+ - 4
32
+ - 2
33
+ - 2
34
+ version: 4.2.2
35
+ type: :runtime
36
+ version_requirements: *id001
22
37
  description: Optionsful provide dynamic information via HTTP's OPTION method.
23
38
  email: kayaman@baurets.net
24
39
  executables: []