generate_pdf.groovy 1.6 KB
Newer Older
Jorge Aguilera's avatar
Jorge Aguilera committed
1
println """= 101 Groovy Script : que en mi local funcionan
Jorge Aguilera's avatar
Jorge Aguilera committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Varios
{buildVersion}
:id: 101-groovy-scripts
:doctype: book
:producer: Asciidoctor
:keywords: Asciidoctor, samples, e-book, EPUB3, KF8, MOBI, Asciidoctor.js
:copyright: CC-BY-SA 3.0
// NOTE anthology adds support for an author per chapter; use book for a single author
:publication-type: anthology
:idprefix:
:idseparator: -
:front-cover-image: image:portada.jpg[Front Cover,1050,1600]
:toc: left
:toclevels: 4
:leveloffset: 1
:media: print
:source-highlighter: rouge
:pdf-stylesdir: theme
:pdf-style: custom
:autofit-option:

include::../../jbake/content/index.adoc[]
"""
25
files = [:]
Jorge Aguilera's avatar
Jorge Aguilera committed
26 27 28 29 30 31 32 33 34 35

void scanDir( File dir ){
    dir.listFiles().findAll{!it.isDirectory()}.sort{it.name}.each{ f->
        if( !f.name.endsWith('.adoc'))
            return
        if( ["index.adoc","index-en.adoc","about.adoc","about-en.adoc",'plantuml.adoc'].contains(f.name))
            return
        if( f.name.endsWith('-en.adoc'))
            return

36 37 38 39 40
        String when = f.text.split('\n')[2]
        if( when.startsWith("if")) println f.name
        List list = files[when] ?: []
        list.add f
        files[when] = list
Jorge Aguilera's avatar
Jorge Aguilera committed
41 42 43 44 45 46 47 48 49
    }
    dir.listFiles().findAll{it.isDirectory()}.sort{it.name}.each{ d ->
        if( ['slides','js'].contains(d.name))
            return
        scanDir(d)
    }
}

scanDir(new File("src/jbake/content/"))
Jorge Aguilera's avatar
Jorge Aguilera committed
50
files.values().flatten().each{ f->
51 52 53 54 55 56 57 58 59
    String text = f.text.split('\n').find{
        it.startsWith(":jbake-script:")
    } ?: ''

     println """<<<<
$text
include::../../jbake/content/${f.parentFile.name}/${f.name}[]"""
}
//files.keySet().each{ println it}