Skip to content

Commit

Permalink
Can now insert custom strings before or after snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
knatten committed Oct 19, 2011
1 parent 89105b0 commit 2fc4179
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
5 changes: 5 additions & 0 deletions python/SnippetySnip/snippetysnip.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ def insert_snippets(old_buffer, snippet_getter=get_snippet):
new_buffer.append(line)
match = re.search(snippet_begin, line)
if match:
arguments = get_arguments(line)
file_name, snippet_name = match.groups()
if arguments.get('before'):
new_buffer.append(arguments['before'])
new_buffer.extend(snippet_getter(file_name, snippet_name).split("\n")[:-1])
if arguments.get('after'):
new_buffer.append(arguments['after'])
new_buffer.append(remove_arguments(line).replace("snippetysnip", "snippetysnip_end"))
end_line = find_end_line(old_buffer[line_no:], file_name, snippet_name)
if end_line != -1:
Expand Down
25 changes: 22 additions & 3 deletions python/SnippetySnip/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,33 @@ def test_inserts_before(self):
expected = [
"foo",
"<!-- snippetysnip:snippy.cpp:snippet:(before=\"[sourcecode]\") -->",
#"[sourcecode]",
"[sourcecode]",
"line1",
"line2",
#"[/sourcecode]",
"<!-- snippetysnip_end:snippy.cpp:snippet -->",
"bar"
]
self.assertEqual(expected, insert_snippets(buffer, fake_get_snippet))
actual = insert_snippets(buffer, fake_get_snippet)
self.assertEqual(expected, actual)

def test_inserts_before_and_after(self):
buffer = [
"foo",
"<!-- snippetysnip:snippy.cpp:snippet:(before=\"[sourcecode]\", after=\"[/sourcecode]\") -->",
"bar"
]
expected = [
"foo",
"<!-- snippetysnip:snippy.cpp:snippet:(before=\"[sourcecode]\", after=\"[/sourcecode]\") -->",
"[sourcecode]",
"line1",
"line2",
"[/sourcecode]",
"<!-- snippetysnip_end:snippy.cpp:snippet -->",
"bar"
]
actual = insert_snippets(buffer, fake_get_snippet)
self.assertEqual(expected, actual)


class Test_get_arguments(unittest.TestCase):
Expand Down

0 comments on commit 2fc4179

Please sign in to comment.