code2pdf 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/code2pdf/convert_to_pdf.rb +22 -14
- data/lib/code2pdf/version.rb +1 -1
- data/spec/code2pdf/convert_to_pdf_spec.rb +1 -1
- metadata +163 -113
@@ -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:
|
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
|
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[:
|
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)
|
60
|
+
File.exists?(dir) && FileTest.directory?(dir)
|
57
61
|
end
|
58
62
|
|
59
63
|
def valid_file?(file)
|
60
|
-
File.exists?(file)
|
64
|
+
File.exists?(file) && FileTest.file?(file)
|
61
65
|
end
|
62
66
|
|
63
67
|
def read_files(path=nil)
|
64
|
-
@files ||= []
|
68
|
+
@files ||= []
|
69
|
+
path ||= @from
|
65
70
|
Dir.foreach(path) do |item|
|
66
71
|
item_path = "#{path}/#{item}"
|
67
|
-
|
68
|
-
|
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
|
-
|
76
|
+
end
|
77
|
+
elsif valid_file?(item_path)
|
78
|
+
unless in_file_blacklist?(item_path)
|
71
79
|
content = processing_file(item_path)
|
72
|
-
@files << [
|
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
|
-
#
|
84
|
-
content << line_content.gsub(/</,'<').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(/</,'<').gsub(/^/, "<color rgb='AAAAAA'>#{line_number + 1}</color> ")
|
85
93
|
end
|
86
94
|
end
|
87
95
|
content
|
data/lib/code2pdf/version.rb
CHANGED
@@ -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 '
|
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
|
-
|
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
|
-
|
19
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
45
|
-
segments:
|
46
|
-
- 0
|
47
|
-
version: "0"
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
48
38
|
type: :development
|
49
|
-
|
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
|
-
-
|
49
|
+
executables:
|
50
|
+
- !binary |-
|
51
|
+
Y29kZTJwZGY=
|
55
52
|
extensions: []
|
56
|
-
|
57
53
|
extra_rdoc_files: []
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
-
|
62
|
-
|
63
|
-
-
|
64
|
-
|
65
|
-
-
|
66
|
-
|
67
|
-
-
|
68
|
-
|
69
|
-
-
|
70
|
-
|
71
|
-
-
|
72
|
-
|
73
|
-
-
|
74
|
-
|
75
|
-
-
|
76
|
-
|
77
|
-
-
|
78
|
-
|
79
|
-
-
|
80
|
-
|
81
|
-
-
|
82
|
-
|
83
|
-
-
|
84
|
-
|
85
|
-
-
|
86
|
-
|
87
|
-
-
|
88
|
-
|
89
|
-
-
|
90
|
-
|
91
|
-
-
|
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
|
-
|
106
|
-
|
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
|
-
|
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.
|
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
|
-
-
|
127
|
-
|
128
|
-
-
|
129
|
-
|
130
|
-
-
|
131
|
-
|
132
|
-
-
|
133
|
-
|
134
|
-
|
135
|
-
-
|
136
|
-
|
137
|
-
|
138
|
-
-
|
139
|
-
|
140
|
-
|
141
|
-
-
|
142
|
-
|
143
|
-
-
|
144
|
-
|
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:
|