Login  Register

Output single adoc file from includes?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Output single adoc file from includes?

Chuck
Hi,

I'm either missing the instruction to do this and you may direct me to the instruction or point me where to enter a feature request, as appropriate.

I have an adoc file which contains many include files to make the final document. Is there a way to output a single adoc  file which contains the contents of the various include files via the asciidoctor command?

Thanks,

Chuck
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Output single adoc file from includes?

graphitefriction
Administrator
Hi Chuck,

You can output a single adoc file using the following Ruby script. Just replace the sample.adoc names with your file name, and remove the -- from the top and bottom of the script.

--
require 'asciidoctor'

source = File.read 'sample.adoc'
doc = Asciidoctor::Document.new
reader = Asciidoctor::PreprocessorReader.new doc, source
combined_source = reader.read
File.open('sample-combined.adoc', 'w') {|f| f.write combined_source }
--

Save the script with the extension .rb in the directory with your docs.
Then, in your terminal, navigate to the directory where you saved the ruby script and type the following command to execute the file with Ruby:

 ruby <script-name>.rb

Note: I didn't write the script, it's courtesy of @mojavelinux, because I'm also rendering lots of files with lots of includes :D

I don't know how to preprocess includes from the CLI alone, but maybe @mojavelinux will have some tips.

Cheers,

Sarah
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Output single adoc file from includes?

mojavelinux
Administrator
Chuck,

I realized there is a little bit more to this story after having used it myself. It's necessary to parse the header of the document before passing it to the reader.

Here's the script I'm using.

[source,ruby]
--
require 'asciidoctor'

source_file = ARGV[0]
if !source_file
  warn 'You must provide a source file'
  exit 1
end
output_file = source_file.sub(/\.adoc$/, '-preprocessed.adoc')
source = File.read source_file
doc = Asciidoctor.load_file ARGV[0], :safe => :safe, :parse_header_only => true
reader = Asciidoctor::PreprocessorReader.new doc, source
preprocessed_source = reader.read.gsub(/^include::/, '\\include::')
File.open(output_file, 'w') {|f| f.write preprocessed_source }
--

I think this would be a nice feature to put into the Asciidoctor API. Perhaps an option `:preprocess_only => true` and a corresponding cli flag. wdyt?

-Dan


On Tue, Oct 15, 2013 at 10:24 PM, graphitefriction [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hi Chuck,

You can output a single adoc file using the following Ruby script. Just replace the sample.adoc names with your file name, and remove the -- from the top and bottom of the script.

--
require 'asciidoctor'

source = File.read 'sample.adoc'
doc = Asciidoctor::Document.new
reader = Asciidoctor::PreprocessorReader.new doc, source
combined_source = reader.read
File.open('sample-combined.adoc', 'w') {|f| f.write combined_source }
--

Save the script with the extension .rb in the directory with your docs.
Then, in your terminal, navigate to the directory where you saved the ruby script and type the following command to execute the file with Ruby:

 ruby <script-name>.rb

Note: I didn't write the script, it's courtesy of @mojavelinux, because I'm also rendering lots of files with lots of includes :D

I don't know how to preprocess includes from the CLI alone, but maybe @mojavelinux will have some tips.

Cheers,

Sarah


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Output-single-adoc-file-from-includes-tp808p809.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Output single adoc file from includes?

asotobu
Hi, I have been reading this entry and I think I am missing something important. Let me explain:

I have a project with 4 AsciiDoc file. One parent file which has three include directives, that includes  each file. Then I render the parent file using Asciidoctor-Maven-Plugin and the output is only one html file with content of all files rendered inside.

So I think I am missing something about the problem presented here.  
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Output single adoc file from includes?

mojavelinux
Administrator

Alex,

This is more about diagnostics. It's when you want to see, or retrieve, the effective AsciiDoc source as the processor sees it once all the preprocessor directives are evaluated (e.g., include, ifdef, etc)

For instance, I needed a single source file version of the quick reference for the asciidoctor.js example since includes don't (yet) work in that environment.

For typical use of Asciidoctor, this isn't something you would need.

-Dan

On Nov 29, 2013 1:45 PM, "asotobu [via Asciidoctor :: Discussion]" <[hidden email]> wrote:
Hi, I have been reading this entry and I think I am missing something important. Let me explain:

I have a project with 4 AsciiDoc file. One parent file which has three include directives, that includes  each file. Then I render the parent file using Asciidoctor-Maven-Plugin and the output is only one html file with content of all files rendered inside.

So I think I am missing something about the problem presented here.  


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Output-single-adoc-file-from-includes-tp808p1158.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Output single adoc file from includes?

asotobu
Thank you so much Dan for the clarification. At first I thought it was what you have explained me bit then I reread again and I started to doubt to finally see I was missing something. Thank you 

El divendres 29 de novembre de 2013, mojavelinux [via Asciidoctor :: Discussion] ha escrit:

Alex,

This is more about diagnostics. It's when you want to see, or retrieve, the effective AsciiDoc source as the processor sees it once all the preprocessor directives are evaluated (e.g., include, ifdef, etc)

For instance, I needed a single source file version of the quick reference for the asciidoctor.js example since includes don't (yet) work in that environment.

For typical use of Asciidoctor, this isn't something you would need.

-Dan

On Nov 29, 2013 1:45 PM, "asotobu [via Asciidoctor :: Discussion]" <[hidden email]> wrote:
Hi, I have been reading this entry and I think I am missing something important. Let me explain:

I have a project with 4 AsciiDoc file. One parent file which has three include directives, that includes  each file. Then I render the parent file using Asciidoctor-Maven-Plugin and the output is only one html file with content of all files rendered inside.

So I think I am missing something about the problem presented here.  


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Output-single-adoc-file-from-includes-tp808p1158.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/Output-single-adoc-file-from-includes-tp808p1159.html
To unsubscribe from Output single adoc file from includes?, click here.
NAML


--
Enviat amb Gmail Mobile