Skip to content
Snippets Groups Projects
Commit 7dc3b833 authored by hluk's avatar hluk
Browse files

Move scripting reference to docs

parent 01616417
No related branches found
No related tags found
No related merge requests found
...@@ -13,7 +13,7 @@ CopyQ is advanced clipboard manager with editing and scripting features. ...@@ -13,7 +13,7 @@ CopyQ is advanced clipboard manager with editing and scripting features.
- [Mailing List](https://groups.google.com/group/copyq) - [Mailing List](https://groups.google.com/group/copyq)
- [Bug Reports](https://github.com/hluk/CopyQ/issues) - [Bug Reports](https://github.com/hluk/CopyQ/issues)
- [Donate](https://www.bountysource.com/teams/copyq) - [Donate](https://www.bountysource.com/teams/copyq)
- [Scripting Reference](https://github.com/hluk/CopyQ/blob/master/src/scriptable/README.md) - [Scripting API](https://copyq.readthedocs.io/en/latest/scripting-api.html)
## Overview ## Overview
...@@ -156,7 +156,7 @@ Create an image items: ...@@ -156,7 +156,7 @@ Create an image items:
Read more: Read more:
- [Scripting](https://copyq.readthedocs.io/en/latest/scripting.html) - [Scripting](https://copyq.readthedocs.io/en/latest/scripting.html)
- [Scripting Reference](https://github.com/hluk/CopyQ/blob/master/src/scriptable/README.md) - [Scripting API](https://copyq.readthedocs.io/en/latest/scripting-api.html)
## Build from Source Code ## Build from Source Code
......
...@@ -291,7 +291,7 @@ omitted. ...@@ -291,7 +291,7 @@ omitted.
Throws an exception if some items cannot be removed. Throws an exception if some items cannot be removed.
.. js:function:: edit([row\|text] ...) .. js:function:: edit([row|text] ...)
Edits items in current tab. Edits items in current tab.
...@@ -400,8 +400,7 @@ omitted. ...@@ -400,8 +400,7 @@ omitted.
.. js:function:: String config(optionName, value, ...) .. js:function:: String config(optionName, value, ...)
Sets multiple options and return list with values in format Sets multiple options and return list with values in format ``optionName=newValue``.
``optionName=newValue``.
Throws an exception if there is an invalid option in which case it won't Throws an exception if there is an invalid option in which case it won't
set any options. set any options.
...@@ -422,8 +421,7 @@ omitted. ...@@ -422,8 +421,7 @@ omitted.
.. js:function:: Value source(fileName) .. js:function:: Value source(fileName)
Evaluates script file and returns result of last expression in the Evaluates script file and returns result of last expression in the script.
script.
This is useful to move some common code out of commands. This is useful to move some common code out of commands.
...@@ -464,8 +462,7 @@ omitted. ...@@ -464,8 +462,7 @@ omitted.
.. js:function:: String toUnicode(ByteArray) .. js:function:: String toUnicode(ByteArray)
Returns string for bytes with encoding detected by checking Byte Order Returns string for bytes with encoding detected by checking Byte Order Mark (BOM).
Mark (BOM).
.. js:function:: ByteArray fromUnicode(String, encodingName) .. js:function:: ByteArray fromUnicode(String, encodingName)
...@@ -863,7 +860,9 @@ Types ...@@ -863,7 +860,9 @@ Types
.. js:class:: Item (Object) .. js:class:: Item (Object)
Type is ``Object`` and each property is MIME type with data. Object with MIME types of an item.
Each property is MIME type with data.
Example: Example:
...@@ -876,7 +875,9 @@ Types ...@@ -876,7 +875,9 @@ Types
.. js:class:: FinishedCommand (Object) .. js:class:: FinishedCommand (Object)
Type is ``Object`` and properties are: Properties of finished command.
Properties are:
- ``stdout`` - standard output - ``stdout`` - standard output
- ``stderr`` - standard error output - ``stderr`` - standard error output
...@@ -884,7 +885,9 @@ Types ...@@ -884,7 +885,9 @@ Types
.. js:class:: NetworkReply (Object) .. js:class:: NetworkReply (Object)
Type is ``Object`` and properties are: Received network reply object.
Properties are:
- ``data`` - reply data - ``data`` - reply data
- ``error`` - error string (set only if an error occurred) - ``error`` - error string (set only if an error occurred)
...@@ -950,8 +953,7 @@ These MIME types values are assigned to global variables prefixed with ...@@ -950,8 +953,7 @@ These MIME types values are assigned to global variables prefixed with
.. js:data:: mimeOwner (application/x-copyq-owner) .. js:data:: mimeOwner (application/x-copyq-owner)
If available, the clipboard was set from CopyQ (from script or copied If available, the clipboard was set from CopyQ (from script or copied items).
items).
Such clipboard is ignored in CopyQ, i.e. it won't be stored in clipboard Such clipboard is ignored in CopyQ, i.e. it won't be stored in clipboard
tab and automatic commands won't be executed on it. tab and automatic commands won't be executed on it.
......
// Generated by "utils/script_docs_to_cpp.py" from "src/scriptable/README.md". // Generated by "utils/script_docs_to_cpp.py" from "docs/scripting-api.rst".
template <typename AddDocumentationCallback> template <typename AddDocumentationCallback>
void addDocumentation(AddDocumentationCallback addDocumentation) void addDocumentation(AddDocumentationCallback addDocumentation)
{ {
...@@ -117,10 +117,6 @@ void addDocumentation(AddDocumentationCallback addDocumentation) ...@@ -117,10 +117,6 @@ void addDocumentation(AddDocumentationCallback addDocumentation)
addDocumentation("Dir", "Dir", "Wrapper for QDir Qt class."); addDocumentation("Dir", "Dir", "Wrapper for QDir Qt class.");
addDocumentation("TemporaryFile", "TemporaryFile", "Wrapper for QTemporaryFile Qt class."); addDocumentation("TemporaryFile", "TemporaryFile", "Wrapper for QTemporaryFile Qt class.");
addDocumentation("arguments", "(Array)", "Array for accessing arguments passed to current function or the script"); addDocumentation("arguments", "(Array)", "Array for accessing arguments passed to current function or the script");
addDocumentation("Item", "(Object)", "Type is `Object` and each property is MIME type with data.");
addDocumentation("FinishedCommand", "(Object)", "Type is `Object` and properties are:");
addDocumentation("NetworkReply", "(Object)", "Type is `Object` and properties are:");
addDocumentation("Command", "(Object)", "Wrapper for a command (from Command dialog).");
addDocumentation("mimeText", "(text/plain)", "Data contains plain text content."); addDocumentation("mimeText", "(text/plain)", "Data contains plain text content.");
addDocumentation("mimeHtml", "(text/html)", "Data contains HTML content."); addDocumentation("mimeHtml", "(text/html)", "Data contains HTML content.");
addDocumentation("mimeUriList", "(text/uri-list)", "Data contains list of links to files, web pages etc."); addDocumentation("mimeUriList", "(text/uri-list)", "Data contains list of links to files, web pages etc.");
......
This diff is collapsed.
#!/usr/bin/python #!/usr/bin/python
''' '''
Parses API for C++ from scriptable README file. Parses API for C++ from Scriptable API documentation.
''' '''
import re import re
readme_path = 'src/scriptable/README.md' readme_path = 'docs/scripting-api.rst'
output_path = 'src/gui/commandcompleterdocumentation.h' output_path = 'src/gui/commandcompleterdocumentation.h'
header = '''// Generated by "utils/script_docs_to_cpp.py" from "src/scriptable/README.md". header = '''// Generated by "utils/script_docs_to_cpp.py" from "%s".
template <typename AddDocumentationCallback> template <typename AddDocumentationCallback>
void addDocumentation(AddDocumentationCallback addDocumentation) void addDocumentation(AddDocumentationCallback addDocumentation)
{ {
...@@ -16,12 +16,10 @@ void addDocumentation(AddDocumentationCallback addDocumentation) ...@@ -16,12 +16,10 @@ void addDocumentation(AddDocumentationCallback addDocumentation)
footer = '}' footer = '}'
# Function/variable/type name in the README file # Regex for function/variable/type name in documentation
re_title = re.compile(r''' re_title = re.compile(r'''
# title in Markdown
^\#{6}\s*
(?: (?:
^\.\.\s*js:function::\s*
(?P<function_api> (?P<function_api>
# function return value # function return value
.*? .*?
...@@ -33,15 +31,16 @@ re_title = re.compile(r''' ...@@ -33,15 +31,16 @@ re_title = re.compile(r'''
| |
^\.\.\s*js:data::\s*
# variable name # variable name
(?P<variable_name>\w+) (?P<variable_name>\w+)
# followed by space \s*
\s
# followed by opening parenthesis # followed by opening parenthesis
(?P<variable_api>\(.*) (?P<variable_api>\(.*)
| |
^\.\.\s*js:class::\s*
# type name # type name
(?P<type_name>\w+)$ (?P<type_name>\w+)$
) )
...@@ -49,18 +48,19 @@ re_title = re.compile(r''' ...@@ -49,18 +48,19 @@ re_title = re.compile(r'''
def main(): def main():
with open(output_path, mode='w', encoding='utf-8') as output_file: with open(output_path, mode='w', encoding='utf-8') as output_file:
output_file.write(header + '\n') output_file.write((header % readme_path) + '\n')
with open(readme_path, mode='r', encoding='utf-8') as readme_file: with open(readme_path, mode='r', encoding='utf-8') as readme_file:
match = None match = None
for line in readme_file: for line in readme_file:
line = line.strip() line = line.strip().replace('``', '`')
if line: if line:
if match: if match:
name = match.group('function_name') or match.group('variable_name') or match.group('type_name') name = match.group('function_name') or match.group('variable_name') or match.group('type_name')
api = match.group('function_api') or match.group('variable_api') or name api = match.group('function_api') or match.group('variable_api') or name
description = line.strip()
output = ' addDocumentation("{}", "{}", "{}");\n'\ output = ' addDocumentation("{}", "{}", "{}");\n'\
.format(name, api, line) .format(name, api, description)
output_file.write(output) output_file.write(output)
match = None match = None
else: else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment