curies 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +10 -0
- data/License.txt +20 -0
- data/Manifest.txt +21 -0
- data/README.txt +76 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +71 -0
- data/config/requirements.rb +17 -0
- data/lib/curies.rb +6 -0
- data/lib/curies/curie.rb +95 -0
- data/lib/curies/version.rb +9 -0
- data/log/debug.log +0 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/spec/curies_spec.rb +48 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +7 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- metadata +89 -0
data/History.txt
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
== 0.5.0 2008-03-19
|
2
|
+
|
3
|
+
* Initial release:
|
4
|
+
* Should fully implement the W3C spec [http://www.w3.org/TR/curie/]
|
5
|
+
* Allows the creation of CURIEs
|
6
|
+
* Allows the parsing of a string as a putative CURIE
|
7
|
+
* Allows prefixes/namespaces to be added and removed
|
8
|
+
* Parses both safe and unsafe CURIEs but only outputs safe CURIEs
|
9
|
+
* Includes the FOAF namespace loaded by default
|
10
|
+
|
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 FIXME full name
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
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.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
config/hoe.rb
|
7
|
+
config/requirements.rb
|
8
|
+
lib/curies.rb
|
9
|
+
lib/curies/curie.rb
|
10
|
+
lib/curies/version.rb
|
11
|
+
log/debug.log
|
12
|
+
script/destroy
|
13
|
+
script/generate
|
14
|
+
script/txt2html
|
15
|
+
setup.rb
|
16
|
+
spec/curies_spec.rb
|
17
|
+
spec/spec.opts
|
18
|
+
spec/spec_helper.rb
|
19
|
+
tasks/deployment.rake
|
20
|
+
tasks/environment.rake
|
21
|
+
tasks/website.rake
|
data/README.txt
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
= Curies
|
2
|
+
|
3
|
+
* http://curies.rubyforge.org
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
The Curies library implements the CURIE syntax for expressing Compact URIs.
|
8
|
+
|
9
|
+
In a nutshell, a CURIE is a compact way of representing a URI. For example, suppose you've got an XML document in which
|
10
|
+
you'll be writing many attributes of the form "http://www.amazon.com/?isbn=123478753". With a CURIE, you can represent those as
|
11
|
+
"[amazon:123478753]" where "amazon" is a registered prefix in your document.
|
12
|
+
|
13
|
+
This library is small, but useful if you're writing a parser for a language that uses CURIEs.
|
14
|
+
I wrote it because I'm implementing an RDF/JSON library and, because the RDF/JSON spec isn't
|
15
|
+
finalized yet, I've taken the liberty of using CURIEs rather than QNAMEs.
|
16
|
+
|
17
|
+
See http://www.w3.org/TR/curie/ for more information on the CURIE specification.
|
18
|
+
|
19
|
+
== FEATURES:
|
20
|
+
|
21
|
+
== 0.5.0 2008-03-19
|
22
|
+
|
23
|
+
* Initial release:
|
24
|
+
* Should fully implement the W3C spec [http://www.w3.org/TR/curie/]
|
25
|
+
* Allows the creation of CURIEs
|
26
|
+
* Allows the parsing of a string as a putative CURIE
|
27
|
+
* Allows prefixes/namespaces to be added and removed
|
28
|
+
* Parses both safe and unsafe CURIEs but only outputs safe CURIEs
|
29
|
+
* Includes the FOAF namespace loaded by default
|
30
|
+
|
31
|
+
== SYNOPSIS:
|
32
|
+
|
33
|
+
<pre syntax="ruby">require 'curies'</pre>
|
34
|
+
<pre syntax="ruby">c = Curie.new("foaf", "person")</pre>
|
35
|
+
|
36
|
+
<pre syntax="ruby">c.to_s</pre>
|
37
|
+
<pre syntax="ruby">=>"[foaf:person]"</pre>
|
38
|
+
|
39
|
+
<pre syntax="ruby">Curie.parse "[foaf:name]"</pre>
|
40
|
+
<pre syntax="ruby">"http://xmlns.com/foaf/0.1/person"</pre>
|
41
|
+
|
42
|
+
<pre syntax="ruby">Curie.parse "[foo:bar]"</pre>
|
43
|
+
<pre syntax="ruby">"RuntimeError: Sorry, no namespace or prefix registered for curies with the prefix foo"</pre>
|
44
|
+
<pre syntax="ruby">Curie.add_prefixes! :foo => "http://www.example.com/ns/foo/"</pre>
|
45
|
+
<pre syntax="ruby">=> {"foo"=>"http://www.example.com/ns/foo/", "foaf"=>"http://xmlns.com/foaf/0.1/"}</pre>
|
46
|
+
<pre syntax="ruby">Curie.parse "[foo:bar]"</pre>
|
47
|
+
<pre syntax="ruby">=> "http://www.example.com/ns/foo/bar"</pre>
|
48
|
+
|
49
|
+
== INSTALL:
|
50
|
+
|
51
|
+
sudo gem install curies
|
52
|
+
|
53
|
+
== LICENSE:
|
54
|
+
|
55
|
+
(The MIT License)
|
56
|
+
|
57
|
+
Copyright (c) 2009 Pius A. Uzamere II, The Uyiosa Corporation
|
58
|
+
|
59
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
60
|
+
a copy of this software and associated documentation files (the
|
61
|
+
'Software'), to deal in the Software without restriction, including
|
62
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
63
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
64
|
+
permit persons to whom the Software is furnished to do so, subject to
|
65
|
+
the following conditions:
|
66
|
+
|
67
|
+
The above copyright notice and this permission notice shall be
|
68
|
+
included in all copies or substantial portions of the Software.
|
69
|
+
|
70
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
71
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
72
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
73
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
74
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
75
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
76
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/config/hoe.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'curies/version'
|
2
|
+
|
3
|
+
AUTHOR = 'Pius Uzamere' # can also be an array of Authors
|
4
|
+
EMAIL = "pius+curie@uyiosa.com"
|
5
|
+
|
6
|
+
DESCRIPTION = "Curies implements the CURIE syntax for expressing Compact URIs. See http://www.w3.org/TR/curie/ for more information."
|
7
|
+
GEM_NAME = 'curies' # what ppl will type to install your gem
|
8
|
+
RUBYFORGE_PROJECT = 'curies' # The unix name for your project
|
9
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
10
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
11
|
+
|
12
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
13
|
+
@config = nil
|
14
|
+
RUBYFORGE_USERNAME = "unknown"
|
15
|
+
def rubyforge_username
|
16
|
+
unless @config
|
17
|
+
begin
|
18
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
19
|
+
rescue
|
20
|
+
puts <<-EOS
|
21
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
22
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
23
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
24
|
+
EOS
|
25
|
+
exit
|
26
|
+
end
|
27
|
+
end
|
28
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
REV = nil
|
33
|
+
# UNCOMMENT IF REQUIRED:
|
34
|
+
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
|
35
|
+
VERS = Curies::VERSION::STRING + (REV ? ".#{REV}" : "")
|
36
|
+
RDOC_OPTS = ['--quiet', '--title', 'curies documentation',
|
37
|
+
"--opname", "index.html",
|
38
|
+
"--line-numbers",
|
39
|
+
"--main", "README",
|
40
|
+
"--inline-source"]
|
41
|
+
|
42
|
+
class Hoe
|
43
|
+
def extra_deps
|
44
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
45
|
+
@extra_deps
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Generate all the Rake tasks
|
50
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
51
|
+
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
52
|
+
p.developer(AUTHOR, EMAIL)
|
53
|
+
p.description = DESCRIPTION
|
54
|
+
p.summary = DESCRIPTION
|
55
|
+
p.url = HOMEPATH
|
56
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
57
|
+
p.test_globs = ["test/**/test_*.rb"]
|
58
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
59
|
+
|
60
|
+
# == Optional
|
61
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
62
|
+
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
63
|
+
|
64
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
69
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
70
|
+
hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
71
|
+
hoe.rsync_args = '-av --delete --ignore-errors'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
16
|
+
|
17
|
+
require 'curies'
|
data/lib/curies.rb
ADDED
data/lib/curies/curie.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
class String
|
2
|
+
def could_be_a_safe_curie?
|
3
|
+
self[0,1] == "[" and self[length - 1, length] == "]"
|
4
|
+
end
|
5
|
+
def curie_parts
|
6
|
+
if self.could_be_a_safe_curie?
|
7
|
+
g = self.split(':')
|
8
|
+
a = g[0][1,g[0].length]
|
9
|
+
b = g[1][0,g[1].length-1]
|
10
|
+
[a,b]
|
11
|
+
else
|
12
|
+
raise "not a real curie"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Curie
|
18
|
+
DEFAULT_MAPPINGS = {"cal" => "http://www.w3.org/2002/12/cal/ical#",
|
19
|
+
"cc" => "http://creativecommons.org/ns#",
|
20
|
+
"contact" => "http://www.w3.org/2001/vcard-rdf/3.0#",
|
21
|
+
"dc" => "http://purl.org/dc/elements/1.1/",
|
22
|
+
"foaf" => "http://xmlns.com/foaf/0.1/",
|
23
|
+
"rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
|
24
|
+
"rdfs" => "http://www.w3.org/2000/01/rdf-schema#",
|
25
|
+
"xsd" => "http://www.w3.org/2001/XMLSchema#",
|
26
|
+
"http" => "http" }
|
27
|
+
@@mappings = {}
|
28
|
+
@@mappings.merge! DEFAULT_MAPPINGS
|
29
|
+
|
30
|
+
attr_reader :prefix
|
31
|
+
attr_reader :reference
|
32
|
+
|
33
|
+
def initialize(prefix, reference)
|
34
|
+
@prefix, @reference = prefix, reference
|
35
|
+
end
|
36
|
+
|
37
|
+
def ==(other)
|
38
|
+
return false unless other.is_a?(Curie)
|
39
|
+
return true if self.to_s == other.to_s
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.parse(curie_string, opts = {})
|
43
|
+
if opts[:treat_unsafe_as_normal_strings] and not curie_string.could_be_a_safe_curie?
|
44
|
+
a = [curie_string, :string]
|
45
|
+
return a
|
46
|
+
end
|
47
|
+
if not(curie_string.index(':')) #just some random string that doesn't even have a colon!
|
48
|
+
#strip off brackets if they exist
|
49
|
+
curie_string = curie_string[1,curie_string.length-2] if curie_string.could_be_a_safe_curie?
|
50
|
+
return curie_string
|
51
|
+
elsif curie_string.could_be_a_safe_curie?
|
52
|
+
pivot = curie_string.index(':')
|
53
|
+
prefix = curie_string[1,pivot-1]
|
54
|
+
reference = curie_string[pivot+1, curie_string.length].chop
|
55
|
+
else
|
56
|
+
pivot = curie_string.index(':')
|
57
|
+
prefix = curie_string[0,pivot]
|
58
|
+
reference = curie_string[pivot+1, curie_string.length]
|
59
|
+
end
|
60
|
+
if opts[:in_parts]
|
61
|
+
return [qualified_uri_for(prefix), reference]
|
62
|
+
else
|
63
|
+
return qualified_uri_for(prefix) + reference
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.qualified_uri_for(prefix)
|
68
|
+
return @@mappings[prefix] if @@mappings[prefix]
|
69
|
+
raise "Sorry, no namespace or prefix registered for curies with the prefix #{prefix}"
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.add_prefixes!(mappings)
|
73
|
+
@@mappings.merge! mappings.stringify_keys
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.remove_prefixes!(prefixes)
|
77
|
+
prefixes = [prefixes] unless prefixes.respond_to? :each
|
78
|
+
for prefix in prefixes
|
79
|
+
@@mappings.delete prefix.to_s
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def to_s
|
84
|
+
"[#{@prefix}:#{@reference}]"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class Hash #nodoc
|
89
|
+
def stringify_keys #nodoc
|
90
|
+
inject({}) do |options, (key, value)|
|
91
|
+
options[key.to_s] = value
|
92
|
+
options
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/log/debug.log
ADDED
File without changes
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/script/txt2html
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
begin
|
5
|
+
require 'newgem'
|
6
|
+
rescue LoadError
|
7
|
+
puts "\n\nGenerating the website requires the newgem RubyGem"
|
8
|
+
puts "Install: gem install newgem\n\n"
|
9
|
+
exit(1)
|
10
|
+
end
|
11
|
+
require 'redcloth'
|
12
|
+
require 'syntax/convertors/html'
|
13
|
+
require 'erb'
|
14
|
+
require File.dirname(__FILE__) + '/../lib/curies/version.rb'
|
15
|
+
|
16
|
+
version = Curies::VERSION::STRING
|
17
|
+
download = 'http://rubyforge.org/projects/curies'
|
18
|
+
|
19
|
+
class Fixnum
|
20
|
+
def ordinal
|
21
|
+
# teens
|
22
|
+
return 'th' if (10..19).include?(self % 100)
|
23
|
+
# others
|
24
|
+
case self % 10
|
25
|
+
when 1: return 'st'
|
26
|
+
when 2: return 'nd'
|
27
|
+
when 3: return 'rd'
|
28
|
+
else return 'th'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Time
|
34
|
+
def pretty
|
35
|
+
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def convert_syntax(syntax, source)
|
40
|
+
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
41
|
+
end
|
42
|
+
|
43
|
+
if ARGV.length >= 1
|
44
|
+
src, template = ARGV
|
45
|
+
template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
|
46
|
+
|
47
|
+
else
|
48
|
+
puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
|
49
|
+
exit!
|
50
|
+
end
|
51
|
+
|
52
|
+
template = ERB.new(File.open(template).read)
|
53
|
+
|
54
|
+
title = nil
|
55
|
+
body = nil
|
56
|
+
File.open(src) do |fsrc|
|
57
|
+
title_text = fsrc.readline
|
58
|
+
body_text = fsrc.read
|
59
|
+
syntax_items = []
|
60
|
+
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
|
61
|
+
ident = syntax_items.length
|
62
|
+
element, syntax, source = $1, $2, $3
|
63
|
+
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
|
64
|
+
"syntax-temp-#{ident}"
|
65
|
+
}
|
66
|
+
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
67
|
+
body = RedCloth.new(body_text).to_html
|
68
|
+
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
|
69
|
+
end
|
70
|
+
stat = File.stat(src)
|
71
|
+
created = stat.ctime
|
72
|
+
modified = stat.mtime
|
73
|
+
|
74
|
+
$stdout << template.result(binding)
|