class Marksman::Parser

Public Instance Methods

parse(file) click to toggle source
# File lib/marksman/parser.rb, line 8
def parse(file)
  metadata, markdown = load_file(file)
  slides = split_slides(markdown).map do |slide|
    sections = separate_presenter_notes(slide)
    Slide.new(
      slide: generate_html(sections.slide).strip,
      notes: generate_html(sections.notes).strip
    )
  end

  Presentation.new(filename: File.basename(file), metadata: metadata, slides: slides)
end

Private Instance Methods

generate_html(slide) click to toggle source
# File lib/marksman/parser.rb, line 49
def generate_html(slide)
  markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,{fenced_code_blocks: true})
  markdown.render(slide || '')
end
load_file(file) click to toggle source
# File lib/marksman/parser.rb, line 23
def load_file(file)
  content = File.read(file)
  if content.match /^(---\s*\n.*?\n?)^(?:---\s*$\n?)(.*)/m
    [parse_yaml($1), $2]
  else
    [{}, content]
  end
end
parse_yaml(data) click to toggle source
# File lib/marksman/parser.rb, line 32
def parse_yaml(data)
  yaml = YAML.load(data)
  yaml.keys.each do |key|
    yaml[key.to_sym] = yaml.delete key
  end
  yaml
end
separate_presenter_notes(slide) click to toggle source
# File lib/marksman/parser.rb, line 40
def separate_presenter_notes(slide)
  sections = slide.split(/^(?:\*{1}\s?){3,}\s*$/).each(&:strip)
  Slide.new(slide: sections[0], notes: sections[1])
end
split_slides(markdown) click to toggle source
# File lib/marksman/parser.rb, line 45
def split_slides(markdown)
  slides = markdown.split(/^(?:[-]{1}\s?){3,}\s*$/).each(&:strip)
end