public
Fork of ndemonner/stone
Description: Plug-and-play data persistence created for small Ruby web applications.
Homepage: http://stone.rubyforge.org
Clone URL: git://github.com/juretta/stone.git
Search Repo:
Skeleton for gem built.

* Added newgem functionality
* Spec harness built
* Sandbox for specs built
ndemonner (author)
Tue Apr 08 10:28:49 -0700 2008
commit  2509c86cb0610cb6dc909d39b3b654e82b62f7e4
tree    4d1f6803c063de06cbe7dbee0221b19cbac074f0
parent  c2caf3c8c3390e303819ae65f387e7d5843a98c5
...
 
 
 
 
...
1
2
3
4
0
@@ -1 +1,5 @@
0
+== 0.0.1 2008-04-08
0
+
0
+* 1 major enhancement:
0
+ * Initial release
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
0
@@ -1 +1,21 @@
0
+Copyright (c) 2008 Nick DeMonner
0
+
0
+Permission is hereby granted, free of charge, to any person obtaining
0
+a copy of this software and associated documentation files (the
0
+"Software"), to deal in the Software without restriction, including
0
+without limitation the rights to use, copy, modify, merge, publish,
0
+distribute, sublicense, and/or sell copies of the Software, and to
0
+permit persons to whom the Software is furnished to do so, subject to
0
+the following conditions:
0
+
0
+The above copyright notice and this permission notice shall be
0
+included in all copies or substantial portions of the Software.
0
+
0
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
0
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
0
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
0
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
0
@@ -1 +1,38 @@
0
+History.txt
0
+License.txt
0
+Manifest.txt
0
+README
0
+Rakefile
0
+config/hoe.rb
0
+config/requirements.rb
0
+lib/stone.rb
0
+lib/stone.rb.33984.0
0
+lib/stone/core_ext/string.rb
0
+lib/stone/resource.rb
0
+lib/stone/utilities.rb
0
+lib/stone/version.rb
0
+log/debug.log
0
+sandbox_for_specs/sample_resources/author.rb
0
+sandbox_for_specs/sample_resources/comment.rb
0
+sandbox_for_specs/sample_resources/person.rb
0
+sandbox_for_specs/sample_resources/post.rb
0
+script/console
0
+script/destroy
0
+script/generate
0
+script/txt2html
0
+setup.rb
0
+spec/resource_spec.rb
0
+spec/spec_helper.rb
0
+spec/stone_spec.rb
0
+spec/utilities_spec.rb
0
+tasks/deployment.rake
0
+tasks/environment.rake
0
+tasks/website.rake
0
+test/test_helper.rb
0
+test/test_stone.rb
0
+website/index.html
0
+website/index.txt
0
+website/javascripts/rounded_corners_lite.inc.js
0
+website/stylesheets/screen.css
0
+website/template.html.erb
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,33 +1 @@
0
-# Stone is a:
0
-#
0
-# Super-simple data persistence layer created for small applications.
0
-#
0
-# Any class can be made to persist simply by including Stone::Resource
0
-
0
-# Here is an example model class
0
-
0
-class Author
0
- include Stone::Resource
0
-
0
- field :first_name, String
0
- field :last_name, String
0
- field :email, String, :format => :email, :mandatory => true
0
-
0
- field :birthday, String, :format => /d{2}\/d{2}\/d{4}/
0
- field :created_at, DateTime, :default => DateTime.now
0
-
0
- has_many :posts
0
-
0
- before_save :nervous
0
- after_save :whew
0
-
0
- def nervous
0
- puts "Will it save?!?!?!"
0
- end
0
-
0
- def whew
0
- puts "Whew. It saved."
0
- end
0
-
0
-end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
0
@@ -1 +1,49 @@
0
+= Stone
0
+
0
+* stone.rubyforge.org
0
+
0
+== DESCRIPTION:
0
+
0
+Super-simple data persistence layer created for small applications.
0
+
0
+== FEATURES/PROBLEMS:
0
+
0
+* FIX (list of features or problems)
0
+
0
+== SYNOPSIS:
0
+
0
+ FIX (code sample of usage)
0
+
0
+== REQUIREMENTS:
0
+
0
+* FIX (list of requirements)
0
+
0
+== INSTALL:
0
+
0
+* FIX (sudo gem install, anything else)
0
+
0
+== LICENSE:
0
+
0
+(The MIT License)
0
+
0
+Copyright (c) 2008 Nick DeMonner
0
+
0
+Permission is hereby granted, free of charge, to any person obtaining
0
+a copy of this software and associated documentation files (the
0
+'Software'), to deal in the Software without restriction, including
0
+without limitation the rights to use, copy, modify, merge, publish,
0
+distribute, sublicense, and/or sell copies of the Software, and to
0
+permit persons to whom the Software is furnished to do so, subject to
0
+the following conditions:
0
+
0
+The above copyright notice and this permission notice shall be
0
+included in all copies or substantial portions of the Software.
0
+
0
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
0
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
0
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
0
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
0
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
0
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
0
@@ -1 +1,19 @@
0
+require 'config/requirements'
0
+require 'config/hoe' # setup Hoe + all gem configuration
0
+require "rake"
0
+require "rake/clean"
0
+require "spec/rake/spectask"
0
+require 'lib/stone'
0
+
0
+Dir['tasks/**/*.rake'].each { |rake| load rake }
0
+
0
+Spec::Rake::SpecTask.new('specs') do |t|
0
+ t.spec_opts = ["--format", "specdoc", "--colour"]
0
+ t.spec_files = Dir['spec/**/*_spec.rb'].sort
0
+end
0
+
0
+desc "Run specs"
0
+task :ok do
0
+ sh "rake specs"
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
0
@@ -1 +1,71 @@
0
+require 'stone/version'
0
+
0
+AUTHOR = 'Nick DeMonner' # can also be an array of Authors
0
+EMAIL = "nick@cladby.com"
0
+DESCRIPTION = "Super-simple data persistence layer created for small applications."
0
+GEM_NAME = 'stone' # what ppl will type to install your gem
0
+RUBYFORGE_PROJECT = 'stone' # The unix name for your project
0
+HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
0
+DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
0
+
0
+@config_file = "~/.rubyforge/user-config.yml"
0
+@config = nil
0
+RUBYFORGE_USERNAME = "unknown"
0
+def rubyforge_username
0
+ unless @config
0
+ begin
0
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
0
+ rescue
0
+ puts <<-EOS
0
+ERROR: No rubyforge config file found: #{@config_file}
0
+Run 'rubyforge setup' to prepare your env for access to Rubyforge
0
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
0
+ EOS
0
+ exit
0
+ end
0
+ end
0
+ RUBYFORGE_USERNAME.replace @config["username"]
0
+end
0
+
0
+
0
+REV = nil
0
+# UNCOMMENT IF REQUIRED:
0
+# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
0
+VERS = Stone::VERSION::STRING + (REV ? ".#{REV}" : "")
0
+RDOC_OPTS = ['--quiet', '--title', 'stone documentation',
0
+ "--opname", "index.html",
0
+ "--line-numbers",
0
+ "--main", "README",
0
+ "--inline-source"]
0
+
0
+class Hoe
0
+ def extra_deps
0
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
0
+ @extra_deps
0
+ end
0
+end
0
+
0
+# Generate all the Rake tasks
0
+# Run 'rake -T' to see list of generated tasks (from gem root directory)
0
+$hoe = Hoe.new(GEM_NAME, VERS) do |p|
0
+ p.developer(AUTHOR, EMAIL)
0
+ p.description = DESCRIPTION
0
+ p.summary = DESCRIPTION
0
+ p.url = HOMEPATH
0
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
0
+ p.test_globs = ["test/**/test_*.rb"]
0
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
0
+
0
+ # == Optional
0
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
0
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
0
+
0
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
0
+
0
+end
0
+
0
+CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
0
+PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
0
+$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
0
+$hoe.rsync_args = '-av --delete --ignore-errors'
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
0
@@ -1 +1,16 @@
0
+require 'fileutils'
0
+include FileUtils
0
+
0
+require 'rubygems'
0
+%w[rake hoe newgem rubigen].each do |req_gem|
0
+ begin
0
+ require req_gem
0
+ rescue LoadError
0
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
0
+ puts "Installation: gem install #{req_gem} -y"
0
+ exit
0
+ end
0
+end
0
+
0
+$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
0
@@ -1 +1,57 @@
0
+require 'fileutils'
0
+require 'lib/stone/core_ext/string'
0
+require 'rubygems'
0
+require 'validatable'
0
+require 'english/inflect'
0
+require 'facets'
0
+require 'yaml'
0
+require 'fastercsv'
0
+require 'lib/stone/resource'
0
+require 'lib/stone/utilities'
0
+
0
+STONE_ROOT = Dir.pwd
0
+
0
+$:.unshift(File.dirname(__FILE__)) unless
0
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
0
+
0
+module Stone
0
+ class << self
0
+
0
+ # See Stone::Utilities.backup
0
+ def backup(from_path, to_path = nil)
0
+ Stone::Utilities.backup(from_path, to_path)
0
+ end
0
+
0
+ # See Stone::Utilities.export
0
+ def export(path, to_format)
0
+ Stone::Utilities.export(path, to_format)
0
+ end
0
+
0
+ # See Stone::Utilities.import
0
+ def import(path, type)
0
+ Stone::Utilities.import(path, type)
0
+ end
0
+
0
+ # See Stone::Utilities.metrics_for
0
+ def metrics_for(path)
0
+ Stone::Utilities.metrics_for(path)
0
+ end
0
+
0
+ # Creates or updates a datastore at +path+
0
+ # === Parameters
0
+ # +path+<String>::
0
+ # Path to create datastore (usually an application's root)
0
+ # +resources+<Array>:: A list of resources that exist for the application
0
+ def build_datastore(path, resources)
0
+ FileUtils.mkdir(path/"datastore") unless File.exists?(path/"datastore")
0
+ resources.each do |resource|
0
+ name = File.basename(resource).gsub(".rb", "").pluralize
0
+ unless File.exists? path/"datastore"/name
0
+ FileUtils.mkdir(path/"datastore"/name)
0
+ end
0
+ end
0
+ end
0
+
0
+ end # self
0
+end # Stone
...
 
 
 
 
 
...
1
2
3
4
5
0
@@ -1 +1,6 @@
0
+class String #:nodoc:
0
+ def /(o)
0
+ File.join(self, o.to_s)
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
0
@@ -1 +1,72 @@
0
+module Stone
0
+
0
+ # Adds the ability to persist any class it is included in
0
+ # === Example
0
+ #
0
+ # class Post
0
+ # include Stone::Resource
0
+ #
0
+ # field :body, String
0
+ # end
0
+ #
0
+ module Resource
0
+
0
+ class << self
0
+ end # self
0
+
0
+ def self.included(base)
0
+ base.send(:extend, self)
0
+ base.send(:include, ::Validatable)
0
+ end
0
+
0
+ @@fields = {}
0
+
0
+ def field(name, klass, *opts)
0
+ unless @@fields[self.to_s.downcase.to_sym]
0
+ @@fields[self.to_s.downcase.to_sym] = [{:name => name, :klass => klass}]
0
+ else
0
+ @@fields[self.to_s.downcase.to_sym] << {:name => name, :klass => klass}
0
+ end
0
+
0
+ name = name.to_s
0
+
0
+ self.class_eval <<-EOS, __FILE__, __LINE__
0
+ def #{name}
0
+ @#{name}
0
+ end
0
+
0
+ def #{name}=(value)
0
+ @#{name} = value
0
+ end
0
+ EOS
0
+
0
+ end
0
+
0
+ def before_save(meth, *opts)
0
+
0
+ end
0
+
0
+ def has_many(resource)
0
+
0
+ end
0
+
0
+ def has_one(resource)
0
+
0
+ end
0
+
0
+ def belongs_to(resource)
0
+
0
+ end
0
+
0
+ def save
0
+
0
+ end
0
+
0
+ def fields
0
+ @@fields
0
+ end
0
+
0
+ end # Resource
0
+
0
+end # Stone
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
0
@@ -1 +1,54 @@
0
+module Stone
0
+
0
+ # Provides a bunch of utilities for manipulating and examining data
0
+ class Utilities
0
+
0
+ class << self
0
+
0
+ # Creates an archive of the datastore at +from_path+ and puts it
0
+ # in +to_path+ (or +from_path+ if +to_path+ is not provided)
0
+ # === Parameters
0
+ # from_path<String>::
0
+ # The path to the existing data (either to a dir or file)
0
+ # to_path<String>:: The format of the existing data
0
+ def backup(from_path, to_path = nil)
0
+
0
+ end
0
+
0
+ # Imports data from another database to create a new Stone
0
+ # datastore from the imported data.
0
+ # === Parameters
0
+ # path<String>:: The path to the existing data (either to a dir or file)
0
+ # format<Symbol>:: The format of the existing data
0
+ # === Options for +format+
0
+ # +sql+:: SQL
0
+ # +yaml+:: YAML
0
+ # +csv+:: CSV
0
+ def import(path, format)
0
+
0
+ end
0
+
0
+ # Exports data from an existing Stone datastore to a file of the given
0
+ # +format+
0
+ # === Parameters
0
+ # path<String>:: The path to the existing datastore root dir
0
+ # format<Symbol>:: The format of the outputted data
0
+ # === Options for +format+
0
+ # +sql+:: SQL
0
+ # +yaml+:: YAML
0
+ # +csv+:: CSV
0
+ def export(path, format)
0
+
0
+ end
0
+
0
+ # Provides a bunch of useful metrics about a given Stone datastore
0
+ # === Parameters
0
+ # path<String>:: Location of Stone datastore root dir
0
+ def metrics_for(path)
0
+
0
+ end
0
+ end # self
0
+
0
+ end # Utilities
0
+end # Stone
...
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
0
@@ -1 +1,10 @@
0
+module Stone #:nodoc:
0
+ module VERSION #:nodoc:
0
+ MAJOR = 0
0
+ MINOR = 0
0
+ TINY = 1
0
+
0
+ STRING = [MAJOR, MINOR, TINY].join('.')
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
0
@@ -1 +1,18 @@
0
+class Author #:nodoc:
0
+ include Stone::Resource
0
+
0
+ field :name, String
0
+ field :email, String
0
+
0
+ validates_presence_of :name, :email
0
+
0
+ before_save :cap_name
0
+
0
+ has_many :posts
0
+ has_many :comments
0
+
0
+ def cap_name
0
+ self.name = self.name.titlecase
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
0
@@ -1 +1,10 @@
0
+class Comment #:nodoc:
0
+ include Stone::Resource
0
+
0
+ field :body, String
0
+
0
+ belongs_to :post
0
+ belongs_to :person
0
+ belongs_to :author
0
+end
...
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
0
@@ -1 +1,11 @@
0
+#!/usr/bin/env ruby
0
+# File: script/console
0
+irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
0
+
0
+libs = " -r irb/completion"
0
+# Perhaps use a console_lib to store any extra methods I may want available in the cosole
0
+# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
0
+libs << " -r #{File.dirname(__FILE__) + '/../lib/stone.rb'}"
0
+puts "Loading stone gem"
0
+exec "#{irb} #{libs} --simple-prompt"
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0
@@ -1 +1,15 @@
0
+#!/usr/bin/env ruby
0
+APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
0
+
0
+begin
0
+ require 'rubigen'
0
+rescue LoadError
0
+ require 'rubygems'
0
+ require 'rubigen'
0
+end
0
+require 'rubigen/scripts/destroy'
0
+
0
+ARGV.shift if ['--help', '-h'].include?(ARGV[0])
0
+RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
0
+RubiGen::Scripts::Destroy.new.run(ARGV)
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0
@@ -1 +1,15 @@
0
+#!/usr/bin/env ruby
0
+APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
0
+
0
+begin
0
+ require 'rubigen'
0
+rescue LoadError
0
+ require 'rubygems'
0
+ require 'rubigen'
0
+end
0
+require 'rubigen/scripts/generate'
0
+
0
+ARGV.shift if ['--help', '-h'].include?(ARGV[0])
0
+RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
0
+RubiGen::Scripts::Generate.new.run(ARGV)
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
0
@@ -1 +1,75 @@
0
+#!/usr/bin/env ruby
0
+
0
+require 'rubygems'
0
+begin
0
+ require 'newgem'
0
+rescue LoadError
0
+ puts "\n\nGenerating the website requires the newgem RubyGem"
0
+ puts "Install: gem install newgem\n\n"
0
+ exit(1)
0
+end
0
+require 'redcloth'
0
+require 'syntax/convertors/html'
0
+require 'erb'
0
+require File.dirname(__FILE__) + '/../lib/stone/version.rb'
0
+
0
+version = Stone::VERSION::STRING
0
+download = 'http://rubyforge.org/projects/stone'
0
+
0
+class Fixnum
0
+ def ordinal
0
+ # teens
0
+ return 'th' if (10..19).include?(self % 100)
0
+ # others
0
+ case self % 10
0
+ when 1: return 'st'
0
+ when 2: return 'nd'
0
+ when 3: return 'rd'
0
+ else return 'th'
0
+ end
0
+ end
0
+end
0
+
0
+class Time
0
+ def pretty
0
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
0
+ end
0
+end
0
+
0
+def convert_syntax(syntax, source)
0
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
0
+end
0
+
0
+if ARGV.length >= 1
0
+ src, template = ARGV
0
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
0
+
0
+else
0
+ puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
0
+ exit!
0
+end
0
+
0
+template = ERB.new(File.open(template).read)
0
+
0
+title = nil
0
+body = nil
0
+File.open(src) do |fsrc|
0
+ title_text = fsrc.readline
0
+ body_text = fsrc.read
0
+ syntax_items = []
0
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
0
+ ident = syntax_items.length
0
+ element, syntax, source = $1, $2, $3
0
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
0
+ "syntax-temp-#{ident}"
0
+ }
0
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
0
+ body = RedCloth.new(body_text).to_html
0
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
0
+end
0
+stat = File.stat(src)
0
+created = stat.ctime
0
+modified = stat.mtime
0
+
0
+$stdout << template.result(binding)
...