Class: HltSiteBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/hlt-site_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}) ⇒ HltSiteBuilder

Returns a new instance of HltSiteBuilder.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hlt-site_builder.rb', line 22

def initialize(file, options={})

  @opt = {style: true}.merge options
  @dynarex = Dynarex.new
  @dynarex.parse File.read file

  if @dynarex.summary['container_id'] then
    @opt.merge!(container_id: @dynarex.summary['container_id'])
  end

end

Instance Method Details

#docs_eachObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/hlt-site_builder.rb', line 34

def docs_each()

  pages = @pages.to_a
  pages[0][0] = 'index'

  pages.keys.each do |pg_name| 

    filename = format_filename(pg_name)
    doc = Rexle.new(File.read filename)
    yield(filename, doc) 
  end

end

#generate(options = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/hlt-site_builder.rb', line 48

def generate(options={})

  opt = {css: false}.merge options

  keys = @dynarex.records.keys
  @template = keys.shift

  @pages = keys.inject({}) do |r, x| 
    label, val = x.split(/\n/,2)
    r.merge({label.strip.to_sym => val})
  end

  style = @opt[:style]

  if opt[:css] == true then


    @opt[:style] = true 
    generate_pages @pages.keys
    @htc = HtmlToCss.new

    File.write 'css/layout.css', @htc.to_layout
    File.write 'css/style.css', @htc.to_style
    @opt[:style] = style    

  end

  generate_pages @pages.keys
  puts 'files generated'
end

#pages_eachObject



82
83
84
85
86
87
88
89
90
91
# File 'lib/hlt-site_builder.rb', line 82

def pages_each()

  pages = @pages.to_a
  pages[0][0] = 'index'
  pages.keys.each do |pg_name| 
    filename = format_filename(pg_name)
    content = File.read filename
    yield(filename, content) 
  end
end

#to_layoutObject



79
# File 'lib/hlt-site_builder.rb', line 79

def to_layout()  @htc.to_layout   end

#to_styleObject



80
# File 'lib/hlt-site_builder.rb', line 80

def to_style()   @htc.to_style    end