oreilly-snippets 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +25 -0
- data/lib/oreilly/snippets/version.rb +1 -1
- data/lib/oreilly/snippets.rb +4 -11
- data/spec/process_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c050b3514c9fad043f6558927fe6b7e446628f0
|
4
|
+
data.tar.gz: 7168ec00e39cc8eb811b7bf44a24a0188a71aefb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3770d0c1f2eb97b7730d60928e3f1e1f0335ea9949244a901aca4eb5ff37f647ccd9981e685a7ddc0deca538728f79f9c2a672ab05956bc4c4b3c415c84a8045
|
7
|
+
data.tar.gz: 5a7031154a6427e11c03168b5736400a7dee1e630e569203294fc99857b160384fe41bea51db053bac9c7dd31a18c73c2fe4b09f06f2582c9b146d535d73524f
|
data/README.md
CHANGED
@@ -81,6 +81,12 @@ directory, then grab the file at the specific SHA hash. This means you
|
|
81
81
|
can write code inside a repository, and add a snippet pointing to that
|
82
82
|
exact revision in the repository.
|
83
83
|
|
84
|
+
Also, you can specify line numbers and use just certain lines within the file retrieved:
|
85
|
+
|
86
|
+
```
|
87
|
+
[filename="../../github.js.test", language="js", sha="8e05a916fe0b1a9d3e:coffeetech.js, lines="1..5"]
|
88
|
+
```
|
89
|
+
|
84
90
|
NB: This format of snippets is not currently compatible with Atlas
|
85
91
|
from O'Reilly. However, you can always process the snippet and write
|
86
92
|
out a normal Asciidoc file, a file which will be compatible with
|
@@ -111,6 +117,25 @@ The file structure I use for this:
|
|
111
117
|
* Use the live-reload plugin for Chrome:
|
112
118
|
https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei
|
113
119
|
|
120
|
+
It looks like this:
|
121
|
+
|
122
|
+
```
|
123
|
+
# Files which have been processed by oreilly-snippets and
|
124
|
+
# have regulard [source,javascript] style code blocks
|
125
|
+
chapter1.asciidoc
|
126
|
+
chapter2.asciidoc
|
127
|
+
# Files with the exact same name which have the oreilly-snippets
|
128
|
+
# code includes. These are the files I edit.
|
129
|
+
/pre/chapter1.asciidoc
|
130
|
+
/pre/chapter2.asciidoc
|
131
|
+
# The rendered HTML files. I open these in my browser and the live-reload
|
132
|
+
# plugin reloads once I edit anything in the /pre directory.
|
133
|
+
chapter1.asciidoc.html
|
134
|
+
chapter2.asciidoc.html
|
135
|
+
```
|
136
|
+
|
137
|
+
Here is the `Guardfile`
|
138
|
+
|
114
139
|
```
|
115
140
|
require 'asciidoctor'
|
116
141
|
require 'oreilly/snippets'
|
data/lib/oreilly/snippets.rb
CHANGED
@@ -8,19 +8,13 @@ COMMENTS = {
|
|
8
8
|
module Oreilly
|
9
9
|
module Snippets
|
10
10
|
|
11
|
-
def self.get_content_from_file( spec, identifier, language, sha=nil )
|
11
|
+
def self.get_content_from_file( spec, identifier, language, sha=nil, numbers=nil )
|
12
12
|
contents = nil
|
13
13
|
line_numbers = nil
|
14
14
|
|
15
15
|
if sha
|
16
|
-
|
17
|
-
|
18
|
-
# Strip off the line numbers and use them later
|
19
|
-
first = sha.index ":"
|
20
|
-
second = (sha.index ":", first+1)+1
|
21
|
-
numbers = sha[second..-1]
|
22
|
-
sae = numbers.split( ".." ).map { |d| Integer(d) }
|
23
|
-
sha = sha[0..second-2]
|
16
|
+
if numbers
|
17
|
+
sae = numbers.split( ".." ).map { |d| Integer(d)+1 }
|
24
18
|
line_numbers = [sae[0], sae[1]]
|
25
19
|
end
|
26
20
|
# Use the filename to change into the directory and use git-show
|
@@ -28,7 +22,6 @@ module Oreilly
|
|
28
22
|
Dir.chdir spec if spec
|
29
23
|
contents = `git show #{sha}`
|
30
24
|
Dir.chdir cwd if spec
|
31
|
-
|
32
25
|
else
|
33
26
|
contents = File.read( spec )
|
34
27
|
end
|
@@ -62,7 +55,7 @@ module Oreilly
|
|
62
55
|
rv = input
|
63
56
|
if snippets and snippets.length > 0
|
64
57
|
snippets.each do |s|
|
65
|
-
content = get_content_from_file( s[:filename], s[:identifier], s[:language], s[:sha] )
|
58
|
+
content = get_content_from_file( s[:filename], s[:identifier], s[:language], s[:sha], s[:lines] )
|
66
59
|
rv = rv.gsub( s[:full], content )
|
67
60
|
end
|
68
61
|
end
|
data/spec/process_spec.rb
CHANGED
@@ -14,7 +14,7 @@ snippet~~~~
|
|
14
14
|
END
|
15
15
|
|
16
16
|
WITH_SHA_LINE_NUMBERS = <<END
|
17
|
-
[filename="#{ROOT}", language="js", sha="c863f786f5959799d7c:test.js
|
17
|
+
[filename="#{ROOT}", language="js", sha="c863f786f5959799d7c:test.js" lines="1..3"]
|
18
18
|
snippet~~~~
|
19
19
|
Put any descriptive text you want here. It will be replaced with the
|
20
20
|
snippet~~~~
|
@@ -167,7 +167,7 @@ describe Oreilly::Snippets do
|
|
167
167
|
original = `git show c863f786f5959799d7c11312a7ba1d603ff16339:test.js`
|
168
168
|
Dir.chdir cwd
|
169
169
|
lines = original.split /\n/
|
170
|
-
original = lines[
|
170
|
+
original = lines[2..4].join "\n"
|
171
171
|
output.strip.should == original.strip
|
172
172
|
end
|
173
173
|
end
|