raml_doc 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb509f65b7d5e684ddb654c634e5df1ed362cca9
4
- data.tar.gz: 74ae09b07265b376073210822400f525f57e9bad
3
+ metadata.gz: dc012ee4e6a0c7032553609f4354ce5a0a4274ed
4
+ data.tar.gz: 07ed2ad378f1c4bd4ff3e64790172956011f8251
5
5
  SHA512:
6
- metadata.gz: 39891942cccebdb7c4f237f45ba9bcf8a10ceac19b7dd272f15891247bb710f96186671910158b3a8c48225fde063df30a5f44ed25e6d6b91e670492d8b7e5bd
7
- data.tar.gz: 0c4e9d0972f31c8763bb54200647727fafe540150201e93b69a62308c9967a61d9d2e20221904797754cd905dd11b8a66ca5f606b5bb131da8093cc659a24313
6
+ metadata.gz: 0ffa2e35a55fc56ae093947a964b2545003ce1101ec8fb3f80257d4b3ef8da3b405b2baca4fc7cf8da9527791ed51596a0c4a75fe9c2f57066332733d01fd6f5
7
+ data.tar.gz: d9f3282c09f2862bda6b13626946e4205b33fa56da766e306ef006d66caa6c147e8e5a790080e3818e35275a16408032defeebbe35e41c96666c50df0e485aeb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- raml_doc (0.1.0)
4
+ raml_doc (0.0.1)
5
5
  kramdown (= 1.11.1)
6
6
  raml_ruby (= 0.1.2)
7
7
 
data/README.md CHANGED
@@ -1,41 +1,19 @@
1
1
  # RamlDoc
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/raml_doc`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Generate API documentation from RAML files.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ ## Install
6
6
 
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'raml_doc'
7
+ ```sh
8
+ gem install raml_doc
13
9
  ```
14
10
 
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install raml_doc
22
-
23
11
  ## Usage
24
12
 
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/raml_doc.
36
-
37
-
38
- ## License
39
-
40
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
13
+ ```sh
14
+ raml-doc --help
15
+ ```
41
16
 
17
+ ```sh
18
+ raml-doc -s /path/to/api.raml -t default -f html > /path/to/api.html
19
+ ```
data/bin/raml-doc ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "optparse"
4
+ require "bundler/setup"
5
+ require "raml_doc"
6
+
7
+ options = {
8
+ :template => "default",
9
+ :format => "html"
10
+ }
11
+
12
+ option_parser = OptionParser.new do |opts|
13
+ opts.banner = "Usage: ramldoc [options]"
14
+
15
+ opts.on("-v", "--version", "The source RAML file") do |value|
16
+ if value
17
+ puts "RamlDoc #{RamlDoc::VERSION}"
18
+ exit 0
19
+ end
20
+ end
21
+
22
+ opts.on("-s", "--source-file FILE", "The source RAML file") do |value|
23
+ options[:source_file] = value
24
+ end
25
+
26
+ opts.on("-t", "--template [default]", "The output template to use") do |value|
27
+ options[:template] = value
28
+ end
29
+
30
+ opts.on("-f", "--format [html]", "The output file format") do |value|
31
+ options[:template] = value
32
+ end
33
+ end
34
+
35
+ option_parser.parse!
36
+
37
+ source_file = options[:source_file]
38
+ template = options[:template]
39
+ format = options[:format]
40
+
41
+ puts RamlDoc.generate(source_file, template, format)
@@ -35,41 +35,47 @@
35
35
  <div>
36
36
  <ul class="nav nav-tabs" role="tablist">
37
37
  <li role="presentation" class="active">
38
- <a href="#description-<%= resource.resource_path_name %>" aria-controls="home" role="tab" data-toggle="tab">
38
+ <a href="#<%= method_element_id method, "description" %>" aria-controls="home" role="tab" data-toggle="tab">
39
39
  <i class="fa fa-info-circle" aria-hidden="true"></i>
40
40
  Description
41
41
  </a>
42
42
  </li>
43
- <li role="presentation">
44
- <a href="#headers-<%= resource.resource_path_name %>" aria-controls="home" role="tab" data-toggle="tab">
45
- <i class="fa fa-code" aria-hidden="true"></i>
46
- Headers
47
- </a>
48
- </li>
49
- <li role="presentation">
50
- <a href="#querystring-parameters<%= resource.resource_path_name %>" aria-controls="profile" role="tab" data-toggle="tab">
51
- <i class="fa fa-code" aria-hidden="true"></i>
52
- Querystring Parameters
53
- </a>
54
- </li>
55
- <li role="presentation">
56
- <a href="#responses-<%= resource.resource_path_name %>" aria-controls="home" role="tab" data-toggle="tab">
57
- <i class="fa fa-code" aria-hidden="true"></i>
58
- Responses
59
- </a>
60
- </li>
43
+ <% if present? method.headers %>
44
+ <li role="presentation">
45
+ <a href="#<%= method_element_id method, "request-headers" %>" aria-controls="home" role="tab" data-toggle="tab">
46
+ <i class="fa fa-code" aria-hidden="true"></i>
47
+ Request Headers
48
+ </a>
49
+ </li>
50
+ <% end %>
51
+ <% if present? method.query_parameters %>
52
+ <li role="presentation">
53
+ <a href="#<%= method_element_id method, "querystring-parameters" %>" aria-controls="profile" role="tab" data-toggle="tab">
54
+ <i class="fa fa-code" aria-hidden="true"></i>
55
+ Querystring Parameters
56
+ </a>
57
+ </li>
58
+ <% end %>
59
+ <% if present? method.responses %>
60
+ <li role="presentation">
61
+ <a href="#<%= method_element_id method, "responses" %>" aria-controls="home" role="tab" data-toggle="tab">
62
+ <i class="fa fa-code" aria-hidden="true"></i>
63
+ Responses
64
+ </a>
65
+ </li>
66
+ <% end %>
61
67
  </ul>
62
68
 
63
69
  <div class="tab-content">
64
- <div role="tabpanel" class="tab-pane active" id="description-<%= resource.resource_path_name %>">
70
+ <div role="tabpanel" class="tab-pane active" id="<%= method_element_id method, "description" %>">
65
71
  <p class="lead">
66
72
  <%= markdown method.description %>
67
73
  </p>
68
74
  </div>
69
- <div role="tabpanel" class="tab-pane" id="headers-<%= resource.resource_path_name %>">
75
+ <div role="tabpanel" class="tab-pane" id="<%= method_element_id method, "request-headers" %>">
70
76
  <p>...</p>
71
77
  </div>
72
- <div role="tabpanel" class="tab-pane" id="querystring-parameters<%= resource.resource_path_name %>">
78
+ <div role="tabpanel" class="tab-pane" id="<%= method_element_id method, "querystring-parameters" %>">
73
79
  <p>
74
80
  <ul>
75
81
  <% method.query_parameters.each do |_, parameter| %>
@@ -84,7 +90,7 @@
84
90
  </ul>
85
91
  </p>
86
92
  </div>
87
- <div role="tabpanel" class="tab-pane" id="responses-<%= resource.resource_path_name %>">
93
+ <div role="tabpanel" class="tab-pane" id="<%= method_element_id method, "responses" %>">
88
94
  <p>...</p>
89
95
  </div>
90
96
  </div>
@@ -95,6 +101,18 @@
95
101
  <% end %>
96
102
  </div>
97
103
 
104
+ <footer class="footer">
105
+ <div class="container">
106
+ <hr>
107
+ <p class="pull-right text-muted">
108
+ Created with
109
+ <a href="http://raml.org/">RAML&#8482;</a>
110
+ /
111
+ <a href="https://github.com/hopsoft/raml_doc">RAML Doc</a>
112
+ </p>
113
+ </div>
114
+ </footer>
115
+
98
116
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
99
117
  <style type="text/css" rel="stylesheet">
100
118
  @import url(https://fonts.googleapis.com/css?family=Raleway:600|Merriweather);
@@ -1,3 +1,3 @@
1
1
  module RamlDoc
2
- VERSION = "0.0.0"
2
+ VERSION = "0.0.1"
3
3
  end
data/lib/raml_doc/view.rb CHANGED
@@ -9,14 +9,25 @@ module RamlDoc
9
9
  @raml = raml
10
10
  end
11
11
 
12
- def render(template)
13
- template_path = File.join(File.expand_path("../templates", __FILE__), "#{template}.html.erb")
12
+ def render(template, format)
13
+ template_path = File.join(File.expand_path("../templates", __FILE__), format, template, "index.#{format}.erb")
14
14
  template = ERB.new(File.read(template_path))
15
15
  template.result binding
16
16
  end
17
17
 
18
+ def present?(value)
19
+ return !value.empty? if value.respond_to?(:empty?)
20
+ !!value
21
+ end
22
+
18
23
  def markdown(string)
19
24
  Kramdown::Document.new(string).to_html
20
25
  end
26
+
27
+ def method_element_id(method, *args)
28
+ args << method.name
29
+ args << method.parent.resource_path_name
30
+ args.compact.join "-"
31
+ end
21
32
  end
22
33
  end
data/lib/raml_doc.rb CHANGED
@@ -4,9 +4,9 @@ require "raml_doc/version"
4
4
  require "raml_doc/view"
5
5
 
6
6
  module RamlDoc
7
- def self.generate(file_path, template)
7
+ def self.generate(file_path, template, format)
8
8
  raml = Raml.parse_file(file_path)
9
9
  view = View.new(raml)
10
- view.render template
10
+ view.render template, format
11
11
  end
12
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raml_doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
@@ -83,7 +83,8 @@ dependencies:
83
83
  description:
84
84
  email:
85
85
  - natehop@gmail.com
86
- executables: []
86
+ executables:
87
+ - raml-doc
87
88
  extensions: []
88
89
  extra_rdoc_files: []
89
90
  files:
@@ -93,11 +94,11 @@ files:
93
94
  - README.md
94
95
  - Rakefile
95
96
  - bin/console
96
- - bin/ramldoc
97
+ - bin/raml-doc
97
98
  - bin/setup
98
99
  - lib/raml_doc.rb
99
100
  - lib/raml_doc/raml_helper.rb
100
- - lib/raml_doc/templates/default.html.erb
101
+ - lib/raml_doc/templates/html/default/index.html.erb
101
102
  - lib/raml_doc/version.rb
102
103
  - lib/raml_doc/view.rb
103
104
  homepage: https://github.com/hopsoft/raml_doc
data/bin/ramldoc DELETED
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "optparse"
4
- require "bundler/setup"
5
- require "raml_doc"
6
-
7
- options = {
8
- :template => "default"
9
- }
10
-
11
- option_parser = OptionParser.new do |opts|
12
- opts.banner = "Usage: ramldoc [options]"
13
-
14
- opts.on("-f", "--file FILE", "The RAML file used to generate docs") do |f|
15
- options[:file] = f
16
- end
17
-
18
- opts.on("-t", "--template [default]", "The template used to generate docs") do |t|
19
- options[:template] = t
20
- end
21
- end
22
-
23
- option_parser.parse!
24
-
25
- puts RamlDoc.generate(options[:file], options[:template])
26
-