Skip to content

Commit

Permalink
More power in extracting source code
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed May 7, 2014
1 parent 1c42c78 commit 24ee3b8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions template-engine/cogutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
LAST_LINES = None
LAST_FILENAME = None

def include(filename, first=None, numlines=None, numblanks=None, dedent=True):
def include(filename, first=None, after=None, numlines=None, numblanks=None, dedent=True):
"""
Include text from a file.
"""
Expand All @@ -17,7 +17,7 @@ def include(filename, first=None, numlines=None, numblanks=None, dedent=True):
else:
lines = LAST_LINES

including = "".join(selected_lines(lines, first, numlines, numblanks))
including = "".join(selected_lines(lines, first, after, numlines, numblanks))
if dedent:
including = textwrap.dedent(including)

Expand All @@ -26,10 +26,14 @@ def include(filename, first=None, numlines=None, numblanks=None, dedent=True):
cog.outl("```")


def selected_lines(lines, first=None, numlines=None, numblanks=None):
def selected_lines(lines, first=None, after=None, numlines=None, numblanks=None):
ready = after is None
including = False
for line in lines:
if first is not None and first in line:
if not ready:
if after in line:
ready = True
if ready and first is not None and first in line:
including = True
if including:
if numblanks is not None and not line.strip():
Expand Down

0 comments on commit 24ee3b8

Please sign in to comment.