oreilly-snippets 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTI1MTRhNzZiNmZiN2U1NWQ5ODJkMDRjNDEwNmE0MTllMGI3MGRmMg==
4
+ YTAwOGQ0YTdhODBiMjI1MThjMTZkNTQyMzkwMjdlN2ViYmRjYjE3YQ==
5
5
  data.tar.gz: !binary |-
6
- YzkwMmViMjc3ZjJlNDA3Y2ZjMTUxNWEzYzI0NDVjMGUwN2ZmMzc3Zg==
6
+ ZDlmMjc1YTY5MWZlMmJiM2MwYjA0OGY4NWQzNDFlYzE5M2UyYzY2ZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmFiNzAzMzEzNDk4MmJhMzg2MTMyNTIxOWU3Y2I0OGMwYmZjZWI5Njc5YzVk
10
- YWMzNzNjNDgzMzg0Nzc3NTZhYTg4ODI4NGNiYzlmOTk4NGYxYjQ4NWQ5NzM2
11
- ZGVkOTU0N2I3NDk0MTMwNzY1ZDhiN2FhNDliZWU2ZTNlMGZmZDE=
9
+ YWMyOTRmNGQ4NDhhMGE1MTk5ZTMzZTA3MDA1MTdhZDRhMzhmMzVmMDYyNzg1
10
+ NGRmYWE3M2MxNmZjODk0MWE0YWY1ZWU5MzUwYTlhYzE1MTNlZjFiYzBjZmEz
11
+ YzJjMDI2MDJlYjY3ZTI2YWNiMDFlMzc0NTBlMTliMDQ0MGVkOTY=
12
12
  data.tar.gz: !binary |-
13
- NTljZmQxNDI2NzAxZTVlMjBhMThiM2U2ZDM2OGU5YWY0NzAxNjYwOTRiMGRl
14
- NmM2OGVjZWVhNjcyZTczMDMwMTMxNmJjZWFjMGNkOTNkMGFlOWNkYjIyNzA4
15
- ZDFjOGMyNmEyMTI5OTQyNjk4ZDM1ZGY1NjQxYTBkMjhmMjU1ZTg=
13
+ MGE0NjY5MTA5ZmIzYTI3YzVjMTcxNzdiMDQ2ZjQxZjRiZTk2NmRmOWY3M2I5
14
+ MjUwY2ZmNjE4ZWNiOGYyZmVmMzJkZjU2YWI2YjM3OWZjMDllNTAwNDBiYmFm
15
+ MmQzZjc3ZDllMDlhZWJlMGYwZDMwZTU0ZWEwYTEwNDQ3Y2ZiN2Q=
data/README.md CHANGED
@@ -145,6 +145,7 @@ If you want the default to be to flatten (avoiding setting it each
145
145
  snippet declaration), you can set that using the config method: `Oreilly::Snippets.config( flatten: true )`
146
146
 
147
147
  At the moment, flattening does not work perfectly for Java files. You can ignore java with `Oreilly::Snippets.config( flatten: true, skip_flattening: { java: true } )`
148
+
148
149
  #### Incompatibilities with Atlas from O'Reilly
149
150
 
150
151
  NB: This format of snippets is not currently compatible with Atlas
@@ -152,6 +153,14 @@ from O'Reilly. However, you can always process the snippet and write
152
153
  out a normal Asciidoc file, a file which will be compatible with
153
154
  Atlas. See below for an example using Guard.
154
155
 
156
+ ### Normalizing Callouts
157
+
158
+ If you use callouts, you might run into a situation where you write 10
159
+ of them inside a snippet, and then you break that snippet into
160
+ two. Your second snippet will have callouts 6-10. If you specify
161
+ `normcallouts="true"` in your snippet, this module will rewrite those to
162
+ start from 1.
163
+
155
164
  ### Using with Guard and live-reload
156
165
 
157
166
  One nice workflow is to edit files in your editor, then have guard
@@ -1,5 +1,5 @@
1
1
  module Oreilly
2
2
  module Snippets
3
- VERSION = "0.0.11"
3
+ VERSION = "0.0.12"
4
4
  end
5
5
  end
@@ -15,7 +15,7 @@ module Oreilly
15
15
  @@_config.merge!( opts )
16
16
  end
17
17
 
18
- def self.get_content_from_file( spec, identifier, language, sha=nil, numbers=nil, flatten=false )
18
+ def self.get_content_from_file( spec, identifier, language, sha=nil, numbers=nil, flatten=false, normcallouts=false )
19
19
  contents = nil
20
20
  line_numbers = nil
21
21
  error = false
@@ -62,11 +62,22 @@ module Oreilly
62
62
  end
63
63
  end
64
64
 
65
+ if normcallouts
66
+ rv = normalize_callouts( rv )
67
+ end
68
+
65
69
  rv = "INVALID SNIPPET, WARNING" if error
66
70
  # rv = scrub_other_identifiers( contents, comments )
67
71
  rv
68
72
  end
69
73
 
74
+ def self.normalize_callouts( rv )
75
+ # Find something that looks like comment character + whitespace + < + number + >
76
+ index = 0
77
+ rv.gsub!( /([\/#]) <\d+>/ ) { |c| index += 1; "#{$1} <#{index}>" }
78
+ rv
79
+ end
80
+
70
81
  def self.skip_flattening( language )
71
82
  rv = ( !!@@_config[:skip_flattening] and language and !!@@_config[:skip_flattening][language.to_sym] )
72
83
  # rv = ( !!@@_config[:skip_flattening] and !!@@_config[:skip_flattening][language.to_sym] )
@@ -107,7 +118,7 @@ module Oreilly
107
118
  rv = input
108
119
  if snippets and snippets.length > 0
109
120
  snippets.each do |s|
110
- content = get_content_from_file( s[:filename], s[:identifier], s[:language], s[:sha], s[:lines], s[:flatten] )
121
+ content = get_content_from_file( s[:filename], s[:identifier], s[:language], s[:sha], s[:lines], s[:flatten], s[:normcallouts] )
111
122
  rv = rv.gsub( s[:full], content )
112
123
  end
113
124
  end
@@ -0,0 +1,2 @@
1
+ OK().do( <2> ).it()
2
+ another.thing( <3> ).bad()
@@ -0,0 +1,2 @@
1
+ something().is().here() // <2>
2
+ another.thing().ok() // <3>
@@ -0,0 +1,2 @@
1
+ something.do.it # <2>
2
+ yeah.it.works # <3>
data/spec/process_spec.rb CHANGED
@@ -37,6 +37,28 @@ snippet~~~~
37
37
 
38
38
  END
39
39
 
40
+ NORMALIZE_CALLOUTS_JS = <<"END"
41
+ [filename="spec/fixtures/normalize_callouts.js", normcallouts="true"]
42
+ snippet~~~~
43
+ ...
44
+ snippet~~~~
45
+ END
46
+
47
+ HONEYPOT_NORMALIZE_CALLOUTS = <<"END"
48
+ [filename="spec/fixtures/normalize_callouts.honey", normcallouts="true"]
49
+ snippet~~~~
50
+ ...
51
+ snippet~~~~
52
+ END
53
+
54
+
55
+ NORMALIZE_CALLOUTS_RB = <<"END"
56
+ [filename="spec/fixtures/normalize_callouts.rb", normcallouts="true"]
57
+ snippet~~~~
58
+ ...
59
+ snippet~~~~
60
+ END
61
+
40
62
 
41
63
  FULL = <<END
42
64
  [filename="spec/fixtures/factorial.js", language="js", identifier="FACTORIAL_FUNC"]
@@ -195,6 +217,25 @@ describe Oreilly::Snippets do
195
217
  output.should_not match( /END FACTORIAL_FUNC/ )
196
218
  end
197
219
 
220
+ describe "#normcallouts" do
221
+ it "should normalize callouts" do
222
+ output = Oreilly::Snippets.process( NORMALIZE_CALLOUTS_JS )
223
+ output.should match( /<1>/ )
224
+ output.should_not match( /<3>/ )
225
+ end
226
+
227
+ it "should normalize callouts with alternative comments" do
228
+ output = Oreilly::Snippets.process( NORMALIZE_CALLOUTS_RB )
229
+ output.should match( /<1>/ )
230
+ output.should_not match( /<3>/ )
231
+ end
232
+
233
+ it "should not mistakenly normalize callouts" do
234
+ output = Oreilly::Snippets.process( HONEYPOT_NORMALIZE_CALLOUTS )
235
+ output.should match( /<2>/ )
236
+ end
237
+ end
238
+
198
239
  describe "#flatten" do
199
240
  before( :each ) do
200
241
  @with_spaces = File.read( "spec/fixtures/with_spaces.rb" )
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.11
4
+ version: 0.0.12
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-08-18 00:00:00.000000000 Z
11
+ date: 2015-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,6 +72,9 @@ files:
72
72
  - spec/fixtures/coffeetech.js
73
73
  - spec/fixtures/factorial.java
74
74
  - spec/fixtures/factorial.js
75
+ - spec/fixtures/normalize_callouts.honey
76
+ - spec/fixtures/normalize_callouts.js
77
+ - spec/fixtures/normalize_callouts.rb
75
78
  - spec/fixtures/with_spaces.rb
76
79
  - spec/fixtures/with_tabs.rb
77
80
  - spec/process_spec.rb
@@ -104,6 +107,9 @@ test_files:
104
107
  - spec/fixtures/coffeetech.js
105
108
  - spec/fixtures/factorial.java
106
109
  - spec/fixtures/factorial.js
110
+ - spec/fixtures/normalize_callouts.honey
111
+ - spec/fixtures/normalize_callouts.js
112
+ - spec/fixtures/normalize_callouts.rb
107
113
  - spec/fixtures/with_spaces.rb
108
114
  - spec/fixtures/with_tabs.rb
109
115
  - spec/process_spec.rb