Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.

Commit

Permalink
Re-allow macro-only bzl, fix runtime failure. (#37)
Browse files Browse the repository at this point in the history
This patch:
 - fixes the use of undeclared attributes introduced by b14ff10.
 - allows doc for macro-only bzl to be emitted.
  • Loading branch information
DavidDecotigny authored and davidzchen committed Dec 15, 2016
1 parent a35e4e7 commit 8d4d9be
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
12 changes: 6 additions & 6 deletions skydoc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,15 @@ class MarkdownWriter(object):

def __init__(self, writer_options):
self.__options = writer_options
self.__env = _create_jinja_environment(self.__options.link_ext)

def write(self, rulesets):
"""Write the documentation for the rules contained in rulesets."""
try:
temp_dir = tempfile.mkdtemp()
output_files = []
for ruleset in rulesets:
if len(ruleset.rules) > 0:
if not ruleset.empty():
output_files.append(self._write_ruleset(temp_dir, ruleset))
if self.__options.overview:
output_files.append(self._write_overview(temp_dir, rulesets))
Expand Down Expand Up @@ -168,8 +169,7 @@ def write(self, rulesets):

def _write_ruleset(self, output_dir, ruleset):
# Load template and render Markdown.
env = _create_jinja_environment(self.__options.link_ext)
template = env.get_template('markdown.jinja')
template = self.__env.get_template('markdown.jinja')
out = template.render(ruleset=ruleset)

# Write output to file. Output files are created in a directory structure
Expand All @@ -187,10 +187,10 @@ def _write_overview(self, output_dir, rulesets):
template = self.__env.get_template('markdown_overview.jinja')
out = template.render(rulesets=rulesets)

output_file = "%s/%s.md" % (output_dir, self.options.overview_filename)
output_file = "%s/%s.md" % (output_dir, self.__options.overview_filename)
with open(output_file, "w") as f:
f.write(out)
return (output_file, "%s.md" % self.options.overview_filename)
return (output_file, "%s.md" % self.__options.overview_filename)

class HtmlWriter(object):
"""Writer for generating documentation in HTML."""
Expand All @@ -211,7 +211,7 @@ def write(self, rulesets):
temp_dir = tempfile.mkdtemp()
output_files = []
for ruleset in rulesets:
if len(ruleset.rules) > 0:
if not ruleset.empty():
output_files.append(self._write_ruleset(temp_dir, ruleset, nav))
if self.__options.overview:
output_files.append(self._write_overview(temp_dir, rulesets, nav))
Expand Down
6 changes: 6 additions & 0 deletions skydoc/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,9 @@ def __init__(self, bzl_file, language, title, description, strip_prefix,
else:
assert rule_proto.type == build_pb2.RuleDefinition.REPOSITORY_RULE
self.repository_rules.append(definition)

def empty(self):
"""Return True if there is nothing to document."""
return not any([self.rules,
self.macros,
self.repository_rules])
24 changes: 21 additions & 3 deletions skydoc/templates/toc.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,31 @@ See the License for the specific language governing permissions and
limitations under the License.
#}
<nav class="toc">
<h2>Rules</h2>
<ul>
% if ruleset.description:
<li><a href="#overview">Overview</a></li>
<h2><a href="#overview">Overview</a></h2>
% endif
% if ruleset.repository_rules[0] is defined:
<h2>Repository Rules</h2>
<ul>
% for rule in ruleset.repository_rules:
<li><a href="#{{ rule.name }}">{{ rule.name }}</a></li>
% endfor
</ul>
% endif
% if ruleset.rules[0] is defined:
<h2>Rules</h2>
<ul>
% for rule in ruleset.rules:
<li><a href="#{{ rule.name }}">{{ rule.name }}</a></li>
% endfor
</ul>
% endif
% if ruleset.macros[0] is defined:
<h2>Macros</h2>
<ul>
% for macro in ruleset.macros:
<li><a href="#{{ macro.name }}">{{ macro.name }}</a></li>
% endfor
</ul>
% endif
</nav>

0 comments on commit 8d4d9be

Please sign in to comment.