]> git.armaanb.net Git - stagit.git/blobdiff - highlight
FileBlob wrapper.
[stagit.git] / highlight
index c67e70319b31a8f834597897aa9cea7fd1a56ec6..2b46f20fdd885d4c0df382109c7c818d51520d2c 100755 (executable)
--- a/highlight
+++ b/highlight
@@ -8,7 +8,27 @@ stdin = ARGF.file
 filename = stdin.readline.strip  # Read first line (filename).
 contents = stdin.read            # Read rest (code).
 
-detected = Linguist::FileBlob.new(filename).language
+class FakeBlob < Linguist::FileBlob
+  def initialize(path, content, base_bath=nil)
+    super(path, base_bath)
+    @content = content
+  end
+
+  def data
+    @content
+  end
+
+  def size
+    @content.bytesize
+  end
+end
+
+blob = FakeBlob.new(filename, contents)
+detected = if blob.language
+             blob.language.name
+           else
+             "Text only"
+           end
 
 # Debugging
 #puts "File #{filename}"
@@ -18,7 +38,7 @@ detected = Linguist::FileBlob.new(filename).language
 #pp detected
 
 html = Pygments.highlight(contents,
-  :lexer => detected.name,
+  :lexer => detected,
   :formatter => 'html',
   :options => {
     :encoding => 'utf-8',