summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2023-06-21 03:00:51 +0000
committerNorbert Preining <norbert@preining.info>2023-06-21 03:00:51 +0000
commit16d6a70c44a97b15c195cf6b10f59f3deadd0e66 (patch)
tree5bcad01a9bbbb2a9f79dc7f9838bcda60024164d /web
parentcce87a5ab0d6acdcd0d1425a8a86696c803785b4 (diff)
CTAN sync 202306210300
Diffstat (limited to 'web')
-rw-r--r--web/javascripthttp/README.md2
-rw-r--r--web/javascripthttp/javascripthttp-doc.pdfbin0 -> 177033 bytes
-rw-r--r--web/javascripthttp/javascripthttp-doc.tex78
-rw-r--r--web/javascripthttp/javascripthttp.sty49
4 files changed, 76 insertions, 53 deletions
diff --git a/web/javascripthttp/README.md b/web/javascripthttp/README.md
index 5f8eb15fce..4fac3528a3 100644
--- a/web/javascripthttp/README.md
+++ b/web/javascripthttp/README.md
@@ -1,5 +1,5 @@
# README for JAVASCRIPTHTTP
-Version v1.0
+Version v1.1
## INTRODUCTION
This small package adds commands for LaTeX to create buttons with which to fetch content from the internet. The content can be transformed and displayed in textfields. For these interactive elements to work, a PDF using the commands provided by this package must be opened in Acrobat Pro.
diff --git a/web/javascripthttp/javascripthttp-doc.pdf b/web/javascripthttp/javascripthttp-doc.pdf
new file mode 100644
index 0000000000..850638ab7f
--- /dev/null
+++ b/web/javascripthttp/javascripthttp-doc.pdf
Binary files differ
diff --git a/web/javascripthttp/javascripthttp-doc.tex b/web/javascripthttp/javascripthttp-doc.tex
index 70e7c99a12..b836692eee 100644
--- a/web/javascripthttp/javascripthttp-doc.tex
+++ b/web/javascripthttp/javascripthttp-doc.tex
@@ -1,10 +1,14 @@
-\documentclass{article}
-
+\documentclass[a4paper]{article}
+\usepackage[english]{babel}
\usepackage{listings}
\usepackage{javascripthttp}
\usepackage{hyperref}
\begin{document}
+
+\setlength{\parindent}{0pt}
+\setlength{\parskip}{5pt plus 2pt minus 1pt}
+
\title{JavascriptHttp Documentation \& Manual}
\author{Cedric Zwahlen \\ \texttt{cedric-vince@gmx.ch}}
@@ -20,12 +24,12 @@
{\noindent The aim of this package is to make it as easy as possible to \textit{get} or \textit{post} data from or to REST-API's from within a PDF document.
Specifically, this package adds LaTeX commands to create highly customisable buttons with which to fetch, transform and display data from a remote location. \\
These features make use of Javascript, which means a PDF using them \textbf{only works with Adobe Acrobat Pro}.
-Other PDF viewers (including Acrobat Reader) may still display the interactive elements, but will not be able to run Javascript or access the internet.}
+Other PDF viewers (including Acrobat Reader) may still display the interactive elements, but will not be able to run Javascript or access the internet. }
\section{Prerequisites}
{\noindent Acrobat Pro blocks Networking code by default. Because this package requires it, you must first change some settings.\\
-Navigate to \textbf{Preferences\textgreater Security (Enhanced)}. Then, add the path to your PDF via the 'Add Folder Path' button. }
+Navigate to \textbf{Preferences\textgreater Security (Enhanced)}. Then, add the path to your PDF via the 'Add Folder Path' button. The javascripthttp package depends on the acrotex macro. More information about acrotex can be found here: \url{https://www.ctan.org/pkg/acrotex} }
\section{Textfields}
@@ -45,6 +49,18 @@ Navigate to \textbf{Preferences\textgreater Security (Enhanced)}. Then, add the
}
\end{description}
+\begin{description}
+ \item[\textbackslash SimpleTextFieldShortReadonly] { \sffamily
+ \{$\langle$unique identifier$\rangle$\}
+ }
+\end{description}
+
+\begin{description}
+ \item[\textbackslash SimpleTextFieldMultilineReadonly] { \sffamily
+ \{$\langle$unique identifier$\rangle$\}
+ }
+\end{description}
+
{\noindent A readonly textfield does not accept user input. It's content can only be changed through Javascript code. }
\newpage
@@ -84,36 +100,12 @@ To display the value "Mango", pass 'abc.1.xyz' (including ') as the keypath.\\
Finally, $\langle$target$\rangle$ specifies the name of the textfield, in which to display the value of the property specified in $\langle$keypath$\rangle$. If no such textfield exists, then nothing is displayed. This parameter is optional.\\
}
-{\noindent Below is a textfield and a SimpleButton that demonstrates the configuration described above. It fetches the current time from here \url{https://www.timeapi.io/api/Time/current/zone?timeZone=Europe/Zurich} and displays it.\\}
-
-\SimpleTextFieldReadonly{field1}
-
-\SimpleGET
-{time}
-{Get the Time}
-{'https://www.timeapi.io/api/Time/current/zone?timeZone=Europe/Zurich'}
-{'time'}
-[field1]
-
\subsection{URL Interpolation}
{\noindent You can use URL interpolation to insert contents of a textfield into your URL. To do this, wrap the $\langle$unique identifier$\rangle$ of a textfield in curly braces where you want to insert its content in the URL. An example:
\begin{lstlisting}
https://api.datamuse.com/words?rel_rhy={textfield1}
\end{lstlisting}
-Here, the content of 'textfield1' is inserted at the end of the URL before a request is sent. You can use multiple interpolations in one URL. The below example makes use of this interpolation to fetch a rhyme for a given word.\\
-}
-
-\SimpleGET
-{datamuse2}
-{What Rhymes With:}
-{'https://api.datamuse.com/words?rel_rhy={enter1}'}
-{'0.word'}
-[field2]
-
-\SimpleTextField{enter1}
-
-\SimpleTextFieldReadonly{field2}
\subsection{Using Lambdas}
@@ -126,16 +118,7 @@ If you pass a lambda as the $\langle$URL$\rangle$ parameter, the function must r
\subsubsection{Keypath Argument}
{\noindent If you need to perform additional operations on received data, you can pass a Javascript lambda as the $\langle$keypath$\rangle$ parameter instead of a string. Allowing anyone to execute arbitrary code might introduce a security risk, so documents from unknown origins should not be trusted. The lambda takes two arguments; the data received from remote as a Javascript object, and a reference to 'this'. If your lambda returns a string, it will be displayed in the field specified by $\langle$target$\rangle$.\\
-This demonstration uses the below lambda to get a list of holidays from \url{https://date.nager.at/api/v3/publicholidays/2023/CH}, and picks one at random.\\}
-
-\SimpleTextFieldReadonly{field3}
-
-\SimpleGET
-{holiday}
-{Get a Holiday}
-{'https://date.nager.at/api/v3/publicholidays/2023/CH'}
-{(json,doc) => { const x = Math.floor(Math.random() * json.length); const h = doc.extractKeypath(json,x + '.localName',doc); return h; }}
-[field3]
+Consider the below example. A lambda is used to get a list of holidays from \url{https://date.nager.at/api/v3/publicholidays/2023/CH}, and then pick one at random.\\}
\begin{lstlisting}
(json,doc) => {
@@ -169,16 +152,17 @@ If you want to display custom error messages in case an operation fails, you can
\end{lstlisting}
If you do not want to display any custom error messages, simply pass \{\} – an empty object.\\}
-\SimpleTextFieldReadonly{field4}
+\section{Generic Button}
+
+\begin{description}
+ \item[\textbackslash SimpleClosure] { \sffamily
+ \{$\langle$id$\rangle$\}
+ \{$\langle$label$\rangle$\}
+ \{$\langle$closure$\rangle$\}
+ }
+\end{description}
-\SimplePOST
-{post3}
-{POST to Remote}
-{'http://httpbin.org/anything'}
-{'json.stuff'}
-{() => {return { 'stuff' : 'This is your content.' }}}
-{{ "418": "teapot"}}
-[field4]
+{\noindent Also provided as part of this package is a button, that simply takes a lambda. This button can be used to provide other functionality to tie various components together.}
\section{Error Handling}
diff --git a/web/javascripthttp/javascripthttp.sty b/web/javascripthttp/javascripthttp.sty
index a56b533d93..68a89a830a 100644
--- a/web/javascripthttp/javascripthttp.sty
+++ b/web/javascripthttp/javascripthttp.sty
@@ -15,9 +15,8 @@
%
% This work consists of the files javascripthttp.sty and javascripthttp-doc.tex
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{javascripthttp}[JavascriptHTTP Package, Version 1.0]
+\ProvidesPackage{javascripthttp}[JavascriptHTTP Package, Version 1.1]
-\RequirePackage[dvipsnames]{xcolor}
\RequirePackage{setspace}
\RequirePackage{insdljs}
\RequirePackage{xparse}
@@ -27,15 +26,23 @@
}
\newcommand{\SimpleTextFieldReadonly}[1] {
-\TextField[name=#1,width=32em,height=2em,bordercolor={0.5 .5 .5},readonly=true]{}
+\TextField[name=#1,width=29em,height=2em,bordercolor={0.5 .5 .5},readonly=true]{}
+}
+
+\newcommand{\SimpleTextFieldShortReadonly}[1] {
+\TextField[name=#1,width=9em,height=2em,bordercolor={0.5 .5 .5},readonly=true]{}
+}
+
+\newcommand{\SimpleTextFieldMultilineReadonly}[1] {
+\TextField[name=#1,width=29em,height=4em,bordercolor={0.5 .5 .5},readonly=true,multiline=true]{}
}
\newcommand{\SimpleTextField}[1] {
-\TextField[name=#1,width=32em,height=2em,bordercolor={0.5 .5 .5}]{}
+\TextField[name=#1,width=29em,height=2em,bordercolor={0.5 .5 .5}]{}
}
\newcommand{\ErrorField} {
-\TextField[name=errorField,width=32em,height=2em,bordercolor={0.0 .0 .0},readonly=true]{}
+\TextField[name=errorField,width=29em,height=2em,bordercolor={0.0 .0 .0},readonly=true]{}
}
% new
@@ -49,6 +56,12 @@
}
+\NewDocumentCommand{\SimpleClosure}{v v +v}{
+
+ \PushButton[name=#1, onclick={ this["simpleClosure"] = #3; this["simpleClosure"](this); }]{\sffamily \large #2}
+
+}
+
\NewDocumentCommand{\SimplePOST}{v v +v +v +v +v o}{
\IfNoValueTF{#7}
@@ -215,6 +228,32 @@ function processSimpleButton(url, method, name, payload, keypath, errors)
getJSONFrom(resolved, extractKeypath, keypath, payload, name, method, errors, this);
}
+function removeHTML(str) {
+
+ const re = /(.*?)(&.*?;)/g;
+
+ var m;
+
+ var stitch = 0;
+ var res = '';
+
+ do {
+ m = re.exec(str);
+ if (m) {
+
+ console.println(m[0]);
+ console.println(m[1]);
+
+ stitch += m[0].length;
+ res += m[1];
+
+ }
+
+ } while (m);
+
+ return res + str.substring(stitch);
+}
+
/*
Extracts a property of a javascript object based on the provided keypath.