gimli 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -49,6 +49,8 @@ To apply some style to the pdf or override the standard style add a css file in
49
49
 
50
50
  Standard behavior is for gimli to output the files in the current directory. To override this use the @-o@ flag to point out another output directory. Gimli tries to create it if it doesn't exist.
51
51
 
52
+ Gimli also plays nice with Jekyll style markup files. You can pass gimli the @-y@ flag to have it remove Jekyll's YAML front matter from the top of your markup files. Allowing you to use gimli & Jekyll together on your Blog/Resume/Catalogue to create nicely formatted versions for online and offline viewing.
53
+
52
54
  Run @gimli -h@ for a full list of options available
53
55
 
54
56
  h2. Syntax highlighting
data/bin/gimli CHANGED
@@ -9,5 +9,5 @@ if ARGV.flags.version?
9
9
  exit
10
10
  end
11
11
 
12
- Gimli.process! ARGV.flags.file, ARGV.flags.recursive?, ARGV.flags.merge?, ARGV.flags.outputfilename, ARGV.flags.outputdir, ARGV.flags.stylesheet
12
+ Gimli.process! ARGV.flags.file, ARGV.flags.recursive?, ARGV.flags.merge?, ARGV.flags.removefrontmatter, ARGV.flags.outputfilename, ARGV.flags.outputdir, ARGV.flags.stylesheet
13
13
 
@@ -10,10 +10,10 @@ require 'gimli/path'
10
10
  module Gimli
11
11
 
12
12
  # Starts the processing of selected files
13
- def self.process!(file, recursive = false, merge = false, output_filename = nil, output_dir = nil, stylesheet = nil)
13
+ def self.process!(file, recursive = false, merge = false, remove_front_matter = false, output_filename = nil, output_dir = nil, stylesheet = nil)
14
14
 
15
15
 
16
16
  @files = Path.list_valid(file, recursive).map { |file| MarkupFile.new(file) }
17
- Converter.new(@files, output_filename, output_dir, stylesheet).convert!(merge)
17
+ Converter.new(@files, merge, remove_front_matter, output_filename, output_dir, stylesheet).convert!
18
18
  end
19
19
  end
@@ -13,21 +13,27 @@ module Gimli
13
13
 
14
14
  # Initialize the converter with a File
15
15
  # @param [Array] files The list of Gimli::MarkupFile to convert (passing a single file will still work)
16
- def initialize(files, output_filename = nil, output_dir = nil, stylesheet = nil)
16
+ # @param [Boolean] merge
17
+ # @param [Boolean] remove_front_matter
18
+ # @param [String] output_filename
19
+ # @param [String] output_dir
20
+ # @param [String] stylesheet
21
+ def initialize(files, merge = false, remove_front_matter = false, output_filename = nil, output_dir = nil, stylesheet = nil)
17
22
  @files = files
23
+ @merge = merge
24
+ @remove_front_matter = remove_front_matter
18
25
  @output_filename = output_filename
19
26
  @output_dir = output_dir
20
27
  @stylesheet = stylesheet
21
28
  end
22
29
 
23
30
  # Convert the file and save it as a PDF file
24
- # @param [Boolean] merge if true a single pdf with all input files are created
25
- def convert!(merge = false)
31
+ def convert!
26
32
  merged_contents = []
27
33
  @files.each do |file|
28
- markup = Markup.new file
34
+ markup = Markup.new file, @remove_front_matter
29
35
  html = convert_image_urls markup.render, file.filename
30
- if merge
36
+ if @merge
31
37
  html = "<div class=\"page-break\"></div>#{html}" unless merged_contents.empty?
32
38
  merged_contents << html
33
39
  else
@@ -106,7 +112,7 @@ module Gimli
106
112
  end
107
113
  else
108
114
  output_filename = Time.now.to_s.split(' ').join('_')
109
- output_filename = @files.last.name if @files.length == 1 || ARGV.flags.merge?
115
+ output_filename = @files.last.name if @files.length == 1 || @merge
110
116
  output_filename = @output_filename unless @output_filename.nil?
111
117
  end
112
118
 
@@ -26,8 +26,9 @@ module Gimli
26
26
  # Initialize a new Markup object.
27
27
  #
28
28
  # @param [Gimli::File] file The Gimli::File to process
29
+ # @param [Boolean] do_remove_yaml_front_matter Should we remove the front matter?
29
30
  # @return [Gimli::Markup]
30
- def initialize(file)
31
+ def initialize(file, do_remove_yaml_front_matter = false)
31
32
  @filename = file.filename
32
33
  @name = file.name
33
34
  @data = file.data
@@ -35,6 +36,7 @@ module Gimli
35
36
  @tagmap = {}
36
37
  @codemap = {}
37
38
  @premap = {}
39
+ @do_remove_yaml_front_matter = do_remove_yaml_front_matter
38
40
  end
39
41
 
40
42
  # Render the content with Gollum wiki syntax on top of the file's own
@@ -42,7 +44,9 @@ module Gimli
42
44
  #
43
45
  # @return [String] The formatted data
44
46
  def render
45
- data = extract_code(@data.dup)
47
+ data = @data.dup
48
+ data = remove_yaml_front_matter(data) if @do_remove_yaml_front_matter
49
+ data = extract_code(data)
46
50
  data = extract_tags(data)
47
51
  begin
48
52
  data = data.force_encoding('utf-8') if data.respond_to? :force_encoding
@@ -68,6 +72,15 @@ module Gimli
68
72
  doc.to_xhtml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XHTML, :encoding => 'UTF-8')
69
73
  end
70
74
 
75
+ # Removes YAML Front Matter
76
+ # Useful if you want to PDF your Jekyll site.
77
+ #
78
+ # @param [String] data - The raw string data.
79
+ # @return [String] Returns the string data with frontmatter removed
80
+ def remove_yaml_front_matter(data)
81
+ data.gsub(/^(---\s*\n.*?\n?)^(---\s*$\n?)/m, '')
82
+ end
83
+
71
84
  # Extract all tags into the tagmap and replace with placeholders.
72
85
  #
73
86
  # @param [String] data - The raw string data.
@@ -28,6 +28,10 @@ module Gimli extend OptiFlagSet
28
28
  description 'Merge markup files into single pdf file'
29
29
  alternate_forms 'm'
30
30
  end
31
+ optional_switch_flag 'removefrontmatter' do
32
+ description 'Remove yaml frontmatter from your files.'
33
+ alternate_forms 'y'
34
+ end
31
35
  optional_switch_flag 'version' do
32
36
  description 'Show version information and quit'
33
37
  alternate_forms 'v'
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Gimli
4
4
 
5
- Version = "0.2.0"
5
+ Version = "0.2.1"
6
6
 
7
7
  end
8
8
 
@@ -0,0 +1,7 @@
1
+ ---
2
+ layout: test
3
+ ---
4
+
5
+
6
+
7
+ This should be at the top of the file
@@ -31,7 +31,7 @@ describe Gimli::Converter do
31
31
  file = Gimli::MarkupFile.new 'fake'
32
32
  output_filename = 'my_file'
33
33
 
34
- converter = Gimli::Converter.new [file], output_filename
34
+ converter = Gimli::Converter.new [file], false, false, output_filename
35
35
  mock(converter).output_dir { Dir.getwd }
36
36
 
37
37
  converter.output_file.should == File.join(Dir.getwd, "#{output_filename}.pdf")
@@ -50,7 +50,7 @@ describe Gimli::Converter do
50
50
  dir = '/tmp/out'
51
51
 
52
52
  file = Gimli::MarkupFile.new 'fake'
53
- converter = Gimli::Converter.new file, nil, dir
53
+ converter = Gimli::Converter.new file, false, false, nil, dir
54
54
 
55
55
  mock(File).directory?(dir) { true }
56
56
 
@@ -68,7 +68,7 @@ describe Gimli::Converter do
68
68
  file = Gimli::MarkupFile.new 'fake'
69
69
  stylesheet = '/home/me/gimli/my-style.css'
70
70
 
71
- converter = Gimli::Converter.new file, nil, nil, stylesheet
71
+ converter = Gimli::Converter.new file, false, false, nil, nil, stylesheet
72
72
 
73
73
  converter.stylesheet.should == stylesheet
74
74
  end
@@ -58,5 +58,14 @@ describe Gimli::Markup do
58
58
  markup.render.should == output
59
59
  end
60
60
 
61
+ it "should remove yaml front matter if asked to" do
62
+ output = "<p>This should be at the top of the file</p>"
63
+
64
+ file = Gimli::MarkupFile.new File.expand_path('../../fixtures/yaml_front_matter.textile', __FILE__)
65
+ markup = Gimli::Markup.new file, true
66
+
67
+ markup.render.should == output
68
+ end
69
+
61
70
  end
62
71
 
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.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-08-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: github-markup
16
- requirement: &22561440 !ruby/object:Gem::Requirement
16
+ requirement: &22129260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.5.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *22561440
24
+ version_requirements: *22129260
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redcarpet
27
- requirement: &22557940 !ruby/object:Gem::Requirement
27
+ requirement: &22128480 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.17.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *22557940
35
+ version_requirements: *22128480
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: RedCloth
38
- requirement: &22556960 !ruby/object:Gem::Requirement
38
+ requirement: &22127580 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 4.2.7
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *22556960
46
+ version_requirements: *22127580
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: org-ruby
49
- requirement: &22555840 !ruby/object:Gem::Requirement
49
+ requirement: &22125580 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.5.3
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *22555840
57
+ version_requirements: *22125580
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: creole
60
- requirement: &22555200 !ruby/object:Gem::Requirement
60
+ requirement: &22124000 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.4.2
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *22555200
68
+ version_requirements: *22124000
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: wikicloth
71
- requirement: &22554420 !ruby/object:Gem::Requirement
71
+ requirement: &22122800 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.6.3
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *22554420
79
+ version_requirements: *22122800
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: albino
82
- requirement: &22553060 !ruby/object:Gem::Requirement
82
+ requirement: &22122100 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 1.3.3
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *22553060
90
+ version_requirements: *22122100
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: nokogiri
93
- requirement: &22551860 !ruby/object:Gem::Requirement
93
+ requirement: &22121380 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 1.4.4
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *22551860
101
+ version_requirements: *22121380
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: wkhtmltopdf-binary
104
- requirement: &22550100 !ruby/object:Gem::Requirement
104
+ requirement: &22081420 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 0.9.5.3
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *22550100
112
+ version_requirements: *22081420
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: pdfkit
115
- requirement: &22546560 !ruby/object:Gem::Requirement
115
+ requirement: &22080260 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 0.5.2
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *22546560
123
+ version_requirements: *22080260
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: optiflag
126
- requirement: &22545840 !ruby/object:Gem::Requirement
126
+ requirement: &22079540 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ~>
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0.7'
132
132
  type: :runtime
133
133
  prerelease: false
134
- version_requirements: *22545840
134
+ version_requirements: *22079540
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: rake
137
- requirement: &22545180 !ruby/object:Gem::Requirement
137
+ requirement: &22079080 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *22545180
145
+ version_requirements: *22079080
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: rspec
148
- requirement: &22544200 !ruby/object:Gem::Requirement
148
+ requirement: &22078580 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,10 +153,10 @@ dependencies:
153
153
  version: '0'
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *22544200
156
+ version_requirements: *22078580
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: rr
159
- requirement: &22543320 !ruby/object:Gem::Requirement
159
+ requirement: &22078140 !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
162
162
  - - ! '>='
@@ -164,10 +164,10 @@ dependencies:
164
164
  version: '0'
165
165
  type: :development
166
166
  prerelease: false
167
- version_requirements: *22543320
167
+ version_requirements: *22078140
168
168
  - !ruby/object:Gem::Dependency
169
169
  name: bundler
170
- requirement: &22542540 !ruby/object:Gem::Requirement
170
+ requirement: &22077620 !ruby/object:Gem::Requirement
171
171
  none: false
172
172
  requirements:
173
173
  - - ! '>='
@@ -175,7 +175,7 @@ dependencies:
175
175
  version: '0'
176
176
  type: :development
177
177
  prerelease: false
178
- version_requirements: *22542540
178
+ version_requirements: *22077620
179
179
  description: Utility for converting markup files to pdf files. Useful for reports
180
180
  etc.
181
181
  email: fredrik.wallgren@gmail.com
@@ -198,6 +198,7 @@ files:
198
198
  - spec/spec_helper.rb
199
199
  - spec/fixtures/code_with_utf8.textile
200
200
  - spec/fixtures/code_block_with_utf8.textile
201
+ - spec/fixtures/yaml_front_matter.textile
201
202
  - spec/fixtures/recursion/level2/level2.markdown
202
203
  - spec/fixtures/recursion/level1.textile
203
204
  - spec/fixtures/code_block.textile
@@ -223,7 +224,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
223
224
  version: '0'
224
225
  segments:
225
226
  - 0
226
- hash: 1493974172056676610
227
+ hash: 2493386614260603891
227
228
  required_rubygems_version: !ruby/object:Gem::Requirement
228
229
  none: false
229
230
  requirements:
@@ -232,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
233
  version: '0'
233
234
  segments:
234
235
  - 0
235
- hash: 1493974172056676610
236
+ hash: 2493386614260603891
236
237
  requirements: []
237
238
  rubyforge_project: gimli
238
239
  rubygems_version: 1.8.6