Class: JekyllLiquidDebug

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-liquid-debug.rb

Defined Under Namespace

Classes: Parser

Class Method Summary collapse

Class Method Details

.runObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/jekyll-liquid-debug.rb', line 68

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
    # 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