oreilly-snippets 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/oreilly/snippets.rb +24 -3
- data/lib/oreilly/snippets/version.rb +1 -1
- data/spec/fixtures/some.xml +5 -0
- data/spec/process_spec.rb +57 -0
- metadata +11 -9
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NmYxN2YxYTYzZDk2Nzc4YzIxNWY3Y2RlNzIzODJkYTgyNDViZDYwNg==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d0682d9e05b50a2090ed835c3e5c57a03d759b5f
|
4
|
+
data.tar.gz: 831879746851e37f84c1723acaca638b0d2fba96
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NmY5MzNlZWE2NjQ1ODNjMjk5MDY3Yjg5Zjk2ZTk5MmE4Mjc2ODM4Y2U4M2I4
|
11
|
-
ZDQwOGIxOWQyMzZiZWIwZmQ1NjdkMzA2ZTdmOTUyNDRlMmY0ZmQ=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZWQyZWQzY2RiYWY1ZjZlNDNjOTg0NWQ0MWRlODY4NmM0ZWY2MGYwMTY3NzJk
|
14
|
-
NmY0NGM2Y2E0NzJhNzJjYjhjYjc2YmYwZmRlMmRiMjQ4NWE0Yzg1ZDk3MDNk
|
15
|
-
ZjcxMjA4NDc4NzY1ODFjODE4YzEzYTA2ZjFkN2FkNDU4YTFkYjM=
|
6
|
+
metadata.gz: 4711957ef11fe51514ac17bbd19153767d1303ffbefc15afdd3d2c3437ec3fdb4a3283808c2a189813c3f27caed115d547bf18aa61f6ed94909d9c5acc32893a
|
7
|
+
data.tar.gz: 9e1f79bd5ab14061c6854a551305137402a2088bf220ee37d3277a88e01ce2f40da009d04d1199e2478d7779c3c08a22821d398ebd435323a4e8396152fd9df8
|
data/lib/oreilly/snippets.rb
CHANGED
@@ -25,8 +25,19 @@ module Oreilly
|
|
25
25
|
flatten = s[:flatten]
|
26
26
|
normcallouts = s[:normcallouts]
|
27
27
|
callouts_prefix = s[:callouts_prefix]
|
28
|
+
callouts_wrap = s[:callouts_wrap]
|
28
29
|
callouts = s[:callouts]
|
29
30
|
|
31
|
+
if callouts_wrap
|
32
|
+
if callouts_prefix
|
33
|
+
raise "Cannot use both callout prefix and wrap together"
|
34
|
+
end
|
35
|
+
|
36
|
+
if -1 == callouts_wrap.index( '{x}' )
|
37
|
+
raise "Improper use of callouts: needs to be like '<!-- {x} -->' ('{x}' must be a placeholder)"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
30
41
|
contents = nil
|
31
42
|
line_numbers = nil
|
32
43
|
error = false
|
@@ -74,7 +85,7 @@ module Oreilly
|
|
74
85
|
end
|
75
86
|
|
76
87
|
if callouts
|
77
|
-
rv = process_callouts( rv, callouts, callouts_prefix )
|
88
|
+
rv = process_callouts( rv, callouts, callouts_prefix, callouts_wrap )
|
78
89
|
elsif normcallouts
|
79
90
|
rv = normalize_callouts( rv )
|
80
91
|
end
|
@@ -84,7 +95,7 @@ module Oreilly
|
|
84
95
|
rv
|
85
96
|
end
|
86
97
|
|
87
|
-
def self.process_callouts( input, callouts, comment_character = nil )
|
98
|
+
def self.process_callouts( input, callouts, comment_character = nil, wrap = nil )
|
88
99
|
rv = nil
|
89
100
|
# Strip them out and figure out the comment character
|
90
101
|
rv = input.gsub( /([#\/]\/?) ?<\d+>/ ) { |c| comment_character ||= $1; '' }
|
@@ -107,7 +118,17 @@ module Oreilly
|
|
107
118
|
lines = rv.split /\n/
|
108
119
|
list.each_with_index do |c,i|
|
109
120
|
index = c.to_i - 1
|
110
|
-
|
121
|
+
|
122
|
+
if lines.length > index and index >= 0
|
123
|
+
callout = nil
|
124
|
+
if wrap
|
125
|
+
callout = wrap.gsub( '{x}', "<#{i+1}>" )
|
126
|
+
else
|
127
|
+
callout = "#{comment_character} <#{i+1}>"
|
128
|
+
end
|
129
|
+
|
130
|
+
lines[index] += callout
|
131
|
+
end
|
111
132
|
end
|
112
133
|
rv = lines.join "\n"
|
113
134
|
end
|
data/spec/process_spec.rb
CHANGED
@@ -87,6 +87,28 @@ snippet~~~~
|
|
87
87
|
snippet~~~~
|
88
88
|
END
|
89
89
|
|
90
|
+
CALLOUTS_WRAP_AND_PREFIX_JS = <<"END"
|
91
|
+
[filename="spec/fixtures/normalize_callouts_long.js", callouts_prefix="#", callouts_wrap="# {1} #", callouts="1,10,15"]
|
92
|
+
snippet~~~~
|
93
|
+
...
|
94
|
+
snippet~~~~
|
95
|
+
END
|
96
|
+
|
97
|
+
CALLOUTS_WRAP_XML = <<"END"
|
98
|
+
[filename="spec/fixtures/some.xml", callouts_wrap="<!-- {x} -->", callouts="1,2,3"]
|
99
|
+
snippet~~~~
|
100
|
+
...
|
101
|
+
snippet~~~~
|
102
|
+
END
|
103
|
+
|
104
|
+
INVALID_CALLOUTS_WRAP_XML = <<"END"
|
105
|
+
[filename="spec/fixtures/some.xml", callouts_wrap="<!-- no x! -->", callouts="1,2,3"]
|
106
|
+
snippet~~~~
|
107
|
+
...
|
108
|
+
snippet~~~~
|
109
|
+
END
|
110
|
+
|
111
|
+
|
90
112
|
NORMALIZE_CALLOUTS_JS = <<"END"
|
91
113
|
[filename="spec/fixtures/normalize_callouts.js", normcallouts="true"]
|
92
114
|
snippet~~~~
|
@@ -296,6 +318,41 @@ describe Oreilly::Snippets do
|
|
296
318
|
lines[14].should match( /# <3>/ )
|
297
319
|
end
|
298
320
|
|
321
|
+
it "should add a prefix character to a callout to makes sure the code is runnable" do
|
322
|
+
output = Oreilly::Snippets.process( CALLOUTS_PREFIX_JS )
|
323
|
+
lines = output.split /\n/
|
324
|
+
lines[0].should match( /# <1>/ )
|
325
|
+
lines[9].should match( /# <2>/ )
|
326
|
+
lines[14].should match( /# <3>/ )
|
327
|
+
end
|
328
|
+
|
329
|
+
it "should properly wrap callouts" do
|
330
|
+
output = Oreilly::Snippets.process( CALLOUTS_WRAP_XML )
|
331
|
+
lines = output.split /\n/
|
332
|
+
lines[0].should match( /<!-- <1> -->/ )
|
333
|
+
lines[1].should match( /<!-- <2> -->/ )
|
334
|
+
lines[2].should match( /<!-- <3> -->/ )
|
335
|
+
end
|
336
|
+
|
337
|
+
it "should raise an error when prefix and wrap are used together for callouts" do
|
338
|
+
lambda {
|
339
|
+
output = Oreilly::Snippets.process( CALLOUTS_WRAP_AND_PREFIX_JS )
|
340
|
+
}.should raise_error
|
341
|
+
end
|
342
|
+
|
343
|
+
it "should raise an error when wrap is misued" do
|
344
|
+
lambda {
|
345
|
+
output = Oreilly::Snippets.process( INVALID_CALLOUTS_WRAP_JS )
|
346
|
+
}.should raise_error
|
347
|
+
end
|
348
|
+
|
349
|
+
it "should raise an error when wrap is misued" do
|
350
|
+
lambda {
|
351
|
+
output = Oreilly::Snippets.process( CALLOUTS_WRAP_AND_PREFIX_JS )
|
352
|
+
}.should raise_error
|
353
|
+
end
|
354
|
+
|
355
|
+
|
299
356
|
it "should add callouts using a default comment" do
|
300
357
|
output = Oreilly::Snippets.process( REALLY_LONG_CALLOUTS_JS )
|
301
358
|
lines = output.split /\n/
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oreilly-snippets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Dawson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,28 +28,28 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: Use O'Reilly style snippets inside your markup (asciidoc or markdown)
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- spec/fixtures/normalize_callouts.rb
|
79
79
|
- spec/fixtures/normalize_callouts_long.js
|
80
80
|
- spec/fixtures/really_long_line.rb
|
81
|
+
- spec/fixtures/some.xml
|
81
82
|
- spec/fixtures/with_spaces.rb
|
82
83
|
- spec/fixtures/with_tabs.rb
|
83
84
|
- spec/process_spec.rb
|
@@ -92,17 +93,17 @@ require_paths:
|
|
92
93
|
- lib
|
93
94
|
required_ruby_version: !ruby/object:Gem::Requirement
|
94
95
|
requirements:
|
95
|
-
- -
|
96
|
+
- - '>='
|
96
97
|
- !ruby/object:Gem::Version
|
97
98
|
version: '0'
|
98
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
100
|
requirements:
|
100
|
-
- -
|
101
|
+
- - '>='
|
101
102
|
- !ruby/object:Gem::Version
|
102
103
|
version: '0'
|
103
104
|
requirements: []
|
104
105
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.2.
|
106
|
+
rubygems_version: 2.2.2
|
106
107
|
signing_key:
|
107
108
|
specification_version: 4
|
108
109
|
summary: See the README
|
@@ -116,6 +117,7 @@ test_files:
|
|
116
117
|
- spec/fixtures/normalize_callouts.rb
|
117
118
|
- spec/fixtures/normalize_callouts_long.js
|
118
119
|
- spec/fixtures/really_long_line.rb
|
120
|
+
- spec/fixtures/some.xml
|
119
121
|
- spec/fixtures/with_spaces.rb
|
120
122
|
- spec/fixtures/with_tabs.rb
|
121
123
|
- spec/process_spec.rb
|