Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unify template engine #576

Merged
merged 1 commit into from
Apr 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 13 additions & 40 deletions lib/review/htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

require 'review/builder'
require 'review/htmlutils'
require 'review/htmllayout'
require 'review/template'
require 'review/textutils'

module ReVIEW
Expand Down Expand Up @@ -58,46 +58,23 @@ def builder_init_file
private :builder_init_file

def result
if @book.htmlversion == 5
htmlfilename = "./html/layout-html5.html.erb"
else
htmlfilename = "./html/layout-xhtml1.html.erb"
end

layout_file = File.join(@book.basedir, "layouts", "layout.html.erb")
if !File.exist?(layout_file) && File.exist?(File.join(@book.basedir, "layouts", "layout.erb"))
raise ReVIEW::ConfigError, "layout.erb is obsoleted. Please use layout.html.erb."
end
if File.exist?(layout_file)
if ENV["REVIEW_SAFE_MODE"].to_i & 4 > 0
warn "user's layout is prohibited in safe mode. ignored."
else
title = strip_html(compile_inline(@chapter.title))
language = @book.config['language']
stylesheets = @book.config["stylesheet"]

toc = ""
toc_level = 0
@chapter.headline_index.items.each do |i|
caption = "<li>#{strip_html(compile_inline(i.caption))}</li>\n"
if toc_level == i.number.size
# do nothing
elsif toc_level < i.number.size
toc += "<ul>\n" * (i.number.size - toc_level)
toc_level = i.number.size
elsif toc_level > i.number.size
toc += "</ul>\n" * (toc_level - i.number.size)
toc_level = i.number.size
toc += "<ul>\n" * (toc_level - 1)
end
toc += caption
end
toc += "</ul>" * toc_level

return messages() +
HTMLLayout.new(
{'body' => @output.string, 'title' => title, 'toc' => toc,
'builder' => self,
'language' => language,
'stylesheets' => stylesheets,
'next' => @chapter.next_chapter,
'prev' => @chapter.prev_chapter},
layout_file).result
layout_file = File.expand_path(htmlfilename, ReVIEW::Template::TEMPLATE_DIR)
end
else
layout_file = File.expand_path(htmlfilename, ReVIEW::Template::TEMPLATE_DIR)
end

# default XHTML header/footer
Expand All @@ -107,14 +84,10 @@ def result
@body = @output.string
@language = @book.config['language']
@stylesheets = @book.config["stylesheet"]
@next = @chapter.next_chapter
@prev = @chapter.prev_chapter

if @book.htmlversion == 5
htmlfilename = "layout-html5.html.erb"
else
htmlfilename = "layout-xhtml1.html.erb"
end
tmplfile = File.expand_path('./html/'+htmlfilename, ReVIEW::Template::TEMPLATE_DIR)
tmpl = ReVIEW::Template.load(tmplfile)
tmpl = ReVIEW::Template.load(layout_file)
tmpl.result(binding)
end

Expand Down
43 changes: 0 additions & 43 deletions lib/review/htmllayout.rb

This file was deleted.

2 changes: 2 additions & 0 deletions lib/review/template.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'erb'
module ReVIEW
class Template
include ERB::Util

TEMPLATE_DIR = File.join(File.dirname(__FILE__), "../../templates")

def self.load(filename, mode = 1)
Expand Down