Changeset 318
- Timestamp:
- 05/05/08 03:20:27 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/picolena/templates/lib/plain_text_extractors/plain_text.rb
r312 r318 4 4 aka "plain text file" 5 5 with {|source| 6 if File.plain_text?(source) then 7 encoding=File.encoding(source) 8 if encoding.empty? then 9 File.read(source) 10 else 11 %x{iconv -f #{encoding} -t utf8 "#{source}" 2>/dev/null} 12 end 6 raise "Binary file : #{source}" unless File.plain_text?(source) 7 encoding=File.encoding(source) 8 if encoding.empty? then 9 File.read(source) 13 10 else 14 nil11 %x{iconv -f #{encoding} -t utf8 "#{source}" 2>/dev/null} 15 12 end 16 13 } trunk/lib/picolena/templates/spec/models/plain_text_extractor_spec.rb
r312 r318 30 30 31 31 it "should not extract content of binary files" do 32 PlainTextExtractor.extract_content_from("spec/test_dirs/indexed/others/BIN_FILE_WITHOUT_EXTENSION").should be_blank 32 bin_file="spec/test_dirs/indexed/others/BIN_FILE_WITHOUT_EXTENSION" 33 lambda{PlainTextExtractor.extract_content_from(bin_file)}.should raise_error(RuntimeError, "Binary file : "<<bin_file) 33 34 end 34 35 end
