cdoc 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5f4b354e7e92871ae1929676d97e545ad8be1c4
4
- data.tar.gz: c9112088372b2abe90305b2e5f0dd90b04d7748c
3
+ metadata.gz: d820713e809296ad393075f97bc7c4f1b0765855
4
+ data.tar.gz: 4f62f92271bbe59df2ca5dcc0d04f5b9204c4e4b
5
5
  SHA512:
6
- metadata.gz: 4adfd8b396b11d9c29f5288ea27ad2187071406809e78041bd050d81f4ede494f38305a7b58dd58e68edec42b6c9b4239ceaca83328402024b7878945b277f72
7
- data.tar.gz: e4c3666b68e3ced0cc529db5eeaec74a37796c6d3a16245489884c2f925cfaa508ffd38c6f0e72fba4f2a42243fd05e9380aa73535666ced318559472cb3288b
6
+ metadata.gz: 861e8677bf2e5736dda1cfe3ad259855604a751406b95a2d2f1678f26a4db0b349b0cfb57a484ca68e4426982b040f968dffd1c77adeb2b46f2161c2596bd5ab
7
+ data.tar.gz: f9568d2ceb4f963ab377fe0b47d4125be4254bc0e18f0bfd5b7d60748d4cd00f5b58de305453ca37e18077b9501b48b7a4143736e4b3b0da163ac1511cd230c8
data/bin/cdoc CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "cdoc"
4
+ require_relative "../lib/cdoc"
5
5
 
6
6
  # Aims to generate documentaion for Rails controller
7
7
  # default target folder is app/controllers in a Rails application
@@ -6,6 +6,12 @@ require 'json'
6
6
 
7
7
  module Cdoc
8
8
 
9
+ module Helpers
10
+ def to_id(str)
11
+ str.gsub(/\W/, '').downcase
12
+ end
13
+ end
14
+
9
15
  class DocRenderer < Redcarpet::Render::HTML
10
16
  def block_code(code, lang='text')
11
17
  lang = lang && lang.split.first || "text"
@@ -14,22 +20,43 @@ module Cdoc
14
20
  end
15
21
 
16
22
  class DocString
23
+
24
+ include Helpers
25
+
17
26
  def initialize
18
27
  @docstring = ''
28
+ @content = []
19
29
  end
20
30
 
21
31
  def title(title)
22
32
  @title = title
23
- @docstring << "\n" + "# #{title}" + "\n"
24
33
  end
25
34
 
26
35
  def section(str)
27
- @docstring << "\n" + "## #{str}" + "\n"
36
+ template = "<p id='%{id}'><h3>%{str}</h3></p>"
37
+ @content << template % { id: to_id(str), str: str }
38
+ end
39
+
40
+ def sidebar(sidebar)
41
+ @sidebar = sidebar
28
42
  end
29
43
 
30
44
  def subsection(str)
31
- lines = str.split("\n")
45
+
46
+ template = %q(
47
+ <div class="panel panel-default" id="accounts">
48
+ <div class="panel-heading">
49
+ <h3 class="panel-title">%{section_header}</h3>
50
+ </div>
51
+ <div class="panel-body">
52
+ %{section_body}
53
+ </div>
54
+ </div>)
55
+
56
+ lines = str.split("\n")
32
57
  index = 0
58
+ section_header = ''
59
+ sub_section = []
33
60
 
34
61
  loop do
35
62
  line = lines[index]
@@ -51,38 +78,47 @@ module Cdoc
51
78
  begin
52
79
  json = JSON.parse(code_str)
53
80
  code_str = JSON.pretty_generate(json)
54
- block = ["\n", '```json', code_str, '```'].join("\n")
81
+ block = ['<pre><code>', code_str, '</code></pre>'].join('')
55
82
  rescue JSON::ParserError => e
56
- puts e.message
57
- block = ["\n", '```', code_str, '```'].join("\n")
83
+ # puts e.message
84
+ block = ['<pre><code>', code_str, '</code></pre>'].join("\n")
58
85
  end
59
86
 
60
87
  break
61
88
  else
62
- code_block << line.sub(' ', '')
89
+ code_block << line.sub(' ', '') unless line.strip.empty?
63
90
  index = index + 1
64
91
  end
65
92
  end
66
93
  else
67
- block = line
94
+ block = [line, '<br/>'].join('')
95
+ end
96
+
97
+ if index == 0
98
+ section_header = block
99
+ else
100
+ sub_section << block
68
101
  end
69
102
 
70
- @docstring << block
71
103
  index = index + 1
72
104
  end
73
105
 
74
- @docstring << "\n"
106
+ @content << template % { section_header: section_header, section_body: sub_section.join("\n")}
75
107
  end
76
108
 
77
109
  def tagged_line(line, tag)
110
+ if ['url', 'endpoint', 'api'].include?(tag.downcase)
111
+ # set the title of the section
112
+ end
113
+
78
114
  t = line.sub(tag, '').strip
79
- t_l = "\n" + tag.sub('@','').capitalize
115
+ t_l = ['<small>', tag.sub('@', '').capitalize, '</small>']
80
116
 
81
117
  if !t.empty?
82
- t_l = t_l + " **#{t.strip}**\n\n"
118
+ t_l = t_l + ['<strong>', t.strip, '</strong>']
83
119
  end
84
120
 
85
- t_l
121
+ ['<p>', t_l, '</p>'].flatten.join("\n")
86
122
  end
87
123
 
88
124
  def finish
@@ -97,13 +133,17 @@ module Cdoc
97
133
  f.close
98
134
  end
99
135
 
136
+ def content
137
+ @content.flatten.join('')
138
+ end
139
+
100
140
  def render_as_html
101
- layout_file = File.join(File.dirname(__FILE__), 'layouts/default.html')
141
+ layout_file = File.join(File.dirname(__FILE__), 'layouts/bootstrap.html')
102
142
  layout = File.read(layout_file)
103
143
  f = File.open('doc/index.html', 'w+')
104
144
  renderer = DocRenderer.new
105
145
  markdown = Redcarpet::Markdown.new(renderer, fenced_code_blocks: true)
106
- html = layout % { title: @title, content: markdown.render(@docstring)}
146
+ html = layout % { title: @title, sidebar: @sidebar, content: content }
107
147
  f.write(html)
108
148
  f.close
109
149
 
@@ -116,6 +156,8 @@ module Cdoc
116
156
 
117
157
  class CDoc
118
158
 
159
+ include Helpers
160
+
119
161
  attr_accessor :files, :docstring
120
162
 
121
163
  def initialize
@@ -124,10 +166,14 @@ module Cdoc
124
166
  @doc = DocString.new
125
167
  end
126
168
 
127
- def sidebar_section(headers)
128
- headers.each do |title|
129
- title.capitalize
169
+ def generate_sidebar(keys)
170
+ tmpl_item = '<a href="#%{id}" class="list-group-item">%{item}</a>'
171
+
172
+ items = keys.map do |key|
173
+ tmpl_item % { id: to_id(key), item: key.capitalize }
130
174
  end
175
+
176
+ ['<div class="list-group">', items, '</div>'].flatten.join("\n")
131
177
  end
132
178
 
133
179
  def generate
@@ -135,7 +181,9 @@ module Cdoc
135
181
 
136
182
  @file_groups = files.group_by { |f| File.basename(f, '_controller.rb') }
137
183
 
138
- @sidebar = sidebar_section(@file_groups.keys)
184
+ sidebar = generate_sidebar(@file_groups.keys)
185
+
186
+ @doc.sidebar(sidebar)
139
187
 
140
188
  @file_groups.each do |group, files|
141
189
  @doc.section(group.capitalize)
@@ -1,3 +1,3 @@
1
1
  module Cdoc
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -0,0 +1,62 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1">
7
+ <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
8
+ <title>%{title}</title>
9
+
10
+ <!-- Bootstrap -->
11
+ <!--<link href="/css/bootstrap.min.css" rel="stylesheet">-->
12
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
13
+ <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
14
+ <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
15
+ <!--[if lt IE 9]>
16
+ <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
17
+ <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
18
+ <![endif]-->
19
+ </head>
20
+ <body>
21
+ <nav class="navbar navbar-default">
22
+ <div class="container-fluid">
23
+ <!-- Brand and toggle get grouped for better mobile display -->
24
+ <div class="navbar-header">
25
+ <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
26
+ <span class="sr-only">Toggle navigation</span>
27
+ <span class="icon-bar"></span>
28
+ <span class="icon-bar"></span>
29
+ <span class="icon-bar"></span>
30
+ </button>
31
+ <a class="navbar-brand" href="#">Chillr</a>
32
+ </div>
33
+
34
+ <!-- Collect the nav links, forms, and other content for toggling -->
35
+ <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
36
+ <ul class="nav navbar-nav navbar-right">
37
+ <li class="dropdown">
38
+ <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">More<span class="caret"></span></a>
39
+ <ul class="dropdown-menu">
40
+ <li><a href="#">Action</a></li>
41
+ </ul>
42
+ </li>
43
+ </ul>
44
+ </div><!-- /.navbar-collapse -->
45
+ </div><!-- /.container-fluid -->
46
+ </nav>
47
+ <div class="container">
48
+ <div class="row">
49
+ <div class="col-md-3">
50
+ %{sidebar}
51
+ </div>
52
+ <div class="col-md-8">
53
+ %{content}
54
+ </div>
55
+ </div>
56
+ </div>
57
+ <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
58
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
59
+ <!-- Include all compiled plugins (below), or include individual files as needed -->
60
+ <script src="/js/bootstrap.min.js"></script>
61
+ </body>
62
+ </html>
@@ -13,4 +13,4 @@
13
13
  <body>
14
14
  %{content}
15
15
  </body>
16
- </html>
16
+ </html>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cdoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Deepak Kumar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-07 00:00:00.000000000 Z
11
+ date: 2017-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet
@@ -102,6 +102,7 @@ files:
102
102
  - cdoc.gemspec
103
103
  - lib/cdoc.rb
104
104
  - lib/cdoc/version.rb
105
+ - lib/layouts/bootstrap.html
105
106
  - lib/layouts/default.html
106
107
  - lib/styles/markdown4.css
107
108
  - lib/styles/pygments_github.css