= LiquiDoc
LiquiDoc is a system for true single-sourcing of technical content and data in flat files. It is especially suited for projects with various required output formats, but it is intended for any project with complex, source-controlled input data for use in documentation, user interfaces, and even back-end code. The command-line utility engages templating systems to parse complex data into rich text output.
Sources can be flat files in formats such as XML (eXtensible Markup Language), JSON (JavaScript Object Notation), CSV (comma-separated values), and our preferred human-editable format: YAML (acronym link:https://en.wikipedia.org/wiki/YAML#History_and_name[in dispute]). LiquiDoc also accepts regular expressions to parse unconventionally formatted files.
Output can (or will) be pretty much any flat file, including semi-structured data like JSON and XML, as well as rich text/multimedia formats like HTML, PDF, slide decks, and more.
== Purpose
LiquiDoc is a build tool for documentation projects and modules. Unlike tools that are mere converters, LiquiDoc can be configured to perform multiple operations at once for generating content from multiple data source files, each output in various formats based on distinct templates. It can be integrated into build- and package-management systems. The tool currently provides for very basic configuration of build jobs. From a single data file, multiple template-driven parsing operations can be performed to produce totally different output formats from the same dataset.
In order to achieve true single sourcing, a data source file in the simplest, most manageable format applicable to the job and preferred by the team, can serve as the canonical authority. But rather than using this file as a reference, every stakeholder on the team can draw from it programmatically. Feature teams who need structured data in different formats can read the semi-structured source file from a common location and parse it using native libraries. Alternatively, LiquiDoc can parse it into a generated source file during the product build procedure and save a copy locally for the application build to pick up.
Upcoming capabilities include a secondary publish function for generating link:http://asciidoctor.org/[Asciidoctor] output from data-driven AsciiDoc files into PDF, ePub, and even JavaScript slide presentations, as well as integrated AsciiDoc- or Markup-based Jekyll static website generation.
== Installation
[NOTE] Your system must be running Ruby 2.3 or later. Linux and MacOS users should be okay. See https://www.ruby-lang.org/en/downloads/[Ruby downloads] if you're on Windows.
. Create a file called Gemfile
in your project's root directory.
source 'https://rubygems.org'
+ [TIP] This file is included in the link:https://github.com/briandominick/liquidoc-boilerplate[LiquiDoc boilerplate files].
. Run bundle install
to prepare dependencies.
+
If you do not have Bundler installed, use gem install bundler
, then repeat this step.
== Usage
LiquiDoc provides a Ruby command-line tool for processing source files into new text files based on templates you define. These definitions can be command-line options, or they can be instructed by preset configurations you define in separate configuration files.
[TIP] .Quickstart If you want to try the tool out with dummy data and templates, clone link:https://github.com/briandominick/liquidoc-boilerplate[this boilerplate repo] and run the suggested commands.
Give LiquiDoc (1) any proper YAML, JSON, XML, or CSV (with header row) data file and (2) a template mapping any of the data to token variables with Liquid markup -- LiquiDoc returns STDOUT feedback or writes a new file (or multiple files) based on that template.
[TIP]
Repeat without the --stdout
flag and you'll find the generated files in _output/
.
[TIP]
Add --verbose
to see the steps LiquiDoc is taking.
=== Configuration
The best way to use LiquiDoc is with a configuration file. This not only makes the command line much easier to manage (requiring just a configuration file path argument), it also adds the ability to perform more complex builds.
Here is the basic structure of a valid config file:
compile: data: source_data_file.json # <1> builds: # <2>
[A-Z_]+)\s(?.*)\s(?true|false)\n
----
.Example -- array derived from sample.free using above regex pattern
[source,ruby]
----
data[0].code #=> A_B
data[0].description #=> A thing that *SnASFHE&"\|+1Dsaghf
data[0].required #=> true
data[1].code #=> G_H
data[1].description #=> Some text for &hdf'" 1t`F
data[1].required #=> false
----
Free-form/regex parsing is obviously more complicated than the other data types.
Its use case is usually when you simply cannot control the form your source takes.
The regex type is also handy when the content of some fields would be burdensome to store in conventional semi-structured formats like those natively parsed by LiquiDoc.
This is the case for jumbled content containing characters that require escaping, so you can keep source like that from the example above in the simplest possible form.
=== Templating
LiquiDoc will add the powers of Asciidoctor in a future release, enabling initial reformatting of complex source data _into_ AsciiDoc format using Liquid templates, followed by final publishing into rich formats such as PDF, HTML, and even slide presentations.
link:https://help.shopify.com/themes/liquid/basics[*Liquid*] is used for parsing complex variable data, typically for iterated output.
For instance, a data structure of glossary terms and definitions that needs to be looped over and pressed into a more publish-ready markup, such as Markdown, AsciiDoc, reStructuredText, LaTeX, or HTML.
Any valid Liquid-formatted template is accepted, in the form of a text file with any extension.
For data sourced in CSV format or extracted through regex source parsing, all data is passed to the Liquid template parser as an array called *data*, containing one or more rows to be iterated through.
Data sourced in YAML, XML, or JSON may be passed as complex structures with custom names determined in the file contents.
Looping through known data formats is fairly straightforward.
A for loop iterates through your data, item by item.
Each item or row contains one or more key-value pairs.
[[rows_asciidoc]]
.Example -- rows.asciidoc Liquid template
[source,liquid]
----
{% for row in data %}{{ row.name }}::
{{ row.description }}
+
[horizontal.simple]
Required:: {% if row.required == "true" %}*Yes*{% else %}No{% endif %}
{% endfor %}
----
In <>, we're instructing Liquid to iterate through our data items, generating a data structure called `row` each time.
The double-curly-bracketed tags convey variables to evaluate.
This means `{{ row.name }}` is intended to express the value of the *name* parameter in the item presently being parsed.
The other curious marks such as `::` and `[horizontal.simple]` are AsciiDoc markup -- they are the formatting we are trying to introduce to give the content form and semantic relevance.
.Non-printing Markup
****
In Liquid and most templating systems, any row containing a non-printing “tag” will print leave a blank line in the output after parsing.
For this reason, it is advised that you stack tags horizontally when you do not wish to generate a blank line, as with the first row above.
A non-printing tag such as `{% endfor %}` will generate a blank line that is convenient in the output but likely to cause clutter here.
This side effect of templating is unfortunate, as it discourages elegant, “accordian-style” code nesting, as in the HTML example below (<>).
In the end, ugly Liquid templates can generate elegant markup output with exquisite precision.
****
The above would generate the following:
[[asciidoc_formatted_source]]
.Example -- AsciiDoc-formatted output
[source,asciidoc]
----
A_B::
A thing that *SnASFHE&"\|+1Dsaghf
+
[horizontal.simple]
Required::: *Yes*
G_H::
Some text for &hdf'" 1t`F
+
[horizontal.simple]
Required::: No
----
The generically styled AsciiDoc rich text reflects the distinctive structure with (very little) more elegance.
.AsciiDoc rich text (rendered)
====
A_B::
A thing that *SnASFHE&"\|+1Dsaghf
+
[horizontal.simple]
Required::: *Yes*
G_H::
Some text for &hdf'" 1t`F
+
[horizontal.simple]
Required::: No
====
The implied structures are far more evident when displayed as HTML derived from Asciidoctor parsing of the LiquiDoc-generated AsciiDoc source (from <>).
[[parsed_html]]
.AsciiDoc parsed into HTML
[source,html]
----
- A_B
-
A thing that *SnASFHE&"\|+1Dsaghf
Required
Yes
- G_H
-
Some text for &hdf'" 1t`F
Required
No
----
Remember, all this started out as that little old free-form text file.
.Example -- sample.free free-form data source file
----
A_B A thing that *SnASFHE&"\|+1Dsaghf true
G_H Some text for &hdf 1t`F false
----
=== Output
After this parsing, files are written in any of the given output formats, or else just written to system as STDOUT (when you add the `--stdout` flag to your command or set `output: stdout` in your config file).
Liquid templates can be used to produce any flat-file format imaginable.
Just format valid syntax with your source data and Liquid template, then save with the proper extension, and you're all set.
== Contributing
Contributions are open and welcome.
This repo is maintained by Rocana's documentation manager, who taught himself basic Ruby scripting just to build LiquiDoc and related tooling.
Instructional pull requests are encouraged!
== License
LiquiDoc is provided by Rocana, Inc under the MIT License.