polyglot-0.3.3/0000755000004100000410000000000011655242766013434 5ustar www-datawww-datapolyglot-0.3.3/License.txt0000644000004100000410000000204211655242766015555 0ustar www-datawww-dataCopyright (c) 2007 Clifford Heath 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. polyglot-0.3.3/Rakefile0000644000004100000410000000247011655242766015104 0ustar www-datawww-datarequire 'rubygems' require 'rake' require 'yaml' require 'jeweler' require './lib/polyglot/version' Jeweler::Tasks.new do |gem| gem.name = "polyglot" gem.version = Polyglot::VERSION::STRING gem.homepage = "http://github.com/cjheath/polyglot" gem.license = "MIT" gem.summary = %Q{Augment 'require' to load non-Ruby file types} gem.description = %Q{ The Polyglot library allows a Ruby module to register a loader for the file type associated with a filename extension, and it augments 'require' to find and load matching files.} gem.email = %w[clifford.heath@gmail.com] gem.authors = ["Clifford Heath"] gem.files.exclude "website/**/*.*", "script/*" end Jeweler::RubygemsDotOrgTasks.new require 'rdoc/task' Rake::RDocTask.new do |rdoc| rdoc.rdoc_dir = 'rdoc' rdoc.title = "polyglot #{Polyglot::VERSION::STRING}" rdoc.rdoc_files.include('README.txt') rdoc.rdoc_files.include('lib/**/*.rb') end desc 'Generate website files' task :website_generate do sh %q{ruby script/txt2html website/index.txt > website/index.html} end desc 'Upload website files via rsync' task :website_upload do rfconfig = YAML.load_file("#{ENV['HOME']}/.rubyforge/user-config.yml") ENV['RSYNC_PASSWORD'] = rfconfig['password'] sh %{rsync -aCv website #{rfconfig['username']}@rubyforge.org:/var/www/gforge-projects/polyglot} end polyglot-0.3.3/History.txt0000644000004100000410000000304411655242766015637 0ustar www-datawww-data== 0.3.2 2011-07-27 * 1 minor fix: * Load file without extension if found exactly as required == 0.3.1 2010-02-29 * 1 minor fix: * Enumerable strings are deprecated in Ruby 1.8.8 == 0.3.0 2010-02-14 * 1 minor fix: * Compatibility with Rails 3 == 0.2.9 2009-09-13 * 1 minor fix: * Use to_s on Pathname to support Ruby 1.9 == 0.2.8 2009-08-18 * 1 minor fix: * Previous fix for LoadErrors failed for cucumber. == 0.2.7 2009-08-17 * 1 minor fix: * Fix Polyglot catching LoadErrors not raised in Polyglot.find and re-raising the wrong message. == 0.2.6 2009-06-21 * 1 significant fix: * Require using absolute pathname now works correctly on Ruby 1.8 == 0.2.5 2009-03-04 * 1 significant fix: * Polyglot's require may be called with a Pathname, or other object allowed by Kernel#require that doesn't support [] (Kernel#require uses to_str apparently) == 0.2.4 2008-05-29 * 1 significant fix: * Previous LoadError change is checked in this time (oops!) == 0.2.3 2008-05-29 * 2 minor enhancements: * Raise MissingSourceFile exception instead of LoadError if ActiveSupport is loaded * Re-raise original exception new one on require load fail == 0.2.2 2008-05-12 * 2 minor enhancements: * Doesn't search $: when asked to load an absolute path * Adds a helpful exception message on LoadError == 0.2.1 2008-03-05 * 1 minor defect: * code to raise LoadError itself raised an exception == 0.2.0 2008-02-13 * 1 major enhancement: * Doesn't reload on every require == 0.1.0 2007-10-22 * 1 major enhancement: * Initial release polyglot-0.3.3/metadata.yml0000644000004100000410000000234411655242766015742 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: polyglot version: !ruby/object:Gem::Version version: 0.3.3 prerelease: platform: ruby authors: - Clifford Heath autorequire: bindir: bin cert_chain: [] date: 2011-11-01 00:00:00.000000000 Z dependencies: [] description: ! ' The Polyglot library allows a Ruby module to register a loader for the file type associated with a filename extension, and it augments ''require'' to find and load matching files.' email: - clifford.heath@gmail.com executables: [] extensions: [] extra_rdoc_files: - README.txt files: - History.txt - License.txt - README.txt - Rakefile - lib/polyglot.rb - lib/polyglot/version.rb homepage: http://github.com/cjheath/polyglot licenses: - MIT post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 1.8.10 signing_key: specification_version: 3 summary: Augment 'require' to load non-Ruby file types test_files: [] polyglot-0.3.3/README.txt0000644000004100000410000000453711655242766015143 0ustar www-datawww-data= polyglot * http://github.com/cjheath/polyglot == DESCRIPTION: Author: Clifford Heath, 2007 The Polyglot library allows a Ruby module to register a loader for the file type associated with a filename extension, and it augments 'require' to find and load matching files. This supports the creation of DSLs having a syntax that is most appropriate to their purpose, instead of abusing the Ruby syntax. Files are sought using the normal Ruby search path. == EXAMPLE: In file rubyglot.rb, define and register a file type handler: require 'polyglot' class RubyglotLoader def self.load(filename, options = nil, &block) File.open(filename) {|file| # Load the contents of file as Ruby code: # Implement your parser here instead! Kernel.eval(file.read) } end end Polyglot.register("rgl", RubyglotLoader) In file test.rb: require 'rubyglot' # Create my file type handler require 'hello' # Can add extra options or even a block here puts "Ready to go" Hello.new In file hello.rgl (this simple example uses Ruby code): puts "Initializing" class Hello def initialize() puts "Hello, world\n" end end Run: $ ruby test.rb Initializing Ready to go Hello, world $ == INSTALL: sudo gem install polyglot == LICENSE: (The MIT License) Copyright (c) 2007 Clifford Heath 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. polyglot-0.3.3/lib/0000755000004100000410000000000011655242766014202 5ustar www-datawww-datapolyglot-0.3.3/lib/polyglot.rb0000644000004100000410000000374611655242766016412 0ustar www-datawww-datarequire 'pathname' module Polyglot @registrations ||= {} # Guard against reloading @loaded ||= {} class PolyglotLoadError < LoadError; end class NestedLoadError < LoadError def initialize le @le = le end def reraise raise @le end end def self.register(extension, klass) extension = [extension] unless Array === extension extension.each{|e| @registrations[e] = klass } end def self.find(file, *options, &block) is_absolute = Pathname.new(file).absolute? (is_absolute ? [""] : $:).each{|lib| base = is_absolute ? "" : lib+File::SEPARATOR # In Windows, repeated SEPARATOR chars have a special meaning, avoid adding them matches = Dir["#{base}#{file}{,.#{@registrations.keys*',.'}}"] # Revisit: Should we do more do if more than one candidate found? $stderr.puts "Polyglot: found more than one candidate for #{file}: #{matches*", "}" if matches.size > 1 if path = matches[0] return [ path, @registrations[path.gsub(/.*\./,'')]] end } return nil end def self.load(*a, &b) file = a[0].to_str return if @loaded[file] # Check for $: changes or file time changes and reload? begin source_file, loader = Polyglot.find(file, *a[1..-1], &b) if (loader) begin loader.load(source_file) @loaded[file] = true rescue LoadError => e raise Polyglot::NestedLoadError.new(e) end else raise PolyglotLoadError.new("Failed to load #{file} using extensions #{(@registrations.keys+["rb"]).sort*", "}") end end end end module Kernel alias polyglot_original_require require def require(*a, &b) polyglot_original_require(*a, &b) rescue LoadError => load_error begin Polyglot.load(*a, &b) rescue Polyglot::NestedLoadError => e e.reraise rescue LoadError # Raise the original exception, possibly a MissingSourceFile with a path raise load_error end end end polyglot-0.3.3/lib/polyglot/0000755000004100000410000000000011655242766016053 5ustar www-datawww-datapolyglot-0.3.3/lib/polyglot/version.rb0000644000004100000410000000022411655242766020063 0ustar www-datawww-datamodule Polyglot #:nodoc: module VERSION #:nodoc: MAJOR = 0 MINOR = 3 TINY = 3 STRING = [MAJOR, MINOR, TINY].join('.') end end