Class: Asciibook::Builders::HtmlBuilder
- Inherits:
-
BaseBuilder
- Object
- BaseBuilder
- Asciibook::Builders::HtmlBuilder
- Defined in:
- lib/asciibook/builders/html_builder.rb
Instance Method Summary collapse
- #build ⇒ Object
- #copy_assets ⇒ Object
- #generate_pages ⇒ Object
-
#initialize(book) ⇒ HtmlBuilder
constructor
A new instance of HtmlBuilder.
Methods inherited from BaseBuilder
Constructor Details
#initialize(book) ⇒ HtmlBuilder
Returns a new instance of HtmlBuilder.
4 5 6 7 8 |
# File 'lib/asciibook/builders/html_builder.rb', line 4 def initialize(book) super @dest_dir = File.join(@book.dest_dir, 'html') @theme_dir = File.join(@book.theme_dir, 'html') end |
Instance Method Details
#build ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/asciibook/builders/html_builder.rb', line 10 def build FileUtils.mkdir_p @dest_dir FileUtils.rm_r Dir.glob("#{@dest_dir}/*") generate_pages copy_assets end |
#copy_assets ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/asciibook/builders/html_builder.rb', line 30 def copy_assets @book.assets.each do |path| copy_file(path, @book.base_dir, @dest_dir) end Dir.glob('**/*.{jpb,png,gif,svg,css,js,eot,ttf,woff,woff2}', File::FNM_CASEFOLD, base: @theme_share_dir).each do |path| copy_file(path, @theme_share_dir, @dest_dir) end Dir.glob('**/*.{jpb,png,gif,svg,css,js,eot,ttf,woff,woff2}', File::FNM_CASEFOLD, base: @theme_dir).each do |path| copy_file(path, @theme_dir, @dest_dir) end end |
#generate_pages ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/asciibook/builders/html_builder.rb', line 18 def generate_pages layout = Liquid::Template.parse(File.read(File.join(@theme_dir, 'layout.html'))) @book.pages.each do |page| File.open(File.join(@dest_dir, page.path), 'w') do |file| file.write layout.render({ 'book' => @book.to_hash, 'page' => page.to_hash }) end end end |