|
| 1 | +package grails.doc.internal |
| 2 | + |
| 3 | +import grails.doc.PdfBuilder |
| 4 | +import spock.lang.Specification |
| 5 | + |
| 6 | +class PublishPDFSpec extends Specification { |
| 7 | + |
| 8 | + void "generate pdf from docs"() { |
| 9 | + when: |
| 10 | + System.setProperty('grails.docs.clean.html','true') |
| 11 | + String pdfName = 'single.pdf' |
| 12 | + def outputDir = new File('/Users/sdelamo/git/grails/grails-doc/build/docs') |
| 13 | + def currFile = new File(outputDir, "guide/single.html") |
| 14 | + def pdfBuilder = new PdfBuilder() |
| 15 | + def xml = pdfBuilder.createXml(currFile, outputDir.absolutePath) |
| 16 | + pdfBuilder.createPdf(xml, |
| 17 | + new File(currFile.parentFile, pdfName), |
| 18 | + new File(outputDir, "guide/single.html")) |
| 19 | + |
| 20 | + then: |
| 21 | + noExceptionThrown() |
| 22 | + } |
| 23 | + |
| 24 | + void "remove CssLinks"() { |
| 25 | + given: |
| 26 | + String html = """ |
| 27 | +<head> |
| 28 | + <title>The Grails Framework 3.2.11</title> |
| 29 | + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 30 | + <link rel="stylesheet" href="../css/main.css" type="text/css" media="screen, print" title="Style" charset="utf-8" /> |
| 31 | + <link rel="stylesheet" href="../css/pdf.css" type="text/css" media="print" title="PDF" charset="utf-8" /> |
| 32 | + <script type="text/javascript"> |
| 33 | +function addJsClass(el) { |
| 34 | + var classes = document.body.className.split(" "); |
| 35 | + classes.push("js"); |
| 36 | + document.body.className = classes.join(" "); |
| 37 | +} |
| 38 | + </script> |
| 39 | + </head> |
| 40 | + """ |
| 41 | + String expected = """ |
| 42 | +<head> |
| 43 | + <title>The Grails Framework 3.2.11</title> |
| 44 | + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 45 | + |
| 46 | + |
| 47 | + <script type="text/javascript"> |
| 48 | +function addJsClass(el) { |
| 49 | + var classes = document.body.className.split(" "); |
| 50 | + classes.push("js"); |
| 51 | + document.body.className = classes.join(" "); |
| 52 | +} |
| 53 | + </script> |
| 54 | + </head> |
| 55 | + """ |
| 56 | + when: |
| 57 | + String output = PdfBuilder.removeCssLinks(html) |
| 58 | + |
| 59 | + then: |
| 60 | + output == expected |
| 61 | + |
| 62 | + } |
| 63 | +} |
0 commit comments