43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/rundoc/code_section.rb', line 43
def render
result = []
env = {}
env[:commands] = []
env[:fence_start] = +"#{fence}#{lang}"
env[:fence_end] = "#{fence}#{AUTOGEN_WARNING}"
env[:before] = []
env[:after] = []
env[:document_path] = @document_path
@stack.each do |s|
unless s.respond_to?(:call)
result << s
next
end
code_command = s
code_output = code_command.call(env) || ""
code_line = code_command.to_md(env) || ""
env[:commands] << {object: code_command, output: code_output, command: code_line}
tmp_result = []
tmp_result << code_line if code_command.render_command?
tmp_result << code_output if code_command.render_result?
result << tmp_result unless code_command.hidden?
end
return env[:replace] if env[:replace]
return "" if hidden?
array = [env[:before]]
result.flatten!
result.compact!
result.map! { |s| s.respond_to?(:rstrip) ? s.rstrip : s }
result.reject!(&:empty?)
result.map!(&:to_s)
if !result.empty?
array << env[:fence_start]
array << result
array << env[:fence_end]
end
array << env[:after]
array.flatten!
array.compact!
array.map! { |s| s.respond_to?(:rstrip) ? s.rstrip : s }
array.reject!(&:empty?)
array.map!(&:to_s)
array.join("\n") << "\n"
end
|