gimli 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,9 +2,10 @@
2
2
 
3
3
  require 'gimli/version'
4
4
  require 'gimli/setup'
5
- require 'gimli/file'
5
+ require 'gimli/markupfile'
6
6
  require 'gimli/converter'
7
7
  require 'gimli/albino'
8
+ require 'gimli/path'
8
9
 
9
10
  module Gimli
10
11
 
@@ -15,27 +16,10 @@ module Gimli
15
16
  puts "Version: #{Gimli::Version}"
16
17
  return
17
18
  end
18
-
19
- @files = []
20
- if ARGV.flags.file?
21
- Gimli.load_file(ARGV.flags.file)
22
- else
23
- Dir.glob("*").each do |file|
24
- Gimli.load_file(file)
25
- end
26
- end
27
-
28
- @files.each do |file|
29
- converter = Converter.new file
19
+
20
+ Path.list_valid(ARGV.flags.file, ARGV.flags.recursive?).each do |file|
21
+ converter = Converter.new(MarkupFile.new(file))
30
22
  converter.convert!
31
23
  end
32
24
  end
33
-
34
- # Add file to the files to be converted if it's valid
35
- # @param [String] file
36
- def self.load_file(file)
37
- file = File.new file
38
- @files << file if file.valid?
39
- end
40
- end
41
-
25
+ end
@@ -3,7 +3,7 @@
3
3
  module Gimli
4
4
 
5
5
  # Class used to load files and determine if they are valid
6
- class File
6
+ class MarkupFile
7
7
  attr_reader :filename, :name, :data, :format
8
8
 
9
9
  # Accepted formats
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ module Gimli
4
+
5
+ # Class used to interact with directory structure
6
+ class Path
7
+
8
+ # Return an array of paths to valid markup file matching the passed pattern
9
+ # @param [String] target
10
+ # @param [Bool] recursive
11
+ def self.list_valid(target, recursive = false)
12
+ if recursive
13
+ target ||= Dir.pwd
14
+ if File.directory?(target)
15
+ target = File.join(target, '**', '*')
16
+ end
17
+ else
18
+ target ||= Dir.pwd
19
+ if File.directory?(target)
20
+ target = File.join(target, '*')
21
+ end
22
+ end
23
+ Dir.glob(target).keep_if { |file| MarkupFile.new(file).valid? }
24
+ end
25
+ end
26
+ end
@@ -5,7 +5,7 @@ require 'optiflag'
5
5
  # Set up the flags available
6
6
  module Gimli extend OptiFlagSet
7
7
  optional_flag 'file' do
8
- description 'The file to convert if you do not want to convert all in the current folder'
8
+ description 'The file or folder to convert if you do not want to convert all in the current folder'
9
9
  alternate_forms 'f'
10
10
  end
11
11
  optional_flag 'outputdir' do
@@ -16,6 +16,10 @@ module Gimli extend OptiFlagSet
16
16
  description 'The stylesheet to use to override the standard'
17
17
  alternate_forms 's'
18
18
  end
19
+ optional_switch_flag 'recursive' do
20
+ description 'Recurse current or target directory and convert all valid markup files'
21
+ alternate_forms 'r'
22
+ end
19
23
  optional_switch_flag 'version' do
20
24
  description 'Show version information and quit'
21
25
  alternate_forms 'v'
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Gimli
4
4
 
5
- Version = "0.1.5"
5
+ Version = "0.1.6"
6
6
 
7
7
  end
8
8
 
@@ -0,0 +1 @@
1
+ h1. Level 1
@@ -6,7 +6,7 @@ require './lib/gimli'
6
6
 
7
7
  describe Gimli::Converter do
8
8
  it 'should give the correct output_file with none given' do
9
- file = Gimli::File.new 'fake'
9
+ file = Gimli::MarkupFile.new 'fake'
10
10
  name = 'my_file'
11
11
  mock(file).name { name }
12
12
 
@@ -17,7 +17,7 @@ describe Gimli::Converter do
17
17
  end
18
18
 
19
19
  it 'should give the correct output_file with one given' do
20
- file = Gimli::File.new 'fake'
20
+ file = Gimli::MarkupFile.new 'fake'
21
21
  name = 'my_file'
22
22
  mock(file).name { name }
23
23
 
@@ -30,7 +30,7 @@ describe Gimli::Converter do
30
30
  it 'should give the correct output_dir when none given' do
31
31
  dir = Dir.getwd
32
32
 
33
- file = Gimli::File.new 'fake'
33
+ file = Gimli::MarkupFile.new 'fake'
34
34
  converter = Gimli::Converter.new file
35
35
 
36
36
  converter.output_dir.should == dir
@@ -39,7 +39,7 @@ describe Gimli::Converter do
39
39
  it 'should give the correct output_dir when given' do
40
40
  dir = '/tmp/out'
41
41
 
42
- file = Gimli::File.new 'fake'
42
+ file = Gimli::MarkupFile.new 'fake'
43
43
  converter = Gimli::Converter.new file
44
44
 
45
45
  mock(ARGV).flags.mock!.outputdir? { true }
@@ -50,7 +50,7 @@ describe Gimli::Converter do
50
50
  end
51
51
 
52
52
  it 'should use stylesheet if exists in folder' do
53
- file = Gimli::File.new 'fake'
53
+ file = Gimli::MarkupFile.new 'fake'
54
54
  converter = Gimli::Converter.new file
55
55
 
56
56
  mock(ARGV).flags.mock!.stylesheet? { false }
@@ -59,7 +59,7 @@ describe Gimli::Converter do
59
59
  end
60
60
 
61
61
  it 'should use stylesheet if given' do
62
- file = Gimli::File.new 'fake'
62
+ file = Gimli::MarkupFile.new 'fake'
63
63
  converter = Gimli::Converter.new file
64
64
 
65
65
  style = '/home/me/gimli/my-style.css'
@@ -71,7 +71,7 @@ describe Gimli::Converter do
71
71
  end
72
72
 
73
73
  it 'should convert relative image urls to absolute' do
74
- file = Gimli::File.new 'fake'
74
+ file = Gimli::MarkupFile.new 'fake'
75
75
  converter = Gimli::Converter.new file
76
76
 
77
77
  html = '<p>foo</p><img src="test.jpg" alt="" /><p>bar</p><img src="test2.jpg" alt="" />'
@@ -81,7 +81,7 @@ describe Gimli::Converter do
81
81
  end
82
82
 
83
83
  it 'should not rewrite non relative urls' do
84
- file = Gimli::File.new 'fake'
84
+ file = Gimli::MarkupFile.new 'fake'
85
85
  converter = Gimli::Converter.new file
86
86
 
87
87
  html = '<p>foo</p><img src="https://d3nwyuy0nl342s.cloudfront.net/images/modules/header/logov3-hover.png" alt="" /><p>bar</p>'
@@ -90,7 +90,7 @@ describe Gimli::Converter do
90
90
  end
91
91
 
92
92
  it 'should work on both absolute and relative images' do
93
- file = Gimli::File.new 'fake'
93
+ file = Gimli::MarkupFile.new 'fake'
94
94
  converter = Gimli::Converter.new file
95
95
 
96
96
  html = '<p>foo</p><img src="test.jpg" alt="" /><p>bar</p><img src="/tmp/test2.jpg" alt="" /> <img src="https://d3nwyuy0nl342s.cloudfront.net/images/modules/header/logov3-hover.png" alt="" />'
@@ -4,24 +4,24 @@ require './spec/spec_helper'
4
4
 
5
5
  require './lib/gimli'
6
6
 
7
- describe Gimli::File do
7
+ describe Gimli::MarkupFile do
8
8
  it 'should recognize valid format' do
9
- file = Gimli::File.new 'fake'
9
+ file = Gimli::MarkupFile.new 'fake'
10
10
  file.valid_format?('textile').should be_true
11
11
  end
12
12
 
13
13
  it 'should recognize invalid format' do
14
- file = Gimli::File.new 'fake'
14
+ file = Gimli::MarkupFile.new 'fake'
15
15
  file.valid_format?('abc123').should be_false
16
16
  end
17
17
 
18
18
  it 'should recognize nil as invalid format' do
19
- file = Gimli::File.new 'fake'
19
+ file = Gimli::MarkupFile.new 'fake'
20
20
  file.valid_format?(nil).should be_false
21
21
  end
22
22
 
23
23
  it 'should give the name as the filename without the extension' do
24
- file = Gimli::File.new 'test.txt'
24
+ file = Gimli::MarkupFile.new 'test.txt'
25
25
  file.name.should == File.basename(file.filename, File.extname(file.filename))
26
26
  end
27
27
  end
@@ -14,7 +14,7 @@ describe Gimli::Markup do
14
14
 
15
15
  output_without_pygments = "<p>a</p>\n<pre><code>x = 1</code></pre>\n<p>b</p>"
16
16
 
17
- file = Gimli::File.new File.expand_path('../../fixtures/code_block.textile', __FILE__)
17
+ file = Gimli::MarkupFile.new File.expand_path('../../fixtures/code_block.textile', __FILE__)
18
18
  markup = Gimli::Markup.new file
19
19
 
20
20
  # Check if the html seems to be highlighted
@@ -36,7 +36,7 @@ describe Gimli::Markup do
36
36
  output_without_pygments = "<p>a</p>\n<pre><code>&lt;h1&gt;Abcåäö&lt;/h1&gt;\n&lt;img " +
37
37
  "src=\"åäö.png\" alt=\"ÅÄÖ\" /&gt;</code></pre>"
38
38
 
39
- file = Gimli::File.new File.expand_path('../../fixtures/code_block_with_utf8.textile', __FILE__)
39
+ file = Gimli::MarkupFile.new File.expand_path('../../fixtures/code_block_with_utf8.textile', __FILE__)
40
40
  markup = Gimli::Markup.new file
41
41
 
42
42
  # Check if the html seems to be highlighted
@@ -52,7 +52,7 @@ describe Gimli::Markup do
52
52
  output = "<p>a</p>\n<code>&lt;img src=\"åäö.png\" " +
53
53
  "alt=\"Abcåäö\" /&gt;</code>\n<p>b</p>"
54
54
 
55
- file = Gimli::File.new File.expand_path('../../fixtures/code_with_utf8.textile', __FILE__)
55
+ file = Gimli::MarkupFile.new File.expand_path('../../fixtures/code_with_utf8.textile', __FILE__)
56
56
  markup = Gimli::Markup.new file
57
57
 
58
58
  markup.render.should == output
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+
3
+ require './spec/spec_helper'
4
+
5
+ require './lib/gimli'
6
+
7
+ describe Gimli::Path do
8
+
9
+ it 'should find all files in the current directory, with no specified target, without recursion' do
10
+ mock(Dir).pwd { './spec/fixtures/recursion/' }
11
+ Gimli::Path.list_valid(nil, false).length.should == 1
12
+ end
13
+
14
+ it 'should find all files in all subdirectories, with no specified target, with recursion ' do
15
+ mock(Dir).pwd { './spec/fixtures/recursion/' }
16
+ Gimli::Path.list_valid(nil, true).length.should == 2
17
+ end
18
+
19
+ it 'should find all files in all subdirectories, with a specified directory, with recursion' do
20
+ Gimli::Path.list_valid('./spec/fixtures/recursion/', true).length.should == 2
21
+ end
22
+
23
+ it 'should find one file, with a specified file, without recursion' do
24
+ Gimli::Path.list_valid('./spec/fixtures/recursion/level1.textile', false).length.should == 1
25
+ end
26
+
27
+ # What is the sound of one file recursing?
28
+ it 'should find one file, with a specified file, with recursion' do
29
+ Gimli::Path.list_valid('README.textile', true).length.should == 1
30
+ end
31
+
32
+ end
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.5
4
+ version: 0.1.6
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-27 00:00:00.000000000 +02:00
12
+ date: 2011-05-28 00:00:00.000000000 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
17
- requirement: &20582820 !ruby/object:Gem::Requirement
17
+ requirement: &8153660 !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: *20582820
25
+ version_requirements: *8153660
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: github-markup
28
- requirement: &20582380 !ruby/object:Gem::Requirement
28
+ requirement: &8153220 !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: *20582380
36
+ version_requirements: *8153220
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: redcarpet
39
- requirement: &20581960 !ruby/object:Gem::Requirement
39
+ requirement: &8152800 !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: *20581960
47
+ version_requirements: *8152800
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: RedCloth
50
- requirement: &20581540 !ruby/object:Gem::Requirement
50
+ requirement: &8152380 !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: *20581540
58
+ version_requirements: *8152380
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: org-ruby
61
- requirement: &20581120 !ruby/object:Gem::Requirement
61
+ requirement: &8151960 !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: *20581120
69
+ version_requirements: *8151960
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: creole
72
- requirement: &20580700 !ruby/object:Gem::Requirement
72
+ requirement: &8151540 !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: *20580700
80
+ version_requirements: *8151540
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: wikicloth
83
- requirement: &20580280 !ruby/object:Gem::Requirement
83
+ requirement: &8151120 !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: *20580280
91
+ version_requirements: *8151120
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: albino
94
- requirement: &20579860 !ruby/object:Gem::Requirement
94
+ requirement: &8150700 !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: *20579860
102
+ version_requirements: *8150700
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: nokogiri
105
- requirement: &20579440 !ruby/object:Gem::Requirement
105
+ requirement: &8150280 !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: *20579440
113
+ version_requirements: *8150280
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: wkhtmltopdf-binary
116
- requirement: &20579020 !ruby/object:Gem::Requirement
116
+ requirement: &8149860 !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: *20579020
124
+ version_requirements: *8149860
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: pdfkit
127
- requirement: &20578600 !ruby/object:Gem::Requirement
127
+ requirement: &8144320 !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: *20578600
135
+ version_requirements: *8144320
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: optiflag
138
- requirement: &20573260 !ruby/object:Gem::Requirement
138
+ requirement: &8143860 !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: :runtime
145
145
  prerelease: false
146
- version_requirements: *20573260
146
+ version_requirements: *8143860
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: rspec
149
- requirement: &20572820 !ruby/object:Gem::Requirement
149
+ requirement: &8143440 !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements:
152
152
  - - ! '>='
@@ -154,10 +154,10 @@ dependencies:
154
154
  version: '0'
155
155
  type: :development
156
156
  prerelease: false
157
- version_requirements: *20572820
157
+ version_requirements: *8143440
158
158
  - !ruby/object:Gem::Dependency
159
159
  name: rr
160
- requirement: &20572320 !ruby/object:Gem::Requirement
160
+ requirement: &8142980 !ruby/object:Gem::Requirement
161
161
  none: false
162
162
  requirements:
163
163
  - - ! '>='
@@ -165,7 +165,7 @@ dependencies:
165
165
  version: '0'
166
166
  type: :development
167
167
  prerelease: false
168
- version_requirements: *20572320
168
+ version_requirements: *8142980
169
169
  description: Utility for converting markup files to pdf files. Useful for reports
170
170
  etc.
171
171
  email: fredrik.wallgren@gmail.com
@@ -178,8 +178,9 @@ extra_rdoc_files:
178
178
  files:
179
179
  - bin/gimli
180
180
  - lib/gimli/version.rb
181
+ - lib/gimli/path.rb
181
182
  - lib/gimli/albino.rb
182
- - lib/gimli/file.rb
183
+ - lib/gimli/markupfile.rb
183
184
  - lib/gimli/markup.rb
184
185
  - lib/gimli/setup.rb
185
186
  - lib/gimli/converter.rb
@@ -187,7 +188,10 @@ files:
187
188
  - spec/spec_helper.rb
188
189
  - spec/fixtures/code_with_utf8.textile
189
190
  - spec/fixtures/code_block_with_utf8.textile
191
+ - spec/fixtures/recursion/level2/level2.markdown
192
+ - spec/fixtures/recursion/level1.textile
190
193
  - spec/fixtures/code_block.textile
194
+ - spec/gimli/path_spec.rb
191
195
  - spec/gimli/converter_spec.rb
192
196
  - spec/gimli/markup_spec.rb
193
197
  - spec/gimli/file_spec.rb