datashift 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +25 -0
- data/Gemfile.lock +211 -0
- data/LICENSE.txt +27 -0
- data/README.markdown +286 -0
- data/README.rdoc +19 -0
- data/Rakefile +96 -0
- data/VERSION +5 -0
- data/bin/autospec +16 -0
- data/bin/convert_to_should_syntax +16 -0
- data/bin/erubis +16 -0
- data/bin/htmldiff +16 -0
- data/bin/jeweler +16 -0
- data/bin/ldiff +16 -0
- data/bin/nokogiri +16 -0
- data/bin/rackup +16 -0
- data/bin/rails +16 -0
- data/bin/rake +16 -0
- data/bin/rake2thor +16 -0
- data/bin/ri +16 -0
- data/bin/rspec +16 -0
- data/bin/spree +16 -0
- data/bin/thor +16 -0
- data/bin/tilt +16 -0
- data/bin/tt +16 -0
- data/datashift.gemspec +178 -0
- data/lib/applications/jruby/jexcel_file.rb +397 -0
- data/lib/applications/jruby/word.rb +79 -0
- data/lib/datashift.rb +114 -0
- data/lib/datashift/exceptions.rb +12 -0
- data/lib/datashift/file_definitions.rb +353 -0
- data/lib/datashift/mapping_file_definitions.rb +88 -0
- data/lib/datashift/method_detail.rb +237 -0
- data/lib/datashift/method_mapper.rb +257 -0
- data/lib/generators/csv_generator.rb +36 -0
- data/lib/generators/excel_generator.rb +122 -0
- data/lib/generators/generator_base.rb +14 -0
- data/lib/helpers/core_ext/to_b.rb +24 -0
- data/lib/helpers/spree_helper.rb +131 -0
- data/lib/java/poi-3.7/._poi-3.7-20101029.jar5645100390082102460.tmp +0 -0
- data/lib/java/poi-3.7/LICENSE +507 -0
- data/lib/java/poi-3.7/NOTICE +21 -0
- data/lib/java/poi-3.7/RELEASE_NOTES.txt +115 -0
- data/lib/java/poi-3.7/lib/commons-logging-1.1.jar +0 -0
- data/lib/java/poi-3.7/lib/junit-3.8.1.jar +0 -0
- data/lib/java/poi-3.7/lib/log4j-1.2.13.jar +0 -0
- data/lib/java/poi-3.7/ooxml-lib/dom4j-1.6.1.jar +0 -0
- data/lib/java/poi-3.7/ooxml-lib/geronimo-stax-api_1.0_spec-1.0.jar +0 -0
- data/lib/java/poi-3.7/ooxml-lib/xmlbeans-2.3.0.jar +0 -0
- data/lib/java/poi-3.7/poi-3.7-20101029.jar +0 -0
- data/lib/java/poi-3.7/poi-examples-3.7-20101029.jar +0 -0
- data/lib/java/poi-3.7/poi-ooxml-3.7-20101029.jar +0 -0
- data/lib/java/poi-3.7/poi-ooxml-schemas-3.7-20101029.jar +0 -0
- data/lib/java/poi-3.7/poi-scratchpad-3.7-20101029.jar +0 -0
- data/lib/loaders/csv_loader.rb +99 -0
- data/lib/loaders/excel_loader.rb +150 -0
- data/lib/loaders/loader_base.rb +332 -0
- data/lib/loaders/spreadsheet_loader.rb +137 -0
- data/lib/loaders/spree/image_loader.rb +46 -0
- data/lib/loaders/spree/product_loader.rb +225 -0
- data/spec/csv_loader_spec.rb +31 -0
- data/spec/datashift_spec.rb +27 -0
- data/spec/db/migrate/20110803201325_create_test_bed.rb +85 -0
- data/spec/excel_generator_spec.rb +79 -0
- data/spec/excel_loader_spec.rb +177 -0
- data/spec/file_definitions.rb +141 -0
- data/spec/fixtures/BadAssociationName.xls +0 -0
- data/spec/fixtures/DemoNegativeTesting.xls +0 -0
- data/spec/fixtures/ProjectsMultiCategories.xls +0 -0
- data/spec/fixtures/ProjectsSingleCategories.xls +0 -0
- data/spec/fixtures/SimpleProjects.xls +0 -0
- data/spec/fixtures/config/database.yml +25 -0
- data/spec/fixtures/interact_models_db.sqlite +0 -0
- data/spec/fixtures/interact_spree_db.sqlite +0 -0
- data/spec/fixtures/negative/SpreeProdMiss1Mandatory.csv +4 -0
- data/spec/fixtures/negative/SpreeProdMiss1Mandatory.xls +0 -0
- data/spec/fixtures/negative/SpreeProdMissManyMandatory.csv +4 -0
- data/spec/fixtures/negative/SpreeProdMissManyMandatory.xls +0 -0
- data/spec/fixtures/simple_export_spec.xls +0 -0
- data/spec/fixtures/simple_template_spec.xls +0 -0
- data/spec/fixtures/spree/SpreeProducts.csv +4 -0
- data/spec/fixtures/spree/SpreeProducts.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsMultiColumn.csv +4 -0
- data/spec/fixtures/spree/SpreeProductsMultiColumn.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsSimple.csv +4 -0
- data/spec/fixtures/spree/SpreeProductsSimple.xls +0 -0
- data/spec/fixtures/spree/SpreeZoneExample.csv +5 -0
- data/spec/fixtures/spree/SpreeZoneExample.xls +0 -0
- data/spec/fixtures/test_model_defs.rb +57 -0
- data/spec/loader_spec.rb +121 -0
- data/spec/method_mapper_spec.rb +238 -0
- data/spec/spec_helper.rb +116 -0
- data/spec/spree_generator_spec.rb +65 -0
- data/spec/spree_loader_spec.rb +311 -0
- data/spec/spree_method_mapping_spec.rb +215 -0
- data/tasks/config/seed_fu_product_template.erb +15 -0
- data/tasks/config/tidy_config.txt +13 -0
- data/tasks/db_tasks.rake +65 -0
- data/tasks/excel_generator.rake +79 -0
- data/tasks/file_tasks.rake +37 -0
- data/tasks/import/csv.rake +50 -0
- data/tasks/import/excel.rake +67 -0
- data/tasks/spree/image_load.rake +109 -0
- data/tasks/spree/product_loader.rake +44 -0
- data/tasks/word_to_seedfu.rake +167 -0
- data/test/helper.rb +18 -0
- data/test/test_interact.rb +7 -0
- metadata +301 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: Feb 2011
|
4
|
+
# License:: TBD. Free, Open Source. MIT ?
|
5
|
+
#
|
6
|
+
# REQUIRES: JRuby
|
7
|
+
#
|
8
|
+
# Usage::
|
9
|
+
#
|
10
|
+
# In Rakefile:
|
11
|
+
#
|
12
|
+
# require 'datashift'
|
13
|
+
#
|
14
|
+
# DataShift::load_tasks
|
15
|
+
#
|
16
|
+
# Cmd Line:
|
17
|
+
#
|
18
|
+
# => jruby -S rake datashift:import:excel model=<active record class> input=<file.xls>
|
19
|
+
# => jruby -S rake datashift:import:excel model=<active record class> input=C:\MyProducts.xlsverbose=true
|
20
|
+
#
|
21
|
+
require 'datashift'
|
22
|
+
require 'excel_loader'
|
23
|
+
|
24
|
+
namespace :datashift do
|
25
|
+
|
26
|
+
namespace :import do
|
27
|
+
|
28
|
+
desc "Populate a model's table in db with data from .xls (Excel) file"
|
29
|
+
|
30
|
+
task :excel, [:model, :loader, :input, :verbose] => [:environment] do |t, args|
|
31
|
+
|
32
|
+
# in familiar ruby style args seems to have been become empty using this new style for rake 0.9.2
|
33
|
+
# whatever format i try, on both Win and OSX .. so had to revert back to ENV
|
34
|
+
model = ENV['model']
|
35
|
+
input = ENV['input']
|
36
|
+
|
37
|
+
raise "USAGE: jruby -S rake datashift:import:excel input=excel_file.xls model=<Class>" unless(input)
|
38
|
+
raise "ERROR: Cannot process without AR Model - please supply model=<Class>" unless(model)
|
39
|
+
raise "ERROR: Could not find file #{args[:input]}" unless File.exists?(input)
|
40
|
+
|
41
|
+
begin
|
42
|
+
klass = Kernel.const_get(model)
|
43
|
+
rescue NameError
|
44
|
+
raise "ERROR: No such AR Model found - check valid model supplied via model=<Class>"
|
45
|
+
end
|
46
|
+
|
47
|
+
if(ENV['loader'])
|
48
|
+
begin
|
49
|
+
loader_klass = Kernel.const_get(ENV['loader'])
|
50
|
+
|
51
|
+
loader = loader_klass.new(klass)
|
52
|
+
|
53
|
+
puts "INFO: Using loader : #{loader.class}"
|
54
|
+
rescue
|
55
|
+
puts "INFO: No specific #{model}Loader found - using generic ExcelLoader"
|
56
|
+
loader = DataShift::ExcelLoader.new(klass)
|
57
|
+
end
|
58
|
+
else
|
59
|
+
puts "INFO: No Loader specified - using generic ExcelLoader"
|
60
|
+
loader = DataShift::ExcelLoader.new(klass)
|
61
|
+
end
|
62
|
+
|
63
|
+
loader.perform_load(input)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: Feb 2011
|
4
|
+
# License:: MIT
|
5
|
+
#
|
6
|
+
# Usage::
|
7
|
+
#
|
8
|
+
# => rake datashift:spree:images input=vendor/extensions/site/fixtures/images
|
9
|
+
# => rake datashift:spree:images input=C:\images\photos large dummy=true
|
10
|
+
#
|
11
|
+
# => rake datashift:spree:images input=C:\images\taxon_icons skip_if_no_assoc=true klass=Taxon
|
12
|
+
#
|
13
|
+
namespace :datashift do
|
14
|
+
|
15
|
+
namespace :spree do
|
16
|
+
|
17
|
+
desc "Populate the DB with images.\nDefault location db/image_seeds, or specify :input=<path> or dir under db/image_seeds with :folder"
|
18
|
+
# :dummy => dummy run without actual saving to DB
|
19
|
+
task :images, :input, :folder, :dummy, :sku, :skip_if_no_assoc, :skip_if_loaded, :model, :needs => :environment do |t, args|
|
20
|
+
|
21
|
+
require 'image_loader'
|
22
|
+
|
23
|
+
raise "USAGE: Please specify one of :input or :folder" if(args[:input] && args[:folder])
|
24
|
+
puts "SKU not specified " if(args[:input] && args[:folder])
|
25
|
+
|
26
|
+
if args[:input]
|
27
|
+
@image_cache = args[:input]
|
28
|
+
else
|
29
|
+
@image_cache = File.join(Rails.root, "db", "image_seeds")
|
30
|
+
@image_cache = File.join(@image_cache, args[:folder]) if(args[:folder])
|
31
|
+
end
|
32
|
+
|
33
|
+
attachment_klazz = Product
|
34
|
+
|
35
|
+
begin
|
36
|
+
attachment_klazz = Kernel.const_get(args[:model]) if(args[:model])
|
37
|
+
rescue NameError
|
38
|
+
attachment_klazz = Product
|
39
|
+
end
|
40
|
+
|
41
|
+
image_loader = ImageLoader.new
|
42
|
+
|
43
|
+
if(File.exists? @image_cache )
|
44
|
+
puts "Loading images from #{@image_cache}"
|
45
|
+
|
46
|
+
missing_records = []
|
47
|
+
Dir.glob("#{@image_cache}/*.{jpg,png,gif}") do |image_name|
|
48
|
+
|
49
|
+
puts "Processing #{image_name} : #{File.exists?(image_name)}"
|
50
|
+
base_name = File.basename(image_name, '.*')
|
51
|
+
|
52
|
+
record = nil
|
53
|
+
if(attachment_klazz == Product && args[:sku])
|
54
|
+
sku = base_name.slice!(/\w+/)
|
55
|
+
sku.strip!
|
56
|
+
base_name.strip!
|
57
|
+
|
58
|
+
puts "Looking fo SKU #{sku}"
|
59
|
+
record = Variant.find_by_sku(sku)
|
60
|
+
if record
|
61
|
+
record = record.product # SKU stored on Variant but we want it's master Product
|
62
|
+
else
|
63
|
+
puts "Looking for NAME [#{base_name}]"
|
64
|
+
record = attachment_klazz.find_by_name(base_name)
|
65
|
+
end
|
66
|
+
else
|
67
|
+
puts "Looking for #{attachment_klazz.name} with NAME [#{base_name}]"
|
68
|
+
record = attachment_klazz.find_by_name(base_name)
|
69
|
+
end
|
70
|
+
|
71
|
+
if(record)
|
72
|
+
puts "Found record for attachment : #{record.inspect}"
|
73
|
+
exists = record.images.detect {|i| puts "COMPARE #{i.attachment_file_name} => #{image_name}"; i.attachment_file_name == image_name }
|
74
|
+
puts "Found existing attachments [#{exists}]" unless(exists.nil?)
|
75
|
+
if(args[:skip_if_loaded] && !exists.nil?)
|
76
|
+
puts "Skipping - Image #{image_name} already loaded for #{attachment_klazz}"
|
77
|
+
next
|
78
|
+
end
|
79
|
+
else
|
80
|
+
missing_records << image_name
|
81
|
+
end
|
82
|
+
|
83
|
+
# Now do actual upload to DB unless we are doing a dummy run,
|
84
|
+
# or the Image must have an associated record
|
85
|
+
unless(args[:dummy] == 'true' || (args[:skip_if_no_assoc] && record.nil?))
|
86
|
+
image_loader.reset()
|
87
|
+
puts "Process Image"
|
88
|
+
image_loader.process( image_name, record )
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
unless missing_records.empty?
|
94
|
+
FileUtils.mkdir_p('MissingRecords') unless File.directory?('MissingRecords')
|
95
|
+
|
96
|
+
puts '\nMISSING Records Report>>'
|
97
|
+
missing_records.each do |i|
|
98
|
+
puts "Copy #{i} to MissingRecords folder"
|
99
|
+
FileUtils.cp( i, 'MissingRecords') unless(args[:dummy] == 'true')
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
else
|
104
|
+
puts "ERROR: Supplied Path #{@image_cache} not accesible"
|
105
|
+
exit(-1)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: Feb 2011
|
4
|
+
# License:: MIT. Free, Open Source.
|
5
|
+
#
|
6
|
+
# REQUIRES: JRuby access to Java
|
7
|
+
#
|
8
|
+
# Usage::
|
9
|
+
#
|
10
|
+
# e.g. => jruby -S rake datashift:spree:products input=vendor/extensions/autotelik/fixtures/SiteSpreadsheetInfo.xls
|
11
|
+
# => jruby -S rake datashift:spree:products input=C:\MyProducts.xls verbose=true
|
12
|
+
#
|
13
|
+
require 'datashift'
|
14
|
+
|
15
|
+
namespace :datashift do
|
16
|
+
|
17
|
+
namespace :spree do
|
18
|
+
|
19
|
+
desc "Populate Spree Product/Variant data from .xls (Excel) or CSV file"
|
20
|
+
task :products, [:input, :verbose, :sku_prefix] => :environment do |t, args|
|
21
|
+
|
22
|
+
input = ENV['input']
|
23
|
+
|
24
|
+
raise "USAGE: jruby -S rake datashift:spree:products input=excel_file.xls" unless input
|
25
|
+
raise "ERROR: Could not find file #{args[:input]}" unless File.exists?(input)
|
26
|
+
|
27
|
+
require 'product_loader'
|
28
|
+
|
29
|
+
# COLUMNS WITH DEFAULTS - TODO create YAML configuration file to drive defaults etc
|
30
|
+
|
31
|
+
loader = DataShift::ProductLoader.new
|
32
|
+
|
33
|
+
loader.set_default_value('available_on', Time.now.to_s(:db) )
|
34
|
+
loader.set_default_value('cost_price', 0.0 )
|
35
|
+
|
36
|
+
loader.set_prefix('sku', args[:sku_prefix] ) if(args[:sku_prefix])
|
37
|
+
|
38
|
+
puts "Loading from file: #{input}"
|
39
|
+
|
40
|
+
loader.perform_load(input, :mandatory => ['sku', 'name', 'price'] )
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: Aug 2010
|
4
|
+
#
|
5
|
+
# License:: Free, OpenSource... MIT ?
|
6
|
+
#
|
7
|
+
# About:: Rake tasks to read Word documents, containing product descriptions,
|
8
|
+
# convert to HTML, tidy the HTML and then create seed_fu ready fixtures,
|
9
|
+
# from a template, with product description supplied by the HTML
|
10
|
+
#
|
11
|
+
# Note cleanest HTML is produced by this combination : saving with WdFormatHTML
|
12
|
+
# not WdFormatFilteredHTML and using the '--word-2000', 'y' option to tidy
|
13
|
+
# (don't use the '--bare' option)
|
14
|
+
#
|
15
|
+
# Not currently available for JRuby due to Win32Ole requirement
|
16
|
+
#
|
17
|
+
# Requires local exes available in PATH for :
|
18
|
+
# Microsoft Word
|
19
|
+
# HTML Tidy - http://tidy.sourceforge.net (Free)
|
20
|
+
#
|
21
|
+
require 'erb'
|
22
|
+
|
23
|
+
namespace :datashift do
|
24
|
+
|
25
|
+
desc "Convert MS Word to HTML and seed_fu fixtures. help=true for detailed usage."
|
26
|
+
|
27
|
+
task :word2html, :help, :needs => [:environment] do |t, args|
|
28
|
+
x =<<-EOS
|
29
|
+
|
30
|
+
USAGE::
|
31
|
+
Convert MS Word docs to HTML and seed_fu fixtures, by default searches for docs
|
32
|
+
in RAILS_ROOT/doc/copy
|
33
|
+
|
34
|
+
You can change the directory where Word document files are located
|
35
|
+
with the COPY_PATH environment variable.
|
36
|
+
|
37
|
+
Examples:
|
38
|
+
# default, to convert all Word files for the current environment
|
39
|
+
rake datashift:word2seedfu
|
40
|
+
|
41
|
+
# to load seed files matching orders or customers
|
42
|
+
rake db:seed SEED=orders,customers
|
43
|
+
|
44
|
+
# to load files from RAILS_ROOT/features/fixtures
|
45
|
+
rake db:seed FIXTURE_PATH=features/fixtures
|
46
|
+
EOS
|
47
|
+
|
48
|
+
if(args[:help])
|
49
|
+
puts x
|
50
|
+
exit(0)
|
51
|
+
end
|
52
|
+
|
53
|
+
site_extension_lib = File.join(SiteExtension.root, 'lib')
|
54
|
+
|
55
|
+
require File.join(site_extension_lib, 'word')
|
56
|
+
|
57
|
+
copy_path = ENV["COPY_PATH"] ? ENV["COPY_PATH"] : File.join(RAILS_ROOT, "doc", "copy")
|
58
|
+
fixtures_path = ENV["FIXTURES_PATH"] ? ENV["FIXTURES_PATH"] : File.join(RAILS_ROOT, "db", "fixtures")
|
59
|
+
|
60
|
+
copy_files = Dir[File.join(copy_path, '*.doc')]
|
61
|
+
|
62
|
+
copy_files.each do |file|
|
63
|
+
|
64
|
+
name = File.basename(file, '.doc')
|
65
|
+
|
66
|
+
puts "\n== Generate raw HTML from #{name}.doc =="
|
67
|
+
|
68
|
+
@word = Word.new(true)
|
69
|
+
|
70
|
+
@word.open( file )
|
71
|
+
|
72
|
+
html_file = File.join(copy_path, "#{name}.ms.html")
|
73
|
+
|
74
|
+
@word.save_as_html( html_file )
|
75
|
+
|
76
|
+
tidy_file = File.join(copy_path, "#{name}.html")
|
77
|
+
|
78
|
+
tidy_config = File.join(site_extension_lib, 'tasks', 'tidy_config.txt')
|
79
|
+
|
80
|
+
puts "tidy cmd line:", "tidy -config #{tidy_config} -clean --show-body-only y --word-2000 y --indent-spaces 2 -output #{tidy_file} #{html_file}"
|
81
|
+
|
82
|
+
result = system("tidy", '-config', "#{tidy_config}", '-clean', '--show-body-only', 'y', '--word-2000', 'y', '--indent-spaces', '2', '-output', "#{tidy_file}", "#{html_file}")
|
83
|
+
|
84
|
+
# TODO maybe report on result, $?
|
85
|
+
|
86
|
+
File.open( tidy_file ) do |f|
|
87
|
+
puts f.read
|
88
|
+
end
|
89
|
+
|
90
|
+
@word.quit
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
desc "Convert MS Word to HTML and seed_fu fixtures. help=true for detailed usage."
|
95
|
+
task :word2seedfu => :environment do
|
96
|
+
site_extension_lib = File.join(SiteExtension.root, 'lib')
|
97
|
+
|
98
|
+
require File.join(site_extension_lib, 'word')
|
99
|
+
|
100
|
+
sku_id = ENV["INITIAL_SKU_ID"] ? ENV["INITIAL_SKU_ID"] : 0
|
101
|
+
sku_prefix = ENV["SKU_PREFIX"] ? ENV["SKU_PREFIX"] : File.basename( RAILS_ROOT )
|
102
|
+
|
103
|
+
seedfu_template = File.join(site_extension_lib, 'tasks', 'seed_fu_product_template.erb')
|
104
|
+
|
105
|
+
begin
|
106
|
+
File.open( seedfu_template ) do |f|
|
107
|
+
@template = ERB.new(f.read)
|
108
|
+
end
|
109
|
+
rescue => e
|
110
|
+
puts "ERROR: #{e.inspect}"
|
111
|
+
puts "Cannot open or read template #{seedfu_template}"
|
112
|
+
raise e
|
113
|
+
end
|
114
|
+
|
115
|
+
copy_path = ENV["COPY_PATH"] ? ENV["COPY_PATH"] : File.join(RAILS_ROOT, "doc", "copy")
|
116
|
+
fixtures_path = ENV["FIXTURES_PATH"] ? ENV["FIXTURES_PATH"] : File.join(RAILS_ROOT, "db", "fixtures")
|
117
|
+
|
118
|
+
copy_files = Dir[File.join(copy_path, '*.doc')]
|
119
|
+
|
120
|
+
copy_files.each do |file|
|
121
|
+
|
122
|
+
name = File.basename(file, '.doc')
|
123
|
+
|
124
|
+
puts "\n== Generate raw HTML from #{name}.doc =="
|
125
|
+
|
126
|
+
@word = Word.new(true)
|
127
|
+
|
128
|
+
@word.open( file )
|
129
|
+
|
130
|
+
html_file = File.join(copy_path, "#{name}.ms.html")
|
131
|
+
|
132
|
+
@word.save_as_html( html_file )
|
133
|
+
|
134
|
+
tidy_file = File.join(copy_path, "#{name}.html")
|
135
|
+
|
136
|
+
tidy_config = File.join(site_extension_lib, 'tasks', 'tidy_config.txt')
|
137
|
+
|
138
|
+
puts "tidy cmd line:", "tidy -config #{tidy_config} -clean --show-body-only y --word-2000 y --indent-spaces 2 -output #{tidy_file} #{html_file}"
|
139
|
+
|
140
|
+
result = system("tidy", '-config', "#{tidy_config}", '-clean', '--show-body-only', 'y', '--word-2000', 'y', '--indent-spaces', '2', '-output', "#{tidy_file}", "#{html_file}")
|
141
|
+
|
142
|
+
# TODO maybe report on result, $?
|
143
|
+
|
144
|
+
File.open( tidy_file ) do |f|
|
145
|
+
@description = f.read
|
146
|
+
end
|
147
|
+
|
148
|
+
sku_id_str = "%03d" % sku_id
|
149
|
+
|
150
|
+
seed_file = "#{sku_id_str}_#{name.gsub(' ', '_')}.rb"
|
151
|
+
puts "\n== Generate seed fu file #{seed_file} =="
|
152
|
+
|
153
|
+
@sku = "#{sku_prefix}_#{sku_id_str}"
|
154
|
+
@name = 'TODO'
|
155
|
+
|
156
|
+
File.open( File.join(fixtures_path, seed_file), 'w' ) do |f|
|
157
|
+
f.write @template.result(binding)
|
158
|
+
puts "\nFile created: #{File.join(fixtures_path, seed_file)}"
|
159
|
+
end
|
160
|
+
|
161
|
+
sku_id += 1
|
162
|
+
|
163
|
+
@word.quit
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'DataShift'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,301 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: datashift
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thomas Statter
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-02-02 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - "="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.1.3
|
23
|
+
requirement: *id001
|
24
|
+
prerelease: false
|
25
|
+
type: :development
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: activerecord
|
28
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - "="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.1.3
|
34
|
+
requirement: *id002
|
35
|
+
prerelease: false
|
36
|
+
type: :development
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: activesupport
|
39
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - "="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 3.1.3
|
45
|
+
requirement: *id003
|
46
|
+
prerelease: false
|
47
|
+
type: :development
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: jruby-openssl
|
50
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
requirement: *id004
|
57
|
+
prerelease: false
|
58
|
+
type: :development
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: activerecord-jdbcsqlite3-adapter
|
61
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
requirement: *id005
|
68
|
+
prerelease: false
|
69
|
+
type: :development
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: spree
|
72
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - "="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.70.3
|
78
|
+
requirement: *id006
|
79
|
+
prerelease: false
|
80
|
+
type: :development
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rspec
|
83
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: "0"
|
89
|
+
requirement: *id007
|
90
|
+
prerelease: false
|
91
|
+
type: :development
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: shoulda
|
94
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: "0"
|
100
|
+
requirement: *id008
|
101
|
+
prerelease: false
|
102
|
+
type: :development
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rdoc
|
105
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: "3.12"
|
111
|
+
requirement: *id009
|
112
|
+
prerelease: false
|
113
|
+
type: :development
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
name: bundler
|
116
|
+
version_requirements: &id010 !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ~>
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: 1.0.0
|
122
|
+
requirement: *id010
|
123
|
+
prerelease: false
|
124
|
+
type: :development
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: jeweler
|
127
|
+
version_requirements: &id011 !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ~>
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 1.8.3
|
133
|
+
requirement: *id011
|
134
|
+
prerelease: false
|
135
|
+
type: :development
|
136
|
+
description: A suite of tools to move data between ActiveRecord models,databases,applications like Excel/Open Office, files and projects including Spree
|
137
|
+
email: rubygems@autotelik.co.uk
|
138
|
+
executables:
|
139
|
+
- autospec
|
140
|
+
- convert_to_should_syntax
|
141
|
+
- erubis
|
142
|
+
- htmldiff
|
143
|
+
- jeweler
|
144
|
+
- ldiff
|
145
|
+
- nokogiri
|
146
|
+
- rackup
|
147
|
+
- rails
|
148
|
+
- rake
|
149
|
+
- rake2thor
|
150
|
+
- ri
|
151
|
+
- rspec
|
152
|
+
- spree
|
153
|
+
- thor
|
154
|
+
- tilt
|
155
|
+
- tt
|
156
|
+
extensions: []
|
157
|
+
|
158
|
+
extra_rdoc_files:
|
159
|
+
- LICENSE.txt
|
160
|
+
- README.markdown
|
161
|
+
- README.rdoc
|
162
|
+
files:
|
163
|
+
- .document
|
164
|
+
- Gemfile
|
165
|
+
- Gemfile.lock
|
166
|
+
- LICENSE.txt
|
167
|
+
- README.markdown
|
168
|
+
- README.rdoc
|
169
|
+
- Rakefile
|
170
|
+
- VERSION
|
171
|
+
- bin/autospec
|
172
|
+
- bin/convert_to_should_syntax
|
173
|
+
- bin/erubis
|
174
|
+
- bin/htmldiff
|
175
|
+
- bin/jeweler
|
176
|
+
- bin/ldiff
|
177
|
+
- bin/nokogiri
|
178
|
+
- bin/rackup
|
179
|
+
- bin/rails
|
180
|
+
- bin/rake
|
181
|
+
- bin/rake2thor
|
182
|
+
- bin/ri
|
183
|
+
- bin/rspec
|
184
|
+
- bin/spree
|
185
|
+
- bin/thor
|
186
|
+
- bin/tilt
|
187
|
+
- bin/tt
|
188
|
+
- datashift.gemspec
|
189
|
+
- lib/applications/jruby/jexcel_file.rb
|
190
|
+
- lib/applications/jruby/word.rb
|
191
|
+
- lib/datashift.rb
|
192
|
+
- lib/datashift/exceptions.rb
|
193
|
+
- lib/datashift/file_definitions.rb
|
194
|
+
- lib/datashift/mapping_file_definitions.rb
|
195
|
+
- lib/datashift/method_detail.rb
|
196
|
+
- lib/datashift/method_mapper.rb
|
197
|
+
- lib/generators/csv_generator.rb
|
198
|
+
- lib/generators/excel_generator.rb
|
199
|
+
- lib/generators/generator_base.rb
|
200
|
+
- lib/helpers/core_ext/to_b.rb
|
201
|
+
- lib/helpers/spree_helper.rb
|
202
|
+
- lib/java/poi-3.7/._poi-3.7-20101029.jar5645100390082102460.tmp
|
203
|
+
- lib/java/poi-3.7/LICENSE
|
204
|
+
- lib/java/poi-3.7/NOTICE
|
205
|
+
- lib/java/poi-3.7/RELEASE_NOTES.txt
|
206
|
+
- lib/java/poi-3.7/lib/commons-logging-1.1.jar
|
207
|
+
- lib/java/poi-3.7/lib/junit-3.8.1.jar
|
208
|
+
- lib/java/poi-3.7/lib/log4j-1.2.13.jar
|
209
|
+
- lib/java/poi-3.7/ooxml-lib/dom4j-1.6.1.jar
|
210
|
+
- lib/java/poi-3.7/ooxml-lib/geronimo-stax-api_1.0_spec-1.0.jar
|
211
|
+
- lib/java/poi-3.7/ooxml-lib/xmlbeans-2.3.0.jar
|
212
|
+
- lib/java/poi-3.7/poi-3.7-20101029.jar
|
213
|
+
- lib/java/poi-3.7/poi-examples-3.7-20101029.jar
|
214
|
+
- lib/java/poi-3.7/poi-ooxml-3.7-20101029.jar
|
215
|
+
- lib/java/poi-3.7/poi-ooxml-schemas-3.7-20101029.jar
|
216
|
+
- lib/java/poi-3.7/poi-scratchpad-3.7-20101029.jar
|
217
|
+
- lib/loaders/csv_loader.rb
|
218
|
+
- lib/loaders/excel_loader.rb
|
219
|
+
- lib/loaders/loader_base.rb
|
220
|
+
- lib/loaders/spreadsheet_loader.rb
|
221
|
+
- lib/loaders/spree/image_loader.rb
|
222
|
+
- lib/loaders/spree/product_loader.rb
|
223
|
+
- spec/csv_loader_spec.rb
|
224
|
+
- spec/datashift_spec.rb
|
225
|
+
- spec/db/migrate/20110803201325_create_test_bed.rb
|
226
|
+
- spec/excel_generator_spec.rb
|
227
|
+
- spec/excel_loader_spec.rb
|
228
|
+
- spec/file_definitions.rb
|
229
|
+
- spec/fixtures/BadAssociationName.xls
|
230
|
+
- spec/fixtures/DemoNegativeTesting.xls
|
231
|
+
- spec/fixtures/ProjectsMultiCategories.xls
|
232
|
+
- spec/fixtures/ProjectsSingleCategories.xls
|
233
|
+
- spec/fixtures/SimpleProjects.xls
|
234
|
+
- spec/fixtures/config/database.yml
|
235
|
+
- spec/fixtures/interact_models_db.sqlite
|
236
|
+
- spec/fixtures/interact_spree_db.sqlite
|
237
|
+
- spec/fixtures/negative/SpreeProdMiss1Mandatory.csv
|
238
|
+
- spec/fixtures/negative/SpreeProdMiss1Mandatory.xls
|
239
|
+
- spec/fixtures/negative/SpreeProdMissManyMandatory.csv
|
240
|
+
- spec/fixtures/negative/SpreeProdMissManyMandatory.xls
|
241
|
+
- spec/fixtures/simple_export_spec.xls
|
242
|
+
- spec/fixtures/simple_template_spec.xls
|
243
|
+
- spec/fixtures/spree/SpreeProducts.csv
|
244
|
+
- spec/fixtures/spree/SpreeProducts.xls
|
245
|
+
- spec/fixtures/spree/SpreeProductsMultiColumn.csv
|
246
|
+
- spec/fixtures/spree/SpreeProductsMultiColumn.xls
|
247
|
+
- spec/fixtures/spree/SpreeProductsSimple.csv
|
248
|
+
- spec/fixtures/spree/SpreeProductsSimple.xls
|
249
|
+
- spec/fixtures/spree/SpreeZoneExample.csv
|
250
|
+
- spec/fixtures/spree/SpreeZoneExample.xls
|
251
|
+
- spec/fixtures/test_model_defs.rb
|
252
|
+
- spec/loader_spec.rb
|
253
|
+
- spec/method_mapper_spec.rb
|
254
|
+
- spec/spec_helper.rb
|
255
|
+
- spec/spree_generator_spec.rb
|
256
|
+
- spec/spree_loader_spec.rb
|
257
|
+
- spec/spree_method_mapping_spec.rb
|
258
|
+
- tasks/config/seed_fu_product_template.erb
|
259
|
+
- tasks/config/tidy_config.txt
|
260
|
+
- tasks/db_tasks.rake
|
261
|
+
- tasks/excel_generator.rake
|
262
|
+
- tasks/file_tasks.rake
|
263
|
+
- tasks/import/csv.rake
|
264
|
+
- tasks/import/excel.rake
|
265
|
+
- tasks/spree/image_load.rake
|
266
|
+
- tasks/spree/product_loader.rake
|
267
|
+
- tasks/word_to_seedfu.rake
|
268
|
+
- test/helper.rb
|
269
|
+
- test/test_interact.rb
|
270
|
+
homepage: http://github.com/autotelik/datashift
|
271
|
+
licenses:
|
272
|
+
- MIT
|
273
|
+
post_install_message:
|
274
|
+
rdoc_options: []
|
275
|
+
|
276
|
+
require_paths:
|
277
|
+
- lib
|
278
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
279
|
+
none: false
|
280
|
+
requirements:
|
281
|
+
- - ">="
|
282
|
+
- !ruby/object:Gem::Version
|
283
|
+
hash: 2
|
284
|
+
segments:
|
285
|
+
- 0
|
286
|
+
version: "0"
|
287
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
288
|
+
none: false
|
289
|
+
requirements:
|
290
|
+
- - ">="
|
291
|
+
- !ruby/object:Gem::Version
|
292
|
+
version: "0"
|
293
|
+
requirements: []
|
294
|
+
|
295
|
+
rubyforge_project:
|
296
|
+
rubygems_version: 1.8.15
|
297
|
+
signing_key:
|
298
|
+
specification_version: 3
|
299
|
+
summary: Shift data betwen applications and Active Record
|
300
|
+
test_files: []
|
301
|
+
|