polyglot-0.3.5/0000755000004100000410000000000013305520630013415 5ustar www-datawww-datapolyglot-0.3.5/polyglot.gemspec0000644000004100000410000000224413305520630016635 0ustar www-datawww-data######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: polyglot 0.3.5 ruby lib Gem::Specification.new do |s| s.name = "polyglot".freeze s.version = "0.3.5" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.require_paths = ["lib".freeze] s.authors = ["Clifford Heath".freeze] s.date = "2014-05-30" s.description = "\nThe Polyglot library allows a Ruby module to register a loader\nfor the file type associated with a filename extension, and it\naugments 'require' to find and load matching files.".freeze s.email = ["clifford.heath@gmail.com".freeze] s.extra_rdoc_files = ["README.txt".freeze] s.files = ["History.txt".freeze, "License.txt".freeze, "README.txt".freeze, "Rakefile".freeze, "lib/polyglot.rb".freeze, "lib/polyglot/version.rb".freeze] s.homepage = "http://github.com/cjheath/polyglot".freeze s.licenses = ["MIT".freeze] s.rubygems_version = "2.5.2.1".freeze s.summary = "Augment 'require' to load non-Ruby file types".freeze end polyglot-0.3.5/History.txt0000644000004100000410000000304413305520630015620 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.5/README.txt0000644000004100000410000000453713305520630015124 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.5/Rakefile0000644000004100000410000000247013305520630015065 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.5/lib/0000755000004100000410000000000013305520630014163 5ustar www-datawww-datapolyglot-0.3.5/lib/polyglot.rb0000644000004100000410000000410713305520630016363 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_dot_relative = file =~ /\.[\/\\]/ paths = is_absolute ? [''] : Array(is_dot_relative ? '.' : nil) + $: paths.each do |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 end return nil end def self.load(*a, &b) file = a[0].to_s 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.5/lib/polyglot/0000755000004100000410000000000013305520630016034 5ustar www-datawww-datapolyglot-0.3.5/lib/polyglot/version.rb0000644000004100000410000000022413305520630020044 0ustar www-datawww-datamodule Polyglot #:nodoc: module VERSION #:nodoc: MAJOR = 0 MINOR = 3 TINY = 5 STRING = [MAJOR, MINOR, TINY].join('.') end end polyglot-0.3.5/License.txt0000644000004100000410000000204213305520630015536 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.