kagemusha 0.0.3 → 0.0.4

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 CHANGED
@@ -1,4 +1,8 @@
1
1
 
2
+ == 0.0.4 2008-07-09
3
+
4
+ ...
5
+
2
6
  == 0.0.3 2007-09-10
3
7
 
4
8
  ...
data/Manifest.txt CHANGED
@@ -4,6 +4,8 @@ Manifest.txt
4
4
  README.ja.txt
5
5
  README.txt
6
6
  Rakefile
7
+ config/hoe.rb
8
+ config/requirements.rb
7
9
  examples/date.rb
8
10
  examples/datetime.rb
9
11
  examples/first.rb
@@ -17,8 +19,20 @@ lib/kagemusha/datetime.rb
17
19
  lib/kagemusha/rand.rb
18
20
  lib/kagemusha/time.rb
19
21
  lib/kagemusha/version.rb
20
- scripts/txt2html
22
+ script/console
23
+ script/console.cmd
24
+ script/destroy
25
+ script/destroy.cmd
26
+ script/generate
27
+ script/generate.cmd
28
+ script/txt2html
29
+ script/txt2html.cmd
21
30
  setup.rb
31
+ tasks/deployment.rake
32
+ tasks/environment.rake
33
+ tasks/website.rake
34
+ test/test_bugs.rb
35
+ test/test_complex_cases.rb
22
36
  test/test_date.rb
23
37
  test/test_datetime.rb
24
38
  test/test_helper.rb
@@ -29,4 +43,4 @@ website/index.html
29
43
  website/index.txt
30
44
  website/javascripts/rounded_corners_lite.inc.js
31
45
  website/stylesheets/screen.css
32
- website/template.rhtml
46
+ website/template.html.erb
data/README.txt CHANGED
@@ -1,64 +1,57 @@
1
-
2
- Kagemusha - a library of testing mock-objects
3
- =============================================
4
-
5
- Welcome to Kagemusha
6
- --------------------
7
-
8
- Kagemusha is a library of helper functions
9
- for testing Ruby scripts. It helps you generating
10
- scoped mock-objects which overrides behavior of
11
- the class restricted in given blocks, without
12
- tainting a global area.
13
-
14
- For example, if you override Date.today when you write
15
- something about dates, then the code will taint global
16
- areas to no purpose.
17
-
18
- If you use Kagemusha, the test code will override
19
- behavior of the class restricted in given block.
20
-
21
- Example:
22
- require "kagemusha"
23
-
24
- musha = Kagemusha.new(Time)
25
- musha.defs(:now) { self.local(2000, 1, 1) }
26
- musha.def(:to_s) { self.strftime("%Y-%m-%d") }
27
-
28
- musha.swap {
29
- p Time.now #=> Sat Jan 01 00:00:00 +0900 2000
30
- p Time.now.to_s #=> "2000-01-01"
31
- }
32
-
33
- Also, it has default useful mock-objects set Date, Time,
34
- rand, and so on.
35
-
36
- Example:
37
- require "kagemusha/date"
38
-
39
- musha = Kagemusha::Date.at(2000, 1, 1)
40
- musha.swap {
41
- p Date.today.to_s #=> "2000-01-01"
42
- }
43
-
44
-
45
- Installation
46
- ------------
47
-
48
- The easiest way to get started with Kagemusha is to
49
- install it via RubyGems. You can do this easily:
50
-
51
- $ gem install kagemusha
52
-
53
-
54
- Examples
55
- --------
56
-
57
- see example directory.
58
-
59
-
60
- Support
61
- --------
62
-
63
- Feel free to mail me:
64
- Yuya Kato <yuyakato at gmail.com>
1
+
2
+ = Kagemusha - a library of testing mock-objects
3
+
4
+ http://kagemusha.rubyforge.org/
5
+
6
+ == DESCRIPTION:
7
+
8
+ Kagemusha is a library of helper functions
9
+ for testing Ruby scripts. It helps you generating
10
+ scoped mock-objects which overrides behavior of
11
+ the class restricted in given blocks, without
12
+ tainting a global area.
13
+
14
+ For example, if you override Date.today when you write
15
+ something about dates, then the code will taint global
16
+ areas to no purpose.
17
+
18
+ If you use Kagemusha, the test code will override
19
+ behavior of the class restricted in given block.
20
+
21
+ Example:
22
+ require "kagemusha"
23
+
24
+ musha = Kagemusha.new(Time)
25
+ musha.defs(:now) { self.local(2000, 1, 1) }
26
+ musha.def(:to_s) { self.strftime("%Y-%m-%d") }
27
+
28
+ musha.swap {
29
+ p Time.now #=> Sat Jan 01 00:00:00 +0900 2000
30
+ p Time.now.to_s #=> "2000-01-01"
31
+ }
32
+
33
+ Also, it has default useful mock-objects set Date, Time,
34
+ rand, and so on.
35
+
36
+ Example:
37
+ require "kagemusha/date"
38
+
39
+ musha = Kagemusha::Date.at(2000, 1, 1)
40
+ musha.swap {
41
+ p Date.today.to_s #=> "2000-01-01"
42
+ }
43
+
44
+ == SYNOPSIS:
45
+
46
+ see example directory.
47
+
48
+ == INSTALL:
49
+
50
+ The easiest way to get started with Kagemusha is to
51
+ install it via RubyGems. You can do this easily:
52
+
53
+ $ gem install kagemusha
54
+
55
+ == LICENSE:
56
+
57
+ Ruby's License
data/Rakefile CHANGED
@@ -1,123 +1,4 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'rake/clean'
4
- require 'rake/testtask'
5
- require 'rake/packagetask'
6
- require 'rake/gempackagetask'
7
- require 'rake/rdoctask'
8
- require 'rake/contrib/rubyforgepublisher'
9
- require 'fileutils'
10
- require 'hoe'
11
-
12
- include FileUtils
13
- require File.join(File.dirname(__FILE__), 'lib', 'kagemusha', 'version')
14
-
15
- AUTHOR = "Yuya Kato" # can also be an array of Authors
16
- EMAIL = "yuyakato at gmail.com"
17
- DESCRIPTION = "Kagemusha is a library of helper functions for testing Ruby scripts."
18
- GEM_NAME = "kagemusha" # what ppl will type to install your gem
19
-
20
- @config_file = "~/.rubyforge/user-config.yml"
21
- @config = nil
22
- def rubyforge_username
23
- unless @config
24
- begin
25
- @config = YAML.load(File.read(File.expand_path(@config_file)))
26
- rescue
27
- puts <<-EOS
28
- ERROR: No rubyforge config file found: #{@config_file}"
29
- Run 'rubyforge setup' to prepare your env for access to Rubyforge
30
- - See http://newgem.rubyforge.org/rubyforge.html for more details
31
- EOS
32
- exit
33
- end
34
- end
35
- @rubyforge_username ||= @config["username"]
36
- end
37
-
38
- RUBYFORGE_PROJECT = 'kagemusha' # The unix name for your project
39
- HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
40
- DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
41
-
42
- NAME = "kagemusha"
43
- REV = nil
44
- # UNCOMMENT IF REQUIRED:
45
- # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
46
- VERS = Kagemusha::VERSION::STRING + (REV ? ".#{REV}" : "")
47
- CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
48
- RDOC_OPTS = ['--quiet', '--title', 'kagemusha documentation',
49
- "--opname", "index.html",
50
- "--line-numbers",
51
- "--main", "README",
52
- "--inline-source"]
53
-
54
- class Hoe
55
- def extra_deps
56
- @extra_deps.reject { |x| Array(x).first == 'hoe' }
57
- end
58
- end
59
-
60
- # Generate all the Rake tasks
61
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
62
- hoe = Hoe.new(GEM_NAME, VERS) do |p|
63
- p.author = AUTHOR
64
- p.description = DESCRIPTION
65
- p.email = EMAIL
66
- p.summary = DESCRIPTION
67
- p.url = HOMEPATH
68
- p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
69
- p.test_globs = ["test/**/test_*.rb"]
70
- p.clean_globs |= CLEAN #An array of file patterns to delete on clean.
71
-
72
- # == Optional
73
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
74
- #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
75
- #p.spec_extras = {} # A hash of extra values to set in the gemspec.
76
- end
77
-
78
- CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\n\n")
79
- PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
80
- hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
81
-
82
- desc 'Generate website files'
83
- task :website_generate do
84
- Dir['website/**/*.txt'].each do |txt|
85
- sh %{ ruby scripts/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
86
- end
87
- end
88
-
89
- desc 'Upload website files to rubyforge'
90
- task :website_upload do
91
- host = "#{rubyforge_username}@rubyforge.org"
92
- remote_dir = "/var/www/gforge-projects/#{PATH}/"
93
- local_dir = 'website'
94
- sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
95
- end
96
-
97
- desc 'Generate and upload website files'
98
- task :website => [:website_generate, :website_upload, :publish_docs]
99
-
100
- desc 'Release the website and new gem version'
101
- task :deploy => [:check_version, :website, :release] do
102
- puts "Remember to create SVN tag:"
103
- puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
104
- "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
105
- puts "Suggested comment:"
106
- puts "Tagging release #{CHANGES}"
107
- end
108
-
109
- desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
110
- task :local_deploy => [:website_generate, :install_gem]
111
-
112
- task :check_version do
113
- unless ENV['VERSION']
114
- puts 'Must pass a VERSION=x.y.z release version'
115
- exit
116
- end
117
- unless ENV['VERSION'] == VERS
118
- puts "Please update your version.rb to match the release version, currently #{VERS}"
119
- exit
120
- end
121
- end
122
-
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
123
3
 
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/config/hoe.rb ADDED
@@ -0,0 +1,73 @@
1
+ require 'kagemusha/version'
2
+
3
+ AUTHOR = 'Yuya Kato' # can also be an array of Authors
4
+ EMAIL = "yuyakato at gmail.com"
5
+ DESCRIPTION = "Kagemusha is a library of helper functions for testing Ruby scripts."
6
+ GEM_NAME = 'kagemusha' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'kagemusha' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+ EXTRA_DEPENDENCIES = [
11
+ # ['activesupport', '>= 1.3.1']
12
+ ] # An array of rubygem dependencies [name, version]
13
+
14
+ @config_file = "~/.rubyforge/user-config.yml"
15
+ @config = nil
16
+ RUBYFORGE_USERNAME = "unknown"
17
+ def rubyforge_username
18
+ unless @config
19
+ begin
20
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
21
+ rescue
22
+ puts <<-EOS
23
+ ERROR: No rubyforge config file found: #{@config_file}
24
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
25
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
26
+ EOS
27
+ exit
28
+ end
29
+ end
30
+ RUBYFORGE_USERNAME.replace @config["username"]
31
+ end
32
+
33
+
34
+ REV = nil
35
+ # UNCOMMENT IF REQUIRED:
36
+ # REV = YAML.load(`svn info`)['Revision']
37
+ VERS = Kagemusha::VERSION::STRING + (REV ? ".#{REV}" : "")
38
+ RDOC_OPTS = ['--quiet', '--title', 'kagemusha documentation',
39
+ "--opname", "index.html",
40
+ "--line-numbers",
41
+ "--main", "README",
42
+ "--inline-source"]
43
+
44
+ class Hoe
45
+ def extra_deps
46
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
47
+ @extra_deps
48
+ end
49
+ end
50
+
51
+ # Generate all the Rake tasks
52
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
53
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
54
+ p.developer(AUTHOR, EMAIL)
55
+ p.description = DESCRIPTION
56
+ p.summary = DESCRIPTION
57
+ p.url = HOMEPATH
58
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
59
+ p.test_globs = ["test/**/test_*.rb"]
60
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
61
+
62
+ # == Optional
63
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
64
+ #p.extra_deps = EXTRA_DEPENDENCIES
65
+
66
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
67
+ end
68
+
69
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
70
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
71
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
72
+ $hoe.rsync_args = '-av --delete --ignore-errors'
73
+ $hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -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]))
@@ -1,6 +1,6 @@
1
1
 
2
2
  #==============================================================================#
3
- # $Id: core.rb 45 2007-09-07 04:49:51Z yuyakato $
3
+ # $Id: core.rb 58 2008-07-09 07:02:25Z yuyakato $
4
4
  #==============================================================================#
5
5
 
6
6
  class Kagemusha #:nodoc:
@@ -48,12 +48,13 @@ class Kagemusha #:nodoc:
48
48
  begin
49
49
  # replace method
50
50
  method = @meta.instance_method(name)
51
+ method = :remove unless @klass.singleton_methods(false).include?(name.to_s)
51
52
  @meta.instance_eval { define_method(name, proc) }
52
53
  original_class_methods[name] = method
53
54
  rescue NameError
54
55
  # insert method
55
56
  @meta.instance_eval { define_method(name, proc) }
56
- original_class_methods[name] = false
57
+ original_class_methods[name] = :undef
57
58
  end
58
59
  else
59
60
  begin
@@ -72,12 +73,13 @@ class Kagemusha #:nodoc:
72
73
  begin
73
74
  # replace method
74
75
  method = @klass.instance_method(name)
76
+ method = :remove unless @klass.instance_methods(false).include?(name.to_s)
75
77
  @klass.instance_eval { define_method(name, proc) }
76
78
  original_instance_methods[name] = method
77
79
  rescue NameError
78
80
  # insert method
79
81
  @klass.instance_eval { define_method(name, proc) }
80
- original_instance_methods[name] = false
82
+ original_instance_methods[name] = :undef
81
83
  end
82
84
  else
83
85
  begin
@@ -94,21 +96,17 @@ class Kagemusha #:nodoc:
94
96
  return yield
95
97
  ensure
96
98
  original_class_methods.each { |name, method|
97
- if method
98
- # replace method
99
- @meta.instance_eval { define_method(name, method) }
100
- else
101
- # remove method
102
- @meta.instance_eval { undef_method(name) }
99
+ case method
100
+ when :remove then @meta.instance_eval { remove_method(name) }
101
+ when :undef then @meta.instance_eval { undef_method(name) }
102
+ else @meta.instance_eval { define_method(name, method) }
103
103
  end
104
104
  }
105
105
  original_instance_methods.each { |name, method|
106
- if method
107
- # replace method
108
- @klass.instance_eval { define_method(name, method) }
109
- else
110
- # remove method
111
- @klass.instance_eval { undef_method(name) }
106
+ case method
107
+ when :remove then @klass.instance_eval { remove_method(name) }
108
+ when :undef then @klass.instance_eval { undef_method(name) }
109
+ else @klass.instance_eval { define_method(name, method) }
112
110
  end
113
111
  }
114
112
  end
@@ -1,13 +1,13 @@
1
1
 
2
2
  #==============================================================================#
3
- # $Id: version.rb 44 2007-09-07 02:32:58Z yuyakato $
3
+ # $Id: version.rb 48 2008-07-09 02:41:13Z yuyakato $
4
4
  #==============================================================================#
5
5
 
6
6
  class Kagemusha #:nodoc:
7
7
  module VERSION #:nodoc:
8
8
  MAJOR = 0
9
9
  MINOR = 0
10
- TINY = 3
10
+ TINY = 4
11
11
 
12
12
  STRING = [MAJOR, MINOR, TINY].join('.')
13
13
  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/kagemusha.rb'}"
9
+ puts "Loading kagemusha gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1 @@
1
+ @ruby script/console %*
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)
@@ -0,0 +1 @@
1
+ @ruby script/destroy %*
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)
@@ -0,0 +1 @@
1
+ @ruby script/generate %*
@@ -1,67 +1,82 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'redcloth'
5
- require 'syntax/convertors/html'
6
- require 'erb'
7
- require File.dirname(__FILE__) + '/../lib/kagemusha/version.rb'
8
-
9
- version = Kagemusha::VERSION::STRING
10
- download = 'http://rubyforge.org/projects/kagemusha'
11
-
12
- class Fixnum
13
- def ordinal
14
- # teens
15
- return 'th' if (10..19).include?(self % 100)
16
- # others
17
- case self % 10
18
- when 1: return 'st'
19
- when 2: return 'nd'
20
- when 3: return 'rd'
21
- else return 'th'
22
- end
23
- end
24
- end
25
-
26
- class Time
27
- def pretty
28
- return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
29
- end
30
- end
31
-
32
- def convert_syntax(syntax, source)
33
- return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
34
- end
35
-
36
- if ARGV.length >= 1
37
- src, template = ARGV
38
- template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
39
-
40
- else
41
- puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
42
- exit!
43
- end
44
-
45
- template = ERB.new(File.open(template).read)
46
-
47
- title = nil
48
- body = nil
49
- File.open(src) do |fsrc|
50
- title_text = fsrc.readline
51
- body_text = fsrc.read
52
- syntax_items = []
53
- body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</>!m){
54
- ident = syntax_items.length
55
- element, syntax, source = $1, $2, $3
56
- syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
57
- "syntax-temp-#{ident}"
58
- }
59
- title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
60
- body = RedCloth.new(body_text).to_html
61
- body.gsub!(%r!(?:<pre><code>)?syntax-temp-(d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
62
- end
63
- stat = File.stat(src)
64
- created = stat.ctime
65
- modified = stat.mtime
66
-
67
- $stdout << template.result(binding)
1
+ #!/usr/bin/env ruby
2
+
3
+ GEM_NAME = 'kagemusha' # what ppl will type to install your gem
4
+ RUBYFORGE_PROJECT = 'kagemusha'
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 = Kagemusha::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)