Skip to content

Commit

Permalink
Refactor TOC (fix #59, fix #77).
Browse files Browse the repository at this point in the history
  • Loading branch information
Ned Zimmerman committed Apr 15, 2018
1 parent 04157fa commit 02756ea
Show file tree
Hide file tree
Showing 11 changed files with 2,522 additions and 48 deletions.
30 changes: 20 additions & 10 deletions assets/styles/components/toc/_left.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,38 @@

.toc-chapter-title {
display: $toc-left-chapter-title-display;
width: if-map-get($toc-title-width, $type);
width: if-map-get($toc-left-title-width, $type);
}

.chapter-subtitle {
display: $toc-left-subtitle-display;
width: if-map-get($toc-title-width, $type);
width: if-map-get($toc-left-subtitle-width, $type);
}

.chapter-author {
display: $toc-left-author-display;
width: if-map-get($toc-title-width, $type);
width: if-map-get($toc-left-author-width, $type);
}

.front-matter,
.part,
.back-matter {
margin-left: if-map-get($toc-left-left-gutter, $type);
.toc-subsection-title {
display: $toc-left-subsection-display;
width: if-map-get($toc-left-subsection-width, $type);
}

.chapter .chapter-subtitle,
.chapter .chapter-author,
.chapter .sections {
margin-left: if-map-get($toc-left-left-gutter, $type);
}
}
}

.toc-subsection-title {
display: $toc-left-subsection-display;
width: if-map-get($toc-left-subsection-width, $type);
@if $type == 'epub' {
#toc {
.chapter-subtitle,
.chapter-author,
.sections {
margin-left: if-map-get($toc-left-left-gutter, $type);
}
}
}
Expand All @@ -55,6 +59,12 @@
width: if-map-get($toc-left-right-gutter, $type);
}

.front-matter,
.part,
.back-matter {
margin-left: if-map-get($toc-left-left-gutter, $type);
}

.part a::before {
content: $toc-part-number-before-content $toc-part-number-content $toc-left-part-number-after-content;
display: $toc-left-part-number-display;
Expand Down
141 changes: 108 additions & 33 deletions assets/styles/variables/_toc.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,28 @@ $toc-subsection-margin-top: 0 !default;
/// @since 1.0.0
$toc-sub-width: 75% !default;

/// Chapter number width in Table of Contents.
/// @type String
/// @deprecated No longer used.
/// @since 1.0.0
$toc-left-chapter-number-width: 1cm !default;

/// Subtitle width for Table of contents.
/// @type String
/// @deprecated No longer used.
/// @since 1.0.0
$toc-title-width: 80% !default;

/// Left gutter width for left-aligned Table of Contents (chapter numbers go here in PDF).
/// @type String | Map
/// @since 1.0.0
$toc-left-left-gutter: (epub: 0, prince: 1cm) !default;
$toc-left-left-gutter: (epub: 2.5em, prince: 1cm) !default;

/// Right gutter width for left-aligned Table of Contents (page numbers go here in PDF).
/// @type String | Map
/// @since 1.0.0
$toc-left-right-gutter: (epub: 0, prince: 1.5cm) !default;

/// Chapter number width in Table of Contents.
/// @type String | Map
$toc-left-chapter-number-width: $toc-left-left-gutter !default;

/// Center of Table of Contents margin right.
/// @type String | Map
$toc-center-margin-right: (
epub: 0,
prince: 0.5cm
) !default;

/// Center of Table of Contents margin left.
/// @type String
/// @type String | Map
$toc-center-margin-left: (
epub: 0,
prince: 0.5cm
) !default;

/// Top margin for a Table of contents block.
/// @type String | Map
$toc-block-margin-top: 1.5em !default;
Expand Down Expand Up @@ -92,20 +85,67 @@ $toc-back-matter-margin-top: (
prince: 0.5em
) !default;

// A hack to set page size variables in EPUB where they aren't actually used.
// Hack: set page size variables in EPUB where they aren't actually used so compile succeeds.
@if $type == 'epub' {
$page-width: 100%;
$page-margin-outside: 10%;
$page-margin-inside: 10%;
$page-width: 11in;
$page-margin-outside: 1in;
$page-margin-inside: 1in;
}

/// Title width for Table of contents.
/// Title width for left-aligned Table of contents.
/// @type String | Map
$toc-title-width: (
epub: 100% - (if-map-get($toc-left-left-gutter, 'epub') + if-map-get($toc-left-right-gutter, 'epub')),
$toc-left-title-width: (
epub: 100%,
prince: $page-width - (if-map-get($toc-left-left-gutter, 'prince') + if-map-get($toc-left-right-gutter, 'prince') + $page-margin-outside + $page-margin-inside)
) !default;

/// Title width for center-aligned Table of contents.
/// @type String | Map
/// @since 1.0.0
$toc-center-title-width: (
epub: 100%,
prince: 100%
) !default;

/// Subtitle width for left-aligned Table of contents.
/// @type String | Map
/// @since 1.0.0
$toc-left-subtitle-width: (
epub: 100%,
prince: $page-width - (if-map-get($toc-left-left-gutter, 'prince') + if-map-get($toc-left-right-gutter, 'prince') + $page-margin-outside + $page-margin-inside)
) !default;

/// Subtitle width for center-aligned Table of contents.
/// @type String | Map
/// @since 1.0.0
$toc-center-subtitle-width: 100% !default;

/// Author width for left-aligned Table of contents.
/// @type String | Map
/// @since 1.0.0
$toc-left-author-width: (
epub: 100%,
prince: $page-width - (if-map-get($toc-left-left-gutter, 'prince') + if-map-get($toc-left-right-gutter, 'prince') + $page-margin-outside + $page-margin-inside)
) !default;

/// Author width for center-aligned Table of contents.
/// @type String | Map
/// @since 1.0.0
$toc-center-author-width: 100% !default;

/// Subsection width for left-aligned Table of contents.
/// @type String | Map
/// @since 1.0.0
$toc-left-subsection-width: (
epub: 100%,
prince: $page-width - (if-map-get($toc-left-left-gutter, 'prince') + if-map-get($toc-left-right-gutter, 'prince') + $page-margin-outside + $page-margin-inside)
) !default;

/// Subsection width for center-aligned Table of contents.
/// @type String | Map
/// @since 1.0.0
$toc-center-subsection-width: 100% !default;

/// Top margin for a Table of Contents subsection.
/// @type String | Map
/// @since 1.0.0
Expand Down Expand Up @@ -512,12 +552,12 @@ $toc-section-title-font-weight: normal !default;
$toc-section-title-text-transform: none !default;

/// Display property for chapter title in left-aligned Table of Contents
/// @type String
/// @type Map
/// @since 1.0.0
$toc-left-chapter-title-display: inline-block !default;

/// Display property for subtitle in left-aligned Table of Contents
/// @type String
/// @type Map
/// @since 1.0.0
$toc-left-subtitle-display: inline-block !default;

Expand Down Expand Up @@ -577,18 +617,53 @@ $toc-back-matter-line-height: $toc-base-line-height !default;
/// @since 1.0.0
$toc-section-line-height: $toc-base-line-height !default;

/// Display property for subsections in left-aligned TOC.
/// @type String
/// @since 1.0.0
$toc-left-subsection-display: inline-block !default;

$toc-left-subsection-width: $toc-title-width !default;

/// Display property for titles in center-aligned TOC.
/// @type String
/// @since 1.0.0
$toc-center-chapter-title-display: block !default;

/// Display property for subtitles in center-aligned TOC.
/// @type String
/// @since 1.0.0
$toc-center-subtitle-display: block !default;

/// Display property for authors in center-aligned TOC.
/// @type String
/// @since 1.0.0
$toc-center-author-display: block !default;

/// Display property for subsections in center-aligned TOC.
/// @type String
/// @since 1.0.0
$toc-center-subsection-display: block !default;
$toc-center-title-width: 100% !default;
$toc-center-subsection-width: 100% !default;

/// Left gutter width in center-aligned TOC.
/// @type String | Map
/// @since 1.0.0
$toc-center-left-gutter: auto !default;

/// Right gutter width in center-aligned TOC.
/// @type String | Map
/// @since 1.0.0
$toc-center-right-gutter: auto !default;

/// Page number display in center-aligned TOC.
/// @type String
/// @since 1.0.0
$toc-center-page-number-display: block !default;

/// Part number display in center-aligned TOC.
/// @type String
/// @since 1.0.0
$toc-center-part-number-display: block !default;

/// Chapter number display in center-aligned TOC.
/// @type String
/// @since 1.0.0
$toc-center-chapter-number-display: block !default;

6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
},
"scripts": {
"test": [
"vendor/bin/pscss tests/epub.scss > tests/output/php/epub.css",
"vendor/bin/pscss tests/prince.scss > tests/output/php/prince.css",
"vendor/bin/pscss tests/epub-toc-left.scss > tests/output/php/epub-toc-left.css",
"vendor/bin/pscss tests/epub-toc-center.scss > tests/output/php/epub-toc-center.css",
"vendor/bin/pscss tests/prince-toc-left.scss > tests/output/php/prince-toc-left.css",
"vendor/bin/pscss tests/prince-toc-center.scss > tests/output/php/prince-toc-center.css",
"vendor/bin/pscss tests/web.scss > tests/output/php/web.css"
]
}
Expand Down
Loading

0 comments on commit 02756ea

Please sign in to comment.