Skip to content

Extract content from a file #4

@dadoonet

Description

@dadoonet

Today we are somehow building static content. I mean content provided within .asciidoc files only.

In Maven land, when you generate the website which contains documentation, you can use Snippets.

It's really handy because you can extract a content to your documentation and this content comes from the source code itself.
It basically means that when a developper changes whatever part of code, the documentation is automatically updated with the new content. If the developper does not update the code, it will most likely not compile anymore.

I'd encourage doing the same thing with our doc build process and try to use the same convention as in Maven land:

// START SNIPPET: snip-id
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
// END SNIPPET: snip-id

The snippet is extracted within two lines containing START SNIPPET and END SNIPPET. Optionally the snipper might have an id in case you have more than one snippet per file.

Most likely snippet start and end tags are provided within comments depending on the language you are using.

For example, in xml, it could be:

<!-- START SNIPPET: snip-id -->
            <dependency>
                <groupId>org.elasticsearch</groupId>
                <artifactId>elasticsearch</artifactId>
                <version>1.5.0</version>
            </dependency>
<!-- END SNIPPET: snip-id -->

To use it, you can add the following to your asciidoc file (example/java.asciidoc):

== This is my doc

[source,java]
--------------------------------------------------
%{snippet|id=snip-id|url=file:///path/to/Sample.java}
--------------------------------------------------

The idea of this change is to first parse all existing documentation files and copy them to another build_dir in case they changed (or at each run).

In the previous example, a file named build_dir/example/java.asciidoc will be created and will contain:

== This is my doc

[source,java]
--------------------------------------------------
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
--------------------------------------------------

Opening this issue now here to open discussion and see if the process I described is the right way for doing that. If so, I think this is something which should be implemented in perl within the build_docs.pl script.

@clintongormley WDYT?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions