Skip to content

Commit

Permalink
separate layout.tex.erb (#950)
Browse files Browse the repository at this point in the history
* accept and run sty/*.erb
* try splitting layout.tex.erb
* move erb_config caller
* add testcase
* bump up 3.0. provide latex-compat2/layout.tex.erb for compatibility 2.0
* update review_version for test
* try to define preamble statically
* use ifdefined. copy definitions from reviewmacro.sty
* moving document contents to sty area...
* move more elements to sty area
* all erb are moved to preamble.
* add hypersetup description
* set underline parameter
* split tex blocks of layout.tex.erb to config.erb, review-jsbook/review-reviewmacro.sty, and review-jsbook/review-basemacros.sty.
* set abstract font names and backward compatibility
* trying jlreq implementaion
* simplify version check
* tombo configuration
* set option null
  • Loading branch information
kmuto authored and takahashim committed Jun 8, 2018
1 parent 4846667 commit 8012c93
Show file tree
Hide file tree
Showing 20 changed files with 1,744 additions and 703 deletions.
1 change: 0 additions & 1 deletion doc/config.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# このファイルはUTF-8エンコーディングで記述してください。

# この設定ファイルでサポートするRe:VIEWのバージョン番号。
# major versionが違うときにはエラーを出す。
review_version: 3.0

# ほかの設定ファイルの継承を指定できる。同じパラメータに異なる値がある場合は、
Expand Down
21 changes: 17 additions & 4 deletions lib/review/configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,33 @@ def [](key)
nil
end

def check_version(version)
def check_version(version, exception: true)
unless self.key?('review_version')
raise ReVIEW::ConfigError, 'configuration file has no review_version property.'
if exception
raise ReVIEW::ConfigError, 'configuration file has no review_version property.'
else
return false
end
end

if self['review_version'].blank?
return true
end

if self['review_version'].to_i != version.to_i ## major version
raise ReVIEW::ConfigError, 'major version of configuration file is different.'
if exception
raise ReVIEW::ConfigError, 'major version of configuration file is different.'
else
return false
end
elsif self['review_version'].to_f > version.to_f ## minor version
raise ReVIEW::ConfigError, "Re:VIEW version '#{version}' is older than configuration file's version '#{self['review_version']}'."
if exception
raise ReVIEW::ConfigError, "Re:VIEW version '#{version}' is older than configuration file's version '#{self['review_version']}'."
else
return false
end
end
return true
end

def name_of(key)
Expand Down
9 changes: 7 additions & 2 deletions lib/review/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def self.execute(*args)
end

def initialize
@template = 'review-jsbook'
@logger = ReVIEW.logger
@review_dir = File.dirname(File.expand_path('../../', __FILE__))
end
Expand Down Expand Up @@ -54,6 +55,9 @@ def parse_options(args)
opts.on('-l', '--locale', 'generate locale.yml file.') do
@locale = true
end
opts.on('--latex-template name', 'specify LaTeX template name. (default: review-jsbook)') do |tname|
@template = tname
end
opts.on('', '--epub-version VERSION', 'define EPUB version') do |version|
@epub_version = version
end
Expand Down Expand Up @@ -145,8 +149,9 @@ def generate_style(dir)
def generate_texmacro(dir)
texmacrodir = dir + '/sty'
FileUtils.mkdir_p texmacrodir
FileUtils.cp [@review_dir + '/test/sample-book/src/sty/reviewmacro.sty',
@review_dir + '/test/sample-book/src/sty/jumoline.sty'], texmacrodir
tdir = File.join(@review_dir, '/templates/latex', @template)
@logger.error "#{tdir} not found." unless File.exist?(tdir)
FileUtils.cp Dir.glob(tdir + '/*.*'), texmacrodir
end

def generate_rakefile(dir)
Expand Down
38 changes: 31 additions & 7 deletions lib/review/latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ def compile_ruby(base, ruby)

# math
def inline_m(str)
if @book.config['review_version'].nil? || @book.config['review_version'].to_f > 2
if @book.config.check_version('2', exception: false)
"$#{str}$"
else
" $#{str}$ "
Expand All @@ -859,7 +859,11 @@ def inline_hi(str)

# index -> italic
def inline_i(str)
macro('textit', escape(str))
if @book.config.check_version('2', exception: false)
macro('textit', escape(str))
else
macro('reviewit', escape(str))
end
end

# index
Expand All @@ -874,7 +878,11 @@ def inline_hidx(str)

# bold
def inline_b(str)
macro('textbf', escape(str))
if @book.config.check_version('2', exception: false)
macro('textbf', escape(str))
else
macro('reviewbold', escape(str))
end
end

# line break
Expand All @@ -889,27 +897,43 @@ def inline_dtp(_str)

## @<code> is same as @<tt>
def inline_code(str)
macro('texttt', escape(str))
if @book.config.check_version('2', exception: false)
macro('texttt', escape(str))
else
macro('reviewcode', escape(str))
end
end

def nofunc_text(str)
escape(str)
end

def inline_tt(str)
macro('texttt', escape(str))
if @book.config.check_version('2', exception: false)
macro('texttt', escape(str))
else
macro('reviewtt', escape(str))
end
end

def inline_del(str)
macro('reviewstrike', escape(str))
end

def inline_tti(str)
macro('texttt', macro('textit', escape(str)))
if @book.config.check_version('2', exception: false)
macro('texttt', macro('textit', escape(str)))
else
macro('reviewtti', escape(str))
end
end

def inline_ttb(str)
macro('texttt', macro('textbf', escape(str)))
if @book.config.check_version('2', exception: false)
macro('texttt', macro('textbf', escape(str)))
else
macro('reviewttb', escape(str))
end
end

def inline_bib(id)
Expand Down
44 changes: 31 additions & 13 deletions lib/review/pdfmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def build_pdf

def generate_pdf(yamlfile)
remove_old_file
erb_config
@path = build_path
begin
@compile_errors = nil
Expand All @@ -248,6 +249,8 @@ def generate_pdf(yamlfile)
copy_sty(File.join(Dir.pwd, 'sty'), @path)
copy_sty(File.join(Dir.pwd, 'sty'), @path, 'fd')
copy_sty(File.join(Dir.pwd, 'sty'), @path, 'cls')
copy_sty(File.join(Dir.pwd, 'sty'), @path, 'erb')
copy_sty(File.join(Dir.pwd, 'sty'), @path, 'tex')
copy_sty(Dir.pwd, @path, 'tex')

build_pdf
Expand Down Expand Up @@ -366,7 +369,7 @@ def date_to_s(date)
d.strftime(ReVIEW::I18n.t('date_format'))
end

def template_content
def erb_config
dclass = @config['texdocumentclass'] || []
@documentclass = dclass[0] || 'jsbook'
@documentclassoption = dclass[1] || 'uplatex,oneside'
Expand Down Expand Up @@ -409,30 +412,45 @@ def template_content
@locale_latex['postchaptername'] = chapter_tuple[1]
@locale_latex['preappendixname'] = appendix_tuple[0]
@locale_latex['postappendixname'] = appendix_tuple[1]

layout_file = File.join(@basedir, 'layouts', 'layout.tex.erb')
if File.exist?(layout_file)
template = layout_file
else
template = File.expand_path('./latex/layout.tex.erb', ReVIEW::Template::TEMPLATE_DIR)
end

@texcompiler = File.basename(@config['texcommand'], '.*')
end

erb = ReVIEW::Template.load(template, '-')
def erb_content(file)
@texcompiler = File.basename(@config['texcommand'], '.*')
erb = ReVIEW::Template.load(file, '-')
puts "erb processes #{File.basename(file)}" if @config['debug']
erb.result(binding)
end

def latex_config
erb_content(File.expand_path('./latex/config.erb', ReVIEW::Template::TEMPLATE_DIR))
end

def template_content
template = File.expand_path('./latex/layout.tex.erb', ReVIEW::Template::TEMPLATE_DIR)
if @config['review_version'] && @config['review_version'].to_f < 3
template = File.expand_path('./latex-compat2/layout.tex.erb', ReVIEW::Template::TEMPLATE_DIR)
end
layout_file = File.join(@basedir, 'layouts', 'layout.tex.erb')
template = layout_file if File.exist?(layout_file)
erb_content(template)
end

def copy_sty(dirname, copybase, extname = 'sty')
unless File.directory?(dirname)
warn "No such directory - #{dirname}"
return
end

Dir.open(dirname) do |dir|
dir.each do |fname|
if File.extname(fname).downcase == '.' + extname
FileUtils.mkdir_p(copybase)
dir.sort.each do |fname|
next unless File.extname(fname).downcase == '.' + extname
FileUtils.mkdir_p(copybase) unless Dir.exist?(copybase)
if extname == 'erb'
File.open(File.join(copybase, fname.sub(/\.erb\Z/, '')), 'w') do |f|
f.print erb_content(File.join(dirname, fname))
end
else
FileUtils.cp File.join(dirname, fname), copybase
end
end
Expand Down
Loading

0 comments on commit 8012c93

Please sign in to comment.