polyglot 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +5 -0
- data/License.txt +1 -1
- data/README.txt +36 -2
- data/lib/polyglot.rb +6 -5
- data/lib/polyglot/version.rb +1 -1
- data/website/index.html +46 -90
- data/website/index.txt +1 -1
- metadata +3 -3
data/History.txt
CHANGED
data/License.txt
CHANGED
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
17
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.txt
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
|
1
|
+
= polyglot
|
2
|
+
|
3
|
+
* http://polyglot.rubyforge.org
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
2
7
|
Author: Clifford Heath, 2007
|
3
8
|
|
4
9
|
The Polyglot library allows a Ruby module to register a loader
|
@@ -10,7 +15,7 @@ appropriate to their purpose, instead of abusing the Ruby syntax.
|
|
10
15
|
|
11
16
|
Files are sought using the normal Ruby search path.
|
12
17
|
|
13
|
-
|
18
|
+
== EXAMPLE:
|
14
19
|
|
15
20
|
In file rubyglot.rb, define and register a file type handler:
|
16
21
|
|
@@ -51,3 +56,32 @@ Run:
|
|
51
56
|
Ready to go
|
52
57
|
Hello, world
|
53
58
|
$
|
59
|
+
|
60
|
+
== INSTALL:
|
61
|
+
|
62
|
+
sudo gem install polyglot
|
63
|
+
|
64
|
+
== LICENSE:
|
65
|
+
|
66
|
+
(The MIT License)
|
67
|
+
|
68
|
+
Copyright (c) 2007 Clifford Heath
|
69
|
+
|
70
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
71
|
+
a copy of this software and associated documentation files (the
|
72
|
+
"Software"), to deal in the Software without restriction, including
|
73
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
74
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
75
|
+
permit persons to whom the Software is furnished to do so, subject to
|
76
|
+
the following conditions:
|
77
|
+
|
78
|
+
The above copyright notice and this permission notice shall be
|
79
|
+
included in all copies or substantial portions of the Software.
|
80
|
+
|
81
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
82
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
83
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
84
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
85
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
86
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
87
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/polyglot.rb
CHANGED
@@ -28,16 +28,17 @@ module Polyglot
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.load(*a, &b)
|
31
|
-
|
31
|
+
file = a[0].to_str
|
32
|
+
return if @loaded[file] # Check for $: changes or file time changes and reload?
|
32
33
|
begin
|
33
|
-
source_file, loader = Polyglot.find(*a, &b)
|
34
|
+
source_file, loader = Polyglot.find(file, *a[1..-1], &b)
|
34
35
|
if (loader)
|
35
36
|
loader.load(source_file)
|
36
|
-
@loaded[
|
37
|
+
@loaded[file] = true
|
37
38
|
else
|
38
|
-
msg = "Failed to load #{
|
39
|
+
msg = "Failed to load #{file} using extensions #{(@registrations.keys+["rb"]).sort*", "}"
|
39
40
|
if defined?(MissingSourceFile)
|
40
|
-
raise MissingSourceFile.new(msg,
|
41
|
+
raise MissingSourceFile.new(msg, file)
|
41
42
|
else
|
42
43
|
raise LoadError.new(msg)
|
43
44
|
end
|
data/lib/polyglot/version.rb
CHANGED
data/website/index.html
CHANGED
@@ -33,107 +33,63 @@
|
|
33
33
|
<h1>polyglot</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/polyglot"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/polyglot" class="numbers">0.2.
|
36
|
+
<a href="http://rubyforge.org/projects/polyglot" class="numbers">0.2.5</a>
|
37
37
|
</div>
|
38
|
-
<h2>Poly
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
calling its improved version of ‘require’. Each file extension
|
46
|
-
that can be handled by a custom loader is registered by calling
|
47
|
-
Polyglot.register(“ext”, <class>), and then you can simply
|
48
|
-
require “somefile”, which will find and load “somefile.ext”
|
38
|
+
<h2>Poly => many, glot => languages</h2>
|
39
|
+
<h2>What</h2>
|
40
|
+
<p>Polyglot provides a registry of file types that can be loaded by<br />
|
41
|
+
calling its improved version of ‘require’. Each file extension<br />
|
42
|
+
that can be handled by a custom loader is registered by calling<br />
|
43
|
+
Polyglot.register(“ext”, <class>), and then you can simply<br />
|
44
|
+
require “somefile”, which will find and load “somefile.ext”<br />
|
49
45
|
using your custom loader.</p>
|
50
|
-
|
51
|
-
|
52
|
-
<p>This supports the creation of DSLs having a syntax that is most
|
46
|
+
<p>This supports the creation of DSLs having a syntax that is most<br />
|
53
47
|
appropriate to their purpose, instead of abusing the Ruby syntax.</p>
|
54
|
-
|
55
|
-
|
56
|
-
<p>Required files are attempted first using the normal Ruby loader,
|
57
|
-
and if that fails, Polyglot conducts a search for a file having
|
48
|
+
<p>Required files are attempted first using the normal Ruby loader,<br />
|
49
|
+
and if that fails, Polyglot conducts a search for a file having<br />
|
58
50
|
a supported extension.</p>
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
<p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">polyglot</span></pre></p>
|
65
|
-
|
66
|
-
|
67
|
-
<h2>Example</h2>
|
68
|
-
|
69
|
-
|
70
|
-
<p>Define and register your file type loader in file rubyglot.rb:</p>
|
71
|
-
|
72
|
-
|
73
|
-
<pre><code>require 'polyglot'
|
51
|
+
<h2>Installing</h2>
|
52
|
+
<p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">polyglot</span></pre></p>
|
53
|
+
<h2>Example</h2>
|
54
|
+
<p>Define and register your file type loader in file rubyglot.rb:</p>
|
55
|
+
require ‘polyglot’
|
74
56
|
class RubyglotLoader
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
end
|
57
|
+
def self.load(filename, options = nil, &block)
|
58
|
+
File.open(filename) {|file|
|
59
|
+
# Load the contents of file as Ruby code:
|
60
|
+
# Implement your parser here instead!
|
61
|
+
Kernel.eval(file.read)
|
62
|
+
}
|
82
63
|
end
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
<pre><code>puts "Initializing"
|
64
|
+
end
|
65
|
+
Polyglot.register(“rgl”, RubyglotLoader)
|
66
|
+
<p>This file, hello.rgl, will be loaded (this simple example uses Ruby code):</p>
|
67
|
+
puts “Initializing”
|
90
68
|
class Hello
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
puts "Ready to go"
|
103
|
-
Hello.new</code></pre>
|
104
|
-
|
105
|
-
|
106
|
-
<p>Run:</p>
|
107
|
-
|
108
|
-
|
109
|
-
<pre><code>$ ruby test.rb
|
69
|
+
def initialize()
|
70
|
+
puts “Hello, world\n”
|
71
|
+
end
|
72
|
+
end
|
73
|
+
<p>Call it from file test.rb:</p>
|
74
|
+
require ‘rubyglot’ # Create my file type handler
|
75
|
+
require ‘hello’ # Can add extra options or even a block here
|
76
|
+
puts “Ready to go”
|
77
|
+
Hello.new
|
78
|
+
<p>Run:</p>
|
79
|
+
$ ruby test.rb
|
110
80
|
Initializing
|
111
81
|
Ready to go
|
112
82
|
Hello, world
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
<p>The trunk repository is <code>svn://rubyforge.org/var/svn/polyglot/trunk</code> for anonymous access.</p>
|
123
|
-
|
124
|
-
|
125
|
-
<h2>License</h2>
|
126
|
-
|
127
|
-
|
128
|
-
<p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
|
129
|
-
|
130
|
-
|
131
|
-
<h2>Contact</h2>
|
132
|
-
|
133
|
-
|
134
|
-
<p>Comments are welcome. Send an email to <a href="mailto:cjheath@rubyforge.org">Clifford Heath</a></p>
|
83
|
+
$
|
84
|
+
<h2>How to submit patches</h2>
|
85
|
+
<p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people’s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8z-email">8z: Submit patch</a>, email me on the link below.</p>
|
86
|
+
<p>The trunk repository is <code>svn://rubyforge.org/var/svn/polyglot/trunk</code> for anonymous access.</p>
|
87
|
+
<h2>License</h2>
|
88
|
+
<p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
|
89
|
+
<h2>Contact</h2>
|
90
|
+
<p>Comments are welcome. Send an email to <a href="mailto:cjheath@rubyforge.org">Clifford Heath</a></p>
|
135
91
|
<p class="coda">
|
136
|
-
<a href="cjheath@rubyforge.org">Clifford Heath</a>,
|
92
|
+
<a href="cjheath@rubyforge.org">Clifford Heath</a>, 29th January 2009<br>
|
137
93
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
138
94
|
</p>
|
139
95
|
</div>
|
data/website/index.txt
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyglot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clifford Heath
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-03-04 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
requirements: []
|
83
83
|
|
84
84
|
rubyforge_project: polyglot
|
85
|
-
rubygems_version: 1.
|
85
|
+
rubygems_version: 1.3.1
|
86
86
|
signing_key:
|
87
87
|
specification_version: 2
|
88
88
|
summary: Allows custom language loaders for specified file extensions to be hooked into require
|