Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new tab to display JavaScript client method for plone #91

Merged
merged 1 commit into from Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/_static/sphinxcontrib-httpexample.css
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
21 changes: 21 additions & 0 deletions src/sphinxcontrib/httpexample/builders.py
Expand Up @@ -212,6 +212,25 @@ 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=(',', ': '))
else:
redir_input2 = data

# Output string
output_string = f"{javascript_code}\n|\nconst aliasesData = {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 Expand Up @@ -295,3 +314,5 @@ def astify_json_obj(obj):
tuple(map(ast.Str, token.split(':'))), None)))

return unparse(tree).strip()


7 changes: 6 additions & 1 deletion src/sphinxcontrib/httpexample/directives.py
Expand Up @@ -16,7 +16,8 @@
'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 +128,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
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