Skip to content

Commit

Permalink
snippet_provider_docs (#5)
Browse files Browse the repository at this point in the history
* Changed format of docstrings to be better shown in docs

* Removed part of docs used as a tmp test

* Wrote snippet provider documentation
  • Loading branch information
Ahhhhmed committed Mar 25, 2018
1 parent 3f7c795 commit 08db5e2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
34 changes: 34 additions & 0 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,40 @@ Snippet provider

Provides snippets definitions from a database of snippets.

Snippet definition files
""""""""""""""""""""""""

Snippets definition are writen in json files as shown is the following example.

.. code-block:: json
[
{"name": "for","language": "C++","snippet": "for(#){$}"},
{"name": "if","language": "C++","snippet": "if(#){$}"}
]
Implementation
""""""""""""""

Snippet provider reads all the files containing snippets.
It searches all json files contained in the given list of folders files.
The list of folders is specified in the :code:`path` variable (similar to :code:`os.path`).

.. autoclass:: homotopy.snippet_provider.SnippetProvider
:members: __getitem__, __init__
:member-order: bysource

Usage
"""""

Using this class should be straightforward. Look.

.. code-block:: python
provider = SnippetProvider("C++", ["folder1", "folder2"])
snippet = "for"
snippetExpansion = provider[snippet] # snippetExpansion == "for(#){$}" if used json from above
Utilities
^^^^^^^^^

Expand Down
6 changes: 1 addition & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,4 @@ Homotopy documentation
getting_started
contributing

This is a test for sphinx and Read the Docs. I will add documentation later.

Testing Autodoc functionality:

.. autoclass:: homotopy.snippet_provider.SnippetProvider
Under development.
6 changes: 4 additions & 2 deletions homotopy/snippet_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
class SnippetProvider:
"""
Class for translating simple snippets into code.
Uses a database provided in json files located in path variable.
Uses a database provided in json files located in the path variable.
"""

def __init__(self, language="", path=[]):
"""
Initialize snippet provider instance.
:param language: language to compile to
:param path: list of directories to search for json files containing snippets
"""
Expand All @@ -31,7 +32,8 @@ def __init__(self, language="", path=[]):

def __getitem__(self, item):
"""
Expand single snippet
Expand single snippet.
:param item: snippet
:return: snippet expansion
"""
Expand Down

0 comments on commit 08db5e2

Please sign in to comment.