code2pdf 0.4.2 → 0.4.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4120208812063b2c15e8f852419151082d9251c4d080ac7df3855e896b231b0f
4
- data.tar.gz: dc516f9d6248afa54017097b1ce7950ec0c15bb6ee481a30e3b1df688250c2d6
3
+ metadata.gz: 578c0a73b26a2556547e1067a953e17e7749862ed484fff98a3e39682baab574
4
+ data.tar.gz: ff876deb0d621c9dea99aa94e65a8ff1875401a9163b3884731d8515933dbc8b
5
5
  SHA512:
6
- metadata.gz: 9f35129540fc4441a1e9250892c1bc69aa1f29b516619cc292277e8168071257d0227f523705ac60d11c8d105e5b91021c790b2ed01b6e65c85b93459b97a12b
7
- data.tar.gz: 54d6d8e1460e739d75d1627cee51417861459cc5f090fdc27127895bfa6a07834cc91e2509b2f71f8439492301dd91a831958b3da555ce7b2d80966534b24e0e
6
+ metadata.gz: 27773342081e8622445535edeb161fca71f12f2ae88f10d11303a725c1a050186acc603ae06d5a403bad894603afa83ee2e23f0f0a7057bfd11d43b769d6fbe0
7
+ data.tar.gz: e15c871714be8a33f41675e273da1ec39c85a6437164479a3acfcceede45e049c68769cf9d1c95663aa58201c541a21302f34cc6a0c37d2b61ae7ca34469a35e
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code2pdf (0.4.2)
4
+ code2pdf (0.4.3)
5
5
  pdfkit
6
6
  rouge
7
7
  wkhtmltopdf-binary
@@ -28,7 +28,7 @@ GEM
28
28
  coderay (~> 1.1.0)
29
29
  method_source (~> 0.9.0)
30
30
  rake (12.3.0)
31
- rouge (3.1.0)
31
+ rouge (3.3.0)
32
32
  rspec (3.7.0)
33
33
  rspec-core (~> 3.7.0)
34
34
  rspec-expectations (~> 3.7.0)
@@ -44,7 +44,7 @@ GEM
44
44
  rspec-support (3.7.0)
45
45
  ruby-rc4 (0.1.5)
46
46
  ttfunk (1.5.1)
47
- wkhtmltopdf-binary (0.12.3.1)
47
+ wkhtmltopdf-binary (0.12.4)
48
48
 
49
49
  PLATFORMS
50
50
  ruby
@@ -58,4 +58,4 @@ DEPENDENCIES
58
58
  rspec
59
59
 
60
60
  BUNDLED WITH
61
- 1.16.1
61
+ 1.17.1
data/LICENSE CHANGED
@@ -2,7 +2,7 @@ LICENSE
2
2
 
3
3
  The MIT License
4
4
 
5
- Copyright (c) 2011-2017 Lucas Caton
5
+ Copyright (c) 2011-2018 Lucas Caton
6
6
 
7
7
  Permission is hereby granted, free of charge, to any person obtaining
8
8
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -49,4 +49,4 @@ The blacklist file must be a yaml file named `.code2pdf`, placed in project root
49
49
 
50
50
  ## Copyright
51
51
 
52
- Copyright © 2011-2017 Lucas Caton. See LICENSE for further details.
52
+ Copyright © 2011-2018 Lucas Caton. See LICENSE for further details.
@@ -19,7 +19,7 @@ optparse = OptionParser.new do |opts|
19
19
  exit
20
20
  end
21
21
 
22
- if ARGV.size < 1
22
+ if ARGV.empty?
23
23
  puts opts
24
24
  exit 1
25
25
  end
@@ -1,3 +1,6 @@
1
+ require 'cgi'
2
+ require 'shellwords'
3
+
1
4
  class ConvertToPDF
2
5
  PDF_OPTIONS = {
3
6
  page_size: 'A4'
@@ -45,12 +48,13 @@ class ConvertToPDF
45
48
  def syntax_highlight(file)
46
49
  file_type = File.extname(file.first)[1..-1]
47
50
  file_lexer = Rouge::Lexer.find(file_type)
48
- return file.last unless file_lexer
51
+ return CGI.escapeHTML(file.last) unless file_lexer
49
52
 
50
53
  theme = Rouge::Themes::Base16.mode(:light)
51
54
  formatter = Rouge::Formatters::HTMLInline.new(theme)
52
55
  formatter = Rouge::Formatters::HTMLTable.new(formatter, start_line: 1)
53
- formatter.format(file_lexer.lex(file.last))
56
+ code_data = file.last.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
57
+ formatter.format(file_lexer.lex(code_data))
54
58
  end
55
59
 
56
60
  def invalid_blacklist?
@@ -101,8 +105,8 @@ class ConvertToPDF
101
105
 
102
106
  content = ''
103
107
  File.open(file, 'r') do |f|
104
- if `file #{file}` !~ /text/
105
- content << "<color rgb='777777'>[binary]</color>"
108
+ if `file #{file.shellescape}` !~ /text/
109
+ content << '[binary]'
106
110
  else
107
111
  f.each_line { |line_content| content << line_content }
108
112
  end
@@ -1,3 +1,3 @@
1
1
  module Code2pdf
2
- VERSION = '0.4.2'.freeze
2
+ VERSION = '0.4.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code2pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Caton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-08 00:00:00.000000000 Z
11
+ date: 2018-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pdfkit
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  version: '0'
183
183
  requirements: []
184
184
  rubyforge_project:
185
- rubygems_version: 2.7.3
185
+ rubygems_version: 2.7.7
186
186
  signing_key:
187
187
  specification_version: 4
188
188
  summary: Convert your source code to PDF