class JekyllLiquidDebug

Public Class Methods

run() click to toggle source
# File lib/jekyll-liquid-debug.rb, line 76
def self.run
  args = Parser.parse(ARGV)
  # make Hash dottable
  args = Struct.new(*args.keys).new(*args.values)

  if args.kmd
    puts "Note: using input markdown file < #{args.kmd} >"
    # read input markdown
    fmd = File.open(args.kmd).read

    if args.yaml
      puts "Note: using input YAML file < #{args.yaml} >"
      site = YAML.load_file(args.yaml).to_dot
      fmd = Liquid::Template.parse(fmd).render("site" => site)
    end

    # html conversion
    content = Kramdown::Document.new(fmd).to_html
    fbase = File.basename(args.kmd,".*")
  elsif args.html
    puts "Note: using input html file < #{args.html} >"
    fmd = false
    content = File.open(args.html).read
    fbase = File.basename(args.html,".*")
  else
    puts "Note: using default markdown file < jekyll-markdown.md >"
    fmd = File.open(File.expand_path("../../data/jekyll-markdown.md",__FILE__)).read
    content = Kramdown::Document.new(fmd).to_html
    fbase = 'jekyll-markdown'
  end

  # output html
  if args.outhtml
    name = fbase + ".html"
    puts "Note: writing < html > to file < #{name} >"
    File.new(name,'w').write(content)
  end

  # output markdown
  if args.outmd
    if args.html
      name = "jekyll-markdown.md"
      FileUtils.cp(File.expand_path("../../data/jekyll-markdown.md",__FILE__), '.')
    else
      name = fbase + ".md"
      File.new(name,'w').write(fmd)
    end
    puts "Note: writing < markdown > to file < #{name} >"
  end

  if args.file
    liquid = File.open(args.file).read
    puts Liquid::Template.parse(liquid).render("content" => content)
  end
end