msword 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/*.jar
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "vendor/msword-java"]
2
+ path = vendor/msword-java
3
+ url = https://github.com/anjlab/msword-java.git
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in msword.gemspec
4
+ gemspec
5
+
6
+ gem 'rake'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 yury
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # MSWord
2
+
3
+ Simple work with MS Word docs
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'msword'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install msword
18
+
19
+ ## Usage
20
+
21
+ Right now this gem supports only **find and replace** command.
22
+
23
+ ```ruby
24
+ require 'msword'
25
+
26
+ MSWord.replace 'src.doc', 'dest.doc', [
27
+ ['hello', 'bye'], ['#{date}', Time.now.to_s]
28
+ ]
29
+
30
+ ```
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ JAR = "vendor/msword-java/target/msword-1.0.0.jar"
2
+ LIB_JAR = "lib/msword.jar"
3
+
4
+ file LIB_JAR => JAR do
5
+ cp JAR, LIB_JAR
6
+ end
7
+
8
+ def mvn command
9
+ sh "cd vendor/msword-java && mvn #{command}"
10
+ end
11
+
12
+ file JAR do
13
+ mvn "clean package"
14
+ end
15
+
16
+ task build: LIB_JAR
17
+
18
+ task :clean do
19
+ mvn "clean"
20
+ rm "lib/msword.jar"
21
+ end
22
+
23
+ require "bundler/gem_tasks"
data/lib/msword.rb ADDED
@@ -0,0 +1,38 @@
1
+ require "msword/version"
2
+ require 'open3'
3
+ require 'multi_json'
4
+
5
+ module MSWord
6
+
7
+ def self.replace input_file, output_file, pairs
8
+ args = {
9
+ src: input_file,
10
+ output: output_file,
11
+ commands: [
12
+ {
13
+ command: :replace,
14
+ args: pairs
15
+ }
16
+ ]
17
+ }
18
+
19
+ process(args)
20
+ end
21
+
22
+ def self.process args
23
+ java_options = args.delete(:java_options) || "-Dfile.encoding=utf8 -Xms512m -Xmx512m -XX:MaxPermSize=256m"
24
+ jar_path = File.join(File.dirname(__FILE__), "msword.jar")
25
+ puts MultiJson.encode(args)
26
+ Open3.popen3("java #{java_options} -jar #{jar_path}") do |stdin, stdout, stderr, wait_thr|
27
+ stdin.write MultiJson.encode(args)
28
+ stdin.close
29
+ exit_status = wait_thr.value
30
+ if exit_status != 0
31
+ puts stdout.read
32
+ puts stderr.read
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,3 @@
1
+ module MSWord
2
+ VERSION = "0.0.1"
3
+ end
data/msword.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'msword/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "msword"
8
+ gem.version = MSWord::VERSION
9
+ gem.authors = ["yury"]
10
+ gem.email = ["yury.korolev@gmail.com"]
11
+ gem.description = %q{Work with MS Word doc files with ruby}
12
+ gem.summary = %q{Work with MS Word doc files with ruby}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.files << 'lib/msword.jar'
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_dependency "multi_json"
22
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: msword
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - yury
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ none: false
21
+ prerelease: false
22
+ name: multi_json
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ! '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ none: false
29
+ type: :runtime
30
+ description: Work with MS Word doc files with ruby
31
+ email:
32
+ - yury.korolev@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - .gitmodules
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - lib/msword.rb
44
+ - lib/msword/version.rb
45
+ - msword.gemspec
46
+ - lib/msword.jar
47
+ homepage: ''
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ segments:
59
+ - 0
60
+ hash: 1438186475137185173
61
+ none: false
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ segments:
68
+ - 0
69
+ hash: 1438186475137185173
70
+ none: false
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 1.8.24
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Work with MS Word doc files with ruby
77
+ test_files: []