Module: Markdown

Defined in:
lib/code_writer/rbmarkdown.rb

Instance Method Summary collapse

Instance Method Details

#author(text) ⇒ Object





82
83
84
# File 'lib/code_writer/rbmarkdown.rb', line 82

def author(text)
  print "Author: #{text}\n\n"
end

#body(text) ⇒ Object





138
139
140
# File 'lib/code_writer/rbmarkdown.rb', line 138

def body(text)
  print "#{text.align_left}\n\n"
end

#chapter(text) ⇒ Object





90
91
92
# File 'lib/code_writer/rbmarkdown.rb', line 90

def chapter(text)
  print "# #{text}\n\n"
end

#code(script) ⇒ Object





146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/code_writer/rbmarkdown.rb', line 146

def code(script)

  # Let's capture the output of Renjin script in our own string.
  $output.set_std_out(String.new)

  puts script.align_left
  puts
  
  begin
    # eval(script, TOPLEVEL_BINDING)
    eval(script, $binding)
  rescue Exception => e
    puts "#{e.class}: #{e.message}"
  end

  $output.set_default_std_out
  puts $output.alternate_out.align_left.indent(4)
  
end

#comment_code(text) ⇒ Object





196
197
198
199
# File 'lib/code_writer/rbmarkdown.rb', line 196

def comment_code(text)
  puts text.align_left.indent(4)
  puts
end

#console(script) ⇒ Object





170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/code_writer/rbmarkdown.rb', line 170

def console(script)
  
  print(script.align_left.prefix("+ ", "> ").indent(4))
  
  # Let's capture the output of Renjin script in our own string.
  $output.set_std_out(String.new)
  
  begin
    print("\n\n")
    # eval(script, TOPLEVEL_BINDING)
    eval(script, $binding)
  rescue Exception => e
    puts "#{e.class}: #{e.message}"
  end
  
  $output.set_default_std_out
  puts
  puts $output.alternate_out.align_left.indent(4)
  puts
  
end

#italic(text) ⇒ Object





222
223
224
# File 'lib/code_writer/rbmarkdown.rb', line 222

def italic(text)
  print "*#{text}*"
end

#list(text) ⇒ Object





213
214
215
216
# File 'lib/code_writer/rbmarkdown.rb', line 213

def list(text)
  puts text.align_left.prefix("* ", paragraph: true).indent(2)
  puts
end

#paragraph(text) ⇒ Object





122
123
124
# File 'lib/code_writer/rbmarkdown.rb', line 122

def paragraph(text)
  puts text
end

#ref(title, publication) ⇒ Object





205
206
207
# File 'lib/code_writer/rbmarkdown.rb', line 205

def ref(title, publication)
  "*#{title}*, #{publication}"
end

#section(text) ⇒ Object





98
99
100
# File 'lib/code_writer/rbmarkdown.rb', line 98

def section(text)
  print "## #{text}\n\n"
end

#set_output(output = StIO.new) ⇒ Object





66
67
68
# File 'lib/code_writer/rbmarkdown.rb', line 66

def set_output(output = StIO.new)
  $output = output
end

#subparagraph(text) ⇒ Object





130
131
132
# File 'lib/code_writer/rbmarkdown.rb', line 130

def subparagraph(text)
  puts text
end

#subsection(text) ⇒ Object





106
107
108
# File 'lib/code_writer/rbmarkdown.rb', line 106

def subsection(text)
  print "### #{text}\n\n"
end

#subsubsection(text) ⇒ Object





114
115
116
# File 'lib/code_writer/rbmarkdown.rb', line 114

def subsubsection(text)
  print "#### #{text}\n\n"
end

#title(text) ⇒ Object





74
75
76
# File 'lib/code_writer/rbmarkdown.rb', line 74

def title(text)
  print "# #{text}\n\n"
end