Skip to content

Commit

Permalink
repackaged the newest version into ye ol gem
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Marney committed Jun 11, 2008
1 parent 46907b9 commit bc17f88
Show file tree
Hide file tree
Showing 23 changed files with 980 additions and 2 deletions.
4 changes: 4 additions & 0 deletions History.txt
@@ -1,3 +1,7 @@
== 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
Expand Down
2 changes: 1 addition & 1 deletion lib/simple_importer.rb
Expand Up @@ -49,7 +49,7 @@ def run(reset_flag = false)
end

# :stopdoc:
VERSION = '1.0.0'
VERSION = '1.0.1'
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
# :startdoc:
Expand Down
4 changes: 4 additions & 0 deletions pkg/simple_importer-1.0.0/History.txt
@@ -1,3 +1,7 @@
== 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
Expand Down
Binary file added pkg/simple_importer-1.0.1.gem
Binary file not shown.
Binary file added pkg/simple_importer-1.0.1.tgz
Binary file not shown.
8 changes: 8 additions & 0 deletions pkg/simple_importer-1.0.1/History.txt
@@ -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!
17 changes: 17 additions & 0 deletions pkg/simple_importer-1.0.1/Manifest.txt
@@ -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
74 changes: 74 additions & 0 deletions pkg/simple_importer-1.0.1/README.txt
@@ -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.
21 changes: 21 additions & 0 deletions pkg/simple_importer-1.0.1/Rakefile
@@ -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
98 changes: 98 additions & 0 deletions pkg/simple_importer-1.0.1/lib/simple_importer.rb
@@ -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
76 changes: 76 additions & 0 deletions pkg/simple_importer-1.0.1/tasks/ann.rake
@@ -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
22 changes: 22 additions & 0 deletions pkg/simple_importer-1.0.1/tasks/annotations.rake
@@ -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
40 changes: 40 additions & 0 deletions pkg/simple_importer-1.0.1/tasks/bones.rake
@@ -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

0 comments on commit bc17f88

Please sign in to comment.