Skip to content

Commit

Permalink
Snippet script almost rewriten, still buggy cause of unicode chars co…
Browse files Browse the repository at this point in the history
…ntained in the body of the syntax. beaknit#34
  • Loading branch information
dgomesbr committed Aug 2, 2016
1 parent d36dcb0 commit 2d3c6e3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.cache
.#*
.DS_Store
*.pyc
19 changes: 15 additions & 4 deletions build/build-snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# vim: ai ts=4 sts=4 et sw=4
"""Build snippets from documentation from AWS."""
import requests
import sys
import collections
from templating import build_with_template
from lxml import html

Expand All @@ -12,30 +14,39 @@
def build_index():
"""Build the main index with key and url for the services."""
toc_uri = BASE_HREF + 'aws-template-resource-type-ref.html'
elem_expr = '//*[@id="main-col-body"]/div[2]/div[2]/ul/li/a'
elem_expr = '//*[@id="main-col-body"]/div[2]/div/ul/li/a'
page = requests.get(toc_uri)
doc = html.fromstring(page.content)
doc = html.fromstring(page.text.decode('utf-8'))
tree = doc.xpath(elem_expr)
index = {}
index = collections.OrderedDict()

for e in tree:
arn = e.text_content()
title = e.text_content().replace('::', '-').replace('AWS-', "").lower()
href = e.get('href')
full_href = BASE_HREF + href
index[arn] = (arn, title, href, full_href)

return index


def generate(index):
"""Will traverse index and generate all the snippets."""
default_suffix = '.sublime-snippet'
for k, v in index.iteritems():
(arn, title, href, full_href) = v
snippet = createSnippet(arn, title, href, full_href)


def createSnippet(arn, title, href, full_href):
"""Create a snippet with the args."""
print build_with_template(arn, title, '')
elem_expr = '//*[@id="main-col-body"]/div/div/pre/code'
page = requests.get(full_href)
doc = doc = html.fromstring(page.text.decode('utf-8'))
tree = doc.xpath(elem_expr)
print 'creating {} {} {}'.format(arn, title, tree)
return build_with_template(arn, title, tree)


def main():
"""Main doc generation."""
Expand Down
9 changes: 8 additions & 1 deletion build/templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
"""Templating operations for the snippets created by the build script."""


import sys


def build_with_template(trigger, title, body):
"""With all args give, transform body with param list and return a complete snippet."""

processed_body = """"${{1:-}}" : {}""".format((body[0]).text_content())

template = """
<snippet>
<content><![CDATA[{}]]></content>
Expand All @@ -12,6 +19,6 @@ def build_with_template(trigger, title, body):
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.cloudformation</scope>
</snippet>
""".format(body, title)
""".format(processed_body, title)

return template

0 comments on commit 2d3c6e3

Please sign in to comment.