documentize 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/documentize/builder.rb +56 -44
- data/lib/documentize/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6cfd72a6925ca9b57ef544c89a68abeb7e46f38
|
4
|
+
data.tar.gz: 863a91330cc7a3a16976c0add757bbfc791735c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc52b6625adc13de1354790016d0b3566d048b882f325af56df3a4d2f336ca4901a2cc637d8d0a422ed2c0c48142815edab96f24407e00601134b3e0524c37d1
|
7
|
+
data.tar.gz: 1bf8be7d0ccb0bfec50d0374a8cbde65bccd7f2156214d146d10ff2d084038d78c38cde9647041b16250e5e4d2035f9c6283b7c5b7b59e5d5118479bd854b56c
|
data/lib/documentize/builder.rb
CHANGED
@@ -1,65 +1,77 @@
|
|
1
1
|
module Documentize
|
2
2
|
class Builder
|
3
3
|
|
4
|
-
|
5
|
-
bad_do_block: /\sdo.*?end/,
|
6
|
-
do_block: /\sdo[\s\|.*]/,
|
7
|
-
flow: /^(if|unless|while|for).*?/
|
8
|
-
}
|
4
|
+
class << self
|
9
5
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
6
|
+
REGEX = {
|
7
|
+
bad_do_block: /\sdo.*?end/,
|
8
|
+
do_block: /\sdo[\s\|.*]/,
|
9
|
+
flow: /^(if|unless|while|for).*?/
|
10
|
+
}
|
11
|
+
|
12
|
+
def make_private
|
13
|
+
@private = true
|
18
14
|
end
|
19
|
-
doc_str
|
20
|
-
end
|
21
15
|
|
16
|
+
def make_public
|
17
|
+
@private = false
|
18
|
+
end
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
20
|
+
def build_docs(branch, indent = 0)
|
21
|
+
doc_str = ""
|
22
|
+
doc_str << "#{' '*indent}# #{@private ? 'Private' : 'Public'}: #{branch[:desc]}\n#{' '*indent}#\n"
|
23
|
+
if branch[:args]
|
24
|
+
branch[:args].each do |arg|
|
25
|
+
doc_str << "#{' '*indent}# #{arg[:name]} - #{arg[:type]}: #{arg[:desc]}\n"
|
26
|
+
end
|
27
|
+
doc_str << "#{' '*indent}# \n"
|
28
|
+
end
|
29
|
+
doc_str
|
30
30
|
end
|
31
|
-
str << ")"
|
32
|
-
end
|
33
31
|
|
34
|
-
def self.build_code(code, indent = 0)
|
35
|
-
str = ""
|
36
|
-
str << build_docs(code, indent) if code[:doc]
|
37
|
-
str << " "*indent
|
38
|
-
str << "#{code[:type] == "method" ? "def" : code[:type]} #{code[:name]}"
|
39
|
-
str << build_args(code[:args]) if code[:args]
|
40
|
-
str << "\n\n"
|
41
32
|
|
42
|
-
|
43
|
-
|
33
|
+
def build_args(args)
|
34
|
+
str = ""
|
35
|
+
str << "("
|
36
|
+
args.each do |arg|
|
37
|
+
str << "#{arg[:name]}"
|
38
|
+
str << " = #{arg[:default]}" if arg[:default]
|
39
|
+
str << ", " unless arg == args[-1]
|
40
|
+
end
|
41
|
+
str << ")"
|
42
|
+
end
|
43
|
+
|
44
|
+
def build_code(code, indent = 0)
|
45
|
+
make_public if(code[:type] == "class")
|
46
|
+
str = ""
|
47
|
+
str << build_docs(code, indent) if code[:doc]
|
48
|
+
str << " "*indent
|
49
|
+
str << "#{code[:type] == "method" ? "def" : code[:type]} #{code[:name]}"
|
50
|
+
str << build_args(code[:args]) if code[:args]
|
51
|
+
str << "\n\n"
|
44
52
|
|
45
|
-
|
53
|
+
code[:content].each do |item|
|
54
|
+
if item.is_a?(Hash)
|
46
55
|
|
47
|
-
|
56
|
+
str << build_code(item, indent+1)
|
48
57
|
|
49
|
-
|
58
|
+
else
|
59
|
+
make_private if(item =~ /private/)
|
60
|
+
indent -= 1 if item =~ /end/ && item !~ REGEX[:bad]
|
50
61
|
|
51
|
-
|
52
|
-
|
62
|
+
str << " "*(indent+1) + "#{item} \n"
|
63
|
+
str << "\n" if item =~ /end/ && item !~ REGEX[:bad]
|
53
64
|
|
54
|
-
|
65
|
+
indent += 1 if (item =~ REGEX[:do_block] || item =~ REGEX[:flow]) && item !~ REGEX[:bad]
|
55
66
|
|
67
|
+
end
|
56
68
|
end
|
57
|
-
end
|
58
69
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
70
|
+
str << " " * indent
|
71
|
+
str << "end\n"
|
72
|
+
indent -= 1
|
73
|
+
str << "\n"
|
74
|
+
end
|
63
75
|
end
|
64
76
|
end
|
65
77
|
end
|
data/lib/documentize/version.rb
CHANGED