aboutsummaryrefslogtreecommitdiff
path: root/hyde.rb
blob: 3adfce004e2773ad6d46e0ca2129e1a14b223f1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/local/bin/ruby

require "erb"
require "optparse"
require "yaml"

options = {}
OptionParser.new do |opt|
  opt.on("-f", "--file-name FILENAME", "File name of the page you want to render") {
    |o| options[:fileName] = o
  }
  opt.on("-t", "--title TITLE", "Title of the rendered page") {
    |o| options[:title] = o
  }
  opt.on("-m", "--master MASTER", "Master file page") {
    |o| options[:master] = o
  }
  opt.on("-n", "--page-name NAME", "page name") {
    |o| options[:pageName] = o
  }
end.parse!

#puts options

class Page
  def initialize title, pageFileName, pageName
    @title = title
    @pageFileName = pageFileName
    @pageName = pageName
  end

  def render path
    content = File.read(File.expand_path(path))
    t = ERB.new(content)
    t.result(binding)
  end
end

if(!File.exist?(options[:fileName] + '.config'))
  puts 'Cannot find: ' + options[:fileName] + '.config'
  exit -1
end

config = YAML.load_file(options[:fileName] + '.config')

title = config['title']
pageName = config['pageName']

page = Page.new(title, options[:fileName], pageName)

if options[:master] == nil
  puts page.render("master.rhtml")
else
  puts page.render(options[:master])
end