konjac 0.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,3 +4,4 @@
4
4
  Gemfile.lock
5
5
  doc/
6
6
  pkg/*
7
+ spec/office/bin/sample.*.diff
data/.rspec CHANGED
@@ -1 +1,4 @@
1
1
  --color
2
+ --tag ~excel
3
+ --tag ~power_point
4
+ --tag ~word
data/Rakefile CHANGED
@@ -1,7 +1,31 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rdoc/task"
3
+ require "rspec/core/rake_task"
3
4
  require "sdoc"
4
5
 
6
+ namespace :spec do
7
+ desc "Run specs for Excel"
8
+ RSpec::Core::RakeTask.new(:excel) do |t|
9
+ t.rspec_opts = ["--tag", "excel"]
10
+ end
11
+
12
+ desc "Run specs for PowerPoint"
13
+ RSpec::Core::RakeTask.new(:power_point) do |t|
14
+ t.rspec_opts = ["--tag", "power_point"]
15
+ end
16
+
17
+ desc "Run specs for Word"
18
+ RSpec::Core::RakeTask.new(:word) do |t|
19
+ t.rspec_opts = ["--tag", "word"]
20
+ end
21
+
22
+ desc "Run all specs"
23
+ task :all => [:excel, :power_point, :word]
24
+ end
25
+
26
+ desc "Run specs"
27
+ RSpec::Core::RakeTask.new
28
+
5
29
  # Quick hack until SDoc gets fixed
6
30
  class RDoc::Generator::SDoc; alias :basedir :base_dir; end
7
31
 
@@ -49,7 +49,7 @@ module Konjac
49
49
  when :shape
50
50
  "\r"
51
51
  else
52
- "\n"
52
+ "\v"
53
53
  end
54
54
  end
55
55
  end
@@ -13,6 +13,21 @@ module Konjac
13
13
  def open(path)
14
14
  @application.open path
15
15
  end
16
+
17
+ # Closes the document. If <tt>:saving</tt> is set to +true+ the document
18
+ # will be saved first. If it's set to +false+ the document will not be
19
+ # saved.
20
+ def close(opts = {})
21
+ opts[:saving] = case opts[:saving]
22
+ when true
23
+ :yes
24
+ when false
25
+ :no
26
+ else
27
+ nil
28
+ end
29
+ @document.close :saving => opts[:saving]
30
+ end
16
31
 
17
32
  # Retrieves the POSIX path of the document
18
33
  def path
@@ -1,4 +1,4 @@
1
1
  module Konjac
2
2
  # The current version number of Konjac
3
- VERSION = "0.3"
3
+ VERSION = "0.3.1"
4
4
  end
Binary file
@@ -0,0 +1,5 @@
1
+ # coding: utf-8
2
+ require File.dirname(__FILE__) + "/../spec_helper"
3
+
4
+ describe "Excel", :excel do
5
+ end
@@ -0,0 +1,5 @@
1
+ # coding: utf-8
2
+ require File.dirname(__FILE__) + "/../spec_helper"
3
+
4
+ describe "PowerPoint", :power_point do
5
+ end
@@ -0,0 +1,129 @@
1
+ # coding: utf-8
2
+ require File.dirname(__FILE__) + "/../spec_helper"
3
+
4
+ describe "Word", :word do
5
+ describe "opening the sample document" do
6
+ before :all do
7
+ @export_target = StringIO.new <<-eof
8
+ --- /Users/bryan/Projects/konjac/spec/office/bin/sample.docx
9
+ +++ /Users/bryan/Projects/konjac/spec/office/bin/sample.docx
10
+ @@ 1 @@
11
+ -Normal paragraph
12
+ +Normal paragraph
13
+ @@ 2 @@
14
+ -Paragraph with a
15
+ -line break
16
+ +Paragraph with a
17
+ +line break
18
+ @@ 3 @@
19
+ - Tabbed paragraph
20
+ + Tabbed paragraph
21
+ @@ 4 @@
22
+ -Bullet point 1
23
+ +Bullet point 1
24
+ @@ 5 @@
25
+ -Bullet point 2
26
+ +Bullet point 2
27
+ @@ 6 @@
28
+ -Bullet point 3
29
+ +Bullet point 3
30
+ @@ 7 @@
31
+ -Header 1
32
+ +Header 1
33
+ @@ 8 @@
34
+ -Header 2
35
+ +Header 2
36
+ @@ 9 @@
37
+ -Header 3
38
+ +Header 3
39
+ @@ 11 @@
40
+ -Cell 1
41
+ +Cell 1
42
+ @@ 12 @@
43
+ -Cell 2
44
+ +Cell 2
45
+ @@ 13 @@
46
+ -Cell 3
47
+ +Cell 3
48
+ @@ 15 @@
49
+ -Cell 4
50
+ +Cell 4
51
+ @@ 16 @@
52
+ -Cell 5
53
+ +Cell 5
54
+ @@ 17 @@
55
+ -Cell 6
56
+ +Cell 6
57
+ @@ shape 1 @@
58
+ -Text box
59
+ +Text box
60
+ eof
61
+ @spec_path = File.dirname(File.expand_path(__FILE__))
62
+ @path = File.join(@spec_path, "bin", "sample.docx")
63
+ @diff_path = "#{@path}.diff"
64
+ @doc = Office.word(@path)
65
+ @original_size = @doc.size
66
+ end
67
+
68
+ after :all do
69
+ @doc.close :saving => false
70
+ end
71
+
72
+ it "should open the test document" do
73
+ @doc.read.should == ["Normal paragraph"]
74
+ end
75
+
76
+ it "should return the same path" do
77
+ @doc.path.should == @path
78
+ end
79
+
80
+ it "should export tags to a tags file" do
81
+ File.delete @diff_path rescue Errno::ENOENT
82
+ @doc.export
83
+ File.exists?(@diff_path).should == true
84
+ end
85
+
86
+ it "should have exported the expected tags" do
87
+ @export_target.rewind
88
+ tags = File.open(@diff_path)
89
+ tags.each_line do |tag|
90
+ tag.should == @export_target.readline
91
+ end
92
+ end
93
+
94
+ it "should read some arbitrary items correctly" do
95
+ @doc.read(3).should == ["\tTabbed paragraph"]
96
+ @doc.read(6).should == ["Bullet point 3"]
97
+ @doc.read(13).should == ["Cell 3"]
98
+ @doc.read(1, :type => :shape).should == ["Text box"]
99
+ end
100
+
101
+ it "should import all tags correctly" do
102
+ @export_target.rewind
103
+ @doc.find 1
104
+ index = 0
105
+ lines = []
106
+ File.open(@diff_path, "w") do |file|
107
+ @export_target.each do |line|
108
+ if line =~ /^\+/ && line !~ /^\+\+\+/
109
+ line = "#{line.chomp} - #{index}"
110
+ lines << line[1..-1]
111
+ index += 1
112
+ end
113
+
114
+ file.puts line
115
+ end
116
+ end
117
+ @doc.import
118
+ @doc.data.each do |tag|
119
+ tag.added.each do |tag_part|
120
+ tag_part.should == lines.shift
121
+ end
122
+ end
123
+ end
124
+
125
+ it "should not have any change in size" do
126
+ @doc.size.should == @original_size
127
+ end
128
+ end
129
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,7 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
2
2
  require "konjac"
3
3
  include Konjac
4
+
5
+ RSpec.configure do |config|
6
+ config.treat_symbols_as_metadata_keys_with_true_values = true
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: konjac
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-10 00:00:00.000000000 Z
12
+ date: 2012-02-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: amatch
16
- requirement: &70292199617680 !ruby/object:Gem::Requirement
16
+ requirement: &70305013220300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70292199617680
24
+ version_requirements: *70305013220300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: git
27
- requirement: &70292199617240 !ruby/object:Gem::Requirement
27
+ requirement: &70305013219840 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70292199617240
35
+ version_requirements: *70305013219840
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: highline
38
- requirement: &70292199616720 !ruby/object:Gem::Requirement
38
+ requirement: &70305013219080 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70292199616720
46
+ version_requirements: *70305013219080
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: i18n
49
- requirement: &70292199616220 !ruby/object:Gem::Requirement
49
+ requirement: &70305013218100 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70292199616220
57
+ version_requirements: *70305013218100
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: nokogiri
60
- requirement: &70292199615660 !ruby/object:Gem::Requirement
60
+ requirement: &70305013216940 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70292199615660
68
+ version_requirements: *70305013216940
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rb-appscript
71
- requirement: &70292199614620 !ruby/object:Gem::Requirement
71
+ requirement: &70305013216160 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70292199614620
79
+ version_requirements: *70305013216160
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: sdoc
82
- requirement: &70292199613940 !ruby/object:Gem::Requirement
82
+ requirement: &70305013215520 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70292199613940
90
+ version_requirements: *70305013215520
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: term-ansicolor
93
- requirement: &70292199599480 !ruby/object:Gem::Requirement
93
+ requirement: &70305013214700 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *70292199599480
101
+ version_requirements: *70305013214700
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: trollop
104
- requirement: &70292199598700 !ruby/object:Gem::Requirement
104
+ requirement: &70305013213200 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *70292199598700
112
+ version_requirements: *70305013213200
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: autotest
115
- requirement: &70292199597260 !ruby/object:Gem::Requirement
115
+ requirement: &70305013212040 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70292199597260
123
+ version_requirements: *70305013212040
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: autotest-fsevent
126
- requirement: &70292199596780 !ruby/object:Gem::Requirement
126
+ requirement: &70305013211000 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *70292199596780
134
+ version_requirements: *70305013211000
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: autotest-growl
137
- requirement: &70292199596360 !ruby/object:Gem::Requirement
137
+ requirement: &70305013210200 !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: *70292199596360
145
+ version_requirements: *70305013210200
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: bundler
148
- requirement: &70292199595740 !ruby/object:Gem::Requirement
148
+ requirement: &70305013209760 !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: *70292199595740
156
+ version_requirements: *70305013209760
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: rspec
159
- requirement: &70292199594940 !ruby/object:Gem::Requirement
159
+ requirement: &70305013209200 !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
162
162
  - - ! '>='
@@ -164,7 +164,7 @@ dependencies:
164
164
  version: '0'
165
165
  type: :development
166
166
  prerelease: false
167
- version_requirements: *70292199594940
167
+ version_requirements: *70305013209200
168
168
  description: A Ruby command-line utility for translating files using a YAML wordlist
169
169
  email:
170
170
  - bryan.mckelvey@gmail.com
@@ -216,7 +216,11 @@ files:
216
216
  - spec/config_spec.rb
217
217
  - spec/dictionary_spec.rb
218
218
  - spec/language_spec.rb
219
+ - spec/office/bin/sample.docx
220
+ - spec/office/excel_spec.rb
219
221
  - spec/office/generic_spec.rb
222
+ - spec/office/power_point_spec.rb
223
+ - spec/office/word_spec.rb
220
224
  - spec/office_spec.rb
221
225
  - spec/spec_helper.rb
222
226
  - spec/utils_spec.rb
@@ -249,7 +253,11 @@ test_files:
249
253
  - spec/config_spec.rb
250
254
  - spec/dictionary_spec.rb
251
255
  - spec/language_spec.rb
256
+ - spec/office/bin/sample.docx
257
+ - spec/office/excel_spec.rb
252
258
  - spec/office/generic_spec.rb
259
+ - spec/office/power_point_spec.rb
260
+ - spec/office/word_spec.rb
253
261
  - spec/office_spec.rb
254
262
  - spec/spec_helper.rb
255
263
  - spec/utils_spec.rb