docme 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/docme +66 -1
  3. data/lib/docme.rb +38 -68
  4. data/lib/docme/utils.rb +155 -65
  5. metadata +7 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c08c7f2e03e5e79f4b1099a3beabda310493fee5
4
- data.tar.gz: 03037b1517f00c9c4df2aea2f37b66773c551fb8
3
+ metadata.gz: 09a5b6fd5fd9781268bc673895ca0782893e05db
4
+ data.tar.gz: 0741976b799c2d6ee3eabe81884d54b48bdbee4f
5
5
  SHA512:
6
- metadata.gz: 4d248f6673207bf1b75df821e680f92ad68c76d582c7b365038d96998610b5b6c08df58ca422457996c3075a31048adb77eb4a525468e8a5436f356f3bc4f6a9
7
- data.tar.gz: 602b2d61358c17515652ba11218f8e3c37d159ca59e4dbe703c1f9e71e68d6b180c1efe5f12e5d9eb50362de705e58af91a65c1d09bf44088ea317f39faa1969
6
+ metadata.gz: 9de4cccc8755ac221de6c7901518a20fffff998879049accb1ce4a06be3755d1786796cb7f40822e233acc05a0a23c1f3a01c41ee0ee2366ed98cb2815ab5075
7
+ data.tar.gz: 9c11b04a5e3d8f979f2174e55153f51568c0aefbcb4e74ff792581605b327b8a4fd46230790bb053603f8f1e315c101b1d5e23a8ba5e2048039358e33edeb35b
data/bin/docme CHANGED
@@ -1,4 +1,69 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'docme'
4
- puts Docme.jsParse(ARGV[0])
4
+ require 'docme/utils'
5
+ require 'fileutils'
6
+
7
+ files = Array.new
8
+ path = ARGV[0]
9
+
10
+
11
+ puts "\n ***Begining docme magix***"
12
+
13
+ #create the directory where the site will be stored
14
+ if !File::directory?("docme_site")
15
+ puts "+Setting up docme's living arrangements."
16
+ Dir.mkdir("docme_site")
17
+ puts "Woohoo! docme has a home!"
18
+ end
19
+
20
+ #if a directory was provided
21
+ if File.directory?(path)
22
+ #foreach file in the path specified
23
+ Dir.foreach(path) do |file|
24
+ next if file == '.' || file == '..'
25
+
26
+ next if file.rindex('.', 0)
27
+
28
+ if File.directory?(path+"/"+file)
29
+ Dir.foreach(path + "/"+ file) do |f|
30
+ next if f == '.' || f == '..'
31
+
32
+ next if f.rindex('.', 0)
33
+
34
+ next if File.directory?(path+"/"+f)
35
+
36
+ page = Docme.jsParse(path+"/"+file+"/"+f)
37
+
38
+ #add page to docme dir
39
+ if page != nil
40
+ FileUtils.mv(page, "docme_site/"+page)
41
+ files.push(page)
42
+ end
43
+
44
+ end
45
+ else
46
+ page = Docme.jsParse(path+"/"+file)
47
+
48
+ if page != nil
49
+ FileUtils.mv(page, "docme_site/"+page)
50
+ files.push(page)
51
+ end
52
+ end
53
+
54
+ end
55
+ else #if a single file was provided
56
+ page = Docme.jsParse(path)
57
+ FileUtils.mv(page, "docme_site/"+page)
58
+ files.push(page)
59
+ end
60
+
61
+ renderIndex(files)
62
+
63
+ #add page to docme dir
64
+ FileUtils.mv("index.html", "docme_site/index.html")
65
+
66
+ puts "\nFiles generated by docme:"
67
+ puts files
68
+ puts "\n ***Finished docme magic!***"
69
+ puts "\n You can find your docs inside the `docme_site` folder. \n Hint: look for index.html\n\n"
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'docme/utils'
4
4
  require 'erb'
5
+ require 'fileutils'
5
6
 
6
7
  class Docme
7
8
 
@@ -13,41 +14,30 @@ class Docme
13
14
  raise "Please provide a path to the file you wish to docme."
14
15
  end
15
16
 
16
- puts "\n ***Begining docme magix***"
17
-
18
- #create the directory where the site will be stored
19
- if !File::directory?("docme_site")
20
- puts "+Setting up docme's living arrangements."
21
- Dir.mkdir("docme_site")
22
- end
23
-
24
- puts "Woohoo! docme has a home!"
25
-
26
-
27
17
  #GLOBALS
28
18
  sourceFile = File.open(file).read
29
- docmeDir = "docme"
19
+ file = cleanFilename(file)
30
20
  items = Hash.new
31
21
  collective = Array.new
32
22
  block_content = Hash.new
33
23
  block_attr = nil
34
24
  block_flag = 0
35
- code_flag = 0
36
- code = ""
25
+ multi_line = ""
37
26
 
38
27
 
39
28
  #PARSING
40
29
  sourceFile.each_line do |line|
41
- #strip leading whitespaces
42
- line = line.lstrip
30
+
31
+ stripLine = line.lstrip
32
+
43
33
 
44
34
  #if this is the begining of a comment block then start a new function doc
45
- if line.rindex("/*", 1) == 0
35
+ if stripLine.rindex("/*", 1) == 0
46
36
  next
47
37
  end
48
38
 
49
39
  #if this is the end of a comment block then there is nothing to do
50
- if line.rindex("*/", 1) == 0
40
+ if stripLine.rindex("*/", 1) == 0
51
41
  #end the function section of the erb file
52
42
  collective.push(items)
53
43
  items = Hash.new
@@ -55,19 +45,19 @@ class Docme
55
45
  end
56
46
 
57
47
  #if line begins with '+' then we are defining an attribute
58
- if line.rindex("+",0) == 0
59
- parts = line.split(":")
48
+ if stripLine.rindex("+",0) == 0
49
+ parts = stripLine.split(":")
60
50
 
61
51
  #parts[0] == the attribute name
62
52
  attribute = cleanAttribute(parts[0])
53
+ attribute = attribute.upcase
63
54
 
64
- content = parts[1].lstrip
55
+ content = cleanContent(parts[1])
65
56
 
66
- #if the content begins with '{' then we have a block
67
- if content.rindex("{",0) == 0
57
+ #if the content begins with '{' then we have a regular block
58
+ if content.rindex("{{",0) == 0
68
59
  #go to the next line and look for '-', set block flag
69
60
  #add the attribute to the doc
70
- puts attribute
71
61
  block_flag = 1
72
62
  block_attr = attribute
73
63
  next
@@ -75,77 +65,57 @@ class Docme
75
65
 
76
66
  #add content to the doc
77
67
  items.store(attribute, content)
78
- puts attribute
79
- puts content
68
+ next
80
69
  end
81
70
 
82
- #if line begins with a '-' then we are in a block
83
- if line.rindex("-",0) == 0
84
- parts = line.split(":")
71
+ #if line begins with a '-' then we are in a block, if we are in a block but there are no sub attributes then do a multi-line
72
+ if stripLine.rindex("-",0) == 0
73
+ parts = stripLine.split(":")
85
74
 
86
75
  #parts[0] == the attribute name
87
76
  attribute = cleanAttribute(parts[0])
77
+ attribute = attribute.upcase
88
78
 
89
- content = parts[1].lstrip
90
-
91
- if attribute == "var"
92
- # look for arrow
93
- content_parts = content.split("->")
94
- var_name = content_parts[0]
95
- var_description = content_parts[1].lstrip
96
-
97
- #put the var_name in the doc
98
- #put the var_description in the doc
99
- puts var_name
100
- puts var_description
101
- block_content.store(var_name, var_description)
102
- next
103
- end
104
-
105
- if attribute == "code"
106
- code_flag = 1
107
- #go ahead and skip to next line and process code
108
- next
109
- end
79
+ content = cleanContent(parts[1])
110
80
 
111
81
  #if !var and !code, then process as regular attributes
112
82
  #put the attribute name
113
83
  #put the content
114
- puts attribute
115
- puts content
116
84
  block_content.store(attribute, content)
117
85
  next
118
86
  end
119
87
 
120
- #if code flag is set and we reached the end of a block, then we reached the end of a code block, unset the flag
121
- if code_flag == 1 && line.rindex("}",0) == 0
122
- items.store(block_attr, code)
123
- block_attr = nil
124
- code = ""
125
- code_flag = 0
88
+ if block_flag == 1 && stripLine.rindex("}}",0) != 0
89
+ line = cleanCode(line)
90
+ multi_line.concat(line)
126
91
  next
127
92
  end
128
93
 
129
94
  #if the block flag is set and we reach the end of a block, then we reached the end of a regular block, unset flag
130
- if block_flag == 1 && line.rindex("}",0) == 0
95
+ if block_flag == 1 && stripLine.rindex("}}",0) == 0
131
96
  block_flag = 0
132
- items.store(block_attr, block_content)
97
+
98
+ if multi_line.length > 0
99
+ items.store(block_attr, multi_line)
100
+ else
101
+ items.store(block_attr, block_content)
102
+ end
103
+
104
+ multi_line = ""
133
105
  block_attr = nil
134
106
  block_content = Hash.new
135
107
  next
136
108
  end
137
109
 
138
- #if we are in a code block, then return lines as is
139
- if code_flag == 1
140
- puts line
141
- code.concat(line)
142
- next
143
- end
144
-
110
+ end
145
111
 
112
+ #RENDER SITE
113
+ if collective.length > 0
114
+ page = renderSite(file,collective)
115
+ return page
146
116
  end
147
117
 
148
- renderSite(collective)
118
+ return nil
149
119
 
150
120
  end
151
121
  end
@@ -1,99 +1,185 @@
1
1
  #docme utils
2
2
 
3
- template = '<!DOCTYPE html>
4
- <html>
5
3
 
6
- <head>
7
- <meta name="viewport" content="width=device-width, initial-scale=1">
8
- </head>
9
4
 
10
- <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet" media="screen">
5
+ def cleanAttribute(attr)
6
+ attr = attr.delete("+[")
7
+ attr = attr.delete("]")
8
+ attr = attr.delete("-")
9
+ return attr
10
+ end
11
11
 
12
+ def cleanCode(line)
13
+ line.gsub!("<", "&lt;")
14
+ line.gsub!(">", "&gt;")
12
15
 
13
- <body>
16
+ return line
17
+ end
14
18
 
15
- <% for borg in collective %>
16
- <div class="panel panel-default">
17
- <% for attribute in borg %>
18
- <% if attribute[0] == "title" %>
19
- <div class="panel-heading">
20
- <h3 class="panel-title"><% attribute[1] %></h3>
21
- </div>
22
- <% end %>
23
- <div class="panel-body">
24
- Panel Content
25
- </div>
26
- </div>
19
+ def cleanContent(line)
20
+ line = line.lstrip
21
+ line.chop!
22
+ return line
23
+ end
27
24
 
28
- <% end %>
29
- <% end %>
25
+ def cleanFilename(file)
26
+ file = File.basename(file)
27
+ file = file.split(".")
28
+ file = file[0]
29
+ return file
30
+ end
30
31
 
31
- <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
32
- </body>
32
+ def renderIndex(pages)
33
+ #puts pages
33
34
 
34
- </html>'
35
+ @pages = pages
36
+
37
+ template = '<!DOCTYPE html>
38
+ <html>
39
+
40
+ <style type="text/css">
41
+ #wrapper{
42
+ width: 70%;
43
+ padding-left: 30%;
44
+ font-size:2em;
45
+ }
46
+ </style>
47
+
48
+ <link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet" media="screen">
49
+
50
+ <body>
51
+ <div id="wrapper">
52
+ <div class="list-group">
53
+ <% for @page in @pages %>
54
+
55
+ <% @name = cleanFilename(@page) %>
56
+ <a href="<%= @page %>" class="list-group-item list-group-item-info"><%= @name %></a>
57
+
58
+ <% end %>
59
+ </div>
60
+ </div>
61
+ </body>
62
+
63
+ </html>'
64
+
65
+ renderer = ERB.new(template)
66
+
67
+ File.open("index.html", "w+") do |f|
68
+ f.write(renderer.result(binding))
69
+ end
70
+
71
+ return "index.html"
35
72
 
36
- def cleanAttribute(attr)
37
- attr = attr.delete("+[")
38
- attr = attr.delete("]")
39
- attr = attr.delete("-")
40
- return attr
41
73
  end
42
74
 
43
- def renderSite(content)
75
+ def renderSite(file, content)
44
76
 
45
77
  @collective = content
78
+ @filename = file
46
79
 
47
- puts content
80
+ #puts content
48
81
 
49
82
  template = '<!DOCTYPE html>
50
83
  <html>
51
84
 
52
85
  <head>
53
86
  <meta name="viewport" content="width=device-width, initial-scale=1">
87
+
88
+ <style type="text/css">
89
+ body{
90
+ }
91
+ #panels-wrapper{
92
+ width: 80%;
93
+ float: left;
94
+ padding-left: 10%;
95
+ }
96
+ #side-panel{
97
+ width: 10%;
98
+ float: left;
99
+ padding-left: 10px;
100
+ }
101
+ pre-scrollable{
102
+ overflow-x: scroll;
103
+ white-space: nowrap;
104
+ }
105
+
106
+ p.code{
107
+ border:1px solid #000000;
108
+ overflow-x:scroll;
109
+ white-space: pre;
110
+ font-family:monospace,monospace;
111
+ font-size:1em;
112
+ background-color:#f5f5f5;
113
+ padding:2em;
114
+ }
115
+
116
+ </style>
54
117
  </head>
55
118
 
56
119
  <link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet" media="screen">
57
120
 
58
121
 
59
122
  <body>
60
-
61
- <% for @borg in @collective %>
62
- <div class="panel panel-primary">
63
- <% for @attribute in @borg %>
64
- <% if @attribute[0] == "title" %>
65
- <div class="panel-heading">
66
- <h2 class="panel-title"><%= @attribute[1] %></h2>
67
- </div>
68
- <div class="panel-body">
69
- <% end %>
70
- <% if @attribute[0] != "title"%>
71
- <% if @attribute[1].class == Hash %>
72
- <h4><%= @attribute[0] %></h4>
73
- <table class="table">
74
- <% for @item in @attribute[1]%>
75
- <tr>
76
- <th><%= @item[0] %></th>
77
- <td><%= @item[1] %></td>
78
- </tr>
79
- <% end %>
80
- </table>
81
- <% end %>
82
- <% if @attribute[0] == "example" %>
83
- <h4><%= @attribute[0] %></h4>
84
- <div class ="well">
85
- <pre><code><%= @attribute[1] %></code></pre>
86
- </div>
123
+ <nav class="navbar navbar-default navbar-static-top" role="navigation">
124
+ <div class="container">
125
+ <div class="collapse navbar-collapse">
126
+ <ul class="nav navbar-nav">
127
+ <li><a class="navbar-brand" href="#"><%= @filename%></a></li>
128
+ </ul>
129
+ </div>
130
+ </div>
131
+ </nav>
132
+ <div id="side-panel" class="panel panel-default">
133
+ <a href="index.html" class="list-group-item list-group-item-info">INDEX</a>
134
+ </div>
135
+ <div id="panels-wrapper">
136
+ <% for @borg in @collective %>
137
+ <div class="panel panel-primary">
138
+ <% for @attribute in @borg %>
139
+ <% if @attribute[0] == "TITLE" %>
140
+ <div class="panel-heading" id="<%= @attribute[1]%>">
141
+ <h2 class="panel-title"><%= @attribute[1] %></h2>
142
+ </div>
143
+ <div class="panel-body">
87
144
  <% end %>
88
- <% if @attribute[0] != "example" && @attribute[0] != "title" && @attribute[1].class != Hash%>
89
- <h4><%= @attribute[0]%></h4>
90
- <p><%= @attribute[1] %></p>
145
+ <% if @attribute[0] == "CODE" %>
146
+ <h4>CODE</h4>
147
+ <p class="code"><%= @attribute[1] %></p>
91
148
  <% end %>
92
- <% end %>
93
- <% end %>
149
+ <% if @attribute[0] != "TITLE" && @attribute[0] != "CODE" %>
150
+ <% if @attribute[1].class == Hash %>
151
+ <% if @attribute[0] == "ANCHOR" %>
152
+ <h4><%= @attribute[0] %></h4>
153
+ <table class="table">
154
+ <% for @item in @attribute[1]%>
155
+ <tr>
156
+ <th><%= @item[0] %></th>
157
+ <td><a href="#<%= @item[1] %>"><%= @item[1] %></a></td>
158
+ </tr>
159
+ <% end %>
160
+ </table>
161
+ <% else %>
162
+ <h4><%= @attribute[0] %></h4>
163
+ <table class="table">
164
+ <% for @item in @attribute[1]%>
165
+ <tr>
166
+ <th><%= @item[0] %></th>
167
+ <td><%= @item[1] %></td>
168
+ </tr>
169
+ <% end %>
170
+ </table>
171
+ <% end %>
172
+ <% end %>
173
+ <% if @attribute[0] != "CODE" && @attribute[0] != "TITLE" && @attribute[1].class != Hash%>
174
+ <h4><%= @attribute[0]%></h4>
175
+ <p><%= @attribute[1] %></p>
176
+ <% end %>
177
+ <% end %>
178
+ <% end %>
179
+ </div>
94
180
  </div>
181
+ <% end %>
95
182
  </div>
96
- <% end %>
97
183
 
98
184
  <script src="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
99
185
  </body>
@@ -102,9 +188,13 @@ def renderSite(content)
102
188
 
103
189
  renderer = ERB.new(template)
104
190
 
105
- File.open("index.html", "w+") do |f|
191
+ page = @filename + ".html"
192
+
193
+ File.open(page, "w+") do |f|
106
194
  f.write(renderer.result(binding))
107
195
  end
108
196
 
197
+ return page
198
+
109
199
  end
110
200
 
metadata CHANGED
@@ -1,16 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bailey Belvis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-27 00:00:00.000000000 Z
11
+ date: 2014-05-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: A gem to support easy documentation for javascript files.
13
+ description: A gem to support easy documentation for any file that recognizes `/*
14
+ */` as a code block. This gem lets you easily parse multiple files in a directory
15
+ and generate documentation that can be viewed in the browser. See the homepage
16
+ for syntax and examples.
14
17
  email: baileyb622@gmail.com
15
18
  executables:
16
19
  - docme
@@ -24,7 +27,7 @@ homepage: https://github.com/philosowaffle/docme
24
27
  licenses:
25
28
  - Mozilla Public License
26
29
  metadata: {}
27
- post_install_message:
30
+ post_install_message: 'Woohoo! You now have docme :) '
28
31
  rdoc_options: []
29
32
  require_paths:
30
33
  - lib