Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Commit

Permalink
Compatibility with Pressbooks 4.0, fixes #19.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ned Zimmerman committed Jul 9, 2017
1 parent 947c42b commit 86a869e
Show file tree
Hide file tree
Showing 30 changed files with 1,375 additions and 365 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Expand Up @@ -13,6 +13,9 @@ insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[*.md]
trim_trailing_whitespace = false

[{.jshintrc,*.json,*.yml,*.scss}]
indent_style = space
indent_size = 2
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
@@ -0,0 +1,5 @@
vendor/*
!vendor/autoload.php
!vendor/composer/*
!vendor/mpdf/*
!vendor/setasign/*
5 changes: 3 additions & 2 deletions README.md
@@ -1,2 +1,3 @@
# pressbooks-mpdf
Open source PDF generation for Pressbooks via the mPDF library.
# Pressbooks mPDF

Open source PDF generation for [Pressbooks](https://github.com/pressbooks/pressbooks) via the [mPDF](https://github.com/mpdf/mpdf) library.
19 changes: 16 additions & 3 deletions composer.json
@@ -1,5 +1,18 @@
{
"require": {
"mpdf/mpdf": "^6.1"
}
"license": "GPL-2.0+",
"type" : "wordpress-plugin",
"require": {
"mpdf/mpdf": "^6.1"
},
"require-dev": {
"humanmade/coding-standards": "^0.2.1"
},
"scripts": {
"test": [
"@standards"
],
"standards": [
"vendor/bin/phpcs --standard=phpcs.ruleset.xml *.php inc/"
]
}
}
209 changes: 196 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 7 additions & 67 deletions hooks-admin.php
@@ -1,72 +1,12 @@
<?php

/**
* Add this format to the export page formats list.
*
* @author Book Oven Inc. <code@pressbooks.com>
* @param array $formats a multidimensional array of standard and exotic formats
* @return array $formats
*/
function pb_mpdf_add_to_formats( $formats ) {
$formats['standard'] = array( 'mpdf' => __( 'PDF (mPDF)', 'pressbooks' ) ) + $formats['standard'];
return $formats;
}
add_filter( 'pb_export_formats', 'pb_mpdf_add_to_formats' );

/**
* Add this module to the export batch currently in progress.
*
* @author Book Oven Inc. <code@pressbooks.com>
* @param array $modules an array of active export module classnames
* @return array $modules
*/
function pb_mpdf_add_to_modules( $modules ) {
if ( isset( $_POST['export_formats']['mpdf'] ) ) { // @codingStandardsIgnoreLine
$modules[] = '\Pressbooks\Modules\Export\Mpdf\Pdf';
}
return $modules;
}
add_filter( 'pb_active_export_modules', 'pb_mpdf_add_to_modules' );

/**
* Add format-specific theme options to the theme options page.
*
* @author Book Oven Inc. <code@pressbooks.com>
* @param array $tabs an array of theme options tabs ('slug' => '\Classname')
* @return array $tabs
*/
function pb_mpdf_add_theme_options_tab( $tabs ) {
$tabs['mpdf'] = '\Pressbooks\Modules\ThemeOptions\MPDFOptions';
return $tabs;
}
add_filter( 'pb_theme_options_tabs', 'pb_mpdf_add_theme_options_tab' );

/**
* MPDF overrides.
* @author Brad Payne <brad@bradpayne.ca>
* @license GPLv2
* @copyright Brad Payne
*
* @param string $scss
* @return string $scss
*/
function pb_mpdf_theme_css_override( $scss ) {
$options = get_option( 'pressbooks_theme_options_mpdf' );
$global_options = get_option( 'pressbooks_theme_options_global' );

// indent paragraphs
if ( $options['mpdf_indent_paragraphs'] ) {
$scss .= "p + p, .indent {text-indent: 2.0 em; }" . "\n";
}
// hyphenation
if ( $options['mpdf_hyphens'] ) {
$scss .= "p {hyphens: auto;}" . "\n";
}
// font-size
if ( $options['mpdf_fontsize'] ){
$scss .= 'body {font-size: 1.3em; line-height: 1.3; }' . "\n";
}
// chapter numbers
if ( ! $global_options['chapter_numbers'] ) {
$scss .= "h3.chapter-number {display: none;}" . "\n";
}
return $scss;
}
add_filter( 'pb_mpdf_css_override', 'pb_mpdf_theme_css_override' );
add_filter( 'pb_export_formats', [ '\Pressbooks\Modules\Export\Mpdf\Pdf', 'addToFormats' ] );
add_filter( 'pb_active_export_modules', [ '\Pressbooks\Modules\Export\Mpdf\Pdf', 'addToModules' ] );
add_filter( 'pb_theme_options_tabs', [ '\Pressbooks\Modules\ThemeOptions\MpdfOptions', 'addTab' ] );
add_filter( 'pb_mpdf_css_override', [ '\Pressbooks\Modules\ThemeOptions\MpdfOptions', 'scssOverrides' ] );

0 comments on commit 86a869e

Please sign in to comment.