Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide access to the sourceDir value as attribute #292

Closed
jmini opened this issue Feb 26, 2019 · 4 comments
Closed

Provide access to the sourceDir value as attribute #292

jmini opened this issue Feb 26, 2019 · 4 comments
Labels
2.x Issue related to the 2.x series enhancement
Milestone

Comments

@jmini
Copy link
Contributor

jmini commented Feb 26, 2019

Similar to gradle-rootdir, it would be great if the gradle plugin could provide access to the configured sourceDir.

Use case:

Project
├── docs
│   ├── index.adoc
│   └── other
│       └── other.adoc
└── build.gradle

With this configuration in build.gradle:

asciidoctor {
    sourceDir = file('docs')
    outputDir = file('build/docs')
    backends = ['html5']
    //..
    attributes = ['source-highlighter': 'highlightjs',
                  'highlightjs-theme' : 'github-gist',
                  //
                  ]
}

When using highlightjs, the output looks like this:

build/docs/html5/
├── other
│   └── other.html
├── index.html
└── highlight
    ├── highlight.min.js
    └── styles
        └── github-gist.min.css

The value of highlightjsdir depends from the position of the file relatively to the sourceDir value.

The generated output should be:

For index.html:

<link rel="stylesheet" href="highlight/styles/github-gist.min.css">
<script src="highlight/highlight.min.js"></script>

For other/other.html it should be:

<link rel="stylesheet" href=“../highlight/styles/github-gist.min.css">
<script src=“../highlight/highlight.min.js"></script>

It the gradle plugin would provide a gradle-sourcedir attribute with following value (relative path of sourceDir for the docfile being converted):

  • empty string for docs/index.adoc
  • ../ for docs/other/other.adoc

It would be possible to use it like this:

:highlightjsdir: {gradle-sourcedir}highlight

In the mean time, I have solved it with a preprocessor: https://jmini.github.io/asciidoctorj-sourcedir/

@ysb33r
Copy link
Member

ysb33r commented Feb 26, 2019

Could you solve this with the includedir attribute?

@jmini
Copy link
Contributor Author

jmini commented Feb 28, 2019

Thank you for your feedback.

I am not sure what you mean with includedir, I just found a reference here:
https://asciidoctor.org/docs/user-manual/#include-resolution


I have something similar to the setup described here in this project: doc-as-code-demo.

Each files "knows" its location because I add following on top of each of my files:

// {root} shoud point to the `docs/` folder:
ifndef::root[]
:root: ../
endif::[]

The root value is equals to the gradle-sourcedir I am describing here in this case.


But my setup goes a little bit further, next to the docs/ folder I also have a publish/ folder that creates the final documents (they pick content from the files docs/ folder).

I run gradle either with sourceDir set to docs/ or to publish/.

Project
├── docs
│   ├── index.adoc
│   └── other
│       └── other.adoc
├── publish
│   ├── overview-guide.adoc
│   └── advanced
│       ├── topic1-guide.adoc
│       └── topic2-guide.adoc
└── build.gradle

And in this case, because of my definition of {root} pointing to the docs/ folder, the gradle-sourcedir value is not the same.

NB: this current approach has also some drawbacks, so I might change it in the future...

@ysb33r ysb33r added this to the 2.1.0 milestone Mar 22, 2019
@ysb33r ysb33r mentioned this issue Mar 22, 2019
28 tasks
@ysb33r
Copy link
Member

ysb33r commented Apr 11, 2019

Will add this to 2.1.0. The attribute will be called gradle-relative-srcdir

ysb33r added a commit to ysb33r/asciidoctor-gradle-plugin that referenced this issue Apr 11, 2019
Add this attribute to show the relative path of the containing
directory of the current document that is being processed, to
the source root (i.e. `asciidoctor.sourceDir`).
@ysb33r ysb33r mentioned this issue Apr 11, 2019
@bric3
Copy link
Contributor

bric3 commented Oct 9, 2019

Hi, is it possible to use gradle-relative-srcdir as part of the attributes declared in the asciidoctorj task? In the setup below it does not work but maybe there's some way to do it. Otherwise it imposes to define in all documents highlightjsdir and stylesdir.

attributes = [
        'snippets'          : snippetsDir,
        'source-highlighter': 'highlight.js',
        'highlightjs-theme' : 'gruvbox-dark',
        'highlightjsdir'    : '{gradle-relative-srcdir}/highlight',
        'stylesheet'        : 'asciidark.css',
        'stylesdir'         : '{gradle-relative-srcdir}',
        'linkcss'           : 'true',
        'encoding'          : 'utf-8'
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x Issue related to the 2.x series enhancement
Projects
None yet
Development

No branches or pull requests

4 participants