code_rippa
Advanced tools
+1
-3
| source 'https://rubygems.org' | ||
| # Specify your gem's dependencies in code_rippa.gemspec | ||
| gemspec | ||
| gem "linguist", :git => "https://github.com/github/linguist.git" | ||
| gemspec |
+18
-56
| require 'uv' | ||
| require 'find' | ||
| require 'linguist' | ||
| require 'code_rippa/uv_overrides' | ||
| require 'code_rippa/version' | ||
@@ -10,20 +10,13 @@ YAML::ENGINE.yamler= 'syck' | ||
| def self.rip_file(path, theme, syntax, excluded_exts = []) | ||
| outfile = File.open('out.tex', 'w') | ||
| def self.rip_file(path, theme, syntax) | ||
| begin | ||
| srcfile = File.read(path) | ||
| src_ext = File.extname(path)[1..-1] | ||
| unless excluded_exts.include? src_ext | ||
| outfile.write preamble theme | ||
| outfile.write "\\textcolor{headingcolor}{\\textbf{\\texttt{#{path.gsub('_','\_').gsub('%','\%')}}}}\\\\\n" | ||
| outfile.write "\\textcolor{headingcolor}{\\rule{\\linewidth}{1.0mm}}\\\\\n" | ||
| outfile.write Uv.parse(srcfile, 'latex', syntax, true, theme) | ||
| outfile.write endtag | ||
| outfile.close | ||
| else | ||
| puts "Warning: #{path} not processed. Check arguments." | ||
| end | ||
| src_ext = File.extname(path)[1..-1] | ||
| 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" | ||
| outfile.write Uv.parse(srcfile, 'latex', syntax, true, theme) | ||
| outfile.write endtag | ||
| outfile.close | ||
| rescue Exception => e | ||
@@ -34,11 +27,6 @@ puts e | ||
| 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| | ||
@@ -50,5 +38,3 @@ depth = path.to_s.count('/') | ||
| begin | ||
| is_rippable = rippable?(path, syntax, excluded_exts) | ||
| if is_rippable | ||
@@ -62,3 +48,3 @@ outfile.write "\\textcolor{white}{\\textbf{\\texttt{#{path.gsub('_','\_').gsub('%','\%')}}}}\\\\\n" | ||
| end | ||
| if is_rippable | ||
@@ -79,14 +65,10 @@ outfile.write Uv.parse(File.read(path), 'latex', syntax, true, theme) | ||
| 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, '.*') | ||
@@ -97,7 +79,5 @@ end | ||
| end | ||
| def self.supported_langs | ||
| langs = [] | ||
| Dir.foreach(syntax_path) do |f| | ||
@@ -112,6 +92,4 @@ if File.extname(f) == ".syntax" | ||
| def self.supported_exts | ||
| filetypes = [] | ||
| Dir.foreach(syntax_path) do |f| | ||
@@ -125,3 +103,2 @@ if File.extname(f) == ".syntax" | ||
| end | ||
@@ -133,17 +110,11 @@ def self.bookmarkable?(path, syntax, excluded_exts) | ||
| 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 | ||
@@ -155,9 +126,5 @@ def self.rippable?(path, syntax, excluded_exts) | ||
| 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 | ||
@@ -170,3 +137,2 @@ else | ||
| def self.page_color(theme) | ||
@@ -177,3 +143,2 @@ f = YAML.load(File.read("#{Uv.render_path}/latex/#{theme}.render")) | ||
| def self.heading_color(theme) | ||
@@ -184,3 +149,2 @@ f = YAML.load(File.read("#{Uv.render_path}/latex/#{theme}.render")) | ||
| def self.preamble(theme) | ||
@@ -206,3 +170,2 @@ preamble = '' | ||
| end | ||
@@ -212,3 +175,2 @@ def self.endtag | ||
| end | ||
| end |
| module CodeRippa | ||
| VERSION = "0.0.3" | ||
| VERSION = "0.0.4" | ||
| end |
+14
-1
@@ -84,3 +84,3 @@ # CodeRippa | ||
| 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. | ||
@@ -90,1 +90,14 @@ ## Contributing | ||
| Currently this gem is in its infancy. Any bug reports and feature requests are very welcomed. | ||
| ## Changelog | ||
| ### 0.0.4 | ||
| - Removed dependency on Linguist. | ||
| - Tidier code. | ||
| ### 0.0.1 - 0.0.3 | ||
| - Initial gem push | ||
| - Fixed many stupid bugs along the way | ||
Sorry, the diff of this file is not supported yet