gimli 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -1,12 +1,14 @@
1
1
  h1. gimli - utility for converting markup to pdf
2
2
 
3
+ "!http://travis-ci.org/walle/gimli.png!":http://travis-ci.org/walle/gimli
4
+
3
5
  h2. Description
4
6
 
5
7
  Gimli is a utility for converting markup to pdf files. Useful for reports and such things.
6
8
  It's a developed version of "textile2pdf":https://github.com/walle/textile2pdf to support multiple markup styles and to get syntax highlighting.
7
9
 
8
10
  It's inspired by the markup convertion in "gollum":https://github.com/github/gollum. The markup code is adapted from gollum.
9
- It works by converting the markup to html using "PDFKit":https://github.com/jdpace/PDFKit
11
+ It works by converting the markup to pdf using "PDFKit":https://github.com/jdpace/PDFKit
10
12
  The markup is converted to html using "github/markup":https://github.com/github/markup
11
13
 
12
14
  h3. Markup
data/lib/gimli/markup.rb CHANGED
@@ -14,6 +14,7 @@
14
14
 
15
15
  require 'digest/sha1'
16
16
  require 'cgi'
17
+ require 'iconv'
17
18
 
18
19
  require 'github/markup'
19
20
  require 'nokogiri'
@@ -44,7 +45,8 @@ module Gimli
44
45
  data = extract_code(@data.dup)
45
46
  data = extract_tags(data)
46
47
  begin
47
- data = GitHub::Markup.render(@filename, data.force_encoding('utf-8'))
48
+ data = data.force_encoding('utf-8') if data.respond_to? :force_encoding
49
+ data = GitHub::Markup.render(@filename, data)
48
50
  if data.nil?
49
51
  raise "There was an error converting #{@name} to HTML."
50
52
  end
@@ -54,7 +56,7 @@ module Gimli
54
56
  data = process_tags(data)
55
57
  data = process_code(data)
56
58
 
57
- doc = Nokogiri::HTML::DocumentFragment.parse(data.force_encoding('utf-8'))
59
+ doc = Nokogiri::HTML::DocumentFragment.parse(data, 'UTF-8')
58
60
  yield doc if block_given?
59
61
  data = doc_to_html(doc)
60
62
 
@@ -63,7 +65,7 @@ module Gimli
63
65
  end
64
66
 
65
67
  def doc_to_html(doc)
66
- doc.to_xhtml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XHTML)
68
+ doc.to_xhtml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XHTML, :encoding => 'UTF-8')
67
69
  end
68
70
 
69
71
  # Extract all tags into the tagmap and replace with placeholders.
@@ -226,7 +228,6 @@ module Gimli
226
228
  # @return [String] Returns the marked up String data.
227
229
  def process_code(data)
228
230
  return data if data.nil? || data.size.zero? || @codemap.size.zero?
229
-
230
231
  blocks = []
231
232
  @codemap.each do |id, spec|
232
233
  next if spec[:output] # cached
@@ -236,6 +237,8 @@ module Gimli
236
237
  code.gsub!(/^( |\t)/m, '')
237
238
  end
238
239
 
240
+ code = Iconv.conv('ISO-8859-1//IGNORE', 'utf-8', code)
241
+
239
242
  blocks << [spec[:lang], code]
240
243
  end
241
244
 
data/lib/gimli/version.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Gimli
4
4
 
5
- Version = "0.1.2"
5
+ Version = "0.1.3"
6
6
 
7
7
  end
8
8
 
@@ -8,34 +8,49 @@ describe Gimli::Markup do
8
8
 
9
9
  it 'should give correct code block' do
10
10
 
11
- output = "<p>a</p>\n<div class=\"highlight\"><pre>" +
11
+ output_with_pygments = "<p>a</p>\n<div class=\"highlight\"><pre>" +
12
12
  "<span class=\"n\">x</span> <span class=\"o\">=</span> " +
13
13
  "<span class=\"mi\">1</span>\n</pre>\n</div>\n\n<p>b</p>"
14
14
 
15
+ output_without_pygments = "<p>a</p>\n<pre><code>x = 1</code></pre>\n<p>b</p>"
16
+
15
17
  file = Gimli::File.new File.expand_path('../../fixtures/code_block.textile', __FILE__)
16
18
  markup = Gimli::Markup.new file
17
19
 
18
- markup.render.should == output
20
+ # Check if the html seems to be highlighted
21
+ if markup.render.include? "<div class=\"highlight\">"
22
+ markup.render.should == output_with_pygments
23
+ else
24
+ markup.render.should == output_without_pygments
25
+ end
19
26
  end
20
27
 
21
28
  it 'should give correct code block for utf8' do
22
29
 
23
- output = "<p>a</p>\n<div class=\"highlight\"><pre>" +
24
- "<span class=\"nt\">&lt;h1&gt;</span>Abc&#xC3;&#xA5;&#xC3;&#xA4;&#xC3;&#xB6;<span class=\"nt\">&lt;/h1&gt;</span>\n" +
25
- "<span class=\"nt\">&lt;img</span> <span class=\"na\">src=</span><span class=\"s\">\"&#xC3;&#xA5;&#xC3;&#xA4;&#xC3;&#xB6;.png\"" +
26
- "</span> <span class=\"na\">alt=</span><span class=\"s\">\"&#xC3;&#x85;&#xC3;&#x84;&#xC3;&#x96;\"" +
27
- "</span> <span class=\"nt\">/&gt;</span>\n</pre>\n</div>\n"
30
+ output_with_pygments = "<p>a</p>\n<div class=\"highlight\"><pre>" +
31
+ "<span class=\"nt\">&lt;h1&gt;</span>Abcåäö<span class=\"nt\">&lt;/h1&gt;</span>\n" +
32
+ "<span class=\"nt\">&lt;img</span> <span class=\"na\">src=</span><span class=\"s\">\"åäö.png\"" +
33
+ "</span> <span class=\"na\">alt=</span><span class=\"s\">\"ÅÄÖ\"" +
34
+ "</span> <span class=\"nt\">/&gt;</span>\n</pre>\n</div>\n"
35
+
36
+ output_without_pygments = "<p>a</p>\n<pre><code>&lt;h1&gt;Abcåäö&lt;/h1&gt;\n&lt;img " +
37
+ "src=\"åäö.png\" alt=\"ÅÄÖ\" /&gt;</code></pre>"
28
38
 
29
39
  file = Gimli::File.new File.expand_path('../../fixtures/code_block_with_utf8.textile', __FILE__)
30
40
  markup = Gimli::Markup.new file
31
41
 
32
- markup.render.should == output
42
+ # Check if the html seems to be highlighted
43
+ if markup.render.include? "<div class=\"highlight\">"
44
+ markup.render.should == output_with_pygments
45
+ else
46
+ markup.render.should == output_without_pygments
47
+ end
33
48
  end
34
49
 
35
50
  it 'should give correct code for utf8' do
36
51
 
37
- output = "<p>a</p>\n<code>&lt;img src=\"&#xE5;&#xE4;&#xF6;.png\" " +
38
- "alt=\"Abc&#xE5;&#xE4;&#xF6;\" /&gt;</code>\n<p>b</p>"
52
+ output = "<p>a</p>\n<code>&lt;img src=\"åäö.png\" " +
53
+ "alt=\"Abcåäö\" /&gt;</code>\n<p>b</p>"
39
54
 
40
55
  file = Gimli::File.new File.expand_path('../../fixtures/code_with_utf8.textile', __FILE__)
41
56
  markup = Gimli::Markup.new file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gimli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-05-03 00:00:00.000000000 +02:00
12
+ date: 2011-05-06 00:00:00.000000000 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: github-markup
17
- requirement: &10287260 !ruby/object:Gem::Requirement
17
+ requirement: &16373300 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *10287260
25
+ version_requirements: *16373300
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: redcarpet
28
- requirement: &10286820 !ruby/object:Gem::Requirement
28
+ requirement: &16372860 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *10286820
36
+ version_requirements: *16372860
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: RedCloth
39
- requirement: &10286400 !ruby/object:Gem::Requirement
39
+ requirement: &16372440 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *10286400
47
+ version_requirements: *16372440
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: org-ruby
50
- requirement: &10285980 !ruby/object:Gem::Requirement
50
+ requirement: &16372020 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *10285980
58
+ version_requirements: *16372020
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: creole
61
- requirement: &10285560 !ruby/object:Gem::Requirement
61
+ requirement: &16371600 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *10285560
69
+ version_requirements: *16371600
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: wikicloth
72
- requirement: &10285140 !ruby/object:Gem::Requirement
72
+ requirement: &16371180 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :runtime
79
79
  prerelease: false
80
- version_requirements: *10285140
80
+ version_requirements: *16371180
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: albino
83
- requirement: &10284720 !ruby/object:Gem::Requirement
83
+ requirement: &16402180 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '0'
89
89
  type: :runtime
90
90
  prerelease: false
91
- version_requirements: *10284720
91
+ version_requirements: *16402180
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: nokogiri
94
- requirement: &10284300 !ruby/object:Gem::Requirement
94
+ requirement: &16401760 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: '0'
100
100
  type: :runtime
101
101
  prerelease: false
102
- version_requirements: *10284300
102
+ version_requirements: *16401760
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: wkhtmltopdf-binary
105
- requirement: &10283880 !ruby/object:Gem::Requirement
105
+ requirement: &16401340 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ! '>='
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: '0'
111
111
  type: :runtime
112
112
  prerelease: false
113
- version_requirements: *10283880
113
+ version_requirements: *16401340
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: pdfkit
116
- requirement: &10283460 !ruby/object:Gem::Requirement
116
+ requirement: &16400920 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ! '>='
@@ -121,10 +121,10 @@ dependencies:
121
121
  version: '0'
122
122
  type: :runtime
123
123
  prerelease: false
124
- version_requirements: *10283460
124
+ version_requirements: *16400920
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: optiflag
127
- requirement: &10283040 !ruby/object:Gem::Requirement
127
+ requirement: &16400500 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ! '>='
@@ -132,10 +132,10 @@ dependencies:
132
132
  version: '0'
133
133
  type: :runtime
134
134
  prerelease: false
135
- version_requirements: *10283040
135
+ version_requirements: *16400500
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: rspec
138
- requirement: &10282620 !ruby/object:Gem::Requirement
138
+ requirement: &16400080 !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
141
141
  - - ! '>='
@@ -143,10 +143,10 @@ dependencies:
143
143
  version: '0'
144
144
  type: :development
145
145
  prerelease: false
146
- version_requirements: *10282620
146
+ version_requirements: *16400080
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: rr
149
- requirement: &10282200 !ruby/object:Gem::Requirement
149
+ requirement: &16399660 !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements:
152
152
  - - ! '>='
@@ -154,18 +154,7 @@ dependencies:
154
154
  version: '0'
155
155
  type: :development
156
156
  prerelease: false
157
- version_requirements: *10282200
158
- - !ruby/object:Gem::Dependency
159
- name: yard
160
- requirement: &10281780 !ruby/object:Gem::Requirement
161
- none: false
162
- requirements:
163
- - - ! '>='
164
- - !ruby/object:Gem::Version
165
- version: '0'
166
- type: :development
167
- prerelease: false
168
- version_requirements: *10281780
157
+ version_requirements: *16399660
169
158
  description: Utility for converting markup files to pdf files. Useful for reports
170
159
  etc.
171
160
  email: fredrik.wallgren@gmail.com