MemoryBlob class: wrapper around the content of a file

Makes it possible to detect the language of a snippet of code
without having an actual file on disk
Will allow github-markup to use Linguist without restricting its API
This commit is contained in:
Paul Chaignon
2015-07-12 20:28:42 +02:00
parent d459f7289e
commit 8917f1a91a
3 changed files with 380 additions and 4 deletions

View File

@@ -3,14 +3,21 @@ require "minitest/autorun"
require "mocha/setup"
require "linguist"
require 'color-proximity'
require "linguist/memory_blob"
def fixtures_path
File.expand_path("../fixtures", __FILE__)
end
def fixture_blob(name)
name = File.join(fixtures_path, name) unless name =~ /^\//
Linguist::FileBlob.new(name, fixtures_path)
filepath = (name =~ /^\//)? name : File.join(fixtures_path, name)
Linguist::FileBlob.new(filepath, fixtures_path)
end
def fixture_blob_memory(name)
filepath = (name =~ /^\//)? name : File.join(fixtures_path, name)
content = File.read(filepath)
Linguist::MemoryBlob.new(name, content)
end
def samples_path
@@ -18,6 +25,12 @@ def samples_path
end
def sample_blob(name)
name = File.join(samples_path, name) unless name =~ /^\//
Linguist::FileBlob.new(name, samples_path)
filepath = (name =~ /^\//)? name : File.join(samples_path, name)
Linguist::FileBlob.new(filepath, samples_path)
end
def sample_blob_memory(name)
filepath = (name =~ /^\//)? name : File.join(samples_path, name)
content = File.read(filepath)
Linguist::MemoryBlob.new(name, content)
end