Преглед изворни кода

Better horizontal alignment for code blocks (#68)

* Increment version number

* Better horizontal alignment of code blocks

* Use testthat 3e

* Use expect_known_output() because we need the css files

* Replace `with_mock()` with `mockery::stub()`

* Remove extraneous line

* Set ml and mr for all horiz alignment classes

* Add NEWS for #68
tags/v0.4.1
Garrick Aden-Buie пре 4 година
родитељ
комит
1ff1cc29e1
No account linked to committer's email address
24 измењених фајлова са 490 додато и 227 уклоњено
  1. +3
    -1
      DESCRIPTION
  2. +7
    -0
      NEWS.md
  3. +30
    -0
      inst/resources/template.css
  4. +30
    -0
      tests/testthat/css/duo-header_bg.css
  5. +30
    -0
      tests/testthat/css/duo.css
  6. +30
    -0
      tests/testthat/css/duo_accent.css
  7. +30
    -0
      tests/testthat/css/duo_accent_inverse.css
  8. +0
    -195
      tests/testthat/css/duo_header-bg.css
  9. +30
    -0
      tests/testthat/css/google_fonts.css
  10. +30
    -0
      tests/testthat/css/mono_accent.css
  11. +30
    -0
      tests/testthat/css/mono_accent_inverse.css
  12. +30
    -0
      tests/testthat/css/mono_dark.css
  13. +30
    -0
      tests/testthat/css/mono_light-header_bg.css
  14. +30
    -0
      tests/testthat/css/mono_light.css
  15. +30
    -0
      tests/testthat/css/solarized_dark-header_bg.css
  16. +30
    -0
      tests/testthat/css/solarized_dark.css
  17. +30
    -0
      tests/testthat/css/solarized_light.css
  18. +30
    -0
      tests/testthat/css/xaringan.css
  19. +0
    -3
      tests/testthat/google-font-print.txt
  20. +8
    -8
      tests/testthat/test-ggplot2.R
  21. +0
    -1
      tests/testthat/test-helpers.R
  22. +0
    -1
      tests/testthat/test-style_xaringan.R
  23. +20
    -15
      tests/testthat/test-themes.R
  24. +2
    -3
      tests/testthat/test-utils.R

+ 3
- 1
DESCRIPTION Прегледај датотеку

@@ -1,7 +1,7 @@
Type: Package
Package: xaringanthemer
Title: Custom 'xaringan' CSS Themes
Version: 0.4.0
Version: 0.4.0.9000
Authors@R:
person(given = "Garrick",
family = "Aden-Buie",
@@ -28,6 +28,7 @@ Imports:
utils,
whisker
Suggests:
mockery,
callr,
ggplot2,
knitr,
@@ -39,6 +40,7 @@ Suggests:
xaringan
VignetteBuilder:
knitr
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1

+ 7
- 0
NEWS.md Прегледај датотеку

@@ -1,3 +1,10 @@
# xaringanthemer (development version)

* Text alignment in code blocks in `left`, `center`, or `right` aligned slides
no longer matches the slide text. Instead, the code block width is reduced,
if possible, and the block is pushed to the left, center, or right using
margins (#68).

# xaringanthemer 0.4.0

* Added `text_bold_font_weight` argument to xaringanthemer style functions with

+ 30
- 0
inst/resources/template.css Прегледај датотеку

@@ -220,6 +220,36 @@ table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
color: var(--text-color) !important;
}

/* Horizontal alignment of code blocks */
.remark-slide-content.left pre,
.remark-slide-content.center pre,
.remark-slide-content.right pre {
text-align: start;
width: max-content;
max-width: 100%;
}
.remark-slide-content.left pre,
.remark-slide-content.right pre {
min-width: 50%;
min-width: min(40ch, 100%);
}
.remark-slide-content.center pre {
min-width: 66%;
min-width: min(50ch, 100%);
}
.remark-slide-content.left pre {
margin-left: unset;
margin-right: auto;
}
.remark-slide-content.center pre {
margin-left: auto;
margin-right: auto;
}
.remark-slide-content.right pre {
margin-left: auto;
margin-right: unset;
}

{{#header_background}}
/* Slide Header Background for h1 elements */
.remark-slide-content.header_background > h1{{#auto}},

+ 30
- 0
tests/testthat/css/duo-header_bg.css Прегледај датотеку

@@ -212,6 +212,36 @@ table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
color: var(--text-color) !important;
}

/* Horizontal alignment of code blocks */
.remark-slide-content.left pre,
.remark-slide-content.center pre,
.remark-slide-content.right pre {
text-align: start;
width: max-content;
max-width: 100%;
}
.remark-slide-content.left pre,
.remark-slide-content.right pre {
min-width: 50%;
min-width: min(40ch, 100%);
}
.remark-slide-content.center pre {
min-width: 66%;
min-width: min(50ch, 100%);
}
.remark-slide-content.left pre {
margin-left: unset;
margin-right: auto;
}
.remark-slide-content.center pre {
margin-left: auto;
margin-right: auto;
}
.remark-slide-content.right pre {
margin-left: auto;
margin-right: unset;
}

/* Slide Header Background for h1 elements */
.remark-slide-content.header_background > h1,
.remark-slide-content:not(.normal):not(.inverse):not(.title):not(.middle):not(.bottom) > h1 {

+ 30
- 0
tests/testthat/css/duo.css Прегледај датотеку

@@ -212,6 +212,36 @@ table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
color: var(--text-color) !important;
}

/* Horizontal alignment of code blocks */
.remark-slide-content.left pre,
.remark-slide-content.center pre,
.remark-slide-content.right pre {
text-align: start;
width: max-content;
max-width: 100%;
}
.remark-slide-content.left pre,
.remark-slide-content.right pre {
min-width: 50%;
min-width: min(40ch, 100%);
}
.remark-slide-content.center pre {
min-width: 66%;
min-width: min(50ch, 100%);
}
.remark-slide-content.left pre {
margin-left: unset;
margin-right: auto;
}
.remark-slide-content.center pre {
margin-left: auto;
margin-right: auto;
}
.remark-slide-content.right pre {
margin-left: auto;
margin-right: unset;
}

/* Slide Header Background for h1 elements */
.remark-slide-content.header_background > h1 {
display: block;

+ 30
- 0
tests/testthat/css/duo_accent.css Прегледај датотеку

@@ -214,6 +214,36 @@ table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
color: var(--text-color) !important;
}

/* Horizontal alignment of code blocks */
.remark-slide-content.left pre,
.remark-slide-content.center pre,
.remark-slide-content.right pre {
text-align: start;
width: max-content;
max-width: 100%;
}
.remark-slide-content.left pre,
.remark-slide-content.right pre {
min-width: 50%;
min-width: min(40ch, 100%);
}
.remark-slide-content.center pre {
min-width: 66%;
min-width: min(50ch, 100%);
}
.remark-slide-content.left pre {
margin-left: unset;
margin-right: auto;
}
.remark-slide-content.center pre {
margin-left: auto;
margin-right: auto;
}
.remark-slide-content.right pre {
margin-left: auto;
margin-right: unset;
}

/* Slide Header Background for h1 elements */
.remark-slide-content.header_background > h1 {
display: block;

+ 30
- 0
tests/testthat/css/duo_accent_inverse.css Прегледај датотеку

@@ -214,6 +214,36 @@ table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
color: var(--text-color) !important;
}

/* Horizontal alignment of code blocks */
.remark-slide-content.left pre,
.remark-slide-content.center pre,
.remark-slide-content.right pre {
text-align: start;
width: max-content;
max-width: 100%;
}
.remark-slide-content.left pre,
.remark-slide-content.right pre {
min-width: 50%;
min-width: min(40ch, 100%);
}
.remark-slide-content.center pre {
min-width: 66%;
min-width: min(50ch, 100%);
}
.remark-slide-content.left pre {
margin-left: unset;
margin-right: auto;
}
.remark-slide-content.center pre {
margin-left: auto;
margin-right: auto;
}
.remark-slide-content.right pre {
margin-left: auto;
margin-right: unset;
}

/* Slide Header Background for h1 elements */
.remark-slide-content.header_background > h1 {
display: block;

+ 0
- 195
tests/testthat/css/duo_header-bg.css Прегледај датотеку

@@ -1,195 +0,0 @@
/* -------------------------------------------------------
*
* !! This file was generated by xaringanthemer !!
*
* Changes made to this file directly will be overwritten
* if you used xaringanthemer in your xaringan slides Rmd
*
* Issues or likes?
* - https://github.com/gadenbuie/xaringanthemer
* - https://www.garrickadenbuie.com
*
* Need help? Try:
* - vignette(package = "xaringanthemer")
* - ?xaringanthemer::write_xaringan_theme
* - xaringan wiki: https://github.com/yihui/xaringan/wiki
* - remarkjs wiki: https://github.com/gnab/remark/wiki
*
* Version: a.b.c.d.eeee
*
* ------------------------------------------------------- */
@import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic);
@import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz);
@import url(https://fonts.googleapis.com/css?family=Source+Code+Pro:400,700);


body {
font-family: 'Droid Serif', 'Palatino Linotype', 'Book Antiqua', Palatino, 'Microsoft YaHei', 'Songti SC', serif;
font-weight: normal;
color: #FEFDFD;
}
h1, h2, h3 {
font-family: 'Yanone Kaffeesatz';
font-weight: normal;
color: #F97B64;
}
.remark-slide-content {
background-color: #1F4257;
font-size: 20px;
padding: 1rem 4rem 1rem 4rem;
}
.remark-slide-content h1 {
font-size: 55px;
}
.remark-slide-content h2 {
font-size: 45px;
}
.remark-slide-content h3 {
font-size: 35px;
}
.remark-code, .remark-inline-code {
font-family: 'Source Code Pro', 'Lucida Console', Monaco, monospace;
}
.remark-code {
font-size: 0.9em;
}
.remark-inline-code {
color: #F97B64;
font-size: 1em;
}
.remark-slide-number {
color: #FEFDFD;
opacity: 1;
font-size: 0.9em;
}
strong { color: #F97B64; }
a, a > code {
color: #F97B64;
text-decoration: none;
}
.footnote {
position: absolute;
bottom: 3em;
padding-right: 4em;
font-size: 0.9em;
}
.remark-code-line-highlighted {
background-color: rgba(255,255,0,0.5);
}
.inverse {
background-color: #F97B64;
color: #1F4257;
}
.inverse h1, .inverse h2, .inverse h3 {
color: #1F4257;
}
.title-slide, .title-slide h1, .title-slide h2, .title-slide h3 {
color: #F97B64;
}
.title-slide {
background-color: #1F4257;
}
.title-slide .remark-slide-number {
display: none;
}
/* Two-column layout */
.left-column {
width: 20%;
height: 92%;
float: left;
}
.left-column h2, .left-column h3 {
color: #F97B6499;
}
.left-column h2:last-of-type, .left-column h3:last-child {
color: #F97B64;
}
.right-column {
width: 75%;
float: right;
padding-top: 1em;
}
.pull-left {
float: left;
width: 47%;
}
.pull-right {
float: right;
width: 47%;
}
.pull-right ~ * {
clear: both;
}
img, video, iframe {
max-width: 100%;
}
blockquote {
border-left: solid 5px #F97B6480;
padding-left: 1em;
}
.remark-slide table {
margin: auto;
border-top: 1px solid #666;
border-bottom: 1px solid #666;
}
.remark-slide table thead th {
border-bottom: 1px solid #ddd;
}
th, td {
padding: 5px;
}
.remark-slide thead, .remark-slide tfoot, .remark-slide tr:nth-child(even) {
background: #627A89;
}
table.dataTable tbody {
background-color: #1F4257;
color: #FEFDFD;
}
table.dataTable.display tbody tr.odd {
background-color: #1F4257;
}
table.dataTable.display tbody tr.even {
background-color: #627A89;
}
table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
background-color: rgba(255, 255, 255, 0.5);
}
.dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_processing, .dataTables_wrapper .dataTables_paginate {
color: #FEFDFD;
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
color: #FEFDFD !important;
}

/* Slide Header Background for h1 elements */
.remark-slide-content:not(.normal):not(.inverse):not(.title):not(.middle):not(.bottom) > h1 {
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
background: #F97B64;
color: #1F4257;
padding: 2rem 4rem 1.5rem 4rem;
margin-top: 0;
box-sizing: border-box;
}
.remark-slide-content:not(.normal):not(.inverse):not(.title):not(.middle):not(.bottom) {
padding-top: 7rem;
}

@page { margin: 0; }
@media print {
.remark-slide-scaler {
width: 100% !important;
height: 100% !important;
transform: scale(1) !important;
top: 0 !important;
left: 0 !important;
}
}

+ 30
- 0
tests/testthat/css/google_fonts.css Прегледај датотеку

@@ -208,6 +208,36 @@ table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
color: var(--text-color) !important;
}

/* Horizontal alignment of code blocks */
.remark-slide-content.left pre,
.remark-slide-content.center pre,
.remark-slide-content.right pre {
text-align: start;
width: max-content;
max-width: 100%;
}
.remark-slide-content.left pre,
.remark-slide-content.right pre {
min-width: 50%;
min-width: min(40ch, 100%);
}
.remark-slide-content.center pre {
min-width: 66%;
min-width: min(50ch, 100%);
}
.remark-slide-content.left pre {
margin-left: unset;
margin-right: auto;
}
.remark-slide-content.center pre {
margin-left: auto;
margin-right: auto;
}
.remark-slide-content.right pre {
margin-left: auto;
margin-right: unset;
}

/* Slide Header Background for h1 elements */
.remark-slide-content.header_background > h1 {
display: block;

+ 30
- 0
tests/testthat/css/mono_accent.css Прегледај датотеку

@@ -213,6 +213,36 @@ table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
color: var(--text-color) !important;
}

/* Horizontal alignment of code blocks */
.remark-slide-content.left pre,
.remark-slide-content.center pre,
.remark-slide-content.right pre {
text-align: start;
width: max-content;
max-width: 100%;
}
.remark-slide-content.left pre,
.remark-slide-content.right pre {
min-width: 50%;
min-width: min(40ch, 100%);
}
.remark-slide-content.center pre {
min-width: 66%;
min-width: min(50ch, 100%);
}
.remark-slide-content.left pre {
margin-left: unset;
margin-right: auto;
}
.remark-slide-content.center pre {
margin-left: auto;
margin-right: auto;
}
.remark-slide-content.right pre {
margin-left: auto;
margin-right: unset;
}

/* Slide Header Background for h1 elements */
.remark-slide-content.header_background > h1 {
display: block;

+ 30
- 0
tests/testthat/css/mono_accent_inverse.css Прегледај датотеку

@@ -213,6 +213,36 @@ table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
color: var(--text-color) !important;
}

/* Horizontal alignment of code blocks */
.remark-slide-content.left pre,
.remark-slide-content.center pre,
.remark-slide-content.right pre {
text-align: start;
width: max-content;
max-width: 100%;
}
.remark-slide-content.left pre,
.remark-slide-content.right pre {
min-width: 50%;
min-width: min(40ch, 100%);
}
.remark-slide-content.center pre {
min-width: 66%;
min-width: min(50ch, 100%);
}
.remark-slide-content.left pre {
margin-left: unset;
margin-right: auto;
}
.remark-slide-content.center pre {
margin-left: auto;
margin-right: auto;
}
.remark-slide-content.right pre {
margin-left: auto;
margin-right: unset;
}

/* Slide Header Background for h1 elements */
.remark-slide-content.header_background > h1 {
display: block;

+ 30
- 0
tests/testthat/css/mono_dark.css Прегледај датотеку

@@ -213,6 +213,36 @@ table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
color: var(--text-color) !important;
}

/* Horizontal alignment of code blocks */
.remark-slide-content.left pre,
.remark-slide-content.center pre,
.remark-slide-content.right pre {
text-align: start;
width: max-content;
max-width: 100%;
}
.remark-slide-content.left pre,
.remark-slide-content.right pre {
min-width: 50%;
min-width: min(40ch, 100%);
}
.remark-slide-content.center pre {
min-width: 66%;
min-width: min(50ch, 100%);
}
.remark-slide-content.left pre {
margin-left: unset;
margin-right: auto;
}
.remark-slide-content.center pre {
margin-left: auto;
margin-right: auto;
}
.remark-slide-content.right pre {
margin-left: auto;
margin-right: unset;
}

/* Slide Header Background for h1 elements */
.remark-slide-content.header_background > h1 {
display: block;

+ 30
- 0
tests/testthat/css/mono_light-header_bg.css Прегледај датотеку

@@ -213,6 +213,36 @@ table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
color: var(--text-color) !important;
}

/* Horizontal alignment of code blocks */
.remark-slide-content.left pre,
.remark-slide-content.center pre,
.remark-slide-content.right pre {
text-align: start;
width: max-content;
max-width: 100%;
}
.remark-slide-content.left pre,
.remark-slide-content.right pre {
min-width: 50%;
min-width: min(40ch, 100%);
}
.remark-slide-content.center pre {
min-width: 66%;
min-width: min(50ch, 100%);
}
.remark-slide-content.left pre {
margin-left: unset;
margin-right: auto;
}
.remark-slide-content.center pre {
margin-left: auto;
margin-right: auto;
}
.remark-slide-content.right pre {
margin-left: auto;
margin-right: unset;
}

/* Slide Header Background for h1 elements */
.remark-slide-content.header_background > h1,
.remark-slide-content:not(.normal):not(.inverse):not(.title):not(.middle):not(.bottom) > h1 {

+ 30
- 0
tests/testthat/css/mono_light.css Прегледај датотеку

@@ -213,6 +213,36 @@ table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
color: var(--text-color) !important;
}

/* Horizontal alignment of code blocks */
.remark-slide-content.left pre,
.remark-slide-content.center pre,
.remark-slide-content.right pre {
text-align: start;
width: max-content;
max-width: 100%;
}
.remark-slide-content.left pre,
.remark-slide-content.right pre {
min-width: 50%;
min-width: min(40ch, 100%);
}
.remark-slide-content.center pre {
min-width: 66%;
min-width: min(50ch, 100%);
}
.remark-slide-content.left pre {
margin-left: unset;
margin-right: auto;
}
.remark-slide-content.center pre {
margin-left: auto;
margin-right: auto;
}
.remark-slide-content.right pre {
margin-left: auto;
margin-right: unset;
}

/* Slide Header Background for h1 elements */
.remark-slide-content.header_background > h1 {
display: block;

+ 30
- 0
tests/testthat/css/solarized_dark-header_bg.css Прегледај датотеку

@@ -210,6 +210,36 @@ table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
color: var(--text-color) !important;
}

/* Horizontal alignment of code blocks */
.remark-slide-content.left pre,
.remark-slide-content.center pre,
.remark-slide-content.right pre {
text-align: start;
width: max-content;
max-width: 100%;
}
.remark-slide-content.left pre,
.remark-slide-content.right pre {
min-width: 50%;
min-width: min(40ch, 100%);
}
.remark-slide-content.center pre {
min-width: 66%;
min-width: min(50ch, 100%);
}
.remark-slide-content.left pre {
margin-left: unset;
margin-right: auto;
}
.remark-slide-content.center pre {
margin-left: auto;
margin-right: auto;
}
.remark-slide-content.right pre {
margin-left: auto;
margin-right: unset;
}

/* Slide Header Background for h1 elements */
.remark-slide-content.header_background > h1,
.remark-slide-content:not(.normal):not(.inverse):not(.title):not(.middle):not(.bottom) > h1 {

+ 30
- 0
tests/testthat/css/solarized_dark.css Прегледај датотеку

@@ -210,6 +210,36 @@ table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
color: var(--text-color) !important;
}

/* Horizontal alignment of code blocks */
.remark-slide-content.left pre,
.remark-slide-content.center pre,
.remark-slide-content.right pre {
text-align: start;
width: max-content;
max-width: 100%;
}
.remark-slide-content.left pre,
.remark-slide-content.right pre {
min-width: 50%;
min-width: min(40ch, 100%);
}
.remark-slide-content.center pre {
min-width: 66%;
min-width: min(50ch, 100%);
}
.remark-slide-content.left pre {
margin-left: unset;
margin-right: auto;
}
.remark-slide-content.center pre {
margin-left: auto;
margin-right: auto;
}
.remark-slide-content.right pre {
margin-left: auto;
margin-right: unset;
}

/* Slide Header Background for h1 elements */
.remark-slide-content.header_background > h1 {
display: block;

+ 30
- 0
tests/testthat/css/solarized_light.css Прегледај датотеку

@@ -210,6 +210,36 @@ table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
color: var(--text-color) !important;
}

/* Horizontal alignment of code blocks */
.remark-slide-content.left pre,
.remark-slide-content.center pre,
.remark-slide-content.right pre {
text-align: start;
width: max-content;
max-width: 100%;
}
.remark-slide-content.left pre,
.remark-slide-content.right pre {
min-width: 50%;
min-width: min(40ch, 100%);
}
.remark-slide-content.center pre {
min-width: 66%;
min-width: min(50ch, 100%);
}
.remark-slide-content.left pre {
margin-left: unset;
margin-right: auto;
}
.remark-slide-content.center pre {
margin-left: auto;
margin-right: auto;
}
.remark-slide-content.right pre {
margin-left: auto;
margin-right: unset;
}

/* Slide Header Background for h1 elements */
.remark-slide-content.header_background > h1 {
display: block;

+ 30
- 0
tests/testthat/css/xaringan.css Прегледај датотеку

@@ -209,6 +209,36 @@ table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
color: var(--text-color) !important;
}

/* Horizontal alignment of code blocks */
.remark-slide-content.left pre,
.remark-slide-content.center pre,
.remark-slide-content.right pre {
text-align: start;
width: max-content;
max-width: 100%;
}
.remark-slide-content.left pre,
.remark-slide-content.right pre {
min-width: 50%;
min-width: min(40ch, 100%);
}
.remark-slide-content.center pre {
min-width: 66%;
min-width: min(50ch, 100%);
}
.remark-slide-content.left pre {
margin-left: unset;
margin-right: auto;
}
.remark-slide-content.center pre {
margin-left: auto;
margin-right: auto;
}
.remark-slide-content.right pre {
margin-left: auto;
margin-right: unset;
}

/* Slide Header Background for h1 elements */
.remark-slide-content.header_background > h1 {
display: block;

+ 0
- 3
tests/testthat/google-font-print.txt Прегледај датотеку

@@ -1,3 +0,0 @@
Family: Josefin Sans
Weights: 400,400i,600i,700
URL: https://fonts.googleapis.com/css?family=Josefin+Sans:400,400i,600i,700&display=swap

+ 8
- 8
tests/testthat/test-ggplot2.R Прегледај датотеку

@@ -502,10 +502,10 @@ describe("scale_xaringan_*", {
test_that("register_font() returns the name of the font family if {showtext} is missing", {
text_font_family <- xaringanthemer_font_default("text_font_family")

family_showtext_missing <- testthat::with_mock(
`xaringanthemer:::requires_package` = function(pkg, ...) pkg != "showtext",
register_font(text_font_family, google = TRUE)
)
# Pretend like {showtext} is missing
mockery::stub(register_font, "requires_package", function(pkg, ...) pkg != "showtext")
family_showtext_missing <- register_font(text_font_family, google = TRUE)

expect_equal(family_showtext_missing, text_font_family)
})
@@ -515,10 +515,10 @@ test_that("register_font() returns the name of the font family if {sysfonts} is

text_font_family <- xaringanthemer_font_default("text_font_family")

family_sysfonts_missing <- testthat::with_mock(
`xaringanthemer:::requires_package` = function(pkg, ...) pkg != "sysfonts",
register_font(text_font_family, google = TRUE)
)
# Pretend like {sysfonts} is missing
mockery::stub(register_font, "requires_package", function(pkg, ...) pkg != "sysfonts")
family_sysfonts_missing <- register_font(text_font_family, google = TRUE)

expect_equal(family_sysfonts_missing, text_font_family)
})

+ 0
- 1
tests/testthat/test-helpers.R Прегледај датотеку

@@ -1,4 +1,3 @@
context("test-helpers")

test_that("element_description", {
text_in <- c("multiple", NA, "", ".remark-slide-content", "h1", "pre, code")

+ 0
- 1
tests/testthat/test-style_xaringan.R Прегледај датотеку

@@ -1,4 +1,3 @@
context("test-style_xaringan")

test_that("style_xaringan() writes to specified outfile", {
tmpfile <- tempfile(fileext = ".css")

+ 20
- 15
tests/testthat/test-themes.R Прегледај датотеку

@@ -1,6 +1,8 @@
context("test-themes")

test_theme_file <- function(theme = "duo", theme_file = paste0(theme, ".css"), ...) {
local_edition(2)
on.exit(local_edition(3))

theme_fun <- switch(
theme,
"duo" = style_duo,
@@ -16,6 +18,7 @@ test_theme_file <- function(theme = "duo", theme_file = paste0(theme, ".css"), .
)

tmpfile <- tempfile()
on.exit(unlink(tmpfile), add = TRUE)

theme_fun(outfile = tmpfile, ..., text_font_google = google_font("Noto Serif"))
theme_css <- readLines(tmpfile)
@@ -25,20 +28,22 @@ test_theme_file <- function(theme = "duo", theme_file = paste0(theme, ".css"), .
expect_known_output(cat(theme_css), test_path("css", theme_file))
}

test_that("style_duo()", test_theme_file("duo"))
test_that("style_duo_accent()", test_theme_file("duo_accent"))
test_that("style_duo_accent_inverse()", test_theme_file("duo_accent_inverse"))
test_that("style_mono_accent()", test_theme_file("mono_accent"))
test_that("style_mono_accent_inverse()", test_theme_file("mono_accent_inverse"))
test_that("style_mono_dark()", test_theme_file("mono_dark"))
test_that("style_mono_light()", test_theme_file("mono_light"))
test_that("style_solarized_dark()", test_theme_file("solarized_dark"))
test_that("style_solarized_light()", test_theme_file("solarized_light"))
test_that("google fonts in theme", test_theme_file(
"google_fonts",
header_font_google = google_font("IBM Plex Serif", "700"),
code_font_google = google_font("IBM Plex Mono")
))
test_that("style_duo()", { test_theme_file("duo") })
test_that("style_duo_accent()", { test_theme_file("duo_accent") })
test_that("style_duo_accent_inverse()", { test_theme_file("duo_accent_inverse") })
test_that("style_mono_accent()", { test_theme_file("mono_accent") })
test_that("style_mono_accent_inverse()", { test_theme_file("mono_accent_inverse") })
test_that("style_mono_dark()", { test_theme_file("mono_dark") })
test_that("style_mono_light()", { test_theme_file("mono_light") })
test_that("style_solarized_dark()", { test_theme_file("solarized_dark") })
test_that("style_solarized_light()", { test_theme_file("solarized_light") })
test_that("google fonts in theme", {
test_theme_file(
"google_fonts",
header_font_google = google_font("IBM Plex Serif", "700"),
code_font_google = google_font("IBM Plex Mono")
)
})

test_that("header_background_auto = TRUE", {
test_theme_file("duo", "duo-header_bg.css", header_background_auto = TRUE)

+ 2
- 3
tests/testthat/test-utils.R Прегледај датотеку

@@ -1,7 +1,6 @@
test_that("printing google_font works", {
expect_known_output(
print(google_font("Josefin Sans", "400", "400i", "600i", "700")),
"google-font-print.txt"
expect_snapshot(
google_font("Josefin Sans", "400", "400i", "600i", "700")
)
})


Loading…
Откажи
Сачувај