Class: TomDoc::Generators::Console
Instance Attribute Summary
#options, #scopes
Instance Method Summary
collapse
#constant?, #constant_names, generate, #generate, #initialize, #matches_pattern?, #process, #pygments, #valid?, #valid_tomdoc?, #write, #write_class_methods, #write_instance_methods, #write_scope, #write_scope_footer
Instance Method Details
#args(method) ⇒ Object
19
20
21
22
23
24
25
26
|
# File 'lib/tomdoc/generators/console.rb', line 19
def args(method)
return '' if !method.respond_to?(:args)
if method.args.any?
'(' + method.args.join(', ') + ')'
else
''
end
end
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/tomdoc/generators/console.rb', line 28
def ()
= .to_s
.gsub!(/^# ?/, '')
.gsub!(/(\s*Examples\s*(.+?)\s*Returns)/m) do
$1.sub($2, highlight($2))
end
.gsub!(/^(\s*(\w+) +- )/) do
param = $2
$1.sub(param, param.green)
end
.gsub!(/(true|false|nil)/, '\1'.magenta)
.gsub!(/('.+?')/, '\1'.yellow)
.gsub!(/(".+?")/, '\1'.yellow)
.gsub!(/(\s+:\w+)/, '\1'.red)
.gsub!(/(([A-Z]\w+(::)?)+)/) do
if constant?($1.strip)
$1.split('::').map { |part| part.cyan }.join('::')
else
$1
end
end
end
|
#highlight(text) ⇒ Object
4
5
6
|
# File 'lib/tomdoc/generators/console.rb', line 4
def highlight(text)
pygments(text, '-l', 'ruby')
end
|
#write_method(method, prefix = '') ⇒ Object
13
14
15
16
17
|
# File 'lib/tomdoc/generators/console.rb', line 13
def write_method(method, prefix = '')
write '-' * 80
write "#{prefix}#{method.name}#{args(method)}".bold, ''
write (method.tomdoc)
end
|
8
9
10
11
|
# File 'lib/tomdoc/generators/console.rb', line 8
def (scope, prefix = '')
return if scope.tomdoc.to_s.empty?
write_method(scope, prefix)
end
|