Class: JekyllAsciidoctorPdf::ADoc
- Inherits:
-
Object
- Object
- JekyllAsciidoctorPdf::ADoc
- Defined in:
- lib/jekyll_asciidoctor_pdf/adoc.rb
Class Method Summary collapse
-
.generateBookTypePdf(filename, filename_path, product_name, title, base_path, stream_adoc, parameters, cover_page, theme_pdf, revision, authors) ⇒ Object
We abstract the call to Asciidoctor to convert Stream => PDF.
-
.generatePdf(product_name, file, output_path, parameters, cover_page, theme_pdf, revision, authors) {|front_matter, stream_adoc| ... } ⇒ Object
Generate a PDF of an individual page.
- .getAuthorsList(file) ⇒ Object
- .getCopyright ⇒ Object
-
.getFullsiteTemplate(title, product_name, fullsite, parameters, cover_page, theme_pdf, revision, authors) ⇒ Object
Basic Template for the fullsite pdf .
Class Method Details
.generateBookTypePdf(filename, filename_path, product_name, title, base_path, stream_adoc, parameters, cover_page, theme_pdf, revision, authors) ⇒ Object
We abstract the call to Asciidoctor to convert Stream => PDF
Arguments:
- filename: name of the output file (should include extension e.i. name.pdf)
- filename_path: output path for the filename
- title: title of the cover page
- subtitle: subtitle of the cover page
- base_path: this is the root path to execture the convert process (relative :imagedir attribute use that path)
- stream_adoc: the Asciidoc file as string
- parameters: configuration from YAML file
- cover_page: absolute image for the cover page
- theme_pdf: absolute YAML file with the theme configuration of Asciidoctor-pdf
NOTE:
* We set the mode to :unsafe, due to the error "image has illegal reference to ancestor of jail;"
e.i :imagedirs: ../media
* We allow to read external files with the attribute 'allow-uri-read' => ''
e.i image:http://example.org/image.png
(we may want to block this feature is too expensive)
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/jekyll_asciidoctor_pdf/adoc.rb', line 77 def self.generateBookTypePdf(filename, filename_path, product_name, title, base_path, stream_adoc, parameters, cover_page, theme_pdf, revision, ) Asciidoctor.convert( getFullsiteTemplate(title, product_name, stream_adoc, parameters, cover_page, theme_pdf, revision, ), backend: 'pdf', doctype: 'book', to_file: filename, to_dir: filename_path, mkdirs: true, safe: :unsafe, attributes: { 'allow-uri-read' => '' }, base_dir: base_path ); end |
.generatePdf(product_name, file, output_path, parameters, cover_page, theme_pdf, revision, authors) {|front_matter, stream_adoc| ... } ⇒ Object
Generate a PDF of an individual page
- Remove the jekyll frontmatter
- Execute the convert process
- Let the caller to collect information from the front_matter and from the file itself
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jekyll_asciidoctor_pdf/adoc.rb', line 28 def self.generatePdf(product_name, file, output_path, parameters, cover_page, theme_pdf, revision, ) front_matter = {} content = File.read(file) if content =~ YAML_FRONT_MATTER_REGEXP #content = $POSTMATCH front_matter = SafeYAML.load(Regexp.last_match(1)) end stream_adoc = content.gsub(YAML_FRONT_MATTER_REGEXP, '') # We should think about the performance of get the title in that way adoc = Asciidoctor.load stream_adoc title = adoc.doctitle filename = File.basename(file,'.*') + '.pdf' filename_path = output_path base_path = File.dirname(file) #authors = getAuthorsList(file) generateBookTypePdf(filename, filename_path, product_name, title, base_path, stream_adoc, parameters, cover_page, theme_pdf, revision, ) yield(front_matter, stream_adoc) if block_given? end |
.getAuthorsList(file) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/jekyll_asciidoctor_pdf/adoc.rb', line 11 def self.getAuthorsList(file) names = %x[ git log --pretty=format:"%an" #{file} | sort | uniq ] # last_commit_date can be nil iff the file was not committed. if (names.nil? || names.empty?) return 'NetApp' end return names.split(/\n+/).join(', ') end |
.getCopyright ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/jekyll_asciidoctor_pdf/adoc.rb', line 146 def self.getCopyright() text = " <<<\n *Copyright Information*\n\n Copyright \u00A9 2019\u20132020 NetApp, Inc. All rights reserved. Printed in the U.S. No part of this document\n covered by copyright may be reproduced in any form or by any means-graphic, electronic, or\n mechanical, including photocopying, recording, taping, or storage in an electronic retrieval system-\n without prior written permission of the copyright owner.\n\n Software derived from copyrighted NetApp material is subject to the following license and disclaimer:\n\n THIS SOFTWARE IS PROVIDED BY NETAPP \u201CAS IS\u201D AND WITHOUT ANY EXPRESS OR IMPLIED\n WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WHICH ARE HEREBY\n DISCLAIMED. IN NO EVENT SHALL NETAPP BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\n OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF\n THE POSSIBILITY OF SUCH DAMAGE.\n\n NetApp reserves the right to change any products described herein at any time, and without notice.\n NetApp assumes no responsibility or liability arising from the use of products described herein, \n except as expressly agreed to in writing by NetApp. The use or purchase of this product does not \n convey a license under any patent rights, trademark rights, or any other intellectual property \n rights of NetApp.\n\n The product described in this manual may be protected by one or more U.S. patents, \n foreign patents, or pending applications.\n\n RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the government is subject to\n restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in Technical Data and \n Computer Software clause at DFARS 252.277-7103 (October 1988) and FAR 52-227-19 (June 1987).\n\n *Trademark Information*\n\n\n NETAPP, the NETAPP logo, and the marks listed at http://www.netapp.com/TM are trademarks of\n NetApp, Inc. Other company and product names may be trademarks of their respective owners.\n\n TEXT\n\n return text\nend\n" |
.getFullsiteTemplate(title, product_name, fullsite, parameters, cover_page, theme_pdf, revision, authors) ⇒ Object
Basic Template for the fullsite pdf
TODO: Add more configuracion
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/jekyll_asciidoctor_pdf/adoc.rb', line 97 def self.getFullsiteTemplate(title, product_name, fullsite, parameters, cover_page, theme_pdf, revision, ) copyright = getCopyright() fullsite_config = parameters['fullsite'] if (.nil?) = fullsite_config['authors'] else = end if (revision.nil?) revision_s = DateTime.now.strftime('%m/%d/%Y') else revision_s = revision.strftime('%m/%d/%Y') end text = " = \#{title} : \#{product_name}\n \#{authors_s}\n \#{revision_s}\n :doctype: book\n :experimental:\n :reproducible:\n :icons: font\n :listing-caption: Listing\n :imagesdir: ./media/\n :toc:\n :toclevels: 2\n ifeval::[\"{asciidoctor-version}\" < \"1.5.7\"]\n :legacy-footnoteref:\n endif::[]\n ifdef::backend-pdf[]\n :pdf-theme: \#{theme_pdf}\n :title-page:\n :title-page-background-image: image:\#{cover_page}[fit=none,pdfwidth=100%,position=top]\n :source-highlighter: rouge\n endif::[]\n :chapter-label:\n\n :leveloffset: +1\n \#{fullsite}\n :leveloffset: -1\n \#{copyright}\n TEXT\n\n return text\nend\n" |