Skip to content

Commit

Permalink
Merge pull request #92 from collective/plone-javascript
Browse files Browse the repository at this point in the history
 Added new tab to display JavaScript client method for plone
  • Loading branch information
datakurre authored Feb 19, 2024
2 parents b38804b + ab62be4 commit a3c6eab
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 77 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
COVERALLS_REPO_TOKEN: ${{ secrets.github_token }}
steps:
- uses: actions/checkout@v4.1.1
- uses: cachix/install-nix-action@v22
- uses: cachix/install-nix-action@v25
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: cachix/cachix-action@v12
- uses: cachix/cachix-action@v14
with:
name: datakurre
- run: make nix-show nix-test nix-coverage nix-coveralls nix-docs PYTHON=${{ matrix.python }}
35 changes: 35 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.10"
# You can also specify other tool versions:
# nodejs: "20"
# rust: "1.70"
# golang: "1.20"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py
# You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
# builder: "dirhtml"
# Fail on all warnings to avoid broken references
# fail_on_warning: true

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: docs/requirements.txt
1 change: 1 addition & 0 deletions docs/_static/sphinxcontrib-httpexample.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
.http-example div[class^='highlight'] pre {
white-space: normal;
}
.http-example-JavaScript div[class^='highlight'] pre,
.http-example-http div[class^='highlight'] pre,
.http-example-response div[class^='highlight'] pre {
white-space: pre;
Expand Down
62 changes: 62 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Jinja2==3.0.3
MarkupSafe==2.0.1
alabaster==0.7.12
astunparse==1.6.3
attrs==21.2.0
babel==2.9.1
certifi==2022.12.7
charset-normalizer==2.0.9
coverage==6.2
coveralls==3.3.1
docopt==0.6.2
docutils==0.16
flake8==4.0.1
flake8-blind-except==0.2.0
flake8-coding==1.3.2
flake8-debugger==4.0.0
flake8-isort==4.1.1
flake8-polyfill==1.0.2
flake8-quotes==3.3.1
idna==3.3
imagesize==1.3.0
importlib-metadata==4.10.0
iniconfig==1.1.1
isort==5.10.1
mccabe==0.6.1
packaging==21.3
pep8-naming==0.12.1
pillow==8.4.0
pluggy==1.0.0
poetry-core==1.0.7
py==1.11.0
pycodestyle==2.8.0
pyflakes==2.4.0
pygments==2.10.0
pyparsing==3.0.6
pytest==6.2.5
pytest-cov==2.12.1
pytest-runner==5.3.1
pytz==2021.3
pyyaml==6.0
reportlab==3.6.3
requests==2.26.0
rst2pdf==0.98
six==1.16.0
smartypants==2.0.1
snapshottest==0.5.0
snowballstemmer==2.2.0
sphinx==4.3.2
sphinx-rtd-theme==1.0.0
sphinx-testing==1.0.1
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-httpdomain==1.8.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
termcolor==1.1.0
testfixtures==6.18.3
toml==0.10.2
urllib3==1.26.7
zipp==3.6.0
30 changes: 15 additions & 15 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Code

.. code-block:: rst
.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
GET /Plone/front-page HTTP/1.1
Host: localhost:8080
Expand Down Expand Up @@ -70,7 +70,7 @@ Code
Result
``````

.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
GET /Plone/front-page HTTP/1.1
Host: localhost:8080
Expand Down Expand Up @@ -121,7 +121,7 @@ Result

or with inline response starting with just "HTTP " without the HTTP version:

.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
GET /Plone/front-page HTTP/1.1
Host: localhost:8080
Expand Down Expand Up @@ -179,7 +179,7 @@ Code

.. code-block:: rst
.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
POST /Plone/folder HTTP/1.1
Host: localhost:8080
Expand All @@ -195,7 +195,7 @@ Code
Result
``````

.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
POST /Plone/folder HTTP/1.1
Host: localhost:8080
Expand All @@ -216,7 +216,7 @@ Code

.. code-block:: rst
.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
PATCH /Plone/folder/my-document HTTP/1.1
Host: localhost:8080
Expand All @@ -231,7 +231,7 @@ Code
Result
``````

.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
PATCH /Plone/folder/my-document HTTP/1.1
Host: localhost:8080
Expand All @@ -252,7 +252,7 @@ Code

.. code-block:: rst
.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
GET /items?user_id=12&user_id=13 HTTP/1.1
Host: localhost
Expand All @@ -269,7 +269,7 @@ Code
Result
``````

.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
GET /items?user_id=12&user_id=13 HTTP/1.1
Host: localhost
Expand All @@ -294,14 +294,14 @@ Code

.. code-block:: rst
.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
:request: ../tests/fixtures/001.request.txt
:response: ../tests/fixtures/001.response.txt
Result
``````

.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
:request: ../tests/fixtures/001.request.txt
:response: ../tests/fixtures/001.response.txt

Expand All @@ -313,14 +313,14 @@ Code

.. code-block:: rst
.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
:request: ../tests/fixtures/002.request.txt
:response: ../tests/fixtures/002.response.txt
Result
``````

.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
:request: ../tests/fixtures/002.request.txt
:response: ../tests/fixtures/002.response.txt

Expand All @@ -332,13 +332,13 @@ Code

.. code-block:: rst
.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
:request: ../tests/fixtures/003.request.txt
:response: ../tests/fixtures/003.response.txt
Result
``````

.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
:request: ../tests/fixtures/003.request.txt
:response: ../tests/fixtures/003.response.txt
25 changes: 25 additions & 0 deletions src/sphinxcontrib/httpexample/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,31 @@ def build_httpie_command(request):
return 'echo {} | {}'.format(redir_input, cmd)


def build_plone_javascript_command(request):
javascript_code = 'createAliasesMutation'
redir_input2 = ''

# Request body
data = maybe_str(request.data())
if data:
if is_json(request.headers.get('Content-Type', '')):
redir_input2 = json.dumps(
data, indent=2, sort_keys=True,
separators=(',', ': '),
).encode('utf-8')
else:
redir_input2 = data

# Output string
output_string =\
"{}\n|\nconst aliasesData = '{}';".format(
maybe_str(javascript_code),
maybe_str(redir_input2),
)

return output_string


def flatten_parsed_qs(data):
"""Flatten single value lists in parse_qs results."""
for key, value in data.items():
Expand Down
8 changes: 7 additions & 1 deletion src/sphinxcontrib/httpexample/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
'wget': (builders.build_wget_command, 'bash'),
'httpie': (builders.build_httpie_command, 'bash'),
'requests': (builders.build_requests_command, 'python'),
'python-requests': (builders.build_requests_command, 'python')
'python-requests': (builders.build_requests_command, 'python'),
'plone-javascript': (builders.build_plone_javascript_command,
'javascript'),
}

AVAILABLE_FIELDS = [
Expand Down Expand Up @@ -127,6 +129,10 @@ def run(self):
for name in chosen_builders:
request = parsers.parse_request(raw, config.httpexample_scheme)
builder_, language = AVAILABLE_BUILDERS[name]

# Setting plone JavaScript tab name
name = 'JavaScript' if name == 'plone-javascript' else name

command = builder_(request)

content = StringList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
.http-example div.highlight-bash pre {
white-space: pre-wrap;
}
.http-example-JavaScript div[class^='highlight'] pre,
.http-example-http div[class^='highlight'] pre,
.http-example-response div[class^='highlight'] pre {
white-space: pre;
Expand Down
Loading

0 comments on commit a3c6eab

Please sign in to comment.