-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96f2dce
commit 2e65245
Showing
3 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{%- comment -%}{% raw %}<!-- | ||
Includes the specified lines from an include file. | ||
|
||
Usage: | ||
{% include includelines filename=PATH start=INT count=INT %} | ||
|
||
filename: path to file under _includes | ||
start: first line to include, starting at 1 | ||
starttext: begin with line containing specified text | ||
count: number of lines to include | ||
endtext: ends with line containing specified text | ||
|
||
Example: | ||
|
||
{% include includelines filename='src/HelloWorld.java' start=10 count=5 %} | ||
|
||
-->{% endraw %}{%- endcomment -%} | ||
{%- capture filecontent -%} | ||
{%- include {{include.filename}} -%} | ||
{%- endcapture -%} | ||
{%- assign lines = filecontent | rstrip | newline_to_br | split: '<br />' -%} | ||
{%- assign start = {{include.start}} -%} | ||
{%- assign count = {{include.count}} -%} | ||
{%- for line in lines -%} | ||
{%- if line contains {{include.starttext}} -%} | ||
{%- assign start = forloop.index | minus: 1 -%} | ||
{%- endif -%} | ||
{%- if line contains {{include.endtext}} -%} | ||
{%- assign end = forloop.index | decrement -%} | ||
{%- assign count = end | minus: start -%} | ||
{%- endif -%} | ||
{%- endfor -%} | ||
{%- for line in lines offset: {{start}} limit: {{count}} -%} | ||
{{- line | rstrip -}} | ||
{%- endfor -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters