Permalink
Browse files

removed dependency on linguist

  • Loading branch information...
1 parent 3f26c84 commit d5294234248398dae7fd97e06e627b7661bb3249 Benjamin Tan Wei Hao committed Mar 27, 2012
Showing with 13 additions and 50 deletions.
  1. +1 −3 Gemfile
  2. +1 −1 README.md
  3. +11 −46 lib/code_rippa.rb
View
@@ -1,6 +1,4 @@
source 'https://rubygems.org'
# Specify your gem's dependencies in code_rippa.gemspec
-gemspec
-
-gem "linguist", :git => "https://github.com/github/linguist.git"
+gemspec
View
@@ -81,7 +81,7 @@ Note: In case your system doesn't have `pdflatex`, you can get a [LaTeX](http://
## Credits
-None of this would be possible without the awesome [ultraviolet](https://github.com/giom/ultraviolet) and [spox-ultraviolet](https://github.com/spox/ultraviolet) and [linguist](https://github.com/github/linguist) gems. Props to [__lwheng__](https://github.com/lwheng) for providing most of the LaTeX help.
+None of this would be possible without the awesome [ultraviolet](https://github.com/giom/ultraviolet) and [spox-ultraviolet](https://github.com/spox/ultraviolet) gems. Props to [__lwheng__](https://github.com/lwheng) for providing most of the LaTeX help.
## Contributing
View
@@ -1,20 +1,17 @@
require 'uv'
require 'find'
-require 'linguist'
require 'code_rippa/uv_overrides'
YAML::ENGINE.yamler= 'syck'
module CodeRippa
def self.rip_file(path, theme, syntax, excluded_exts = [])
- outfile = File.open('out.tex', 'w')
-
begin
srcfile = File.read(path)
- src_ext = File.extname(path)[1..-1]
-
+ src_ext = File.extname(path)[1..-1]
unless excluded_exts.include? src_ext
+ outfile = File.open('out.tex', 'w')
outfile.write preamble theme
outfile.write "\\textcolor{headingcolor}{\\textbf{\\texttt{#{path.gsub('_','\_').gsub('%','\%')}}}}\\\\\n"
outfile.write "\\textcolor{headingcolor}{\\rule{\\linewidth}{1.0mm}}\\\\\n"
@@ -23,31 +20,23 @@ def self.rip_file(path, theme, syntax, excluded_exts = [])
outfile.close
else
puts "Warning: #{path} not processed. Check arguments."
- end
-
+ end
rescue Exception => e
puts e
end
end
-
-
def self.rip_dir(dir_path, theme, syntax, excluded_exts = [])
-
+ counter = 0
outfile = File.open('out.tex', 'w')
- counter = 0
-
outfile.write preamble(theme)
-
Find.find(dir_path) do |path|
depth = path.to_s.count('/')
if File.basename(path)[0] == ?.
Find.prune
else
begin
-
is_rippable = rippable?(path, syntax, excluded_exts)
-
if is_rippable
outfile.write "\\textcolor{white}{\\textbf{\\texttt{#{path.gsub('_','\_').gsub('%','\%')}}}}\\\\\n"
outfile.write "\\textcolor{white}{\\rule{\\linewidth}{1.0mm}}\\\\\n"
@@ -56,7 +45,7 @@ def self.rip_dir(dir_path, theme, syntax, excluded_exts = [])
if bookmarkable?(path, syntax, excluded_exts)
outfile.write "\\pdfbookmark[#{depth-2}]{#{File.basename(path).gsub('_','\_').gsub('%','\%')}}{#{counter}}\n"
end
-
+
if is_rippable
outfile.write Uv.parse(File.read(path), 'latex', syntax, true, theme)
outfile.write "\\clearpage\n"
@@ -72,28 +61,22 @@ def self.rip_dir(dir_path, theme, syntax, excluded_exts = [])
end
private
-
def self.syntax_path
Uv.syntax_path
end
-
def self.supported_syntax
syntax = []
-
Dir.foreach(syntax_path) do |f|
if File.extname(f) == ".syntax"
- y = YAML.load(File.read "#{syntax_path}/#{f}")
syntax << File.basename(f, '.*')
end
end
syntax
end
-
def self.supported_langs
langs = []
-
Dir.foreach(syntax_path) do |f|
if File.extname(f) == ".syntax"
y = YAML.load(File.read "#{syntax_path}/#{f}")
@@ -103,10 +86,8 @@ def self.supported_langs
langs
end
-
def self.supported_exts
filetypes = []
-
Dir.foreach(syntax_path) do |f|
if File.extname(f) == ".syntax"
y = YAML.load(File.read "#{syntax_path}/#{f}")
@@ -115,61 +96,47 @@ def self.supported_exts
end
filetypes
end
-
def self.bookmarkable?(path, syntax, excluded_exts)
if FileTest.directory?(path)
true
else
src_ext = File.extname(path)[1..-1]
- lang = Linguist::FileBlob.new(path).language
- lang = lang ? lang.name.downcase : ""
-
- if Linguist::FileBlob.new(path).binary?
+ if excluded_exts.include?(src_ext)
false
- elsif excluded_exts.include?(src_ext)
- false
- elsif supported_syntax.include? lang
- true
+ elsif supported_exts.include?(src_ext)
+ true
else
- false
+ false
end
end
end
-
def self.rippable?(path, syntax, excluded_exts)
if FileTest.directory?(path)
false
else
src_ext = File.extname(path)[1..-1]
- lang = Linguist::FileBlob.new(path).language
- lang = lang ? lang.name.downcase : ""
- if Linguist::FileBlob.new(path).binary?
+ if excluded_exts.include? src_ext
false
- elsif excluded_exts.include? src_ext
- false
- elsif supported_syntax.include? lang
+ elsif supported_exts.include?(src_ext)
true
else
false
end
end
end
-
def self.page_color(theme)
f = YAML.load(File.read("#{Uv.render_path}/latex/#{theme}.render"))
/([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/.match(f['listing']['begin'].split('\\')[3]).to_s
end
-
def self.heading_color(theme)
f = YAML.load(File.read("#{Uv.render_path}/latex/#{theme}.render"))
/([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/.match(f['listing']['begin'].split('\\')[2]).to_s
end
-
def self.preamble(theme)
preamble = ''
preamble << "\\documentclass[a4paper,landscape]{article}\n"
@@ -190,10 +157,8 @@ def self.preamble(theme)
preamble << "\\setlength{\\LTpre}{-10pt}\n"
preamble
end
-
def self.endtag
"\\end{document}\n"
end
-
end

0 comments on commit d529423

Please sign in to comment.