gulp-hotcopy
v0.7.3
Published
A tool to include converted ArchieML-to-JSON copy in a page's nunjucks context.
Downloads
14
Readme
Dynamic copy for your Gulp-generated HTML.
- Documentation: TK / not completed yet
- Issues: https://github.com/DallasMorningNews/gulp-hotcopy/issues/
- Testing: TK
- Coverage: TK
Features
- Descriptions TK.
Installation
This library is very specific to projects built with the latest versions of the generator-dmninteractives tool. As such, the instructions may not be particularly clear to external users.
If you're already using our generator tool, you can add hot copy in four easy steps:
- Run the following line (or add
gulp-hotcopy
to your project's dependencies/devDependencies):
npm install gulp-hotcopy
Add an ArchieML file (with a
.aml
extension) to./src/assets/hotcopy/
.Add the line
"hotCopyDocument": "true"
to yourmeta.json
.Connect the hot copy to your template using the following code:
{% set hotCopy = hotCopyHelper() %}
{% set copy = hotCopy.connect('my_file') %}
NOTE: The my_file
value should have the same name as the .aml file you created earlier. You can connect several .aml files to an individual HTML page — just repeat the second line above, changing both the value passed to hotCopy.connect()
and the variable this output is assigned to on each successive call.
- Test the integration by loading a value from the ArchieML file.
A variable called headline
at the top level of the ArchieML file should now be accessible as {{ copy.headline }}
.
You can also use the following formatters to render pieces of content in standard DMN styles:
{% include "hot-copy/_author-formatter.html" %}
: Renders the first<p>
tag in our byline block, using anauthors
variable at the top level of the ArchieML file. (This formatter expects theauthors
variable to be a list of author objects, each of which must containname
andemail
fields.){% for bodyGraph in copy.body %}{% include "hot-copy/_graph-formatter.html" %}{% endfor %}
: Renders each item listed in the top-levelbody
variable, according to defined styles. Items in this list without a specific type will be rendered by the./src/templates/hot-copy/text-graph.html
(plain paragraph) template. Other types will be rendered by their corresponding.html
file in./src/templates/embeds/
.