Class: HltSiteBuilder
- Inherits:
-
Object
- Object
- HltSiteBuilder
- Defined in:
- lib/hlt-site_builder.rb
Instance Method Summary collapse
- #docs_each ⇒ Object
- #generate(options = {}, &blk) ⇒ Object
-
#initialize(file, options = {}) ⇒ HltSiteBuilder
constructor
A new instance of HltSiteBuilder.
- #pages_each ⇒ Object
- #to_layout ⇒ Object
- #to_style ⇒ Object
Constructor Details
#initialize(file, options = {}) ⇒ HltSiteBuilder
Returns a new instance of HltSiteBuilder.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/hlt-site_builder.rb', line 29 def initialize(file, ={}) @opt = {style: true}.merge @dynarex = Dynarex.new @dynarex.parse File.read file if @dynarex.summary['container_id'] then @opt.merge!(container_id: @dynarex.summary['container_id']) end 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 s = @pages.keys.map do |name| "def #{name.to_s.downcase.gsub(/\s+/,'_').gsub(/\W+/,'')}() @pages[:'#{name}']; end" end.join("\n") self.instance_eval s end |
Instance Method Details
#docs_each ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/hlt-site_builder.rb', line 54 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 = {}, &blk) ⇒ Object
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 |
# File 'lib/hlt-site_builder.rb', line 68 def generate(={}, &blk) opt = {css: false}.merge style = @opt[:style] if opt[:css] == true then @opt[:style] = true generate_pages @pages.keys, &blk @htc = HtmlToCss.new path = 'css' FileUtils.mkdir_p path unless File.exists? path File.write 'css/layout.css', @htc.to_layout File.write 'css/style.css', @htc.to_style @opt[:style] = style end generate_pages @pages.keys, &blk puts 'files generated' end |
#pages_each ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/hlt-site_builder.rb', line 99 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_layout ⇒ Object
96 |
# File 'lib/hlt-site_builder.rb', line 96 def to_layout() @htc.to_layout end |
#to_style ⇒ Object
97 |
# File 'lib/hlt-site_builder.rb', line 97 def to_style() @htc.to_style end |