Login  Register

Re: Include with Glob expression

Posted by glaforge on Jul 01, 2013; 7:29am
URL: https://discuss.asciidoctor.org/Include-with-Glob-expression-tp357p360.html

Perhaps a way to specify that we want a special ordering, like alphabetical ordering would be good?
Because it might be quite random otherwise.
Perhaps even alphabetical by default to have a consistent orderin.

Guillaume


On Mon, Jul 1, 2013 at 9:23 AM, mojavelinux [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Alex,

I love this idea.

This feature will be unique to Asciidoctor since there's no way to extend macros like include::[] in AsciiDoc. But, it will be a much welcomed unique feature :)

One way to support this feature is to use the new extension point I've been working on for the include macro in 0.1.4. Here's how it might be implemented just to give you a taste of how the extension point works:

class GlobIncludeHandler
  def handles?(target)
    target.include? '*'
  end

  def process(document, target, attributes)
    lines = []
    matches = Dir.glob target
    matches.each do |match|
      resolved_path = document.normalize_system_path(match)
      lines.concat File.readlines(resolved_path)
      # append blank line so blocks don't get mashed together
      lines.push "\n"
    end
    lines
  end
end

Asciidoctor::Extensions.register_include_handler GlobIncludeHandler

# or...
# Asciidoctor::Extensions.register_handler :include, GlobIncludeHandler

Voila! Glob includes.

I'm fine with baking this functionality into Asciidoctor, though the extension still provides a way to override Asciidoctor's implementation in case someone has different requirements.

-Dan

Btw, I'm still looking for feedback on the include handler extension (and extensions in general) at https://github.com/asciidoctor/asciidoctor/pull/454


On Mon, Jul 1, 2013 at 12:08 AM, asotobu [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hello,

in Asciidoctor we can include external files into one document by using the include:

include::basics.adoc[]

I think it could be a nice addition if we could use a glob expression instance of a concrete file so, for example we can do something like:

include::**/narrative.txt[]

Basically I am thinking about next use case:

Developers are using Thucydides (and JBehave) for BDD. In Thucydides you can add files called narrative.txt where you can describe using plain text a description of the scenario under test. Thucydides supports AsciiDoc format in narrative.txt files but they are rendered when you run Thucydides report tool. The problem is that maybe you want to have all these scenario files being a part of your project documentation. With current include approach, you will need to add one by one all narrative files inside a parent adoc file, which could be very tedious and hard to maintain. On the other hand if you could do something like

include::**/narrative.txt[]

Then every time you render your documentation, you can be assure that the last scenarios are inserted into rendered files.

What do you think? If you find useful I can create an issue on github and implement a possible solution.

Alex.


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



--



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



--
Guillaume Laforge
Groovy Project Manager
Pivotal, Inc.

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