From 38e8c62dbc9ef1eff5e40fbe124015121c580183 Mon Sep 17 00:00:00 2001 From: Luc Heinrich Date: Mon, 31 May 2010 11:27:30 +0200 Subject: [PATCH] Added release material. Added Readme file. Added rakefile and gemspec. Added license file. --- LICENSE | 21 +++++++++++++++++++ README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++ ffi-expat.gemspec | 17 ++++++++++++++++ rakefile.rb | 8 ++++++++ 4 files changed, 97 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 ffi-expat.gemspec create mode 100644 rakefile.rb diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f030129 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2010 Scott Chacon + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a3bdc55 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +ffi-expat +========= + +ffi-expat is a Ruby FFI wrapper for the expat XML parsing library. + +SAMPLE USE +========== + +ffi-expat is a thin wrapper around the expat calls so using ffi-expat in Ruby is +similar to the way you would use expat in C (modulo the obious language +specifics). + +Here's a simple example which counts the number of each start tags: + + require "rubygems" + require "ffi/expat" + + class Handler + attr_reader :starts + def initialize + @starts = Hash.new + end + def start_elem(parser, tag, attrs) + if @starts.has_key?(tag) + @starts[tag] += 1 + else + @starts[tag] = 1 + end + end + end + + xml = File.read("test.xml") + handler = Handler.new + parser = FFI::Expat.XML_ParserCreate(nil) + FFI::Expat.XML_SetStartElementHandler(parser, handler.method(:start_elem)) + FFI::Expat.XML_Parse(parser, xml, xml.length, true) + FFI::Expat.XML_ParserFree(parser) + + handler.starts.each do |tag, count| + puts "#{tag}: #{count}" + end + +AUTHORS +============== + +Luc Heinrich + +LICENSE +============== + +MIT. \ No newline at end of file diff --git a/ffi-expat.gemspec b/ffi-expat.gemspec new file mode 100644 index 0000000..35b5c8d --- /dev/null +++ b/ffi-expat.gemspec @@ -0,0 +1,17 @@ +require "date" + +spec = Gem::Specification.new do |s| + s.name = "ffi-expat" + s.version = "0.0.1" + s.author = "Luc Heinrich" + s.email = "luc@honk-honk.com" + s.summary = "Ruby FFI wrapper for the expat XML parsing library." + s.homepage = "http://github.com/lucsky/ffi-expat" + s.date = DateTime.now + + s.files = Dir['lib/**/*.rb'] + Dir['test/**/*'] + ["LICENSE", "README.md"] + s.test_files = Dir['test/**/test*.rb'] + s.requirements << "The expat library :)" + s.add_dependency "ffi" + s.has_rdoc = false +end diff --git a/rakefile.rb b/rakefile.rb new file mode 100644 index 0000000..20be78d --- /dev/null +++ b/rakefile.rb @@ -0,0 +1,8 @@ +require "rake/testtask" + +task :default => [:test] + +Rake::TestTask.new do |task| + task.libs << "lib" + task.test_files = FileList["test/test*.rb"] +end