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



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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# 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