foaf_stone 0.0.3

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.
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2007-11-03
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,63 @@
1
+ Copyright (c) 2007 Donald G. Park
2
+
3
+ The "Ruby Licence" from
4
+ http://www.ruby-lang.org/en/LICENSE.txt
5
+
6
+ You can redistribute it and/or modify it under either the terms of the GPL
7
+ (see COPYING.txt file), or the conditions below:
8
+
9
+ 1. You may make and give away verbatim copies of the source form of the
10
+ software without restriction, provided that you duplicate all of the
11
+ original copyright notices and associated disclaimers.
12
+
13
+ 2. You may modify your copy of the software in any way, provided that
14
+ you do at least ONE of the following:
15
+
16
+ a) place your modifications in the Public Domain or otherwise
17
+ make them Freely Available, such as by posting said
18
+ modifications to Usenet or an equivalent medium, or by allowing
19
+ the author to include your modifications in the software.
20
+
21
+ b) use the modified software only within your corporation or
22
+ organization.
23
+
24
+ c) rename any non-standard executables so the names do not conflict
25
+ with standard executables, which must also be provided.
26
+
27
+ d) make other distribution arrangements with the author.
28
+
29
+ 3. You may distribute the software in object code or executable
30
+ form, provided that you do at least ONE of the following:
31
+
32
+ a) distribute the executables and library files of the software,
33
+ together with instructions (in the manual page or equivalent)
34
+ on where to get the original distribution.
35
+
36
+ b) accompany the distribution with the machine-readable source of
37
+ the software.
38
+
39
+ c) give non-standard executables non-standard names, with
40
+ instructions on where to get the original software distribution.
41
+
42
+ d) make other distribution arrangements with the author.
43
+
44
+ 4. You may modify and include the part of the software into any other
45
+ software (possibly commercial). But some files in the distribution
46
+ are not written by the author, so that they are not under this terms.
47
+
48
+ They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
49
+ files under the ./missing directory. See each file for the copying
50
+ condition.
51
+
52
+ 5. The scripts and library files supplied as input to or produced as
53
+ output from the software do not automatically fall under the
54
+ copyright of the software, but belong to whomever generated them,
55
+ and may be sold commercially, and may be aggregated with this
56
+ software.
57
+
58
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
59
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
60
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
61
+ PURPOSE.
62
+
63
+
@@ -0,0 +1,19 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ config/hoe.rb
7
+ config/requirements.rb
8
+ lib/foaf_stone.rb
9
+ lib/foaf_stone/parse.rb
10
+ lib/foaf_stone/person.rb
11
+ lib/foaf_stone/search.rb
12
+ lib/foaf_stone/version.rb
13
+ script/destroy
14
+ script/generate
15
+ script/txt2html
16
+ setup.rb
17
+ test/person_spec.rb
18
+ test/search_spec.rb
19
+ test/foafs/don_park.rdf
@@ -0,0 +1,7 @@
1
+ The foaf_stone gem is a set of classes to simplify
2
+ the retrieval, search, and manipulation of a
3
+ FOAF Person.
4
+
5
+ Details on the FOAF XML format can be found at:
6
+ http://xmlns.com/foaf/spec/
7
+
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
@@ -0,0 +1,71 @@
1
+ require 'foaf_stone/version'
2
+
3
+ AUTHOR = 'Don Park' # can also be an array of Authors
4
+ EMAIL = "don.park@gmail.com"
5
+ DESCRIPTION = "manage personal information and social contacts in FOAF documents"
6
+ GEM_NAME = 'foaf_stone' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'foafstone' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "unknown"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ VERS = FoafStone::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'foaf_stone documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ p.author = AUTHOR
52
+ p.description = DESCRIPTION
53
+ p.email = EMAIL
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 'foaf_stone'
@@ -0,0 +1,6 @@
1
+ basedir = File.dirname(__FILE__)
2
+ $:.unshift basedir
3
+
4
+ require 'foaf_stone/person.rb'
5
+ require 'foaf_stone/search.rb'
6
+ require 'foaf_stone/parse.rb'
@@ -0,0 +1,12 @@
1
+ require 'open-uri'
2
+ require 'rexml/document'
3
+
4
+ class FoafStone
5
+ # This is an empty subclass of REXML::Document. Substuting a
6
+ # different XML parser in the future will be easier this way.
7
+ # Also a useful spot for future helpers.
8
+ class Document < REXML::Document
9
+ end
10
+ class Element < REXML::Element
11
+ end
12
+ end
@@ -0,0 +1,134 @@
1
+ require 'uri'
2
+ require 'rubygems'
3
+ require 'ruby-debug'
4
+
5
+ class FoafStone
6
+ # The Person class represents a person as described by
7
+ # the <foaf:Person> XML element.
8
+ #
9
+ # Manipulation of the data in the foaf:Person is made simpler
10
+ # with these methods.
11
+ #
12
+ # === example:
13
+ # person = FoafStone::Person.new("http://socialnetwork/johndoe/foaf.rdf")
14
+ # puts "I have detailed files about " + person.name
15
+ #
16
+ # person.knows.each { |person| puts person.name + " is a friend." }
17
+ #
18
+ class Person
19
+ attr_reader :uri_base
20
+
21
+ def initialize(start, uri_base=nil)
22
+ if start.kind_of?(String)
23
+ start = URI.parse(start)
24
+ end
25
+ if start.kind_of?(URI)
26
+ create_from_uri(start)
27
+ @uri_base = start
28
+ end
29
+ if start.kind_of?(REXML::Element)
30
+ create_from_xml_element(start)
31
+ @uri_base = uri_base
32
+ end
33
+ end
34
+
35
+ def create_from_uri(uri)
36
+ document = Document.new(open(uri.to_s))
37
+ @document_root = document.elements["/"]
38
+ # If there is only one person, use that
39
+ top_people = @document_root.get_elements("/rdf:RDF/foaf:Person")
40
+ if top_people.size == 1
41
+ @root = top_people.first
42
+ end
43
+ # If there are many people, use the 'me' identifier
44
+ if top_people.size > 1
45
+ @root = @document_root.elements["/rdf:RDF/foaf:Person[@rdf:ID='me']"]
46
+ end
47
+ raise "The foaf:Person cannot be found" if @root.nil?
48
+ end
49
+
50
+ def create_from_xml_element(element)
51
+ @root = element
52
+ end
53
+
54
+ # did the given xml url load and parse?
55
+ def loaded?
56
+ !@root.nil?
57
+ end
58
+
59
+ # read the foaf:img element
60
+ def image_uri
61
+ element = @root.elements["foaf:img"]
62
+ if element.nil?
63
+ element = @root.elements["foaf:depiction"]
64
+ end
65
+ return URI.parse(element.attributes["resource"]) if element
66
+ end
67
+
68
+ # read the rdfs:seeAlso element
69
+ def see_also
70
+ element = @root.elements["rdfs:seeAlso"]
71
+ element.attributes["resource"] if element
72
+ end
73
+
74
+ # read the foaf:homepage element
75
+ def homepage
76
+ element = @root.elements["foaf:homepage"]
77
+ element.attributes["resource"] if element
78
+ end
79
+
80
+ # read the foaf:nick element
81
+ def nick
82
+ nick_element = @root.elements["foaf:nick"]
83
+ nick_element.text if nick_element
84
+ end
85
+
86
+ # read the foaf:name element
87
+ def name
88
+ name_element = @root.elements["foaf:name"]
89
+ name_element.text if name_element
90
+ end
91
+
92
+ # set the foaf:name element
93
+ def name=(name)
94
+ name_element = @root.elements["foaf:name"]
95
+ name_element.text = name if name_element
96
+ end
97
+
98
+ # return an array of People whom this person knows
99
+ def knows
100
+ friends = []
101
+ @root.elements.each("foaf:knows") do |know|
102
+ # There are different ways to specify a foaf:Person
103
+ # from a foaf:Knows element
104
+
105
+ # <foaf:Knows rdf:resource="#rdf_id" />
106
+ rdf_resource = know.attributes["resource"]
107
+ if rdf_resource
108
+ rdf_id = rdf_resource[/[^#]+$/]
109
+ if rdf_resource[/^#/] # local reference
110
+ document_root = @document_root
111
+ else # remote reference
112
+ document = Document.new(open(uri))
113
+ document_root = document.elements["/"]
114
+ end
115
+ friend_root = document_root.elements["/rdf:RDF/foaf:Person[@rdf:ID='#{rdf_id}']"]
116
+ new_person = Person.new(friend_root, rdf_resource)
117
+ end
118
+
119
+ # <foaf:Knows> <foaf:Person/> </foaf:Knows>
120
+ person_literal = know.elements["foaf:Person"]
121
+ if person_literal
122
+ new_person = Person.new(person_literal, @uri_base)
123
+ end
124
+
125
+ friends << new_person
126
+ end
127
+ friends
128
+ end
129
+
130
+ # add to the list of known people
131
+ def <<(other)
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,33 @@
1
+ class FoafStone
2
+ # The Search class explores the social graph.
3
+ #
4
+ # A search is initiatied with the start method.
5
+ # The search is asynchronous, using a seperate
6
+ # thread to load the connected FOAF profiles for
7
+ # a match to the search criteria. A callback object
8
+ # is passed to allow the thread to signal the calling
9
+ # thread that the search has finished.
10
+ #
11
+ class Search
12
+ # 'start' begins an asynchronous search by spawning
13
+ # a new thread that does HTTP requests for foaf documents,
14
+ # starting with the starting_url.
15
+ #
16
+ # the search_term is currently a simple substring match on
17
+ # the name field.
18
+ #
19
+ # the callback object will be sent a search_done message
20
+ # with an array of Person objects that meet the search
21
+ # criteria.
22
+ #
23
+ # === example
24
+ # def search_done(answers)
25
+ # puts "Found #{answer.size} results"
26
+ # end
27
+ # my_foaf_uri="http://my_server/foaf.rdf"
28
+ # FoafStone::Search.start(my_foaf_uri, "Dennis", self)
29
+ #
30
+ def self.start(starting_url, search_term, callback)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ class FoafStone #:nodoc:
2
+ class VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 3
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = 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]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = 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]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -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/foaf_stone/version.rb'
15
+
16
+ version = FoafStone::VERSION::STRING
17
+ download = 'http://rubyforge.org/projects/foaf_stone'
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)