Skip to content

Commit 5ab3a91

Browse files
committed
diagram-generator: use snake_case for path variables
CamelCase is reserved for object factories / constructor functions.
1 parent 5f3a284 commit 5ab3a91

File tree

2 files changed

+55
-46
lines changed

2 files changed

+55
-46
lines changed

diagram-generator/diagram-generator.lua

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,38 @@ local with_working_directory = system.with_working_directory
2121
-- The PlantUML path. If set, uses the environment variable PLANTUML or the
2222
-- value "plantuml.jar" (local PlantUML version). In order to define a
2323
-- PlantUML version per pandoc document, use the meta data to define the key
24-
-- "plantumlPath".
25-
local plantumlPath = os.getenv("PLANTUML") or "plantuml.jar"
24+
-- "plantuml_path".
25+
local plantuml_path = os.getenv("PLANTUML") or "plantuml.jar"
2626

2727
-- The Inkscape path. In order to define an Inkscape version per pandoc
28-
-- document, use the meta data to define the key "inkscapePath".
29-
local inkscapePath = os.getenv("INKSCAPE") or "inkscape"
28+
-- document, use the meta data to define the key "inkscape_path".
29+
local inkscape_path = os.getenv("INKSCAPE") or "inkscape"
3030

3131
-- The Python path. In order to define a Python version per pandoc document,
32-
-- use the meta data to define the key "pythonPath".
33-
local pythonPath = os.getenv("PYTHON")
32+
-- use the meta data to define the key "python_path".
33+
local python_path = os.getenv("PYTHON")
3434

3535
-- The Python environment's activate script. Can be set on a per document
3636
-- basis by using the meta data key "activatePythonPath".
37-
local pythonActivatePath = os.getenv("PYTHON_ACTIVATE")
37+
local python_activate_path = os.getenv("PYTHON_ACTIVATE")
3838

3939
-- The Java path. In order to define a Java version per pandoc document,
40-
-- use the meta data to define the key "javaPath".
41-
local javaPath = os.getenv("JAVA_HOME")
42-
if javaPath then
43-
javaPath = javaPath .. package.config:sub(1,1) .. "bin"
40+
-- use the meta data to define the key "java_path".
41+
local java_path = os.getenv("JAVA_HOME")
42+
if java_path then
43+
java_path = java_path .. package.config:sub(1,1) .. "bin"
4444
.. package.config:sub(1,1) .. "java"
4545
else
46-
javaPath = "java"
46+
java_path = "java"
4747
end
4848

4949
-- The dot (Graphviz) path. In order to define a dot version per pandoc
50-
-- document, use the meta data to define the key "dotPath".
51-
local dotPath = os.getenv("DOT") or "dot"
50+
-- document, use the meta data to define the key "dot_path".
51+
local dot_path = os.getenv("DOT") or "dot"
5252

5353
-- The pdflatex path. In order to define a pdflatex version per pandoc
54-
-- document, use the meta data to define the key "pdflatexPath".
55-
local pdflatexPath = os.getenv("PDFLATEX") or "pdflatex"
54+
-- document, use the meta data to define the key "pdflatex_path".
55+
local pdflatex_path = os.getenv("PDFLATEX") or "pdflatex"
5656

5757
-- The default format is SVG i.e. vector graphics:
5858
local filetype = "svg"
@@ -77,26 +77,35 @@ end
7777
-- meta options was set, it gets used instead of the corresponding
7878
-- environment variable:
7979
function Meta(meta)
80-
plantumlPath = meta.plantumlPath or plantumlPath
81-
inkscapePath = meta.inkscapePath or inkscapePath
82-
pythonPath = meta.pythonPath or pythonPath
83-
pythonActivatePath = meta.activatePythonPath or pythonActivatePath
84-
javaPath = meta.javaPath or javaPath
85-
dotPath = meta.dotPath or dotPath
86-
pdflatexPath = meta.pdflatexPath or pdflatexPath
80+
plantuml_path =
81+
meta.plantuml_path or meta.plantumlPath or plantuml_path
82+
inkscape_path =
83+
meta.inkscape_path or meta.inkscapePath or inkscape_path
84+
python_path =
85+
meta.python_path or meta.pythonPath or python_path
86+
python_activate_path =
87+
meta.activate_python_path or meta.activatePythonPath or python_activate_path
88+
java_path =
89+
meta.java_path or meta.javaPath or java_path
90+
dot_path =
91+
meta.path_dot or meta.dotPath or dot_path
92+
pdflatex_path =
93+
meta.pdflatex_path or meta.pdflatexPath or pdflatex_path
8794
end
8895

8996
-- Call plantuml.jar with some parameters (cf. PlantUML help):
9097
local function plantuml(puml, filetype)
91-
local final = pandoc.pipe(javaPath, {"-jar", plantumlPath, "-t" .. filetype, "-pipe", "-charset", "UTF8"}, puml)
92-
return final
98+
return pandoc.pipe(
99+
java_path,
100+
{"-jar", plantuml_path, "-t" .. filetype, "-pipe", "-charset", "UTF8"},
101+
puml
102+
)
93103
end
94104

95105
-- Call dot (GraphViz) in order to generate the image
96106
-- (thanks @muxueqz for this code):
97107
local function graphviz(code, filetype)
98-
local final = pandoc.pipe(dotPath, {"-T" .. filetype}, code)
99-
return final
108+
return pandoc.pipe(dot_path, {"-T" .. filetype}, code)
100109
end
101110

102111
--
@@ -134,7 +143,7 @@ local function convert_from_pdf(filetype)
134143
return function (pdf_file, outfile)
135144
local inkscape_command = string.format(
136145
'"%s" --without-gui --file="%s" ' .. inkscape_output_args,
137-
inkscapePath,
146+
inkscape_path,
138147
pdf_file,
139148
outfile
140149
)
@@ -166,7 +175,7 @@ local function tikz2image(src, filetype, additional_packages)
166175
f:close()
167176

168177
-- Execute the LaTeX compiler:
169-
pandoc.pipe(pdflatexPath, {'-output-directory', tmpdir, tikz_file}, '')
178+
pandoc.pipe(pdflatex_path, {'-output-directory', tmpdir, tikz_file}, '')
170179

171180
convert(pdf_file, outfile)
172181

@@ -204,9 +213,9 @@ local function py2image(code, filetype)
204213
f:close()
205214

206215
-- Execute Python in the desired environment:
207-
local pycmd = pythonPath .. ' ' .. pyfile
208-
local command = pythonActivatePath
209-
and pythonActivatePath .. ' && ' .. pycmd
216+
local pycmd = python_path .. ' ' .. pyfile
217+
local command = python_activate_path
218+
and python_activate_path .. ' && ' .. pycmd
210219
or pycmd
211220
os.execute(command)
212221

diagram-generator/sample.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ By default, this filter expects the plantuml.jar file to be in the
2121
working directory. Alternatively, the environment variable
2222
`PLANTUML` can be set with a path. If, for example, a specific
2323
PlantUML version is to be used per pandoc document, the
24-
`plantumlPath` meta variable can be set.
24+
`plantuml_path` meta variable can be set.
2525

2626
Furthermore, this filter assumes that Java is located in the
2727
system or user path. This means that from any place of the system
2828
the `java` command is understood. Alternatively, the `JAVA_HOME`
2929
environment variable gets used. To use a specific Java version per
30-
pandoc document, use the `javaPath` meta variable. Please notice
30+
pandoc document, use the `java_path` meta variable. Please notice
3131
that `JAVA_HOME` must be set to the java's home directory e.g.
32-
`c:\Program Files\Java\jre1.8.0_201\` whereas `javaPath` must be
32+
`c:\Program Files\Java\jre1.8.0_201\` whereas `java_path` must be
3333
set to the absolute path of `java.exe` e.g.
3434
`c:\Program Files\Java\jre1.8.0_201\bin\java.exe`.
3535

@@ -50,7 +50,7 @@ dependencies.
5050
This filter assumes that the `dot` command is located in the path
5151
and therefore can be used from any location. Alternatively, you can
5252
set the environment variable `DOT` or use the pandoc's meta variable
53-
`dotPath`.
53+
`dot_path`.
5454

5555
Example usage from [the Graphviz
5656
gallery](https://graphviz.gitlab.io/_pages/Gallery/directed/fsm.html):
@@ -110,13 +110,13 @@ missing packages are installed automatically. This filter uses the
110110
`pdflatex` command which is available by the system's path. Alternatively,
111111
you can set the `PDFLATEX` environment variable. In case you have to use
112112
a specific LaTeX version on a pandoc document basis, you might set the
113-
`pdflatexPath` meta variable.
113+
`pdflatex_path` meta variable.
114114

115115
- An installation of [Inkscape](https://inkscape.org/).
116116
It is assumed that the `inkscape` command is in the path and can be
117117
executed from any location. Alternatively, the environment
118118
variable `INKSCAPE` can be set with a path. If a specific
119-
version per pandoc document is to be used, the `inkscapePath`
119+
version per pandoc document is to be used, the `inkscape_path`
120120
meta-variable can be set.
121121

122122
In order to use additional LaTeX packages, use the optional
@@ -207,7 +207,7 @@ on a Microsoft Windows system ...
207207
to `c:\ProgramData\Anaconda3\python.exe`
208208

209209
- set the environment variable `PYTHON_ACTIVATE` or the meta
210-
key `activatePythonPath` to `c:\ProgramData\Anaconda3\Scripts\activate.bat`.
210+
key `activate_python_path` to `c:\ProgramData\Anaconda3\Scripts\activate.bat`.
211211

212212
Pandoc will activate this Python environment and starts Python with your code.
213213

@@ -235,10 +235,10 @@ All available environment variables:
235235

236236
All available meta keys:
237237

238-
- `plantumlPath`
239-
- `inkscapePath`
240-
- `pythonPath`
241-
- `activatePythonPath`
242-
- `javaPath`
243-
- `dotPath`
244-
- `pdflatexPath`
238+
- `plantuml_path`
239+
- `inkscape_path`
240+
- `python_path`
241+
- `activate_python_path`
242+
- `java_path`
243+
- `dot_path`
244+
- `pdflatex_path`

0 commit comments

Comments
 (0)