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

HTMLパーツのlayoutsでの上書きの許可 #1781

Merged
merged 1 commit into from
Jan 8, 2022
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
28 changes: 9 additions & 19 deletions lib/review/epubmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,22 +315,25 @@ def build_part(part, basetmpdir, htmlfile)
File.open(File.join(basetmpdir, htmlfile), 'w') do |f|
@part_number = part.number
@part_title = part.name.strip
@body = ReVIEW::Template.generate(path: 'html/_part_body.html.erb', binding: binding)

@body = ReVIEW::Template.generate(path: template_name(localfile: '_part_body.html.erb', systemfile: 'html/_part_body.html.erb'), binding: binding)
@language = @producer.config['language']
@stylesheets = @producer.config['stylesheet']
f.write ReVIEW::Template.generate(path: template_name, binding: binding)
end
end

def template_name
def template_name(localfile: 'layout.html.erb', systemfile: nil)
if @basedir
layoutfile = File.join(@basedir, 'layouts', 'layout.html.erb')
layoutfile = File.join(@basedir, 'layouts', localfile)
if File.exist?(layoutfile)
return layoutfile
end
end

if systemfile
return systemfile
end

if @producer.config['htmlversion'].to_i == 5
'./html/layout-html5.html.erb'
else
Expand Down Expand Up @@ -552,25 +555,12 @@ def copy_frontmatter(basetmpdir)
end

def build_titlepage(basetmpdir, htmlfile)
# TODO: should be created via epubcommon
@title = h(@config.name_of('booktitle'))
File.open(File.join(basetmpdir, htmlfile), 'w') do |f|
@body = ''
@body << %Q(<div class="titlepage">\n)
@body << %Q(<h1 class="tp-title">#{h(@config.name_of('booktitle'))}</h1>\n)
if @config['subtitle']
@body << %Q(<h2 class="tp-subtitle">#{h(@config.name_of('subtitle'))}</h2>\n)
end
if @config['aut']
@body << %Q(<h2 class="tp-author">#{h(@config.names_of('aut').join(ReVIEW::I18n.t('names_splitter')))}</h2>\n)
end
if @config['pbl']
@body << %Q(<h3 class="tp-publisher">#{h(@config.names_of('pbl').join(ReVIEW::I18n.t('names_splitter')))}</h3>\n)
end
@body << '</div>'

@body = ReVIEW::Template.generate(path: template_name(localfile: '_titlepage.html.erb', systemfile: 'html/_titlepage.html.erb'), binding: binding)
@language = @producer.config['language']
@stylesheets = @producer.config['stylesheet']

f.write ReVIEW::Template.generate(path: template_name, binding: binding)
end
end
Expand Down
16 changes: 10 additions & 6 deletions lib/review/epubmaker/epubcommon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,18 @@ def coverimage
end
end

def template_name
def template_name(localfile: 'layout.html.erb', systemfile: nil)
if @workdir
layoutfile = File.join(@workdir, 'layouts', 'layout.html.erb')
layoutfile = File.join(@workdir, 'layouts', localfile)
if File.exist?(layoutfile)
return layoutfile
end
end

if systemfile
return systemfile
end

if config['htmlversion'].to_i == 5
'./html/layout-html5.html.erb'
else
Expand All @@ -126,7 +130,7 @@ def cover
@coverimage_src = coverimage
raise ApplicationError, "coverimage #{config['coverimage']} not found. Abort." unless @coverimage_src
end
@body = ReVIEW::Template.generate(path: './html/_cover.html.erb', binding: binding)
@body = ReVIEW::Template.generate(path: template_name(localfile: '_cover.html.erb', systemfile: 'html/_cover.html.erb'), binding: binding)

@title = h(config.name_of('title'))
@language = config['language']
Expand All @@ -152,7 +156,7 @@ def titlepage
if config.names_of('pbl')
@publisher_str = join_with_separator(config.names_of('pbl'), ReVIEW::I18n.t('names_splitter'))
end
@body = ReVIEW::Template.generate(path: './html/_titlepage.html.erb', binding: binding)
@body = ReVIEW::Template.generate(path: template_name(localfile: '_titlepage.html.erb', systemfile: './html/_titlepage.html.erb'), binding: binding)

@language = config['language']
@stylesheets = config['stylesheet']
Expand All @@ -164,7 +168,7 @@ def colophon
@title = h(ReVIEW::I18n.t('colophontitle'))
@isbn_hyphen = isbn_hyphen

@body = ReVIEW::Template.generate(path: './html/_colophon.html.erb', binding: binding)
@body = ReVIEW::Template.generate(path: template_name(localfile: '_colophon.html.erb', systemfile: './html/_colophon.html.erb'), binding: binding)

@language = config['language']
@stylesheets = config['stylesheet']
Expand Down Expand Up @@ -203,7 +207,7 @@ def colophon_history
end
end

ReVIEW::Template.generate(path: './html/_colophon_history.html.erb', binding: binding)
ReVIEW::Template.generate(path: template_name(localfile: '_colophon_history.html.erb', systemfile: './html/_colophon_history.html.erb'), binding: binding)
end

def date_to_s(date)
Expand Down
31 changes: 11 additions & 20 deletions lib/review/webmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,26 +146,27 @@ def build_body(basetmpdir, _yamlfile)
def build_part(part, basetmpdir, htmlfile)
@title = h("#{ReVIEW::I18n.t('part', part.number)} #{part.name.strip}")
File.open("#{basetmpdir}/#{htmlfile}", 'w') do |f|
@body = ''
@body << %Q(<div class="part">\n)
@body << %Q(<h1 class="part-number">#{ReVIEW::I18n.t('part', part.number)}</h1>\n)
@body << %Q(<h2 class="part-title">#{part.name.strip}</h2>\n) if part.name.strip.present?
@body << "</div>\n"

@part_number = part.number
@part_title = part.name.strip
@body = ReVIEW::Template.generate(path: template_name(localfile: '_part_body.html.erb', systemfile: 'html/_part_body.html.erb'), binding: binding)
@language = @config['language']
@stylesheets = @config['stylesheet']
f.write ReVIEW::Template.generate(path: template_name, binding: binding)
end
end

def template_name
def template_name(localfile: 'layout-web.html.erb', systemfile: nil)
if @basedir
layoutfile = File.join(@basedir, 'layouts', 'layout-web.html.erb')
layoutfile = File.join(@basedir, 'layouts', localfile)
if File.exist?(layoutfile)
return layoutfile
end
end

if systemfile
return systemfile
end

if @config['htmlversion'].to_i == 5
'web/html/layout-html5.html.erb'
else
Expand Down Expand Up @@ -281,18 +282,8 @@ def build_indexpage(basetmpdir)

def build_titlepage(basetmpdir, htmlfile)
@title = h('titlepage')
File.open("#{basetmpdir}/#{htmlfile}", 'w') do |f|
@body = ''
@body << %Q(<div class="titlepage">)
@body << %Q(<h1 class="tp-title">#{h(@config.name_of('booktitle'))}</h1>)
if @config['aut']
@body << %Q(<h2 class="tp-author">#{join_with_separator(@config.names_of('aut'), ReVIEW::I18n.t('names_splitter'))}</h2>)
end
if @config['pbl']
@body << %Q(<h3 class="tp-publisher">#{join_with_separator(@config.names_of('pbl'), ReVIEW::I18n.t('names_splitter'))}</h3>)
end
@body << '</div>'

File.open(File.join(basetmpdir, htmlfile), 'w') do |f|
@body = ReVIEW::Template.generate(path: template_name(localfile: '_titlepage.html.erb', systemfile: 'html/_titlepage.html.erb'), binding: binding)
@language = @config['language']
@stylesheets = @config['stylesheet']
f.write ReVIEW::Template.generate(path: template_name, binding: binding)
Expand Down
26 changes: 9 additions & 17 deletions templates/html/_titlepage.html.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
<h1 class="tp-title"><%= @title_str %></h1>
<% if @subtitle_str %>
<h2 class="tp-subtitle"><%= h(@subtitle_str) %></h2>
<div class="titlepage">
<h1 class="tp-title"><%= h(@config.name_of('booktitle')) %></h1>
<% if @config['subtitle'] %>
<h2 class="tp-subtitle"><%= h(@config.name_of('subtitle')) %></h2>
<% end %>
<% if @author_str %>
<p>
<br />
<br />
</p>
<h2 class="tp-author"><%= h(@author_str) %></h2>
<% if @config['aut'] %>
<h2 class="tp-author"><%= h(@config.names_of('aut').join(ReVIEW::I18n.t('names_splitter'))) %></h2>
<% end %>
<% if @publisher_str %>
<p>
<br />
<br />
<br />
<br />
</p>
<h3 class="tp-publisher"><%= h(@publisher_str) %></h3>
<% if @config['pbl'] %>
<h3 class="tp-publisher"><%= h(@config.names_of('pbl').join(ReVIEW::I18n.t('names_splitter'))) %></h3>
<% end %>
</div>
37 changes: 11 additions & 26 deletions test/test_epubmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def setup
config = ReVIEW::Configure.values
config.merge!(
'bookname' => 'sample',
'booktitle' => 'Sample Book',
'title' => 'Sample Book',
'epubversion' => 2,
'urnid' => 'http://example.jp/',
Expand Down Expand Up @@ -806,19 +807,11 @@ def test_title
<title>Sample Book</title>
</head>
<body>
<h1 class="tp-title">Sample Book</h1>
<p>
<br />
<br />
</p>
<h2 class="tp-author">Mr.Smith</h2>
<p>
<br />
<br />
<br />
<br />
</p>
<h3 class="tp-publisher">BLUEPRINT</h3>
<div class="titlepage">
<h1 class="tp-title">Sample Book</h1>
<h2 class="tp-author">Mr.Smith</h2>
<h3 class="tp-publisher">BLUEPRINT</h3>
</div>
</body>
</html>
EOT
Expand All @@ -842,19 +835,11 @@ def test_title_single_value_param
<title>Sample Book</title>
</head>
<body>
<h1 class="tp-title">Sample Book</h1>
<p>
<br />
<br />
</p>
<h2 class="tp-author">Mr.Smith</h2>
<p>
<br />
<br />
<br />
<br />
</p>
<h3 class="tp-publisher">BLUEPRINT</h3>
<div class="titlepage">
<h1 class="tp-title">Sample Book</h1>
<h2 class="tp-author">Mr.Smith</h2>
<h3 class="tp-publisher">BLUEPRINT</h3>
</div>
</body>
</html>
EOT
Expand Down