code_rippa 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in code_rippa.gemspec
4
- gemspec
5
-
6
- gem "linguist", :git => "https://github.com/github/linguist.git"
4
+ gemspec
data/README.md CHANGED
@@ -81,8 +81,21 @@ Note: In case your system doesn't have `pdflatex`, you can get a [LaTeX](http://
81
81
 
82
82
  ## Credits
83
83
 
84
- 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.
84
+ 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.
85
85
 
86
86
  ## Contributing
87
87
 
88
88
  Currently this gem is in its infancy. Any bug reports and feature requests are very welcomed.
89
+
90
+ ## Changelog
91
+
92
+ ### 0.0.4
93
+
94
+ - Removed dependency on Linguist.
95
+ - Tidier code.
96
+
97
+ ### 0.0.1 - 0.0.3
98
+
99
+ - Initial gem push
100
+ - Fixed many stupid bugs along the way
101
+
data/bin/code_rippa CHANGED
@@ -9,7 +9,6 @@ end
9
9
 
10
10
  options = {}
11
11
  option_parser = OptionParser.new do |opts|
12
-
13
12
  opts.banner =<<END
14
13
 
15
14
  Usage: code_rippa [options] input_file_or_directory
@@ -34,9 +33,12 @@ option_parser = OptionParser.new do |opts|
34
33
  Options:
35
34
  END
36
35
 
37
- opts.on('-l', '--list-themes', 'List all available themes') do
38
- puts Uv.themes.join("\n")
39
- exit 0
36
+ opts.on('-s', '--syntax SYNTAX', 'Selected syntax') do |syntax|
37
+ if CodeRippa.supported_syntax.include? syntax
38
+ options[:syntax] = syntax
39
+ else
40
+ raise ArgumentError, "syntax for #{syntax} not found. Use -s to see the list of available syntax."
41
+ end
40
42
  end
41
43
 
42
44
  opts.on('-t', '--theme THEME', 'Selected theme') do |theme|
@@ -52,21 +54,20 @@ END
52
54
  exit 0
53
55
  end
54
56
 
55
- opts.on('-s', '--syntax SYNTAX', 'Selected syntax') do |syntax|
56
- if CodeRippa.supported_syntax.include? syntax
57
- options[:syntax] = syntax
58
- else
59
- raise ArgumentError, "syntax for #{syntax} not found. Use -s to see the list of available syntax."
60
- end
57
+ opts.on('-l', '--list-themes', 'List all available themes') do
58
+ puts Uv.themes.join("\n")
59
+ exit 0
61
60
  end
62
-
63
- # No need to check if its a correct extension.
61
+
62
+ opts.on('-c', '--version', 'Display version number') do
63
+ puts CodeRippa::VERSION
64
+ exit 0
65
+ end
66
+
64
67
  options[:excluded_exts] = []
65
68
  opts.on('-x', '--excluded-exts E1,E2,EN', Array, 'Exclude these extensions when processing') do |exts|
66
-
67
69
  options[:excluded_exts] = exts.sort!
68
70
  valid_exts = exts & CodeRippa.supported_exts
69
-
70
71
  if valid_exts != exts
71
72
  invalid_exts = exts - valid_exts
72
73
  raise ArgumentError, "These extensions are not supported: #{invalid_exts.join(" ")}. Aborting."
@@ -85,9 +86,12 @@ begin
85
86
  option_parser.parse!
86
87
  if options[:theme] and options[:syntax] and ARGV.size == 1
87
88
  if FileTest.file?(ARGV[0])
88
- CodeRippa.rip_file(ARGV[0], options[:theme], options[:syntax], options[:excluded_exts])
89
- elsif FileTest.directory?(ARGV[0])
90
- CodeRippa.rip_dir(ARGV[0], options[:theme], options[:syntax], options[:excluded_exts])
89
+ CodeRippa.rip_file(ARGV[0], options[:theme], options[:syntax])
90
+ elsif File.directory?(ARGV[0])
91
+ Dir.chdir(ARGV[0])
92
+ CodeRippa.rip_dir(Dir.pwd, options[:theme], options[:syntax], options[:excluded_exts])
93
+ else
94
+ raise ArgumentError, "Invalid path. Aborting.\n"
91
95
  end
92
96
  exit 0
93
97
  else
@@ -1,3 +1,3 @@
1
1
  module CodeRippa
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/code_rippa.rb CHANGED
@@ -1,53 +1,39 @@
1
1
  require 'uv'
2
2
  require 'find'
3
- require 'linguist'
4
3
  require 'code_rippa/uv_overrides'
4
+ require 'code_rippa/version'
5
5
 
6
6
  YAML::ENGINE.yamler= 'syck'
7
7
 
8
8
  module CodeRippa
9
9
 
10
- def self.rip_file(path, theme, syntax, excluded_exts = [])
11
- outfile = File.open('out.tex', 'w')
12
-
10
+ def self.rip_file(path, theme, syntax)
13
11
  begin
14
12
  srcfile = File.read(path)
15
- src_ext = File.extname(path)[1..-1]
16
-
17
- unless excluded_exts.include? src_ext
18
- outfile.write preamble theme
19
- outfile.write "\\textcolor{headingcolor}{\\textbf{\\texttt{#{path.gsub('_','\_').gsub('%','\%')}}}}\\\\\n"
20
- outfile.write "\\textcolor{headingcolor}{\\rule{\\linewidth}{1.0mm}}\\\\\n"
21
- outfile.write Uv.parse(srcfile, 'latex', syntax, true, theme)
22
- outfile.write endtag
23
- outfile.close
24
- else
25
- puts "Warning: #{path} not processed. Check arguments."
26
- end
27
-
13
+ src_ext = File.extname(path)[1..-1]
14
+ outfile = File.open('out.tex', 'w')
15
+ outfile.write preamble theme
16
+ outfile.write "\\textcolor{headingcolor}{\\textbf{\\texttt{#{path.gsub('_','\_').gsub('%','\%')}}}}\\\\\n"
17
+ outfile.write "\\textcolor{headingcolor}{\\rule{\\linewidth}{1.0mm}}\\\\\n"
18
+ outfile.write Uv.parse(srcfile, 'latex', syntax, true, theme)
19
+ outfile.write endtag
20
+ outfile.close
28
21
  rescue Exception => e
29
22
  puts e
30
23
  end
31
24
  end
32
25
 
33
-
34
-
35
26
  def self.rip_dir(dir_path, theme, syntax, excluded_exts = [])
36
-
27
+ counter = 0
37
28
  outfile = File.open('out.tex', 'w')
38
- counter = 0
39
-
40
29
  outfile.write preamble(theme)
41
-
42
30
  Find.find(dir_path) do |path|
43
31
  depth = path.to_s.count('/')
44
32
  if File.basename(path)[0] == ?.
45
33
  Find.prune
46
34
  else
47
35
  begin
48
-
49
36
  is_rippable = rippable?(path, syntax, excluded_exts)
50
-
51
37
  if is_rippable
52
38
  outfile.write "\\textcolor{white}{\\textbf{\\texttt{#{path.gsub('_','\_').gsub('%','\%')}}}}\\\\\n"
53
39
  outfile.write "\\textcolor{white}{\\rule{\\linewidth}{1.0mm}}\\\\\n"
@@ -56,7 +42,7 @@ module CodeRippa
56
42
  if bookmarkable?(path, syntax, excluded_exts)
57
43
  outfile.write "\\pdfbookmark[#{depth-2}]{#{File.basename(path).gsub('_','\_').gsub('%','\%')}}{#{counter}}\n"
58
44
  end
59
-
45
+
60
46
  if is_rippable
61
47
  outfile.write Uv.parse(File.read(path), 'latex', syntax, true, theme)
62
48
  outfile.write "\\clearpage\n"
@@ -72,28 +58,22 @@ module CodeRippa
72
58
  end
73
59
 
74
60
  private
75
-
76
61
  def self.syntax_path
77
62
  Uv.syntax_path
78
63
  end
79
-
80
64
 
81
65
  def self.supported_syntax
82
66
  syntax = []
83
-
84
67
  Dir.foreach(syntax_path) do |f|
85
68
  if File.extname(f) == ".syntax"
86
- y = YAML.load(File.read "#{syntax_path}/#{f}")
87
69
  syntax << File.basename(f, '.*')
88
70
  end
89
71
  end
90
72
  syntax
91
73
  end
92
-
93
74
 
94
75
  def self.supported_langs
95
76
  langs = []
96
-
97
77
  Dir.foreach(syntax_path) do |f|
98
78
  if File.extname(f) == ".syntax"
99
79
  y = YAML.load(File.read "#{syntax_path}/#{f}")
@@ -103,10 +83,8 @@ module CodeRippa
103
83
  langs
104
84
  end
105
85
 
106
-
107
86
  def self.supported_exts
108
87
  filetypes = []
109
-
110
88
  Dir.foreach(syntax_path) do |f|
111
89
  if File.extname(f) == ".syntax"
112
90
  y = YAML.load(File.read "#{syntax_path}/#{f}")
@@ -115,41 +93,30 @@ module CodeRippa
115
93
  end
116
94
  filetypes
117
95
  end
118
-
119
96
 
120
97
  def self.bookmarkable?(path, syntax, excluded_exts)
121
98
  if FileTest.directory?(path)
122
99
  true
123
100
  else
124
101
  src_ext = File.extname(path)[1..-1]
125
- lang = Linguist::FileBlob.new(path).language
126
- lang = lang ? lang.name.downcase : ""
127
-
128
- if Linguist::FileBlob.new(path).binary?
102
+ if excluded_exts.include?(src_ext)
129
103
  false
130
- elsif excluded_exts.include?(src_ext)
131
- false
132
- elsif supported_syntax.include? lang
133
- true
104
+ elsif supported_exts.include?(src_ext)
105
+ true
134
106
  else
135
- false
107
+ false
136
108
  end
137
109
  end
138
110
  end
139
-
140
111
 
141
112
  def self.rippable?(path, syntax, excluded_exts)
142
113
  if FileTest.directory?(path)
143
114
  false
144
115
  else
145
116
  src_ext = File.extname(path)[1..-1]
146
- lang = Linguist::FileBlob.new(path).language
147
- lang = lang ? lang.name.downcase : ""
148
- if Linguist::FileBlob.new(path).binary?
117
+ if excluded_exts.include? src_ext
149
118
  false
150
- elsif excluded_exts.include? src_ext
151
- false
152
- elsif supported_syntax.include? lang
119
+ elsif supported_exts.include?(src_ext)
153
120
  true
154
121
  else
155
122
  false
@@ -157,19 +124,16 @@ module CodeRippa
157
124
  end
158
125
  end
159
126
 
160
-
161
127
  def self.page_color(theme)
162
128
  f = YAML.load(File.read("#{Uv.render_path}/latex/#{theme}.render"))
163
129
  /([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/.match(f['listing']['begin'].split('\\')[3]).to_s
164
130
  end
165
131
 
166
-
167
132
  def self.heading_color(theme)
168
133
  f = YAML.load(File.read("#{Uv.render_path}/latex/#{theme}.render"))
169
134
  /([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/.match(f['listing']['begin'].split('\\')[2]).to_s
170
135
  end
171
136
 
172
-
173
137
  def self.preamble(theme)
174
138
  preamble = ''
175
139
  preamble << "\\documentclass[a4paper,landscape]{article}\n"
@@ -190,10 +154,8 @@ module CodeRippa
190
154
  preamble << "\\setlength{\\LTpre}{-10pt}\n"
191
155
  preamble
192
156
  end
193
-
194
157
 
195
158
  def self.endtag
196
159
  "\\end{document}\n"
197
160
  end
198
-
199
161
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_rippa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-26 00:00:00.000000000 Z
12
+ date: 2012-03-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: spox-ultraviolet