aetherical_utils 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-06-14
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
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,30 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ PostInstall.txt
5
+ README.txt
6
+ Rakefile
7
+ config/requirements.rb
8
+ lib/aetherical_utils.rb
9
+ lib/aetherical_utils/attribute.rb
10
+ lib/aetherical_utils/loader.rb
11
+ lib/aetherical_utils/metaid.rb
12
+ lib/aetherical_utils/misc.rb
13
+ lib/aetherical_utils/traiter.rb
14
+ lib/aetherical_utils/version.rb
15
+ script/console
16
+ script/destroy
17
+ script/generate
18
+ script/txt2html
19
+ setup.rb
20
+ spec/aetherical_utils_spec.rb
21
+ spec/spec.opts
22
+ spec/spec_helper.rb
23
+ tasks/deployment.rake
24
+ tasks/environment.rake
25
+ tasks/rspec.rake
26
+ tasks/website.rake
27
+ website/index.txt
28
+ website/javascripts/rounded_corners_lite.inc.js
29
+ website/stylesheets/screen.css
30
+ website/template.html.erb
data/PostInstall.txt ADDED
@@ -0,0 +1,6 @@
1
+
2
+ For more information on aetherical_utils, see http://war.rubyforge.org/aetherical_utils
3
+
4
+
5
+
6
+
data/README.txt ADDED
@@ -0,0 +1,62 @@
1
+ = aetherical_utils
2
+
3
+ http://war.rubyforge.org/aetherical_utils
4
+
5
+ == DESCRIPTION:
6
+
7
+ This library provides a number of utility functions and features which
8
+ were originally part of the WAR gem.
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ * attribute.rb -- provides code to create attributes (like attr_accessor)
13
+ which have a default value which may be a proc / block.
14
+
15
+ * loader.rb -- provides code to create classes on the fly based upon a
16
+ yaml file.
17
+
18
+ * metaid.rb -- from _why
19
+
20
+ * misc.rb -- This contains several things:
21
+ * subclass -- describes subclasses of a class
22
+
23
+ * traiter.rb -- based upon Dwemthy's Array, it is used to create
24
+ classes which have traits. WAR uses this with loader to create
25
+ units and terrain.
26
+
27
+ == SYNOPSIS:
28
+
29
+ See individual files for usage
30
+
31
+ == REQUIREMENTS:
32
+
33
+ None
34
+
35
+ == INSTALL:
36
+
37
+ sudo gem install aetherical_utils
38
+
39
+ == LICENSE:
40
+
41
+ Unless otherwise declared, this code is under the MIT License.
42
+
43
+ Copyright (c) 2008 Matt Williams, matt@aetherical.com
44
+
45
+ Permission is hereby granted, free of charge, to any person obtaining
46
+ a copy of this software and associated documentation files (the
47
+ 'Software'), to deal in the Software without restriction, including
48
+ without limitation the rights to use, copy, modify, merge, publish,
49
+ distribute, sublicense, and/or sell copies of the Software, and to
50
+ permit persons to whom the Software is furnished to do so, subject to
51
+ the following conditions:
52
+
53
+ The above copyright notice and this permission notice shall be
54
+ included in all copies or substantial portions of the Software.
55
+
56
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
57
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
58
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
59
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
60
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
61
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
62
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -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,15 @@
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]))
@@ -0,0 +1,51 @@
1
+ # This is a portion of the Aetherical Utils gem, a collection of
2
+ # utilities developed, in part, for use with the WAR library
3
+ #
4
+ #
5
+ # Author:: Matt Williams (mailto:matt@aetherical.com)
6
+ # Copyright:: Copyright (c) 2008 Matthew Williams, All Rights Reserved
7
+ # License:: MIT License
8
+
9
+ module AethericalUtils
10
+ module Attribute
11
+ # Attribute is a method of declaring default values for a property.
12
+ # These default values may be either an explicit value, such as 1,
13
+ # or "dog", or they may be a block _which is evaluated at runtime_.
14
+ # As such, the block could return different values each time it is
15
+ # invoked.
16
+ #
17
+ # If the attribute is a boolean, denoted by '?', such as
18
+ # 'billable?', then the library will correctly create 'billable?'
19
+ # and 'billable=' methods.
20
+ #
21
+ # *Important*: Since the instance variable ('@billable') may not be
22
+ # defined or the attribute may represent the value returned by a
23
+ # block, it is important to access the attribute via the method
24
+ # ('billable?') as opposed to the instance variable name
25
+ # ('@billable').
26
+
27
+ def self.attribute(*arg,&block)
28
+ (name, default) = arg
29
+ short_name = name.to_s.sub(/\?/,"")
30
+ self.send(:define_method, name) {
31
+ if instance_variables.include? "@#{short_name}"
32
+ self.instance_eval "@#{short_name}"
33
+ else
34
+ if block_given?
35
+ instance_eval &block
36
+ else
37
+ default
38
+ end
39
+ end
40
+ }
41
+ self.send(:define_method, "#{short_name}="){ |value|
42
+ self.instance_eval "@#{short_name} = value"
43
+ }
44
+ end
45
+ end
46
+ end
47
+
48
+
49
+ Object.send(:include, AethericalUtils::Attribute)
50
+
51
+
@@ -0,0 +1,56 @@
1
+ # This is a portion of the War library, a library of utilities
2
+ # and methods for wargaming.
3
+ #
4
+ #
5
+ # Author:: Matt Williams (mailto:matt@aetherical.com)
6
+ # Copyright:: Copyright (c) 2008 Matthew Williams, All Rights Reserved
7
+ # License:: MIT License
8
+
9
+ require 'yaml'
10
+
11
+ module AethericalUtils
12
+ # This class loads and creates classes which have been defined in
13
+ # a yaml file. The file is expected to contain two elements,
14
+ # templates and classes. A sample file looks like:
15
+ # ---
16
+ # templates:
17
+ # soldier:
18
+ # movement: 1
19
+ # vision: 1
20
+ # zone_of_control: 1
21
+ # range: 1
22
+ # classes:
23
+ # - name: militia
24
+ # template: soldier
25
+ # attributes:
26
+ # strength: 50
27
+ # attack: -10
28
+ # defence: 10
29
+ # cost: 50
30
+ # symbol: m
31
+ #
32
+ # The classes are then created from the information in the yaml file
33
+ class Loader
34
+ # This method loads the classes defined in the yaml file.
35
+ # +parent+ represents the parent class of classes being loaded;
36
+ # if not present, it's expected to be in the yaml.
37
+ def self.load_classes(file, parent = nil)
38
+ begin
39
+ y = YAML.load(File.open(file))
40
+ templates = y["templates"] || { }
41
+ klasses = y["classes"] || []
42
+ klasses.each do |klass|
43
+ puts klass['name']
44
+ k = Object.const_set(klass['name'].capitalize,
45
+ Class.new(parent || Object.const_get(klass['parent'].capitalize)))
46
+ k.class_eval <<EOF
47
+ #{(klass['traits'].nil? ? "" : "traits #{klass['traits'].map{ |trait| ":#{trait}"}.join(",")}")}
48
+ #{(templates["#{klass['template']}"] || {}).merge((klass['attributes'] || {})).sort.map{|t| t[1]="\"#{t[1]}\"" if t[1].instance_of?(String); t.join(" ").downcase}.join("\n")}
49
+ EOF
50
+ end
51
+ rescue Exception => e
52
+ puts "Error parsing File #{file}: #{e}"
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,25 @@
1
+ # This class is originally from _why
2
+ # http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html
3
+ #
4
+ #
5
+
6
+ module AethericalUtils
7
+ module Metaid
8
+ # The hidden singleton lurks behind everyone
9
+ def metaclass; class << self; self; end; end
10
+ def meta_eval &blk; metaclass.instance_eval &blk; end
11
+
12
+ # Adds methods to a metaclass
13
+ def meta_def name, &blk
14
+ meta_eval { define_method name, &blk }
15
+ end
16
+
17
+ # Defines an instance method within a class
18
+ def class_def name, &blk
19
+ class_eval { define_method name, &blk }
20
+ end
21
+ end
22
+ end
23
+
24
+ Object.send(:include, AethericalUtils::Metaid)
25
+
@@ -0,0 +1,31 @@
1
+ # This is a portion of the AethericalUtils library.
2
+ #
3
+ #
4
+ # Author:: Matt Williams (mailto:matt@aetherical.com)
5
+ # Copyright:: Copyright (c) 2008 Matthew Williams, All Rights Reserved
6
+ # License:: MIT License
7
+
8
+ module AethericalUtils
9
+ module Misc
10
+ module Subclasses
11
+ # return a list of the subclasses of a class
12
+ def subclasses(direct = false)
13
+ classes = []
14
+ if direct
15
+ ObjectSpace.each_object(Class) do |c|
16
+ next unless c.superclass == self
17
+ classes << c
18
+ end
19
+ else
20
+ ObjectSpace.each_object(Class) do |c|
21
+ next unless c.ancestors.include?(self) and (c != self)
22
+ classes << c
23
+ end
24
+ end
25
+ classes
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ Object.send(:include, AethericalUtils::Misc::Subclasses)
@@ -0,0 +1,33 @@
1
+ # This is a portion of the Aetherical Utils library, a library of utilities
2
+ # used by WAR
3
+ #
4
+ # Author:: Matt Williams (mailto:matt@aetherical.com)
5
+ # Copyright:: Copyright (c) 2008 Matthew Williams, All Rights Reserved
6
+ # License:: MIT License
7
+ # This is a modification of _why's Creature class from DWEMTHY's array
8
+ # The way _why had it, the initialize method would fail if there was not
9
+ # at least one trait defined.
10
+
11
+ require 'aetherical_utils/metaid'
12
+ module AethericalUtils
13
+ class Traiter
14
+ def self.traits( *arr )
15
+ return @traits if arr.empty?
16
+ attr_accessor *arr
17
+ arr.each do |trait|
18
+ meta_def trait do |val|
19
+ @traits ||= {}
20
+ @traits[trait] = val
21
+ end
22
+ end
23
+ class_def :initialize do
24
+
25
+ self.class.traits.each do |k,v|
26
+ instance_variable_set( "@#{k}", v )
27
+ end unless (self.class.traits.nil?)
28
+
29
+ end
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,9 @@
1
+ module AethericalUtils #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ dirname = File.basename(__FILE__).sub(/.rb/,"")
5
+
6
+ Dir[File.dirname(__FILE__) + "/#{dirname}/**/*.rb"].sort.each do |path|
7
+ require "#{path}"
8
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/aetherical_utils.rb'}"
9
+ puts "Loading aetherical_utils gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
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,82 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ GEM_NAME = 'aetherical_utils' # what ppl will type to install your gem
4
+ RUBYFORGE_PROJECT = 'war'
5
+
6
+ require 'rubygems'
7
+ begin
8
+ require 'newgem'
9
+ require 'rubyforge'
10
+ rescue LoadError
11
+ puts "\n\nGenerating the website requires the newgem RubyGem"
12
+ puts "Install: gem install newgem\n\n"
13
+ exit(1)
14
+ end
15
+ require 'redcloth'
16
+ require 'syntax/convertors/html'
17
+ require 'erb'
18
+ require File.dirname(__FILE__) + "/../lib/#{GEM_NAME}/version.rb"
19
+
20
+ version = AethericalUtils::VERSION::STRING
21
+ download = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
22
+
23
+ def rubyforge_project_id
24
+ RubyForge.new.autoconfig["group_ids"][RUBYFORGE_PROJECT]
25
+ end
26
+
27
+ class Fixnum
28
+ def ordinal
29
+ # teens
30
+ return 'th' if (10..19).include?(self % 100)
31
+ # others
32
+ case self % 10
33
+ when 1: return 'st'
34
+ when 2: return 'nd'
35
+ when 3: return 'rd'
36
+ else return 'th'
37
+ end
38
+ end
39
+ end
40
+
41
+ class Time
42
+ def pretty
43
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
44
+ end
45
+ end
46
+
47
+ def convert_syntax(syntax, source)
48
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
49
+ end
50
+
51
+ if ARGV.length >= 1
52
+ src, template = ARGV
53
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
54
+ else
55
+ puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
56
+ exit!
57
+ end
58
+
59
+ template = ERB.new(File.open(template).read)
60
+
61
+ title = nil
62
+ body = nil
63
+ File.open(src) do |fsrc|
64
+ title_text = fsrc.readline
65
+ body_text_template = fsrc.read
66
+ body_text = ERB.new(body_text_template).result(binding)
67
+ syntax_items = []
68
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
69
+ ident = syntax_items.length
70
+ element, syntax, source = $1, $2, $3
71
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
72
+ "syntax-temp-#{ident}"
73
+ }
74
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
75
+ body = RedCloth.new(body_text).to_html
76
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
77
+ end
78
+ stat = File.stat(src)
79
+ created = stat.ctime
80
+ modified = stat.mtime
81
+
82
+ $stdout << template.result(binding)