Skip to content

Commit

Permalink
resolves #1346 allow elements on title page to be disabled from theme…
Browse files Browse the repository at this point in the history
… (PR #1347)
  • Loading branch information
mojavelinux authored Oct 26, 2019
1 parent 188a653 commit 45fce7c
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[

* fix value of implicit page-count attribute when page numbering and running content don't start on same page (#1334)
* fix value of implicit chapter-title attribute on preface pages (#1340)
* allow elements on title page to be disabled from theme using display: none (#1346)
* set chapter-title attribute to value of toc-title attribute on toc pages in book (#1338)
* set section-title attribute to value of toc-title attribute on toc pages in article if page has no other sections (#1338)
* set default footer content in base theme; remove logic to process `footer_<side>_content: none` key (#1320)
Expand Down
28 changes: 28 additions & 0 deletions docs/theming-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,13 @@ TIP: The title page can be disabled for the book doctype by setting the `notitle

3+|[#key-prefix-title-page-title]*Key Prefix:* <<key-prefix-title-page-title,title-page-title>>

|display
|none +
(default: _not set_)
|title-page:
title:
display: none

|font-color
|<<colors,Color>> +
(default: _inherit_)
Expand Down Expand Up @@ -1770,6 +1777,13 @@ TIP: The title page can be disabled for the book doctype by setting the `notitle

3+|[#key-prefix-title-page-subtitle]*Key Prefix:* <<key-prefix-title-page-subtitle,title-page-subtitle>>

|display
|none +
(default: _not set_)
|title-page:
subtitle:
display: none

|font-color
|<<colors,Color>> +
(default: _inherit_)
Expand Down Expand Up @@ -1828,6 +1842,13 @@ TIP: The title page can be disabled for the book doctype by setting the `notitle

3+|[#key-prefix-authors]*Key Prefix:* <<key-prefix-authors,title-page-authors>>

|display
|none +
(default: _not set_)
|title-page:
authors:
display: none

|delimiter
|<<quoted-string,Quoted string>> +
(default: ', ')
Expand Down Expand Up @@ -1886,6 +1907,13 @@ TIP: The title page can be disabled for the book doctype by setting the `notitle

3+|[#key-prefix-revision]*Key Prefix:* <<key-prefix-revision,title-page-revision>>

|display
|none +
(default: _not set_)
|title-page:
revision:
display: none

|delimiter
|<<quoted-string,Quoted string>> +
(default: ', ')
Expand Down
33 changes: 18 additions & 15 deletions lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2615,7 +2615,7 @@ def layout_title_page doc
title_align = (@theme.title_page_align || @base_align).to_sym

# TODO disallow .pdf as image type
if (logo_image_path = (doc.attr 'title-logo-image') || (logo_image_from_theme = @theme.title_page_logo_image))
if @theme.title_page_logo_display != 'none' && (logo_image_path = (doc.attr 'title-logo-image') || (logo_image_from_theme = @theme.title_page_logo_image))
if (logo_image_path.include? ':') && logo_image_path =~ ImageAttributeValueRx
logo_image_attrs = (AttributeList.new $2).parse ['alt', 'width', 'height']
relative_to_imagesdir = true
Expand Down Expand Up @@ -2647,7 +2647,6 @@ def layout_title_page doc

# TODO prevent content from spilling to next page
theme_font :title_page do
doctitle = doc.doctitle partition: true
if (title_top = @theme.title_page_title_top)
if title_top.end_with? 'vh'
title_top = page_height - page_height * title_top.to_f / 100.0
Expand All @@ -2657,29 +2656,32 @@ def layout_title_page doc
# FIXME delegate to method to convert page % to y value
@y = title_top
end
move_down(@theme.title_page_title_margin_top || 0)
indent (@theme.title_page_title_margin_left || 0), (@theme.title_page_title_margin_right || 0) do
theme_font :title_page_title do
layout_prose doctitle.main,
align: title_align,
margin: 0,
line_height: @theme.title_page_title_line_height
unless @theme.title_page_title_display == 'none'
doctitle = doc.doctitle partition: true
move_down(@theme.title_page_title_margin_top || 0)
indent (@theme.title_page_title_margin_left || 0), (@theme.title_page_title_margin_right || 0) do
theme_font :title_page_title do
layout_prose doctitle.main,
align: title_align,
margin: 0,
line_height: @theme.title_page_title_line_height
end
end
move_down(@theme.title_page_title_margin_bottom || 0)
end
move_down(@theme.title_page_title_margin_bottom || 0)
if doctitle.subtitle
if @theme.title_page_subtitle_display != 'none' && (subtitle = (doctitle || (doc.doctitle partition: true)).subtitle)
move_down(@theme.title_page_subtitle_margin_top || 0)
indent (@theme.title_page_subtitle_margin_left || 0), (@theme.title_page_subtitle_margin_right || 0) do
theme_font :title_page_subtitle do
layout_prose doctitle.subtitle,
layout_prose subtitle,
align: title_align,
margin: 0,
line_height: @theme.title_page_subtitle_line_height
end
end
move_down(@theme.title_page_subtitle_margin_bottom || 0)
end
if doc.attr? 'authors'
if @theme.title_page_authors_display != 'none' && (doc.attr? 'authors')
move_down(@theme.title_page_authors_margin_top || 0)
indent (@theme.title_page_authors_margin_left || 0), (@theme.title_page_authors_margin_right || 0) do
# TODO provide an API in core to get authors as an array
Expand All @@ -2695,8 +2697,7 @@ def layout_title_page doc
end
move_down(@theme.title_page_authors_margin_bottom || 0)
end
revision_info = [(doc.attr? 'revnumber') ? %(#{doc.attr 'version-label'} #{doc.attr 'revnumber'}) : nil, (doc.attr 'revdate')].compact
unless revision_info.empty?
unless @theme.title_page_revision_display == 'none' || (revision_info = [(doc.attr? 'revnumber') ? %(#{doc.attr 'version-label'} #{doc.attr 'revnumber'}) : nil, (doc.attr 'revdate')].compact).empty?
move_down(@theme.title_page_revision_margin_top || 0)
revision_text = revision_info.join (@theme.title_page_revision_delimiter || ', ')
if (revremark = doc.attr 'revremark')
Expand All @@ -2713,6 +2714,8 @@ def layout_title_page doc
move_down(@theme.title_page_revision_margin_bottom || 0)
end
end

layout_prose DummyText, margin: 0, line_height: 1, normalize: false if page.empty?
end

def layout_cover_page doc, face
Expand Down
50 changes: 50 additions & 0 deletions spec/document_title_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,56 @@
(expect get_images pdf, 2).to have_size 1
(expect get_images pdf, 3).to have_size 1
end

it 'should allow theme to disable elements on title page' do
pdf_theme = {
title_page_subtitle_display: 'none',
title_page_authors_display: 'none',
title_page_revision_display: 'none',
}

pdf = to_pdf <<~'EOS', pdf_theme: pdf_theme, analyze: true
= Document Title: Subtitle
:doctype: book
Author Name
v1.0, 2020-01-01
first page of content
EOS

(expect pdf.pages).to have_size 2
title_page_texts = pdf.find_text page_number: 1
(expect title_page_texts).to have_size 1
(expect title_page_texts[0][:string]).to eql 'Document Title'
end

it 'should not remove title page if all elements are disabled' do
pdf_theme = {
title_page_title_display: 'none',
title_page_subtitle_display: 'none',
title_page_authors_display: 'none',
title_page_revision_display: 'none',
}

pdf = to_pdf <<~'EOS', pdf_theme: pdf_theme
= Document Title: Subtitle
:doctype: book
:title-page-background-image: image:cover.jpg[]
Author Name
v1.0, 2020-01-01
first page of content
EOS

(expect pdf.pages).to have_size 2
title_page_text = (pdf.page 1).text
(expect title_page_text).to be_empty

image_data = File.binread fixture_file 'cover.jpg'
title_page_images = get_images pdf, 1
(expect title_page_images).to have_size 1
(expect title_page_images[0].data).to eql image_data
end
end

context 'article' do
Expand Down

0 comments on commit 45fce7c

Please sign in to comment.