code2pdf 0.2.1 → 0.3.0

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.
@@ -1,5 +1,4 @@
1
1
  class ConvertToPDF
2
-
3
2
  PDF_OPTIONS = {
4
3
  :page_size => 'A4'
5
4
  }
@@ -22,12 +21,13 @@ class ConvertToPDF
22
21
  end
23
22
 
24
23
  private
24
+
25
25
  def pdf
26
26
  Prawn::Document.new PDF_OPTIONS do |pdf|
27
27
  read_files.each do |file|
28
28
  puts "Converting to PDF => #{file.first}"
29
29
  pdf.font 'Courier' do
30
- pdf.text "File: <strong>#{file.first}</strong>", :size => 12, :inline_format => true
30
+ pdf.text "<strong>File: #{file.first}</strong>", :size => 12, :inline_format => true
31
31
  pdf.move_down 20
32
32
  pdf.text file.last, :size => 12, :inline_format => true
33
33
  pdf.move_down 40
@@ -46,30 +46,38 @@ class ConvertToPDF
46
46
  @blacklist.has_key?(:directories) and @blacklist.has_key?(:files)
47
47
  end
48
48
 
49
- def in_blacklist?(item)
49
+ def in_directory_blacklist?(item_path)
50
+ @blacklist[:directories].include?(item_path.gsub("#{@from}/", '')) if @blacklist
51
+ end
52
+
53
+ def in_file_blacklist?(item_path)
50
54
  if @blacklist
51
- @blacklist[:directories].include?(item) or @blacklist[:files].include?(item)
55
+ @blacklist[:files].include?(item_path.split('/').last) || @blacklist[:files].include?(item_path.gsub("#{@from}/", ''))
52
56
  end
53
57
  end
54
58
 
55
59
  def valid_directory?(dir)
56
- File.exists?(dir) and FileTest.directory?(dir)
60
+ File.exists?(dir) && FileTest.directory?(dir)
57
61
  end
58
62
 
59
63
  def valid_file?(file)
60
- File.exists?(file) and FileTest.file?(file)
64
+ File.exists?(file) && FileTest.file?(file)
61
65
  end
62
66
 
63
67
  def read_files(path=nil)
64
- @files ||= [] ; path ||= @from
68
+ @files ||= []
69
+ path ||= @from
65
70
  Dir.foreach(path) do |item|
66
71
  item_path = "#{path}/#{item}"
67
- unless in_blacklist?(item)
68
- if valid_directory?(item_path) and not ['.','..'].include?(item)
72
+
73
+ if valid_directory?(item_path) and not ['.', '..'].include?(item)
74
+ unless in_directory_blacklist?(item_path)
69
75
  read_files(item_path)
70
- elsif valid_file?(item_path)
76
+ end
77
+ elsif valid_file?(item_path)
78
+ unless in_file_blacklist?(item_path)
71
79
  content = processing_file(item_path)
72
- @files << ["File: <strong>#{item_path}</strong>", content]
80
+ @files << [item_path, content]
73
81
  end
74
82
  end
75
83
  end
@@ -79,9 +87,9 @@ class ConvertToPDF
79
87
  def processing_file(file)
80
88
  content = ''
81
89
  File.open(file,'r') do |f|
82
- f.each_line.with_index do |line_content,line_number|
83
- # TODO: this line is ugly, need find a better way ;D
84
- content << line_content.gsub(/</,'&lt;').gsub(/^/, "<color rgb='AAAAAA'>#{line_number+1}</color> ")
90
+ f.each_line.with_index do |line_content, line_number|
91
+ # FIXME: please, refactore me!
92
+ content << line_content.gsub(/</,'&lt;').gsub(/^/, "<color rgb='AAAAAA'>#{line_number + 1}</color> ")
85
93
  end
86
94
  end
87
95
  content
@@ -1,3 +1,3 @@
1
1
  module Code2pdf
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -8,7 +8,7 @@ describe ConvertToPDF do
8
8
  pdf = 'spec/fixtures/hello_world.pdf'
9
9
  blacklist = 'spec/fixtures/hello_world/.code2pdf'
10
10
  ConvertToPDF.new :from => path, :to => pdf, :except => blacklist
11
- Digest::MD5.hexdigest(File.read(pdf)).should eq 'f0270dcebd0abc942739d3c83ad4b978'
11
+ Digest::MD5.hexdigest(File.read(pdf)).should eq '619b483b7f175d915bd0bea65c2575f3'
12
12
  File.delete pdf
13
13
  end
14
14
 
metadata CHANGED
@@ -1,144 +1,194 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: code2pdf
3
- version: !ruby/object:Gem::Version
4
- hash: 21
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Lucas Caton
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-09-13 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-10-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: prawn
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 47
29
- segments:
30
- - 0
31
- - 12
32
- - 0
20
+ - !ruby/object:Gem::Version
33
21
  version: 0.12.0
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rspec
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.12.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
40
33
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
48
38
  type: :development
49
- version_requirements: *id002
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
50
46
  description: Convert your source code to PDF
51
- email:
47
+ email:
52
48
  - lucascaton@gmail.com
53
- executables:
54
- - code2pdf
49
+ executables:
50
+ - !binary |-
51
+ Y29kZTJwZGY=
55
52
  extensions: []
56
-
57
53
  extra_rdoc_files: []
58
-
59
- files:
60
- - .gitignore
61
- - .rspec
62
- - Gemfile
63
- - Gemfile.lock
64
- - LICENSE.txt
65
- - README.textile
66
- - Rakefile
67
- - bin/code2pdf
68
- - code2pdf.gemspec
69
- - examples/example.pdf
70
- - lib/code2pdf.rb
71
- - lib/code2pdf/convert_to_pdf.rb
72
- - lib/code2pdf/version.rb
73
- - spec/code2pdf/convert_to_pdf_spec.rb
74
- - spec/fixtures/hello_world/.code2pdf
75
- - spec/fixtures/hello_world/doc/HelloWorld.html
76
- - spec/fixtures/hello_world/doc/HelloWorld/Gambi.html
77
- - spec/fixtures/hello_world/doc/HelloWorld/Goodbye.html
78
- - spec/fixtures/hello_world/doc/HelloWorld/Helo.html
79
- - spec/fixtures/hello_world/doc/created.rid
80
- - spec/fixtures/hello_world/doc/index.html
81
- - spec/fixtures/hello_world/doc/lib/gambi_rb.html
82
- - spec/fixtures/hello_world/doc/lib/goodbye_rb.html
83
- - spec/fixtures/hello_world/doc/lib/hello_rb.html
84
- - spec/fixtures/hello_world/doc/rdoc.css
85
- - spec/fixtures/hello_world/doc/tmp_txt.html
86
- - spec/fixtures/hello_world/lib/gambi.rb
87
- - spec/fixtures/hello_world/lib/goodbye.rb
88
- - spec/fixtures/hello_world/lib/hello.rb
89
- - spec/fixtures/hello_world/tmp.txt
90
- - spec/fixtures/purplelist.yml
91
- - spec/spec_helper.rb
54
+ files:
55
+ - !binary |-
56
+ LmdpdGlnbm9yZQ==
57
+ - !binary |-
58
+ LnJzcGVj
59
+ - !binary |-
60
+ R2VtZmlsZQ==
61
+ - !binary |-
62
+ R2VtZmlsZS5sb2Nr
63
+ - !binary |-
64
+ TElDRU5TRS50eHQ=
65
+ - !binary |-
66
+ UkVBRE1FLnRleHRpbGU=
67
+ - !binary |-
68
+ UmFrZWZpbGU=
69
+ - !binary |-
70
+ YmluL2NvZGUycGRm
71
+ - !binary |-
72
+ Y29kZTJwZGYuZ2Vtc3BlYw==
73
+ - !binary |-
74
+ ZXhhbXBsZXMvZXhhbXBsZS5wZGY=
75
+ - !binary |-
76
+ bGliL2NvZGUycGRmLnJi
77
+ - !binary |-
78
+ bGliL2NvZGUycGRmL2NvbnZlcnRfdG9fcGRmLnJi
79
+ - !binary |-
80
+ bGliL2NvZGUycGRmL3ZlcnNpb24ucmI=
81
+ - !binary |-
82
+ c3BlYy9jb2RlMnBkZi9jb252ZXJ0X3RvX3BkZl9zcGVjLnJi
83
+ - !binary |-
84
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC8uY29kZTJwZGY=
85
+ - !binary |-
86
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvSGVsbG9Xb3JsZC5odG1s
87
+ - !binary |-
88
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvSGVsbG9Xb3JsZC9HYW1i
89
+ aS5odG1s
90
+ - !binary |-
91
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvSGVsbG9Xb3JsZC9Hb29k
92
+ YnllLmh0bWw=
93
+ - !binary |-
94
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvSGVsbG9Xb3JsZC9IZWxv
95
+ Lmh0bWw=
96
+ - !binary |-
97
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvY3JlYXRlZC5yaWQ=
98
+ - !binary |-
99
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvaW5kZXguaHRtbA==
100
+ - !binary |-
101
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvbGliL2dhbWJpX3JiLmh0
102
+ bWw=
103
+ - !binary |-
104
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvbGliL2dvb2RieWVfcmIu
105
+ aHRtbA==
106
+ - !binary |-
107
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvbGliL2hlbGxvX3JiLmh0
108
+ bWw=
109
+ - !binary |-
110
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvcmRvYy5jc3M=
111
+ - !binary |-
112
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvdG1wX3R4dC5odG1s
113
+ - !binary |-
114
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9saWIvZ2FtYmkucmI=
115
+ - !binary |-
116
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9saWIvZ29vZGJ5ZS5yYg==
117
+ - !binary |-
118
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9saWIvaGVsbG8ucmI=
119
+ - !binary |-
120
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC90bXAudHh0
121
+ - !binary |-
122
+ c3BlYy9maXh0dXJlcy9wdXJwbGVsaXN0LnltbA==
123
+ - !binary |-
124
+ c3BlYy9zcGVjX2hlbHBlci5yYg==
92
125
  homepage: http://blog.lucascaton.com.br/
93
126
  licenses: []
94
-
95
127
  post_install_message:
96
128
  rdoc_options: []
97
-
98
- require_paths:
129
+ require_paths:
99
130
  - lib
100
- required_ruby_version: !ruby/object:Gem::Requirement
131
+ required_ruby_version: !ruby/object:Gem::Requirement
101
132
  none: false
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- hash: 3
106
- segments:
107
- - 0
108
- version: "0"
109
- required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
138
  none: false
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- hash: 3
115
- segments:
116
- - 0
117
- version: "0"
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
118
143
  requirements: []
119
-
120
144
  rubyforge_project: code2pdf
121
- rubygems_version: 1.8.6
145
+ rubygems_version: 1.8.24
122
146
  signing_key:
123
147
  specification_version: 3
124
148
  summary: Convert your source code to PDF
125
- test_files:
126
- - spec/code2pdf/convert_to_pdf_spec.rb
127
- - spec/fixtures/hello_world/.code2pdf
128
- - spec/fixtures/hello_world/doc/HelloWorld.html
129
- - spec/fixtures/hello_world/doc/HelloWorld/Gambi.html
130
- - spec/fixtures/hello_world/doc/HelloWorld/Goodbye.html
131
- - spec/fixtures/hello_world/doc/HelloWorld/Helo.html
132
- - spec/fixtures/hello_world/doc/created.rid
133
- - spec/fixtures/hello_world/doc/index.html
134
- - spec/fixtures/hello_world/doc/lib/gambi_rb.html
135
- - spec/fixtures/hello_world/doc/lib/goodbye_rb.html
136
- - spec/fixtures/hello_world/doc/lib/hello_rb.html
137
- - spec/fixtures/hello_world/doc/rdoc.css
138
- - spec/fixtures/hello_world/doc/tmp_txt.html
139
- - spec/fixtures/hello_world/lib/gambi.rb
140
- - spec/fixtures/hello_world/lib/goodbye.rb
141
- - spec/fixtures/hello_world/lib/hello.rb
142
- - spec/fixtures/hello_world/tmp.txt
143
- - spec/fixtures/purplelist.yml
144
- - spec/spec_helper.rb
149
+ test_files:
150
+ - !binary |-
151
+ c3BlYy9jb2RlMnBkZi9jb252ZXJ0X3RvX3BkZl9zcGVjLnJi
152
+ - !binary |-
153
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC8uY29kZTJwZGY=
154
+ - !binary |-
155
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvSGVsbG9Xb3JsZC5odG1s
156
+ - !binary |-
157
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvSGVsbG9Xb3JsZC9HYW1i
158
+ aS5odG1s
159
+ - !binary |-
160
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvSGVsbG9Xb3JsZC9Hb29k
161
+ YnllLmh0bWw=
162
+ - !binary |-
163
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvSGVsbG9Xb3JsZC9IZWxv
164
+ Lmh0bWw=
165
+ - !binary |-
166
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvY3JlYXRlZC5yaWQ=
167
+ - !binary |-
168
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvaW5kZXguaHRtbA==
169
+ - !binary |-
170
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvbGliL2dhbWJpX3JiLmh0
171
+ bWw=
172
+ - !binary |-
173
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvbGliL2dvb2RieWVfcmIu
174
+ aHRtbA==
175
+ - !binary |-
176
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvbGliL2hlbGxvX3JiLmh0
177
+ bWw=
178
+ - !binary |-
179
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvcmRvYy5jc3M=
180
+ - !binary |-
181
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9kb2MvdG1wX3R4dC5odG1s
182
+ - !binary |-
183
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9saWIvZ2FtYmkucmI=
184
+ - !binary |-
185
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9saWIvZ29vZGJ5ZS5yYg==
186
+ - !binary |-
187
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC9saWIvaGVsbG8ucmI=
188
+ - !binary |-
189
+ c3BlYy9maXh0dXJlcy9oZWxsb193b3JsZC90bXAudHh0
190
+ - !binary |-
191
+ c3BlYy9maXh0dXJlcy9wdXJwbGVsaXN0LnltbA==
192
+ - !binary |-
193
+ c3BlYy9zcGVjX2hlbHBlci5yYg==
194
+ has_rdoc: