Class: Swift::Playground::Generator

Inherits:
Object
  • Object
show all
Extended by:
Util::SourceIO
Defined in:
lib/swift/playground/generator.rb

Class Method Summary collapse

Methods included from Util::SourceIO

derived_filename, source_as_io

Class Method Details

.generate(markdown, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/swift/playground/generator.rb', line 9

def generate(markdown, options={})
  markdown_file = source_as_io(markdown)

  playground = Playground.new

  pipeline = Util::Pipeline.new(Util::Pipeline::MarkdownFilterChain)
  converted_markdown = pipeline.call(markdown_file.read)[:output]
  converted_markdown.xpath('./section').each do |section|
    case section[:role]
    when 'documentation'
      html = section.inner_html
      playground.sections << DocumentationSection.new(html)
    when 'code'
      code = section.xpath('./pre/code').inner_text
      playground.sections << CodeSection.new(code)
    end
  end

  playground
end