code_rippa 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/code_rippa CHANGED
@@ -13,22 +13,18 @@ option_parser = OptionParser.new do |opts|
13
13
 
14
14
  Usage: code_rippa [options] input_file_or_directory
15
15
 
16
- Parses input_file or directory and outputs a file named out.tex.
17
- It expects both the syntax and theme to be specified.
16
+ Parses input_file or directory and outputs a file named out.tex.
17
+ It expects both the syntax and theme to be specified.
18
18
 
19
19
  Example:
20
20
 
21
- code_rippa -s ruby -t amy path_to_file.rb
21
+ code_rippa -s ruby -t amy path_to_file.rb
22
22
 
23
- Renders the contents of path_to_file.rb into out.tex.
23
+ Renders the contents of path_to_file.rb into out.tex.
24
24
 
25
- Then run
26
-
27
- pdflatex out.tex
28
-
29
- to generate the PDF output.
25
+ Then run `pdflatex out.tex` to generate the PDF output.
30
26
 
31
- "-s" and "-t" are mandatory. The rest are optional.
27
+ "-s" and "-t" are mandatory. The rest are optional.
32
28
 
33
29
  Options:
34
30
  END
@@ -59,7 +55,7 @@ END
59
55
  exit 0
60
56
  end
61
57
 
62
- opts.on('-c', '--version', 'Display version number') do
58
+ opts.on('-v', '--version', 'Display version number') do
63
59
  puts CodeRippa::VERSION
64
60
  exit 0
65
61
  end
data/code_rippa.gemspec CHANGED
@@ -17,5 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.require_paths = ["lib"]
18
18
  gem.version = CodeRippa::VERSION
19
19
  gem.required_ruby_version = '>= 1.9.0'
20
+ gem.add_dependency "rainbow"
21
+ gem.add_dependency "ansi"
20
22
  gem.add_dependency "spox-ultraviolet", "~> 0.10.5"
21
23
  end
data/lib/code_rippa.rb CHANGED
@@ -2,34 +2,77 @@ require 'uv'
2
2
  require 'find'
3
3
  require 'code_rippa/uv_overrides'
4
4
  require 'code_rippa/version'
5
+ require 'ansi/progressbar'
6
+ require 'rainbow'
7
+ include ANSI
5
8
 
6
- YAML::ENGINE.yamler= 'syck'
9
+
10
+ YAML::ENGINE.yamler = 'syck'
7
11
 
8
12
  module CodeRippa
9
-
13
+
14
+ @@supported_syntax = nil
15
+ @@supported_ext = nil
16
+
17
+ # Parses the given file, and writes the output file (out.tex)
18
+ # into the current directory.
19
+ #
20
+ # path - The file path
21
+ # syntax - The syntax to perform parsing/syntax highlighting.
22
+ # Note the the syntax should be supported by code_rippa.
23
+ # excluded_exts - An Array of extensions to ignore during parsing.
24
+ #
25
+ # Examples
26
+ #
27
+ # rip_dir("~/code/ruby/some_folder/some_file.rb", "space_cadet", "ruby", [])
28
+ #
29
+ # Returns nothing.
10
30
  def self.rip_file(path, theme, syntax)
11
31
  begin
12
32
  srcfile = File.read(path)
13
33
  src_ext = File.extname(path)[1..-1]
14
- outfile = File.open('out.tex', 'w')
34
+ outfile = File.open('out.tex', 'w')
15
35
  outfile.write preamble theme
16
36
  outfile.write "\\textcolor{headingcolor}{\\textbf{\\texttt{#{path.gsub('_','\_').gsub('%','\%')}}}}\\\\\n"
17
37
  outfile.write "\\textcolor{headingcolor}{\\rule{\\linewidth}{1.0mm}}\\\\\n"
18
38
  outfile.write Uv.parse(srcfile, 'latex', syntax, true, theme)
19
39
  outfile.write endtag
40
+
41
+ msg = "Completed successfully.\n".color(:green)
42
+ msg << "Output file written to: "
43
+ msg << "#{File.expand_path(outfile)}\n".color(:yellow)
44
+ msg << "Now run "
45
+ msg << "pdflatex #{File.expand_path(outfile)} ".color(:red)
46
+ msg << "** TWICE ** to generate PDF."
47
+ puts msg
20
48
  outfile.close
21
49
  rescue Exception => e
22
50
  puts e
23
51
  end
24
52
  end
25
53
 
54
+ # Parses the given directory, and writes the output file (out.tex)
55
+ # into the current directory.
56
+ #
57
+ # dir_path - The directory path
58
+ # syntax - The syntax to perform parsing/syntax highlighting.
59
+ # Note the the syntax should be supported by code_rippa.
60
+ # excluded_exts - An Array of extensions to ignore during parsing.
61
+ #
62
+ # Examples
63
+ #
64
+ # rip_dir("~/code/ruby/some_folder", "space_cadet", "ruby", [])
65
+ #
66
+ # Returns nothing.
26
67
  def self.rip_dir(dir_path, theme, syntax, excluded_exts = [])
27
- counter = 0
28
- outfile = File.open('out.tex', 'w')
29
- outfile.write preamble(theme)
30
- Find.find(dir_path) do |path|
68
+ pbar = Progressbar.new("Rippin'".color(:blue), Dir["**/*"].length)
69
+ counter = 0
70
+ outfile = File.open('out.tex', 'w')
71
+
72
+ outfile.write preamble theme
73
+ Find.find dir_path do |path|
31
74
  depth = path.to_s.count('/')
32
- if File.basename(path)[0] == ?.
75
+ if File.basename(path)[0] == ?. or File.basename(path) == "out.tex"
33
76
  Find.prune
34
77
  else
35
78
  begin
@@ -52,26 +95,60 @@ module CodeRippa
52
95
  end
53
96
  counter += 1
54
97
  end
98
+ pbar.inc
55
99
  end
100
+
56
101
  outfile.write endtag
102
+ pbar.finish
103
+
104
+ msg = "Completed successfully.\n".color(:green)
105
+ msg << "Output file written to: "
106
+ msg << "#{File.expand_path(outfile)}\n".color(:yellow)
107
+ msg << "Now run "
108
+ msg << "pdflatex #{File.expand_path(outfile)} ".color(:red)
109
+ msg << "** TWICE ** to generate PDF."
110
+ puts msg
111
+
57
112
  outfile.close
58
113
  end
59
114
 
60
- private
115
+ private
61
116
  def self.syntax_path
62
117
  Uv.syntax_path
63
118
  end
64
119
 
120
+ # Returns an Array of supported syntaxes. This is done by parsing
121
+ # all the file names in the syntax folder.
122
+ #
123
+ # Examples
124
+ #
125
+ # supported_syntax
126
+ # # => ['ruby','prolog']
127
+ #
128
+ # Returns an Array of supported languages
65
129
  def self.supported_syntax
66
- syntax = []
67
- Dir.foreach(syntax_path) do |f|
68
- if File.extname(f) == ".syntax"
69
- syntax << File.basename(f, '.*')
130
+ if @@supported_syntax
131
+ @@supported_syntax
132
+ else
133
+ @@supported_syntax = []
134
+ Dir.foreach(syntax_path) do |f|
135
+ if File.extname(f) == ".syntax"
136
+ @@supported_syntax << File.basename(f, '.*')
137
+ end
70
138
  end
139
+ @@supported_syntax
71
140
  end
72
- syntax
73
141
  end
74
142
 
143
+ # Returns an Array of supported languages. This is done by parsing
144
+ # all the file names in the syntax folder.
145
+ #
146
+ # Examples
147
+ #
148
+ # supported_langs
149
+ # # => ['Ruby','Prolog']
150
+ #
151
+ # Returns an Array of supported languages
75
152
  def self.supported_langs
76
153
  langs = []
77
154
  Dir.foreach(syntax_path) do |f|
@@ -82,39 +159,96 @@ module CodeRippa
82
159
  end
83
160
  langs
84
161
  end
85
-
162
+
163
+ # Returns an Array of file extensions that is supported by code_rippa
164
+ #
165
+ # Examples
166
+ #
167
+ # supported_langs
168
+ # # => ['rb', 'Gemfile', 'erb']
169
+ #
170
+ # Returns an Array of supported extensions.
86
171
  def self.supported_exts
87
- filetypes = []
88
- Dir.foreach(syntax_path) do |f|
89
- if File.extname(f) == ".syntax"
90
- y = YAML.load(File.read "#{syntax_path}/#{f}")
91
- filetypes += y["fileTypes"] if y["fileTypes"]
172
+ if @@supported_ext
173
+ @@supported_ext
174
+ else
175
+ @@supported_ext = []
176
+ Dir.foreach(syntax_path) do |f|
177
+ if File.extname(f) == ".syntax"
178
+ y = YAML.load(File.read "#{syntax_path}/#{f}")
179
+ @@supported_ext += y["fileTypes"] if y["fileTypes"]
180
+ end
92
181
  end
182
+ @@supported_ext
93
183
  end
94
- filetypes
95
184
  end
96
185
 
186
+ # Returns True if path should be bookmarked in the output TEX/PDF document.
187
+ #
188
+ # path - The file/directory path
189
+ # syntax - The syntax to perform parsing/syntax highlighting.
190
+ # Note the the syntax should be supported by code_rippa.
191
+ # excluded_exts - An Array of extensions to ignore during parsing.
192
+ #
193
+ #
194
+ # Examples
195
+ #
196
+ # bookmarkable?("hello.rb", "ruby", [])
197
+ # # => true
198
+ #
199
+ # bookmarkable?("hello.rb", "ruby", ["rb", "html"])
200
+ # # => false
201
+ #
202
+ # bookmarkable?("hello.klingon", "klingon", [])
203
+ # # => false
204
+ #
205
+ # Returns True if path should be bookmarked.
97
206
  def self.bookmarkable?(path, syntax, excluded_exts)
98
207
  if FileTest.directory?(path)
99
208
  true
100
209
  else
101
210
  src_ext = File.extname(path)[1..-1]
102
- if excluded_exts.include?(src_ext)
211
+ if File.basename(path) == "out.tex"
212
+ false
213
+ elsif excluded_exts.include?(src_ext)
103
214
  false
104
215
  elsif supported_exts.include?(src_ext)
105
- true
216
+ true
106
217
  else
107
- false
218
+ false
108
219
  end
109
220
  end
110
221
  end
111
-
222
+
223
+ # Returns True if path should be ripped as part of the output TEX file.
224
+ #
225
+ # path - The file. (directories will return false.)
226
+ # syntax - The syntax to perform parsing/syntax highlighting.
227
+ # Note the the syntax should be supported by code_rippa.
228
+ # excluded_exts - An Array of extensions to ignore during parsing.
229
+ #
230
+ #
231
+ # Examples
232
+ #
233
+ # rippable?("hello.rb", "ruby", [])
234
+ # # => true
235
+ #
236
+ # rippable?("~/code/", "ruby", [])
237
+ # # => false
238
+ #
239
+ # rippable?("hello.rb", "ruby", ["rb", "html"])
240
+ # # => false
241
+ #
242
+ # rippable?("hello.klingon", "klingon", [])
243
+ # # => false
244
+ #
245
+ # Returns true if path should be ripped.
112
246
  def self.rippable?(path, syntax, excluded_exts)
113
247
  if FileTest.directory?(path)
114
248
  false
115
249
  else
116
250
  src_ext = File.extname(path)[1..-1]
117
- if excluded_exts.include? src_ext
251
+ if excluded_exts.include? src_ext
118
252
  false
119
253
  elsif supported_exts.include?(src_ext)
120
254
  true
@@ -124,11 +258,34 @@ module CodeRippa
124
258
  end
125
259
  end
126
260
 
261
+ # Returns the hex color code of the page color. This is done by looking at
262
+ # the *.render file of the selected theme.
263
+ #
264
+ # theme - The selected theme.
265
+ #
266
+ # Examples
267
+ #
268
+ # page_color('moc')
269
+ # # => "E8E8E8"
270
+ #
271
+ # Returns an String containing the hex color code of the page.
127
272
  def self.page_color(theme)
128
273
  f = YAML.load(File.read("#{Uv.render_path}/latex/#{theme}.render"))
129
274
  /([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/.match(f['listing']['begin'].split('\\')[3]).to_s
130
275
  end
131
276
 
277
+ # Returns the hex color code of the heading. This is done by looking at
278
+ # the *.render file of the selected theme. The heading is present at
279
+ # the top of each new document in the output TEX/PDF file.
280
+ #
281
+ # theme - The selected theme.
282
+ #
283
+ # Examples
284
+ #
285
+ # heading_color('moc')
286
+ # # => "E8E8E8"
287
+ #
288
+ # Returns an String containing the hex color code of the heading.
132
289
  def self.heading_color(theme)
133
290
  f = YAML.load(File.read("#{Uv.render_path}/latex/#{theme}.render"))
134
291
  /([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/.match(f['listing']['begin'].split('\\')[2]).to_s
@@ -1,5 +1,7 @@
1
1
  require 'uv'
2
2
 
3
+ # These module monkey patches the original Spox's Ultraviolet, in order
4
+ # to override defaults.
3
5
  module Uv
4
6
  @@set_table_columns = true
5
7
 
@@ -1,3 +1,3 @@
1
1
  module CodeRippa
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  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.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,40 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-27 00:00:00.000000000 Z
12
+ date: 2012-03-30 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rainbow
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: ansi
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
14
46
  - !ruby/object:Gem::Dependency
15
47
  name: spox-ultraviolet
16
48
  requirement: !ruby/object:Gem::Requirement