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

layout.tex.erbの分割 #950

Merged
merged 31 commits into from
Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fafc14c
accept and run sty/*.erb
kmuto Feb 24, 2018
1e5dba9
try splitting layout.tex.erb
kmuto Feb 24, 2018
e381157
move erb_config caller
kmuto Feb 24, 2018
9b5d21a
pass compile
kmuto Feb 24, 2018
2348513
suspend some tests temporary
kmuto Feb 24, 2018
119acf9
add testcase
kmuto Feb 24, 2018
d728849
bump up 3.0. provide latex-compat2/layout.tex.erb for compatibility 2.0
kmuto Feb 25, 2018
aead3c7
update review_version for test
kmuto Feb 25, 2018
9ed13d7
Merge branch 'master' into split_layout
kmuto Feb 26, 2018
a2327b0
try to define preamble statically
kmuto Feb 26, 2018
df4d50f
use ifdefined. copy definitions from reviewmacro.sty
kmuto Feb 27, 2018
a0a308a
moving document contents to sty area...
kmuto Feb 27, 2018
0142fe6
move more elements to sty area
kmuto Feb 28, 2018
d5df220
all erb are moved to preamble.
kmuto Feb 28, 2018
80cc16f
add hypersetup description
kmuto Feb 28, 2018
985a173
Merge branch 'master' into split_layout
kmuto Mar 1, 2018
c2ae3a1
pass test.
kmuto Mar 1, 2018
11809bd
fix conflicts
kmuto Mar 28, 2018
1e91332
set underline parameter
kmuto Apr 11, 2018
7f19d79
split tex blocks of layout.tex.erb to config.erb, review-jsbook/revie…
kmuto Apr 27, 2018
c7f9319
set abstract font names and backward compatibility
kmuto Apr 27, 2018
9f49643
trying jlreq implementaion
kmuto Apr 28, 2018
90d1a29
simplify version check
kmuto Apr 28, 2018
84e8a84
tombo configuration
kmuto Apr 28, 2018
275981a
set option null
kmuto May 13, 2018
d841002
revert cosmetic change (#1019)
takahashim Jun 6, 2018
da03ac5
fix all tests (#1020)
takahashim Jun 6, 2018
a80256a
rename version-depend method name (#1021)
takahashim Jun 6, 2018
1493c99
Merge branch 'split_layout' of github.com:kmuto/review into split_layout
kmuto Jun 6, 2018
bbd072f
Merge branch 'master' into split_layout_mastermerge
kmuto Jun 6, 2018
ab3696a
update test.
kmuto Jun 6, 2018
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
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