GeezerVison is showing github.com — New Code Generator strategy. Implement the CodeGenerator ABC, rather · JavaScriptBach/stone@d238928
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .gitignore +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,6 +8,6 @@ parsetab.py | 8 | 8 | /build | 9 | 9 | /dist | 10 | 10 | /MANIFEST | 11 | | -/babelsdk.egg-info | | 11 | +/babelapi.egg-info | 12 | 12 | /setuptools-3.1-py2.7.egg | 13 | 13 | /setuptools-3.1.zip |
Collapse file Copy file name to clipboardExpand all lines: README.rst +10-10Lines changed: 10 additions & 10 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | **************** | 2 | | -BabelSDK | | 2 | +BabelAPI | 3 | 3 | **************** | 4 | 4 |
| 5 | 5 | Define an API once in Babel. Use templates to define how the Babel definition | @@ -31,22 +31,22 @@ Download or clone BabelSDK, and run the following in its root directory:: | 31 | 31 |
| 32 | 32 | $ sudo python setup.py install | 33 | 33 |
| 34 | | -This will install a script ``babelsdk`` to your PATH that can be run from the | | 34 | +This will install a script ``babelapi`` to your PATH that can be run from the | 35 | 35 | command line:: | 36 | 36 |
| 37 | | - $ babelsdk -h | | 37 | + $ babelapi -h | 38 | 38 |
| 39 | 39 | If you did not run ``setup.py`` but have the Python package in your PYTHONPATH, | 40 | | -you can replace ``babelsdk`` with ``python -m babelsdk.cli`` as follows:: | | 40 | +you can replace ``babelapi`` with ``python -m babelapi.cli`` as follows:: | 41 | 41 |
| 42 | | - $ python -m babelsdk.cli -h | | 42 | + $ python -m babelapi.cli -h | 43 | 43 |
| 44 | 44 | Simple Example | 45 | 45 | -------------- | 46 | 46 |
| 47 | 47 | You can compile an example babel and apply it to a documentation template:: | 48 | 48 |
| 49 | | - $ babelsdk example/api/v2_files.babel example/api/v2_users.babel example/template/docs | | 49 | + $ babelapi example/api/v2_files.babel example/api/v2_users.babel example/template/docs | 50 | 50 |
| 51 | 51 | You can view the generated documentation using:: | 52 | 52 |
| @@ -432,12 +432,12 @@ template must satisfy the following conditions: | 432 | 432 | * IDEs that use the outer extension to determine syntax highlighting | 433 | 433 | will continue to work. | 434 | 434 |
| 435 | | -2. The first line of the file must include ``babelsdk(jinja2)``. | | 435 | +2. The first line of the file must include ``babelapi(jinja2)``. | 436 | 436 |
| 437 | 437 | * You'll want to make the first line a comment in the target language. | 438 | 438 |
| 439 | | - * ``# babelsdk(jinja2)`` for Python | 440 | | - * ``<!-- babelsdk(jinja2) -->`` for HTML | | 439 | + * ``# babelapi(jinja2)`` for Python | | 440 | + * ``<!-- babelapi(jinja2) -->`` for HTML | 441 | 441 |
| 442 | 442 | * jinja2 is currently the only available generator. But, this allows for | 443 | 443 | a pluggable architecture for templating engines. | @@ -447,7 +447,7 @@ Jinja2 Templating | 447 | 447 |
| 448 | 448 | You'll want to familiarize yourself with templating in | 449 | 449 | `jinja2 <http://jinja.pocoo.org/docs/>`_. Your template will have access to the | 450 | | -``api`` variable, which maps to the ``babelsdk.api.Api`` object. From this | | 450 | +``api`` variable, which maps to the ``babelapi.api.Api`` object. From this | 451 | 451 | object, you can access all the defined namespaces, data types, and operations. | 452 | 452 | See the Python object definition for more information. | 453 | 453 |
| |
Collapse file Copy file name to clipboard File renamed without changes. Collapse file Copy file name to clipboardExpand all lines: babelapi/api.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | from collections import OrderedDict | 2 | 2 | from distutils.version import StrictVersion | 3 | 3 |
| 4 | | -from babelsdk.data_type import Empty | | 4 | +from babelapi.data_type import Empty | 5 | 5 |
| 6 | 6 | class Api(object): | 7 | 7 | """ | |
Collapse file Copy file name to clipboard File renamed without changes. Collapse file Copy file name to clipboardExpand all lines: babelapi/babel/lexer.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,7 +21,7 @@ def __init__(self): | 21 | 21 | self.lex = None | 22 | 22 | self.tokens_queue = None | 23 | 23 | self.cur_indent = None | 24 | | - self._logger = logging.getLogger('babelsdk.babel.lexer') | | 24 | + self._logger = logging.getLogger('babelapi.babel.lexer') | 25 | 25 | self.last_token = None | 26 | 26 |
| 27 | 27 | def input(self, file_data, **kwargs): | |
Collapse file Copy file name to clipboardExpand all lines: babelapi/babel/parser.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | import logging | 3 | 3 | import ply.yacc as yacc | 4 | 4 |
| 5 | | -from babelsdk.babel.lexer import BabelLexer, BabelNull | | 5 | +from babelapi.babel.lexer import BabelLexer, BabelNull | 6 | 6 |
| 7 | 7 | class BabelOpDef(object): | 8 | 8 | def __init__(self, name, path=None): | @@ -161,7 +161,7 @@ def __init__(self, debug=False): | 161 | 161 | self.debug = debug | 162 | 162 | self.yacc = yacc.yacc(module=self, debug=self.debug, write_tables=self.debug) | 163 | 163 | self.lexer = BabelLexer() | 164 | | - self._logger = logging.getLogger('babelsdk.babel.parser') | | 164 | + self._logger = logging.getLogger('babelapi.babel.parser') | 165 | 165 |
| 166 | 166 | def parse(self, data): | 167 | 167 | return self.yacc.parse(data.lstrip(), lexer=self.lexer, debug=self.debug) | |
Collapse file Copy file name to clipboardExpand all lines: babelapi/babel/tower.py +13-8Lines changed: 13 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | import os | 5 | 5 | import sys | 6 | 6 |
| 7 | | -from babelsdk.babel.parser import BabelParser | 8 | | -from babelsdk.data_type import ( | | 7 | +from babelapi.babel.parser import BabelParser | | 8 | +from babelapi.data_type import ( | 9 | 9 | Binary, | 10 | 10 | Boolean, | 11 | 11 | Empty, | | 23 | 23 | UInt64, | 24 | 24 | Union, | 25 | 25 | ) | 26 | | -from babelsdk.api import ( | | 26 | +from babelapi.api import ( | 27 | 27 | Api, | 28 | 28 | ApiOperation, | 29 | 29 | ) | 30 | | -from babelsdk.babel.parser import ( | | 30 | +from babelapi.babel.parser import ( | 31 | 31 | BabelAlias, | 32 | 32 | BabelInclude, | 33 | 33 | BabelNamespace, | 34 | 34 | BabelOpDef, | 35 | 35 | BabelSymbol, | 36 | 36 | BabelTypeDef, | 37 | 37 | ) | 38 | | -from babelsdk.segmentation import ( | | 38 | +from babelapi.segmentation import ( | 39 | 39 | Segment, | 40 | 40 | SegmentList, | 41 | 41 | Segmentation, | @@ -67,7 +67,7 @@ def __init__(self, paths, version='0.1b1', debug=False): | 67 | 67 | """Creates a new tower of babel.""" | 68 | 68 |
| 69 | 69 | self._debug = debug | 70 | | - self._logger = logging.getLogger('babelsdk.dsl.tower') | | 70 | + self._logger = logging.getLogger('babelapi.dsl.tower') | 71 | 71 |
| 72 | 72 | self.api = Api(version=version) | 73 | 73 |
| @@ -140,7 +140,7 @@ def _create_type(self, env, item): | 140 | 140 |
| 141 | 141 | def _create_field(self, env, babel_field): | 142 | 142 | """ | 143 | | - Given a BabelField, returns a babelsdk.babel.tower.Field object. | | 143 | + Given a BabelField, returns a babelapi.babel.tower.Field object. | 144 | 144 |
| 145 | 145 | A BabelField is composed of symbols. This function resolves symbols to | 146 | 146 | objects that we've instantiated in the current environment. For example, | @@ -240,9 +240,14 @@ def add_to_api(self, path, desc): | 240 | 240 | env, | 241 | 241 | item.error_data_type_name, | 242 | 242 | ) | | 243 | + if item.path: | | 244 | + path = item.path.lstrip('/') | | 245 | + else: | | 246 | + # TODO: Split and add dashes | | 247 | + path = item.name.lower() | 243 | 248 | operation = ApiOperation( | 244 | 249 | item.name, | 245 | | - item.path or item.name, | | 250 | + path, | 246 | 251 | item.doc, | 247 | 252 | request_segmentation, | 248 | 253 | response_segmentation, | |
Collapse file Copy file name to clipboardExpand all lines: babelapi/cli.py +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | """ | 2 | | -A command-line interface for BabelSDK. | | 2 | +A command-line interface for BabelAPI. | 3 | 3 | """ | 4 | 4 |
| 5 | 5 | import argparse | | 8 | 8 | import os | 9 | 9 | import sys | 10 | 10 |
| 11 | | -from babelsdk.compiler import Compiler | 12 | | -from babelsdk.babel.tower import TowerOfBabel | | 11 | +from babelapi.compiler import Compiler | | 12 | +from babelapi.babel.tower import TowerOfBabel | 13 | 13 |
| 14 | 14 | def main(): | 15 | 15 | """The entry point for the program.""" | 16 | 16 |
| 17 | | - cmdline_parser = argparse.ArgumentParser(description='BabelSDK') | | 17 | + cmdline_parser = argparse.ArgumentParser(description='BabelAPI') | 18 | 18 | cmdline_parser.add_argument( | 19 | 19 | '-v', | 20 | 20 | '--verbose', | @@ -74,7 +74,7 @@ def main(): | 74 | 74 | ) | 75 | 75 | c.build() | 76 | 76 |
| 77 | | - if not sys.argv[0].endswith('babelsdk'): | | 77 | + if not sys.argv[0].endswith('babelapi'): | 78 | 78 | # If we aren't running from an entry_point, then return api to make it | 79 | 79 | # easier to do debugging. | 80 | 80 | return api | |
Collapse file Copy file name to clipboardExpand all lines: babelapi/compiler.py +6-6Lines changed: 6 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | import re | 7 | 7 | import shutil | 8 | 8 |
| 9 | | -from babelsdk.generator.generator import CodeGenerator | 10 | | -from babelsdk.generator.jinja import Jinja2Generator | | 9 | +from babelapi.generator.generator import CodeGenerator | | 10 | +from babelapi.generator.jinja import Jinja2Generator | 11 | 11 |
| 12 | 12 | class UnknownGenerator(Exception): pass | 13 | 13 | class MissingBabelPreamble(Exception): pass | @@ -18,7 +18,7 @@ class Compiler(object): | 18 | 18 | languages. | 19 | 19 | """ | 20 | 20 |
| 21 | | - first_line_re = re.compile('babelsdk\((?P<generator>\w+)\)') | | 21 | + first_line_re = re.compile('babelapi\((?P<generator>\w+)\)') | 22 | 22 | template_extension = '.babelt' | 23 | 23 |
| 24 | 24 | def __init__(self, | @@ -29,15 +29,15 @@ def __init__(self, | 29 | 29 | """ | 30 | 30 | Creates a Compiler. | 31 | 31 |
| 32 | | - :param babelsdk.api.Api api: A Babel description of the API. | | 32 | + :param babelapi.api.Api api: A Babel description of the API. | 33 | 33 | :param str source_path: Path to source to be converted. | 34 | 34 | :param str build_path: Location to save compiled sources to. If None, | 35 | 35 | source files are compiled into the same directories. | 36 | 36 | :param bool clean_build: If True, the build_path is removed before | 37 | 37 | source files are compiled into them. | 38 | 38 | """ | 39 | 39 |
| 40 | | - self._logger = logging.getLogger('babelsdk.compiler') | | 40 | + self._logger = logging.getLogger('babelapi.compiler') | 41 | 41 |
| 42 | 42 | self.api = api | 43 | 43 | self.source_path = source_path | @@ -178,7 +178,7 @@ def _process_file(self, source_path, target_path): | 178 | 178 |
| 179 | 179 | # Inject "Generated by" message in place of the preamble | 180 | 180 | new_first_line = first_line.replace(matches.group(0), | 181 | | - 'Generated by BabelSDK') | | 181 | + 'Generated by BabelAPI') | 182 | 182 | rendered_contents = (new_first_line + | 183 | 183 | rendered_contents[len(first_line):]) | 184 | 184 |
| |
|