datashift 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -5
- data/LICENSE.txt +26 -26
- data/README.markdown +326 -305
- data/README.rdoc +19 -19
- data/Rakefile +86 -93
- data/VERSION +1 -1
- data/datashift.gemspec +163 -152
- data/lib/applications/jruby/jexcel_file.rb +410 -408
- data/lib/applications/jruby/word.rb +79 -79
- data/lib/datashift.rb +183 -152
- data/lib/datashift/exceptions.rb +11 -11
- data/lib/datashift/file_definitions.rb +353 -353
- data/lib/datashift/mapping_file_definitions.rb +87 -87
- data/lib/datashift/method_detail.rb +293 -275
- data/lib/datashift/method_dictionary.rb +208 -209
- data/lib/datashift/method_mapper.rb +90 -90
- data/lib/datashift/model_mapper.rb +27 -0
- data/lib/exporters/csv_exporter.rb +36 -0
- data/lib/exporters/excel_exporter.rb +116 -0
- data/lib/exporters/exporter_base.rb +15 -0
- data/lib/generators/csv_generator.rb +36 -36
- data/lib/generators/excel_generator.rb +106 -122
- data/lib/generators/generator_base.rb +13 -13
- data/lib/helpers/core_ext/to_b.rb +24 -24
- data/lib/helpers/rake_utils.rb +42 -0
- data/lib/helpers/spree_helper.rb +194 -153
- data/lib/java/poi-3.7/LICENSE +507 -507
- data/lib/java/poi-3.7/NOTICE +21 -21
- data/lib/java/poi-3.7/RELEASE_NOTES.txt +115 -115
- data/lib/loaders/csv_loader.rb +98 -98
- data/lib/loaders/excel_loader.rb +155 -155
- data/lib/loaders/loader_base.rb +420 -420
- data/lib/loaders/spreadsheet_loader.rb +136 -136
- data/lib/loaders/spree/image_loader.rb +67 -63
- data/lib/loaders/spree/product_loader.rb +289 -248
- data/lib/thor/generate_excel.thor +54 -0
- data/sandbox/app/controllers/application_controller.rb +3 -0
- data/sandbox/config/application.rb +43 -0
- data/sandbox/config/database.yml +34 -0
- data/sandbox/config/environment.rb +7 -0
- data/sandbox/config/environments/development.rb +30 -0
- data/spec/csv_loader_spec.rb +30 -30
- data/spec/datashift_spec.rb +26 -26
- data/spec/db/migrate/20110803201325_create_test_bed.rb +85 -85
- data/spec/excel_exporter_spec.rb +78 -78
- data/spec/excel_generator_spec.rb +78 -78
- data/spec/excel_loader_spec.rb +223 -223
- data/spec/file_definitions.rb +141 -141
- data/spec/fixtures/ProjectsDefaults.yml +29 -29
- data/spec/fixtures/config/database.yml +27 -27
- data/spec/fixtures/datashift_Spree_db.sqlite +0 -0
- data/spec/fixtures/datashift_test_models_db.sqlite +0 -0
- data/spec/fixtures/negative/SpreeProdMiss1Mandatory.csv +4 -4
- data/spec/fixtures/negative/SpreeProdMissManyMandatory.csv +4 -4
- data/spec/fixtures/spree/SpreeProducts.csv +4 -4
- data/spec/fixtures/spree/SpreeProducts.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsMultiColumn.csv +4 -4
- data/spec/fixtures/spree/SpreeProductsMultiColumn.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsSimple.csv +4 -4
- data/spec/fixtures/spree/SpreeProductsWithImages.csv +4 -4
- data/spec/fixtures/spree/SpreeZoneExample.csv +5 -5
- data/spec/fixtures/test_model_defs.rb +57 -57
- data/spec/loader_spec.rb +120 -120
- data/spec/method_dictionary_spec.rb +242 -242
- data/spec/method_mapper_spec.rb +41 -41
- data/spec/spec_helper.rb +154 -116
- data/spec/spree_exporter_spec.rb +67 -0
- data/spec/spree_generator_spec.rb +77 -64
- data/spec/spree_loader_spec.rb +363 -324
- data/spec/spree_method_mapping_spec.rb +218 -214
- data/tasks/config/seed_fu_product_template.erb +15 -15
- data/tasks/config/tidy_config.txt +12 -12
- data/tasks/{excel_generator.rake → export/excel_generator.rake} +101 -78
- data/tasks/file_tasks.rake +36 -36
- data/tasks/import/csv.rake +50 -49
- data/tasks/import/excel.rake +74 -71
- data/tasks/spree/image_load.rake +108 -108
- data/tasks/spree/product_loader.rake +43 -43
- data/tasks/word_to_seedfu.rake +166 -166
- data/test/helper.rb +18 -18
- data/test/test_interact.rb +7 -7
- metadata +16 -8
- data/datashift-0.1.0.gem +0 -0
- data/tasks/db_tasks.rake +0 -66
@@ -1,79 +1,79 @@
|
|
1
|
-
# Author:: Tom Statter
|
2
|
-
# License:: MIT ?
|
3
|
-
#
|
4
|
-
# NOTES ON INVESTIGATING OLE METHODS in irb
|
5
|
-
#
|
6
|
-
# visible = @word_app.ole_method_help( 'Visible' ) # Get a Method Object
|
7
|
-
|
8
|
-
# log( visible.return_type_detail.to_s ) # => ["BOOL"]
|
9
|
-
# log( visible.invoke_kind.to_s ) # => "PROPERTYGET"
|
10
|
-
# log( visible.params.to_s ) # => []
|
11
|
-
|
12
|
-
# @fc.ole_method_help( 'Report' ).params[1].ole_type_detail
|
13
|
-
#
|
14
|
-
# prefs = @word_app.Preferences.Strings.ole_method_help( 'Set' ).params
|
15
|
-
# => [index, newVal]
|
16
|
-
#
|
17
|
-
# WORD_OLE_CONST.constants
|
18
|
-
#
|
19
|
-
# WORD_OLE_CONST.constants.sort.grep /CR/
|
20
|
-
# => ["ClHideCRLF", "LesCR", "LesCRLF"]
|
21
|
-
#
|
22
|
-
# WORD_OLE_CONST.const_get( 'LesCR' ) or WORD_OLE_CONST::LesCR
|
23
|
-
# => 1
|
24
|
-
|
25
|
-
if(Guards::windows?)
|
26
|
-
|
27
|
-
require 'win32ole'
|
28
|
-
|
29
|
-
# Module for constants to be loaded int
|
30
|
-
|
31
|
-
module WORD_OLE_CONST
|
32
|
-
end
|
33
|
-
|
34
|
-
class Word
|
35
|
-
|
36
|
-
attr_reader :wd, :doc
|
37
|
-
|
38
|
-
def initialize( visible )
|
39
|
-
@wd = WIN32OLE.new('Word.Application')
|
40
|
-
|
41
|
-
WIN32OLE.const_load(@wd, WORD_OLE_CONST) if WORD_OLE_CONST.constants.empty?
|
42
|
-
|
43
|
-
@wd.Visible = visible
|
44
|
-
end
|
45
|
-
|
46
|
-
def open(file)
|
47
|
-
@doc = @wd.Documents.Open(file)
|
48
|
-
@doc
|
49
|
-
end
|
50
|
-
|
51
|
-
def save()
|
52
|
-
@doc.Save()
|
53
|
-
@doc
|
54
|
-
end
|
55
|
-
|
56
|
-
# Format : From WORD_OLE_CONST e.g WORD_OLE_CONST::WdFormatHTML
|
57
|
-
#
|
58
|
-
def save_as(name, format)
|
59
|
-
@doc.SaveAs(name, format)
|
60
|
-
return @doc
|
61
|
-
end
|
62
|
-
|
63
|
-
# WdFormatFilteredHTML
|
64
|
-
# WdFormatHTML
|
65
|
-
def save_as_html(name)
|
66
|
-
@doc.SaveAs(name, WORD_OLE_CONST::WdFormatHTML)
|
67
|
-
return @doc
|
68
|
-
end
|
69
|
-
|
70
|
-
def quit
|
71
|
-
@wd.quit()
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
else
|
76
|
-
|
77
|
-
class Word
|
78
|
-
end
|
79
|
-
end
|
1
|
+
# Author:: Tom Statter
|
2
|
+
# License:: MIT ?
|
3
|
+
#
|
4
|
+
# NOTES ON INVESTIGATING OLE METHODS in irb
|
5
|
+
#
|
6
|
+
# visible = @word_app.ole_method_help( 'Visible' ) # Get a Method Object
|
7
|
+
|
8
|
+
# log( visible.return_type_detail.to_s ) # => ["BOOL"]
|
9
|
+
# log( visible.invoke_kind.to_s ) # => "PROPERTYGET"
|
10
|
+
# log( visible.params.to_s ) # => []
|
11
|
+
|
12
|
+
# @fc.ole_method_help( 'Report' ).params[1].ole_type_detail
|
13
|
+
#
|
14
|
+
# prefs = @word_app.Preferences.Strings.ole_method_help( 'Set' ).params
|
15
|
+
# => [index, newVal]
|
16
|
+
#
|
17
|
+
# WORD_OLE_CONST.constants
|
18
|
+
#
|
19
|
+
# WORD_OLE_CONST.constants.sort.grep /CR/
|
20
|
+
# => ["ClHideCRLF", "LesCR", "LesCRLF"]
|
21
|
+
#
|
22
|
+
# WORD_OLE_CONST.const_get( 'LesCR' ) or WORD_OLE_CONST::LesCR
|
23
|
+
# => 1
|
24
|
+
|
25
|
+
if(Guards::windows?)
|
26
|
+
|
27
|
+
require 'win32ole'
|
28
|
+
|
29
|
+
# Module for constants to be loaded int
|
30
|
+
|
31
|
+
module WORD_OLE_CONST
|
32
|
+
end
|
33
|
+
|
34
|
+
class Word
|
35
|
+
|
36
|
+
attr_reader :wd, :doc
|
37
|
+
|
38
|
+
def initialize( visible )
|
39
|
+
@wd = WIN32OLE.new('Word.Application')
|
40
|
+
|
41
|
+
WIN32OLE.const_load(@wd, WORD_OLE_CONST) if WORD_OLE_CONST.constants.empty?
|
42
|
+
|
43
|
+
@wd.Visible = visible
|
44
|
+
end
|
45
|
+
|
46
|
+
def open(file)
|
47
|
+
@doc = @wd.Documents.Open(file)
|
48
|
+
@doc
|
49
|
+
end
|
50
|
+
|
51
|
+
def save()
|
52
|
+
@doc.Save()
|
53
|
+
@doc
|
54
|
+
end
|
55
|
+
|
56
|
+
# Format : From WORD_OLE_CONST e.g WORD_OLE_CONST::WdFormatHTML
|
57
|
+
#
|
58
|
+
def save_as(name, format)
|
59
|
+
@doc.SaveAs(name, format)
|
60
|
+
return @doc
|
61
|
+
end
|
62
|
+
|
63
|
+
# WdFormatFilteredHTML
|
64
|
+
# WdFormatHTML
|
65
|
+
def save_as_html(name)
|
66
|
+
@doc.SaveAs(name, WORD_OLE_CONST::WdFormatHTML)
|
67
|
+
return @doc
|
68
|
+
end
|
69
|
+
|
70
|
+
def quit
|
71
|
+
@wd.quit()
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
else
|
76
|
+
|
77
|
+
class Word
|
78
|
+
end
|
79
|
+
end
|
data/lib/datashift.rb
CHANGED
@@ -1,153 +1,184 @@
|
|
1
|
-
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
-
# Author :: Tom Statter
|
3
|
-
# Date :: Aug 2010
|
4
|
-
# License:: TBD. Free, Open Source. MIT ?
|
5
|
-
#
|
6
|
-
# Details:: Active Record Loader
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
loader_paths
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: Aug 2010
|
4
|
+
# License:: TBD. Free, Open Source. MIT ?
|
5
|
+
#
|
6
|
+
# Details:: Active Record Loader
|
7
|
+
#
|
8
|
+
# # To pull Datashift commands into your main application :
|
9
|
+
#
|
10
|
+
# require 'datashift'
|
11
|
+
#
|
12
|
+
# DataShift::load_commands
|
13
|
+
#
|
14
|
+
require 'rbconfig'
|
15
|
+
|
16
|
+
module DataShift
|
17
|
+
|
18
|
+
module Guards
|
19
|
+
|
20
|
+
def self.jruby?
|
21
|
+
return RUBY_PLATFORM == "java"
|
22
|
+
end
|
23
|
+
def self.mac?
|
24
|
+
RbConfig::CONFIG['target_os'] =~ /darwin/i
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.linux?
|
28
|
+
RbConfig::CONFIG['target_os'] =~ /linux/i
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.windows?
|
32
|
+
RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
if(Guards::jruby?)
|
38
|
+
require 'java'
|
39
|
+
|
40
|
+
class Object
|
41
|
+
def add_to_classpath(path)
|
42
|
+
$CLASSPATH << File.join( DataShift.root_path, 'lib', path.gsub("\\", "/") )
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.gem_version
|
48
|
+
unless(@gem_version)
|
49
|
+
if(File.exists?('VERSION'))
|
50
|
+
File.read( File.join('VERSION') ).match(/.*(\d+.\d+.\d+)/)
|
51
|
+
@gem_version = $1
|
52
|
+
else
|
53
|
+
@gem_version = '1.0.0'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
@gem_version
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.gem_name
|
60
|
+
"datashift"
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.root_path
|
64
|
+
File.expand_path("#{File.dirname(__FILE__)}/..")
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.library_path
|
68
|
+
File.expand_path("#{File.dirname(__FILE__)}/../lib")
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.require_libraries
|
72
|
+
|
73
|
+
loader_libs = %w{ lib }
|
74
|
+
|
75
|
+
# Base search paths - these will be searched recursively
|
76
|
+
loader_paths = []
|
77
|
+
|
78
|
+
loader_libs.each {|l| loader_paths << File.join(root_path(), l) }
|
79
|
+
|
80
|
+
# Define require search paths, any dir in here will be added to LOAD_PATH
|
81
|
+
|
82
|
+
loader_paths.each do |base|
|
83
|
+
$:.unshift base if File.directory?(base)
|
84
|
+
Dir[File.join(base, '**', '**')].each do |p|
|
85
|
+
if File.directory? p
|
86
|
+
$:.unshift p
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
require_libs = %w{ datashift loaders helpers }
|
92
|
+
|
93
|
+
require_libs.each do |base|
|
94
|
+
Dir[File.join(library_path, base, '*.rb')].each do |rb|
|
95
|
+
unless File.directory? rb
|
96
|
+
require rb
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
# Load all the datashift rake tasks and make them available throughout app
|
104
|
+
def self.load_tasks
|
105
|
+
# Long parameter lists so ensure rake -T produces nice wide output
|
106
|
+
ENV['RAKE_COLUMNS'] = '180'
|
107
|
+
base = File.join(root_path, 'tasks', '**')
|
108
|
+
Dir["#{base}/*.rake"].sort.each { |ext| load ext }
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
# Load all the datashift Thor commands and make them available throughout app
|
113
|
+
|
114
|
+
def self.load_commands()
|
115
|
+
|
116
|
+
base = File.join(library_path, 'thor', '**')
|
117
|
+
|
118
|
+
Dir["#{base}/*.thor"].each do |f|
|
119
|
+
|
120
|
+
next unless File.file?(f)
|
121
|
+
Thor::Util.load_thorfile(f)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
def self.load_thorfiles(dir)
|
127
|
+
Dir.chdir(dir) do
|
128
|
+
thor_files = Dir.glob('**/*.thor').delete_if { |x| not File.file?(x) }
|
129
|
+
thor_files.each do |f|
|
130
|
+
Thor::Util.load_thorfile(f)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
module Logging
|
137
|
+
|
138
|
+
class MultiIO
|
139
|
+
|
140
|
+
def initialize(*targets)
|
141
|
+
@targets = []
|
142
|
+
targets.each {|t| @targets << Logger.new(t) }
|
143
|
+
end
|
144
|
+
|
145
|
+
def add(target)
|
146
|
+
@targets << Logger.new(target)
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
def method_missing(method, *args, &block)
|
151
|
+
@targets.each {|t| t.send(method, *args, &block) }
|
152
|
+
end
|
153
|
+
|
154
|
+
def verbose
|
155
|
+
add(STDOUT)
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
require 'logger'
|
161
|
+
|
162
|
+
def logdir
|
163
|
+
@logdir ||= 'log'
|
164
|
+
@logdir
|
165
|
+
end
|
166
|
+
|
167
|
+
def logger
|
168
|
+
@logger ||= open
|
169
|
+
@logger
|
170
|
+
end
|
171
|
+
|
172
|
+
private
|
173
|
+
|
174
|
+
def open( log = 'datashift.log')
|
175
|
+
FileUtils::mkdir(logdir) unless File.directory?(logdir)
|
176
|
+
log_file = File.open( File.join(logdir(), 'datashift.log'), "a")
|
177
|
+
@logger = MultiIO.new(log_file)
|
178
|
+
@logger
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
|
153
184
|
DataShift::require_libraries
|