docme 0.0.0 → 0.0.1

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/docme.rb +25 -13
  3. data/lib/docme/utils.rb +104 -2
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8092d5b797a25febaea7f8a5fefceb7d1abcdd6
4
- data.tar.gz: de1f4530c2d36f17ae757ba8b41bc17cb51abdbc
3
+ metadata.gz: c08c7f2e03e5e79f4b1099a3beabda310493fee5
4
+ data.tar.gz: 03037b1517f00c9c4df2aea2f37b66773c551fb8
5
5
  SHA512:
6
- metadata.gz: f05590f2bca35a3b51268f7575639d06495e4dff166acc60855f63e5c03595325a66ea4208056ae9c4fe3be0e09b2500d5c13c33acf3d7b9afce8acc128205b0
7
- data.tar.gz: 0e67d56038efee0c763e0616afc47b91ed9b63db7b33c8b61ef4d62bc15d0f098da37a21b8c0cb806c76acc59fe3ce3eda8a071d1f68bc220eb7cab22452563b
6
+ metadata.gz: 4d248f6673207bf1b75df821e680f92ad68c76d582c7b365038d96998610b5b6c08df58ca422457996c3075a31048adb77eb4a525468e8a5436f356f3bc4f6a9
7
+ data.tar.gz: 602b2d61358c17515652ba11218f8e3c37d159ca59e4dbe703c1f9e71e68d6b180c1efe5f12e5d9eb50362de705e58af91a65c1d09bf44088ea317f39faa1969
@@ -1,13 +1,13 @@
1
1
  # docme
2
2
 
3
3
  require 'docme/utils'
4
+ require 'erb'
4
5
 
5
6
  class Docme
6
7
 
7
8
  def self.jsParse(file)
8
- #file = ARGV[0]
9
-
10
9
 
10
+ #SETUP
11
11
  #raise exception if no file provided, file does not exsist, the file is not readable, or the file has no content
12
12
  if file== nil || !File.file?(file) || !File.exists?(file)
13
13
  raise "Please provide a path to the file you wish to docme."
@@ -23,25 +23,34 @@ class Docme
23
23
 
24
24
  puts "Woohoo! docme has a home!"
25
25
 
26
+
26
27
  #GLOBALS
27
28
  sourceFile = File.open(file).read
28
29
  docmeDir = "docme"
30
+ items = Hash.new
31
+ collective = Array.new
32
+ block_content = Hash.new
33
+ block_attr = nil
29
34
  block_flag = 0
30
35
  code_flag = 0
36
+ code = ""
31
37
 
38
+
39
+ #PARSING
32
40
  sourceFile.each_line do |line|
33
41
  #strip leading whitespaces
34
42
  line = line.lstrip
35
43
 
36
44
  #if this is the begining of a comment block then start a new function doc
37
45
  if line.rindex("/*", 1) == 0
38
- #logic to add a new function section to the erb file
39
46
  next
40
47
  end
41
48
 
42
49
  #if this is the end of a comment block then there is nothing to do
43
50
  if line.rindex("*/", 1) == 0
44
51
  #end the function section of the erb file
52
+ collective.push(items)
53
+ items = Hash.new
45
54
  next
46
55
  end
47
56
 
@@ -51,7 +60,6 @@ class Docme
51
60
 
52
61
  #parts[0] == the attribute name
53
62
  attribute = cleanAttribute(parts[0])
54
- #add the attribute to the doc
55
63
 
56
64
  content = parts[1].lstrip
57
65
 
@@ -61,10 +69,12 @@ class Docme
61
69
  #add the attribute to the doc
62
70
  puts attribute
63
71
  block_flag = 1
72
+ block_attr = attribute
64
73
  next
65
74
  end
66
75
 
67
76
  #add content to the doc
77
+ items.store(attribute, content)
68
78
  puts attribute
69
79
  puts content
70
80
  end
@@ -75,7 +85,6 @@ class Docme
75
85
 
76
86
  #parts[0] == the attribute name
77
87
  attribute = cleanAttribute(parts[0])
78
- #add the attribute to the doc
79
88
 
80
89
  content = parts[1].lstrip
81
90
 
@@ -89,6 +98,7 @@ class Docme
89
98
  #put the var_description in the doc
90
99
  puts var_name
91
100
  puts var_description
101
+ block_content.store(var_name, var_description)
92
102
  next
93
103
  end
94
104
 
@@ -103,11 +113,15 @@ class Docme
103
113
  #put the content
104
114
  puts attribute
105
115
  puts content
116
+ block_content.store(attribute, content)
106
117
  next
107
118
  end
108
119
 
109
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
110
121
  if code_flag == 1 && line.rindex("}",0) == 0
122
+ items.store(block_attr, code)
123
+ block_attr = nil
124
+ code = ""
111
125
  code_flag = 0
112
126
  next
113
127
  end
@@ -115,25 +129,23 @@ class Docme
115
129
  #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
116
130
  if block_flag == 1 && line.rindex("}",0) == 0
117
131
  block_flag = 0
132
+ items.store(block_attr, block_content)
133
+ block_attr = nil
134
+ block_content = Hash.new
135
+ next
118
136
  end
119
137
 
120
138
  #if we are in a code block, then return lines as is
121
139
  if code_flag == 1
122
140
  puts line
141
+ code.concat(line)
123
142
  next
124
143
  end
125
144
 
126
145
 
127
146
  end
128
147
 
129
- def render()
130
- ERB.new(@template).result(binding)
131
- end
148
+ renderSite(collective)
132
149
 
133
- def save(site)
134
- FIle.open(site, "w+") do |f|
135
- f.write(render)
136
- end
137
- end
138
150
  end
139
151
  end
@@ -1,8 +1,110 @@
1
- #docem utils
1
+ #docme utils
2
+
3
+ template = '<!DOCTYPE html>
4
+ <html>
5
+
6
+ <head>
7
+ <meta name="viewport" content="width=device-width, initial-scale=1">
8
+ </head>
9
+
10
+ <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet" media="screen">
11
+
12
+
13
+ <body>
14
+
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>
27
+
28
+ <% end %>
29
+ <% end %>
30
+
31
+ <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
32
+ </body>
33
+
34
+ </html>'
2
35
 
3
36
  def cleanAttribute(attr)
4
37
  attr = attr.delete("+[")
5
38
  attr = attr.delete("]")
6
39
  attr = attr.delete("-")
7
40
  return attr
8
- end
41
+ end
42
+
43
+ def renderSite(content)
44
+
45
+ @collective = content
46
+
47
+ puts content
48
+
49
+ template = '<!DOCTYPE html>
50
+ <html>
51
+
52
+ <head>
53
+ <meta name="viewport" content="width=device-width, initial-scale=1">
54
+ </head>
55
+
56
+ <link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet" media="screen">
57
+
58
+
59
+ <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>
87
+ <% end %>
88
+ <% if @attribute[0] != "example" && @attribute[0] != "title" && @attribute[1].class != Hash%>
89
+ <h4><%= @attribute[0]%></h4>
90
+ <p><%= @attribute[1] %></p>
91
+ <% end %>
92
+ <% end %>
93
+ <% end %>
94
+ </div>
95
+ </div>
96
+ <% end %>
97
+
98
+ <script src="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
99
+ </body>
100
+
101
+ </html>'
102
+
103
+ renderer = ERB.new(template)
104
+
105
+ File.open("index.html", "w+") do |f|
106
+ f.write(renderer.result(binding))
107
+ end
108
+
109
+ end
110
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docme
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
  - Bailey Belvis