Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repackaged the newest version into ye ol gem
- Loading branch information
Justin Marney
committed
Jun 11, 2008
1 parent
46907b9
commit bc17f88
Showing
23 changed files
with
980 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
== 1.0.1 / 2008-06-11 | ||
|
||
* tsv/csv now support an optional argument that indicates whether or not to ignore the header (first) line of the file | ||
|
||
== 1.0.0 / 2008-06-10 | ||
|
||
* 1 major enhancement | ||
* Birthday! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
History.txt | ||
Manifest.txt | ||
README.txt | ||
Rakefile | ||
lib/simple_importer.rb | ||
tasks/ann.rake | ||
tasks/annotations.rake | ||
tasks/bones.rake | ||
tasks/doc.rake | ||
tasks/gem.rake | ||
tasks/manifest.rake | ||
tasks/post_load.rake | ||
tasks/rubyforge.rake | ||
tasks/setup.rb | ||
tasks/test.rake | ||
test/test_helper.rb | ||
test/test_simple_importer.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
simple_importer | ||
by Justin Marney | ||
http://github.com/gotascii/simple_importer/ | ||
|
||
== DESCRIPTION: | ||
|
||
Simple API for importing from csv, tsv and xml. | ||
|
||
== FEATURES/PROBLEMS: | ||
|
||
* FIXME (list of features or problems) | ||
|
||
== SYNOPSIS: | ||
|
||
# extend your import modules and define import methods | ||
module SpecialImporter | ||
extend AccessoryImporter | ||
|
||
# if true is passed to run, reset will get called first if it exists. | ||
def self.reset | ||
Accessory.find(:all).each {|a| a.destroy } | ||
end | ||
|
||
def self.import | ||
csv('Accessory Schema.csv') do |row| | ||
unless row[0].nil? || row[0] == 'SKU' | ||
accessory = Accessory.create!(:sku => row[0], | ||
:image => row[1], | ||
:thumbnail_image => row[2], | ||
:name => row[3], | ||
:supplier_cost => row[4], | ||
:retail_cost => row[5], | ||
:description => row[6]) | ||
end | ||
end | ||
end | ||
end | ||
|
||
# run your import modules (from a rake task perhaps) | ||
XmlImporter.run | ||
|
||
== REQUIREMENTS: | ||
|
||
Hpricot is required if you intend to import xml. | ||
test/spec and mocha are required to run the tests. | ||
|
||
== INSTALL: | ||
|
||
sudo gem install gotascii-simple_importer -s http://gems.github.com | ||
|
||
== LICENSE: | ||
|
||
(The MIT License) | ||
|
||
Copyright (c) 2008 Justin Marney | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Look in the tasks/setup.rb file for the various options that can be | ||
# configured in this Rakefile. The .rake files in the tasks directory | ||
# are where the options are used. | ||
|
||
load 'tasks/setup.rb' | ||
|
||
ensure_in_path 'lib' | ||
require 'simple_importer' | ||
|
||
task :default => 'spec:run' | ||
|
||
PROJ.name = 'simple_importer' | ||
PROJ.authors = 'Justin Marney' | ||
PROJ.email = 'justin.marney@viget.com' | ||
PROJ.url = 'FIXME (project homepage)' | ||
PROJ.rubyforge_name = 'simple_importer' | ||
|
||
PROJ.spec_opts << '--color' | ||
PROJ.version = SimpleImporter::VERSION | ||
|
||
# EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# $Id$ | ||
|
||
# Equivalent to a header guard in C/C++ | ||
# Used to prevent the class/module from being loaded more than once | ||
unless defined? SimpleImporter | ||
|
||
require 'csv' | ||
|
||
module SimpleImporter | ||
def file(path) | ||
file = File.open(path) | ||
yield file if block_given? | ||
file.close | ||
end | ||
|
||
def csv(path, *args, &block) | ||
file(path) do |f| | ||
parsed_file = CSV::Reader.parse(f) | ||
process_rows(parsed_file, !args.empty?, &block) | ||
end | ||
end | ||
|
||
def tsv(path, *args, &block) | ||
file(path) do |f| | ||
parsed_file = CSV::Reader.parse(f, "\t") | ||
process_rows(parsed_file, !args.empty?, &block) | ||
end | ||
end | ||
|
||
def process_rows(parsed_file, ignore_header, &block) | ||
parsed_file.shift if ignore_header | ||
parsed_file.each do |row| | ||
row.each {|v| v.trim! if v.respond_to? :trim! } | ||
yield row if block_given? | ||
end | ||
end | ||
|
||
def xml(path) | ||
require 'hpricot' unless defined? Hpricot | ||
file(path) do |f| | ||
doc = Hpricot(f) | ||
yield doc if block_given? | ||
end | ||
end | ||
|
||
def run(reset_flag = false) | ||
reset if reset_flag && respond_to?(:reset) | ||
import | ||
end | ||
|
||
# :stopdoc: | ||
VERSION = '1.0.1' | ||
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR | ||
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR | ||
# :startdoc: | ||
|
||
# Returns the version string for the library. | ||
# | ||
def self.version | ||
VERSION | ||
end | ||
|
||
# Returns the library path for the module. If any arguments are given, | ||
# they will be joined to the end of the libray path using | ||
# <tt>File.join</tt>. | ||
# | ||
def self.libpath( *args ) | ||
args.empty? ? LIBPATH : ::File.join(LIBPATH, *args) | ||
end | ||
|
||
# Returns the lpath for the module. If any arguments are given, | ||
# they will be joined to the end of the path using | ||
# <tt>File.join</tt>. | ||
# | ||
def self.path( *args ) | ||
args.empty? ? PATH : ::File.join(PATH, *args) | ||
end | ||
|
||
# Utility method used to rquire all files ending in .rb that lie in the | ||
# directory below this file that has the same name as the filename passed | ||
# in. Optionally, a specific _directory_ name can be passed in such that | ||
# the _filename_ does not have to be equivalent to the directory. | ||
# | ||
def self.require_all_libs_relative_to( fname, dir = nil ) | ||
dir ||= ::File.basename(fname, '.*') | ||
search_me = ::File.expand_path( | ||
::File.join(::File.dirname(fname), dir, '**', '*.rb')) | ||
|
||
Dir.glob(search_me).sort.each {|rb| require rb} | ||
end | ||
|
||
end # module SimpleImporter | ||
|
||
SimpleImporter.require_all_libs_relative_to __FILE__ | ||
|
||
end # unless defined? | ||
|
||
# EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# $Id$ | ||
|
||
begin | ||
require 'bones/smtp_tls' | ||
rescue LoadError | ||
require 'net/smtp' | ||
end | ||
require 'time' | ||
|
||
namespace :ann do | ||
|
||
file PROJ.ann_file do | ||
puts "Generating #{PROJ.ann_file}" | ||
File.open(PROJ.ann_file,'w') do |fd| | ||
fd.puts("#{PROJ.name} version #{PROJ.version}") | ||
fd.puts(" by #{Array(PROJ.authors).first}") if PROJ.authors | ||
fd.puts(" #{PROJ.url}") if PROJ.url | ||
fd.puts(" (the \"#{PROJ.release_name}\" release)") if PROJ.release_name | ||
fd.puts | ||
fd.puts("== DESCRIPTION") | ||
fd.puts | ||
fd.puts(PROJ.description) | ||
fd.puts | ||
fd.puts(PROJ.changes.sub(%r/^.*$/, '== CHANGES')) | ||
fd.puts | ||
PROJ.ann_paragraphs.each do |p| | ||
fd.puts "== #{p.upcase}" | ||
fd.puts | ||
fd.puts paragraphs_of(PROJ.readme_file, p).join("\n\n") | ||
fd.puts | ||
end | ||
fd.puts PROJ.ann_text if PROJ.ann_text | ||
end | ||
end | ||
|
||
desc "Create an announcement file" | ||
task :announcement => PROJ.ann_file | ||
|
||
desc "Send an email announcement" | ||
task :email => PROJ.ann_file do | ||
from = PROJ.ann_email[:from] || PROJ.email | ||
to = Array(PROJ.ann_email[:to]) | ||
|
||
### build a mail header for RFC 822 | ||
rfc822msg = "From: #{from}\n" | ||
rfc822msg << "To: #{to.join(',')}\n" | ||
rfc822msg << "Subject: [ANN] #{PROJ.name} #{PROJ.version}" | ||
rfc822msg << " (#{PROJ.release_name})" if PROJ.release_name | ||
rfc822msg << "\n" | ||
rfc822msg << "Date: #{Time.new.rfc822}\n" | ||
rfc822msg << "Message-Id: " | ||
rfc822msg << "<#{"%.8f" % Time.now.to_f}@#{PROJ.ann_email[:domain]}>\n\n" | ||
rfc822msg << File.read(PROJ.ann_file) | ||
|
||
params = [:server, :port, :domain, :acct, :passwd, :authtype].map do |key| | ||
PROJ.ann_email[key] | ||
end | ||
|
||
params[3] = PROJ.email if params[3].nil? | ||
|
||
if params[4].nil? | ||
STDOUT.write "Please enter your e-mail password (#{params[3]}): " | ||
params[4] = STDIN.gets.chomp | ||
end | ||
|
||
### send email | ||
Net::SMTP.start(*params) {|smtp| smtp.sendmail(rfc822msg, from, to)} | ||
end | ||
end # namespace :ann | ||
|
||
desc 'Alias to ann:announcement' | ||
task :ann => 'ann:announcement' | ||
|
||
CLOBBER << PROJ.ann_file | ||
|
||
# EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# $Id$ | ||
|
||
if HAVE_BONES | ||
|
||
desc "Enumerate all annotations" | ||
task :notes do | ||
Bones::AnnotationExtractor.enumerate( | ||
PROJ, PROJ.annotation_tags.join('|'), :tag => true) | ||
end | ||
|
||
namespace :notes do | ||
PROJ.annotation_tags.each do |tag| | ||
desc "Enumerate all #{tag} annotations" | ||
task tag.downcase.to_sym do | ||
Bones::AnnotationExtractor.enumerate(PROJ, tag) | ||
end | ||
end | ||
end | ||
|
||
end # if HAVE_BONES | ||
|
||
# EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# $Id$ | ||
|
||
require 'pp' | ||
require 'stringio' | ||
|
||
namespace :bones do | ||
|
||
desc 'Show the PROJ open struct' | ||
task :debug do |t| | ||
atr = if ARGV.length == 2 | ||
t.application.top_level_tasks.pop | ||
end | ||
sio = StringIO.new | ||
sep = "\n" + ' '*27 | ||
fmt = "%23s => %s" | ||
|
||
if atr | ||
PP.pp(PROJ.send(atr.to_sym), sio, 49) | ||
sio.seek 0 | ||
val = sio.read | ||
val = val.split("\n").join(sep) | ||
|
||
puts fmt % [atr, val] | ||
else | ||
h = PROJ.instance_variable_get(:@table) | ||
h.keys.map {|k| k.to_s}.sort.each do |k| | ||
sio.truncate 0 | ||
PP.pp(h[k.to_sym], sio, 49) | ||
sio.seek 0 | ||
val = sio.read | ||
val = val.split("\n").join(sep) | ||
|
||
puts fmt % [k, val] | ||
end | ||
end | ||
end | ||
|
||
end # namespace :bones | ||
|
||
# EOF |
Oops, something went wrong.