Module: Awestruct::ReStructuredTextable

Included in:
ReStructuredTextFile
Defined in:
lib/awestruct/restructuredtextable.rb

Instance Method Summary collapse

Instance Method Details

#contentObject



20
21
22
23
# File 'lib/awestruct/restructuredtextable.rb', line 20

def content
  context = site.engine.create_context( self )
  render( context )
end

#execute(command, target) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/awestruct/restructuredtextable.rb', line 25

def execute(command, target)
  out = ''
  Open3.popen3(command) do |stdin, stdout, _|
    stdin.puts target
    stdin.close
    out = stdout.read
  end
  out.gsub("\r", '')
rescue Errno::EPIPE
  ""
end

#render(context) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/awestruct/restructuredtextable.rb', line 4

def render(context)
  hl = 1
  if front_matter['initial_header_level'].to_s =~ /^[1-6]$/
    hl = front_matter['initial_header_level']
  end
  rendered = ''
  begin
    doc = execute( "rst2html --strip-comments --no-doc-title --initial-header-level=#{hl}", context.interpolate_string( raw_page_content ) )
    rendered = Hpricot( doc ).at( '/html/body/div[@class="document"]' ).inner_html.strip
  rescue => e
    puts e
    puts e.backtrace
  end
  rendered
end