Skip to content

Commit 6671696

Browse files
committed
modified .pull command to include entire file if @tag is omitted
1 parent 3c27470 commit 6671696

File tree

9 files changed

+132
-28
lines changed

9 files changed

+132
-28
lines changed

Diff for: README.md

+21-14
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,26 @@ Welcome To Gitdown
99

1010
Gitdown is a simple tool for writing documentation hosted on a github repository. It uses [ditaa][] to convert ascii diagrams into images, and produces [markdown][] documents that can be uploaded to your repository along with code. I made Gitdown so that we could write technical white papers and user guides as plain text (including diagrams) and publish them with a single "git push" command. Gitdown is a simpler version of the tool we use to maintain the [ØMQ][zeromq] [Guide][zguide].
1111

12-
Gitdown is written and maintained by Pieter Hintjens. Please use the issue [tracker][] for all comments and errata. This document was published on Thursday March, 2011 at 22:41:04, and generated by the magic of Gitdown from README.txt.
12+
Gitdown is written and maintained by Pieter Hintjens. Please use the issue [tracker][] for all comments and errata. This document was published on Tuesday February, 2013 at 16:43:34, and generated by the magic of Gitdown from README.txt.
1313

1414
This is version 2011.03.24 of Gitdown. Changelog:
1515

16+
* 2013.02.05: Gyepi Sam changed pull command to make chunk specification optional.
1617
* 2010.03.24: added .pull command to include chunks from other files.
1718
* 2010.10.11: don't do symbol substitution in code blocks.
1819
* 2010.10.09: added .toc token to generate table of contents.
1920

20-
<A name="toc2-31" title="Contents" />
21+
<A name="toc2-32" title="Contents" />
2122
Contents
2223
--------
2324

24-
&emsp;<a href="#toc2-37">License</a>
25-
&emsp;<a href="#toc2-46">Installation and Use</a>
26-
&emsp;<a href="#toc2-71">How it Works</a>
27-
&emsp;<a href="#toc2-126">Gitdown Syntax Summary</a>
28-
&emsp;<a href="#toc2-186">Markdown Syntax Summary</a>
25+
&emsp;<a href="#toc2-38">License</a>
26+
&emsp;<a href="#toc2-47">Installation and Use</a>
27+
&emsp;<a href="#toc2-72">How it Works</a>
28+
&emsp;<a href="#toc2-127">Gitdown Syntax Summary</a>
29+
&emsp;<a href="#toc2-193">Markdown Syntax Summary</a>
2930

30-
<A name="toc2-37" title="License" />
31+
<A name="toc2-38" title="License" />
3132
License
3233
-------
3334

@@ -36,7 +37,7 @@ Copyright (c) 1996-2011 iMatix Corporation
3637

3738
This is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
3839

39-
<A name="toc2-46" title="Installation and Use" />
40+
<A name="toc2-47" title="Installation and Use" />
4041
Installation and Use
4142
--------------------
4243

@@ -61,7 +62,7 @@ To use Gitdown, edit a text document much like this README.txt. Then:
6162

6263
The images directory holds images for all documents in the current directory. You can write documents anywhere on the git tree but if they are not at the root you must tell Gitdown how to create a full image path by setting the SUBDIR symbol (see below).
6364

64-
<A name="toc2-71" title="How it Works" />
65+
<A name="toc2-72" title="How it Works" />
6566
How it Works
6667
------------
6768

@@ -80,7 +81,7 @@ The Gitdown workflow is:
8081

8182
This README acts as an example.
8283

83-
<A name="toc2-126" title="Gitdown Syntax Summary" />
84+
<A name="toc2-127" title="Gitdown Syntax Summary" />
8485
Gitdown Syntax Summary
8586
---------------------
8687

@@ -93,7 +94,7 @@ Gitdown is a pre-processor that adds these syntax elements on top of Markdown:
9394
.set name=value Sets Gitdown symbol
9495
.sub oldval=newval Replaces oldval by newval in every line
9596
.toc [top] Insert table of contents
96-
.pull srcfile@tag[,opts] Pull a chunk of text from sourcefile
97+
.pull srcfile[@tag][,opts] Pull a chunk of text, or the whole file, from srcfile
9798
.end Everything past this is ignored
9899

99100
$\(xxx) Value of variable, anywhere in text
@@ -126,7 +127,13 @@ Gitdown is a pre-processor that adds these syntax elements on top of Markdown:
126127

127128
The top argument for .toc tells it the top header level in the text. Lower levels are shown horizontally. E.g. this file has level 2 headers in the text and uses `.toc 1` to get these laid-out on a single row.
128129

129-
The opts argument for .pull can be: 'code' to indicate the results should be indented 4 spaces. An opts of 'left' removes any left margin. A chunk of text is identified by '@tag' anywhere in the line before the chunk, and any other tag signalling the end. '@end' can be used to close any chunk. Tag names must be alphanumeric.
130+
If the .pull command includes an optional @tag, the named chunk of text is pulled from the source file.
131+
A chunk of text is identified by '@tag' anywhere in the line before the chunk, and any other tag signalling the end. '@end' can be used to close any chunk. Tag names must be alphanumeric.
132+
If @tag is omitted, the entire file is included.
133+
134+
The opts argument for .pull can be: 'code' to indicate the results should be indented 4 spaces.
135+
An opts of 'left' removes any left margin.
136+
130137

131138
These symbols have special meaning:
132139

@@ -140,7 +147,7 @@ These symbols are predefined by gitdown for you:
140147
* SELF specifies the input file name without extension.
141148
* OUTPUT specifies the current output file name,
142149

143-
<A name="toc2-186" title="Markdown Syntax Summary" />
150+
<A name="toc2-193" title="Markdown Syntax Summary" />
144151
Markdown Syntax Summary
145152
-----------------------
146153

Diff for: README.txt

+9-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Gitdown is written and maintained by Pieter Hintjens. Please use the issue [tra
2323

2424
This is version 2011.03.24 of Gitdown. Changelog:
2525

26+
* 2013.02.05: Gyepi Sam changed pull command to make chunk specification optional.
2627
* 2010.03.24: added .pull command to include chunks from other files.
2728
* 2010.10.11: don't do symbol substitution in code blocks.
2829
* 2010.10.09: added .toc token to generate table of contents.
@@ -130,7 +131,7 @@ Gitdown is a pre-processor that adds these syntax elements on top of Markdown:
130131
.set name=value Sets Gitdown symbol
131132
.sub oldval=newval Replaces oldval by newval in every line
132133
.toc [top] Insert table of contents
133-
.pull srcfile@tag[,opts] Pull a chunk of text from sourcefile
134+
.pull srcfile[@tag][,opts] Pull a chunk of text, or the whole file, from srcfile
134135
.end Everything past this is ignored
135136

136137
$\(xxx) Value of variable, anywhere in text
@@ -163,7 +164,13 @@ Gitdown is a pre-processor that adds these syntax elements on top of Markdown:
163164

164165
The top argument for .toc tells it the top header level in the text. Lower levels are shown horizontally. E.g. this file has level 2 headers in the text and uses `.toc 1` to get these laid-out on a single row.
165166

166-
The opts argument for .pull can be: 'code' to indicate the results should be indented 4 spaces. An opts of 'left' removes any left margin. A chunk of text is identified by '@tag' anywhere in the line before the chunk, and any other tag signalling the end. '@end' can be used to close any chunk. Tag names must be alphanumeric.
167+
If the .pull command includes an optional @tag, the named chunk of text is pulled from the source file.
168+
A chunk of text is identified by '@tag' anywhere in the line before the chunk, and any other tag signalling the end. '@end' can be used to close any chunk. Tag names must be alphanumeric.
169+
If @tag is omitted, the entire file is included.
170+
171+
The opts argument for .pull can be: 'code' to indicate the results should be indented 4 spaces.
172+
An opts of 'left' removes any left margin.
173+
167174

168175
These symbols have special meaning:
169176

Diff for: bin/gitdown

+32-12
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,42 @@ while ($line < @input) {
121121
elsif (/^\.\-/) {
122122
# Comment, ignore
123123
}
124-
elsif (/^\.pull (.*)(@[a-zA-Z0-9]+)(,(.*)\s*)?/) {
125-
$source = $1;
126-
$tag = $2;
127-
$opts = $4;
124+
elsif (/^\.pull\s+(.*?)([@,].+)?\s*$/) {
125+
my ($source, $rest) = ($1, $2);
126+
my ($tag, $opts); #tags and opts are both optional
127+
128+
if ($rest =~ /^(@[a-zA-Z0-9]+)(,.+)?/) {
129+
$tag = $1;
130+
$rest = $2;
131+
}
132+
133+
if ($rest =~ /,(.*)/) {
134+
$opts = $1;
135+
}
136+
128137
die "Can't read $source: $!"
129-
unless open (SOURCE, $source);
138+
unless open (SOURCE, $source);
139+
140+
my $apply_opts = sub {
141+
chomp;
142+
$_ = " $_" if ($opts eq "code");
143+
s/^ {4}// if ($opts eq "left");
144+
145+
};
130146
while (<SOURCE>) {
131-
if (/$tag/) {
132-
while (<SOURCE>) {
133-
last if /@[a-zA-Z0-9]+/;
134-
chop;
135-
$_ = " $_" if ($opts eq "code");
136-
s/^ // if ($opts eq "left");
137-
writeln ($_);
147+
if ($tag) {
148+
if (/$tag/) {
149+
while (<SOURCE>) {
150+
last if /@[a-zA-Z0-9]+/;
151+
$apply_opts->();
152+
writeln ($_);
153+
}
138154
}
139155
}
156+
else {
157+
$apply_opts->();
158+
writeln ($_);
159+
}
140160
}
141161
close (SOURCE);
142162
}

Diff for: images/README_1.png

-70 Bytes
Loading

Diff for: images/README_2.png

-13 Bytes
Loading

Diff for: test/chunks

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@ch1
2+
3+
The reward for work well done is the opportunity to do more.
4+
5+
@end
6+
7+
@ch2
8+
9+
for(int i = 0; i < argc ; i++) {
10+
printf("%s\n", argv[i]);
11+
}
12+
13+
@end
14+
15+
@ch3
16+
17+
<files>
18+
<name="/etc/passwd" perm="0600" />
19+
<name="/etc/quotd" />
20+
</files>
21+
22+
@end

Diff for: test/file2

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
There is wisdom in turning as often as possible from the familiar to the
2+
unfamiliar: it keeps the mind nimble, it kills prejudice, and it fosters
3+
humor.

Diff for: test/pull.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
This file should pull three chunks from a file named chunks
2+
3+
This is chunk 1, which is plain text
4+
5+
The reward for work well done is the opportunity to do more.
6+
7+
8+
This is chunk 2, which is code
9+
10+
11+
for(int i = 0; i < argc ; i++) {
12+
printf("%s\n", argv[i]);
13+
}
14+
15+
16+
This is chunk 3, which is left aligned
17+
18+
19+
<files>
20+
<name="/etc/passwd" perm="0600" />
21+
<name="/etc/quotd" />
22+
</files>
23+
24+
25+
This is file2, no chunk, plain text
26+
27+
There is wisdom in turning as often as possible from the familiar to the
28+
unfamiliar: it keeps the mind nimble, it kills prejudice, and it fosters
29+
humor.

Diff for: test/pull.txt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
This file should pull three chunks from a file named chunks
2+
3+
This is chunk 1, which is plain text
4+
.pull chunks@ch1
5+
6+
This is chunk 2, which is code
7+
8+
.pull chunks@ch2,code
9+
10+
This is chunk 3, which is left aligned
11+
12+
.pull chunks@ch3,left
13+
14+
This is file2, no chunk, plain text
15+
16+
.pull file2

0 commit comments

Comments
 (0)