Skip to content

Commit eef8a8f

Browse files
committed
Improve wording of skip flattening functionality
1 parent 8db9b84 commit eef8a8f

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ if anotherVar == "anotherVar"
144144
If you want the default to be to flatten (avoiding setting it each
145145
snippet declaration), you can set that using the config method: `Oreilly::Snippets.config( flatten: true )`
146146

147-
At the moment, flattening does not work perfectly for Java files. You can ignore java with `Oreilly::Snippets.config( flatten: true, flatten_exceptions: { java: true } )`
148-
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 } )`
149148
#### Incompatibilities with Atlas from O'Reilly
150149

151150
NB: This format of snippets is not currently compatible with Atlas

lib/oreilly/snippets.rb

+8-4
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,21 @@ def self.get_content_from_file( spec, identifier, language, sha=nil, numbers=nil
5555
rv = contents
5656
end
5757

58-
if ( flatten or @@_config[:flatten] ) and not flatten_exceptions( language )
59-
rv = flatten_it( rv )
58+
unless skip_flattening( language )
59+
if ( flatten or @@_config[:flatten] )
60+
rv = flatten_it( rv )
61+
end
6062
end
6163

6264
rv = "INVALID SNIPPET, WARNING" if error
6365
# rv = scrub_other_identifiers( contents, comments )
6466
rv
6567
end
6668

67-
def self.flatten_exceptions( language )
68-
@@_config[:flatten_exceptions] and @@_config[:flatten_exceptions][language.to_sym]
69+
def self.skip_flattening( language )
70+
rv = ( !!@@_config[:skip_flattening] and !!@@_config[:skip_flattening][language.to_sym] )
71+
# puts "Skipping flattening for #{language} / #{@@_config[:skip_flattening][language.to_sym]} / #{rv} / (#{@@_config[:skip_flattening].inspect})" if rv
72+
rv
6973
end
7074

7175
def self.flatten_it( content )

lib/oreilly/snippets/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Oreilly
22
module Snippets
3-
VERSION = "0.0.9"
3+
VERSION = "0.0.10"
44
end
55
end

spec/process_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def download_test_repository
216216
// Do something
217217
}
218218
END
219-
Oreilly::Snippets.config( flatten: true, flatten_exceptions: { java: true } )
219+
Oreilly::Snippets.config( flatten: true, skip_flattening: { java: true } )
220220
output = Oreilly::Snippets.process( DONT_USE_JAVA_FOR_FLATTENING )
221221
string.should eq( output )
222222
end

0 commit comments

Comments
 (0)