Skip to content

Commit 431c0b8

Browse files
committed
Better error checking when language not specified
1 parent eef8a8f commit 431c0b8

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/oreilly/snippets.rb

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

58+
# puts "Should we skip flattening? #{language}"
5859
unless skip_flattening( language )
59-
if ( flatten or @@_config[:flatten] )
60+
if flatten or @@_config[:flatten]
6061
rv = flatten_it( rv )
6162
end
6263
end
@@ -67,7 +68,8 @@ def self.get_content_from_file( spec, identifier, language, sha=nil, numbers=nil
6768
end
6869

6970
def self.skip_flattening( language )
70-
rv = ( !!@@_config[:skip_flattening] and !!@@_config[:skip_flattening][language.to_sym] )
71+
rv = ( !!@@_config[:skip_flattening] and language and !!@@_config[:skip_flattening][language.to_sym] )
72+
# rv = ( !!@@_config[:skip_flattening] and !!@@_config[:skip_flattening][language.to_sym] )
7173
# puts "Skipping flattening for #{language} / #{@@_config[:skip_flattening][language.to_sym]} / #{rv} / (#{@@_config[:skip_flattening].inspect})" if rv
7274
rv
7375
end

spec/process_spec.rb

+15
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@
6262
snippet~~~~
6363
END
6464

65+
NO_LANGUAGE_FOR_FLATTENING = <<END
66+
[filename="spec/fixtures/factorial.java", lines="3..5"]
67+
snippet~~~~
68+
Put any descriptive text you want here. It will be replaced with the
69+
specified code snippet when you build ebook outputs
70+
snippet~~~~
71+
END
72+
6573
TEMPLATE = <<END
6674
6775
ABC
@@ -221,6 +229,13 @@ def download_test_repository
221229
string.should eq( output )
222230
end
223231

232+
it "should not crash when flattening if no language is specified" do
233+
Oreilly::Snippets.config( flatten: true, skip_flattening: { java: true } )
234+
lambda {
235+
Oreilly::Snippets.process( NO_LANGUAGE_FOR_FLATTENING )
236+
}.should_not raise_error()
237+
end
238+
224239
it "should support flattening with tabs" do
225240
output = Oreilly::Snippets.process( FLATTEN_WITH_TABS )
226241
output.should == @tabs_flattened

0 commit comments

Comments
 (0)