Login  Register

Re: Include sections of files

Posted by glaforge on Apr 12, 2013; 7:49am
URL: https://discuss.asciidoctor.org/Include-sections-of-files-tp106p117.html

Looking forward to those improvements!

When would you plan the next release with the include line range capability?

Guillaume



On Thu, Apr 11, 2013 at 10:58 PM, mojavelinux [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Here's the issue about including source snippets into the document:


I've created a new issue for adding line range support to the include macro:


Feel free to comment there.

I think the line range support on include::[] can easily make it into the next release. The source snippet support may take longer.

-Dan



On Thu, Apr 11, 2013 at 11:49 AM, Dan Allen <[hidden email]> wrote:

That is precisely one of the features on the roadmap. In fact, it's high priority because we need it to migrate the Arquillian tutorials to AsciiDoc (using Asciidoctor).

Where we are right now is sorting out the syntax for marking the code to be inserted and inserting the code.

My working proposal is to tag the code as follows:

// tag: classdef


class Foo {
    static greet() { "hello" }
}
// tag: classdef

Then use a block macro to insert it:

source::foo.groovy[classdef]

I'd also like to support a resolver that could locate the file in an archive like a jar, a path like an output directory or even a URL.

I'm open to support line number ranges in the include macro, but I don't want to recommend that as the way to go because it's terribly brittle. There will be times when it is needed, so I don't want to deny that ability. I was thinking something like:

include::foo.groovy[from=1, to=3]

I'll make sure there is an issue for this feature and link it here.

-Dan

On Apr 11, 2013 10:51 AM, "glaforge [via Asciidoctor :: Discussion]" <[hidden email]> wrote:
Hi all,

I don't think the genuine AsciiDoc supports this, nor AsciiDoctor, but please tell me if I'm wrong -- I'd be happy if I were!

Is there a way to just include certain bits of a file when using the include directive?

For example, I'd like to include some code samples in a document, by splitting the included file in several sections, separated by some narrative.

More concretely, imagine a Groovy script I want to embed, called foo.groovy:

    class Foo {
        static greet() { "hello" }
    }
    assert Foo.greet() == "hello"

I wish I could say:

    Given a class:
    include::foo.groovy[startLine=1, endLine=3]
    Then you can run the following assert:
    include::foo.groovy[startLine=4, endLine=4]

And you'd get the result:

    Given a class:
    class Foo {
        static greet() { "hello" }
    }
    Then you can run the following assert:
    assert Foo.greet() == "hello"

Basically, I'm looking forward to being able to put code snippets in external files and reference them easily, sometimes in chunks, in the document, so as to have the ability to run the external scripts as part of my unit tests, ie. I was thinking of using AsciiDoctor to write "executable specifications" :-)

Guillaume


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Include-sections-of-files-tp106.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen
Principal Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597




If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Include-sections-of-files-tp106p114.html
To unsubscribe from Include sections of files, click here.
NAML



--
Guillaume Laforge
Groovy Project Manager
SpringSource, a division of VMware

Blog: http://glaforge.appspot.com/
Social: @glaforge / Google+