capigen 0.1.1

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.
Files changed (84) hide show
  1. data/Capfile +22 -0
  2. data/History.txt +3 -0
  3. data/License.txt +20 -0
  4. data/Manifest.txt +83 -0
  5. data/README.txt +35 -0
  6. data/Rakefile +4 -0
  7. data/config/hoe.rb +70 -0
  8. data/config/requirements.rb +17 -0
  9. data/init.rb +3 -0
  10. data/lib/capigen/config.rb +84 -0
  11. data/lib/capigen/helper.rb +51 -0
  12. data/lib/capigen/helpers/gem_helper.rb +15 -0
  13. data/lib/capigen/helpers/package_helper.rb +40 -0
  14. data/lib/capigen/helpers/script_helper.rb +30 -0
  15. data/lib/capigen/helpers/wget_helper.rb +17 -0
  16. data/lib/capigen/packagers/yum.rb +46 -0
  17. data/lib/capigen/profiles.rb +19 -0
  18. data/lib/capigen/recipes.yml +14 -0
  19. data/lib/capigen/templates.rb +65 -0
  20. data/lib/capigen/version.rb +9 -0
  21. data/lib/capigen.rb +26 -0
  22. data/recipes/README +12 -0
  23. data/recipes/bootstrap/patch.rb +87 -0
  24. data/recipes/centos.rb +40 -0
  25. data/recipes/deploy.rb +17 -0
  26. data/recipes/gems.rb +8 -0
  27. data/recipes/imagemagick.rb +9 -0
  28. data/recipes/install.rb +13 -0
  29. data/recipes/memcached.rb +15 -0
  30. data/recipes/mongrel_cluster.rb +49 -0
  31. data/recipes/monit.rb +16 -0
  32. data/recipes/mysql.rb +24 -0
  33. data/recipes/nginx.rb +42 -0
  34. data/recipes/profiles/centos-sick.rb +65 -0
  35. data/recipes/rails.rb +14 -0
  36. data/recipes/ruby.rb +14 -0
  37. data/recipes/sphinx.rb +62 -0
  38. data/script/destroy +14 -0
  39. data/script/generate +14 -0
  40. data/script/txt2html +74 -0
  41. data/setup.rb +1585 -0
  42. data/tasks/capigen.rake +13 -0
  43. data/tasks/deployment.rake +34 -0
  44. data/tasks/environment.rake +7 -0
  45. data/tasks/website.rake +17 -0
  46. data/templates/capistrano/Capfile +22 -0
  47. data/templates/capistrano/deploy.rb.erb +61 -0
  48. data/templates/centos/setup.sh +17 -0
  49. data/templates/centos/sudoers +95 -0
  50. data/templates/imagemagick/install.sh +20 -0
  51. data/templates/memcached/install.sh +27 -0
  52. data/templates/memcached/memcached.initd.centos.erb +70 -0
  53. data/templates/memcached/memcached.monitrc.erb +4 -0
  54. data/templates/mongrel/mongrel_cluster.initd.erb +61 -0
  55. data/templates/mongrel/mongrel_cluster.monitrc.erb +15 -0
  56. data/templates/mongrel/mongrel_cluster.yml.erb +10 -0
  57. data/templates/monit/cert.sh +14 -0
  58. data/templates/monit/install.sh +29 -0
  59. data/templates/monit/monit.cnf +34 -0
  60. data/templates/monit/monit.initd.centos.erb +68 -0
  61. data/templates/monit/monitrc.erb +28 -0
  62. data/templates/monit/patch_inittab.sh +15 -0
  63. data/templates/mysql/install.sh.erb +10 -0
  64. data/templates/mysql/install_db.sql.erb +5 -0
  65. data/templates/mysql/mysql.monitrc.erb +6 -0
  66. data/templates/nginx/install.sh.erb +42 -0
  67. data/templates/nginx/nginx.conf.erb +76 -0
  68. data/templates/nginx/nginx.initd.erb +62 -0
  69. data/templates/nginx/nginx.monitrc.erb +4 -0
  70. data/templates/nginx/nginx_vhost.conf.erb +94 -0
  71. data/templates/rails/database.yml.erb +42 -0
  72. data/templates/ruby/ruby_install.sh +26 -0
  73. data/templates/ruby/rubygems_install.sh +13 -0
  74. data/templates/sphinx/install.sh.erb +22 -0
  75. data/templates/sphinx/sphinx.conf.erb +496 -0
  76. data/templates/sphinx/sphinx.monitrc.erb +4 -0
  77. data/templates/sphinx/sphinx_app.initd.centos.erb +67 -0
  78. data/templates/sphinx/sphinx_app.initd.erb +57 -0
  79. data/website/index.html +93 -0
  80. data/website/index.txt +39 -0
  81. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  82. data/website/stylesheets/screen.css +138 -0
  83. data/website/template.rhtml +48 -0
  84. metadata +141 -0
data/lib/capigen.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'active_support'
2
+ require 'highline'
3
+
4
+ HighLine.track_eof = false
5
+
6
+ $:.unshift File.dirname(__FILE__)
7
+
8
+ module Capigen
9
+ module Helpers
10
+ end
11
+
12
+ module Packagers
13
+ end
14
+ end
15
+
16
+ require "capigen/packagers/yum"
17
+
18
+ require "capigen/helpers/package_helper"
19
+ require "capigen/helpers/wget_helper"
20
+ require "capigen/helpers/script_helper"
21
+ require "capigen/helpers/gem_helper"
22
+ require "capigen/templates"
23
+ require "capigen/profiles"
24
+ require "capigen/helper"
25
+
26
+ require "capigen/config"
data/recipes/README ADDED
@@ -0,0 +1,12 @@
1
+ = Recipes
2
+
3
+ Install tasks are one time tasks (per image).
4
+
5
+ Setup tasks are one time tasks (per application).
6
+
7
+ Update code tasks are called after each deploy (per application).
8
+
9
+
10
+ The bootstrap/patch.rb is not a recipe but is to include Capigen helpers for use within recipes.
11
+
12
+ Scripts and templates are in ./templates
@@ -0,0 +1,87 @@
1
+ #
2
+ # Patches
3
+ #
4
+
5
+ class Capistrano::Configuration::Namespaces::Namespace
6
+
7
+ # Load config helper for use within recipes
8
+ require File.dirname(__FILE__) + "/../../init"
9
+ include Capigen::Helper
10
+
11
+ end
12
+
13
+ class Capistrano::Configuration
14
+ # Load config helper for use within Capfile
15
+ require File.dirname(__FILE__) + "/../../init"
16
+ include Capigen::Helper
17
+
18
+ end
19
+
20
+
21
+ # Patch to add ability to clear sessions
22
+ module Capistrano::Configuration::Connections
23
+
24
+ # Set the user to something new (but save the old user; reset_user will set it back)
25
+ def set_user(new_user)
26
+ backup_user = fetch(:user)
27
+
28
+ return if backup_user == new_user
29
+ @backup_user = backup_user
30
+
31
+ set :user, new_user
32
+ clear_sessions
33
+ end
34
+
35
+ # Reset the old user
36
+ def reset_user
37
+ set :user, @backup_user
38
+ @backup_user = nil
39
+ clear_sessions
40
+ end
41
+
42
+ # Yields the previous user
43
+ def with_user(new_user, &block)
44
+ begin
45
+ set_user(new_user)
46
+ yield @backup_user
47
+ ensure
48
+ reset_user
49
+ end
50
+
51
+ clear_sessions
52
+ end
53
+
54
+ # Close all open session
55
+ def clear_sessions
56
+ sessions.each do |key, session|
57
+ logger.info "Closing: #{key}"
58
+ session.close
59
+ end
60
+ sessions.clear
61
+ reset_password
62
+ end
63
+
64
+ # Reset the password
65
+ def reset_password
66
+ set :password, Proc.new {
67
+ Capistrano::CLI.password_prompt("Password (for #{user}): ")
68
+ }
69
+ end
70
+
71
+ end
72
+
73
+ reset_password
74
+
75
+ # Debug connections
76
+ # class Capistrano::SSH
77
+ #
78
+ # class << self
79
+ #
80
+ # def connect_with_logging(server, options={}, &block)
81
+ # connect_without_logging(server, options, &block)
82
+ # end
83
+ #
84
+ # alias_method_chain :connect, :logging
85
+ #
86
+ # end
87
+ # end
data/recipes/centos.rb ADDED
@@ -0,0 +1,40 @@
1
+ # Tasks for centos OS profiles
2
+ namespace :centos do
3
+
4
+ desc "Setup centos"
5
+ task :setup do
6
+ put load_file("centos/sudoers"), "/tmp/sudoers"
7
+ script_install("centos/setup.sh")
8
+ end
9
+
10
+
11
+ desc "Cleanup"
12
+ task :cleanup do
13
+ package_clean
14
+ end
15
+
16
+ # Add user for an application
17
+ desc "Add user (adds to admin group)"
18
+ task :add_user_for_app do
19
+
20
+ with_user(bootstrap_user) do |user_to_add|
21
+
22
+ sudo "id sick || /usr/sbin/adduser -d #{deploy_to} -G admin #{user_to_add}"
23
+ sudo "chmod a+rx #{deploy_to}"
24
+
25
+ new_password = Capistrano::CLI.password_prompt("Password for user (#{user_to_add}): ")
26
+
27
+ sudo "passwd #{user_to_add}" do |channel, stream, data|
28
+ logger.info data
29
+
30
+ if data =~ /password:/i
31
+ channel.send_data "#{new_password}\n"
32
+ channel.send_data "#{new_password}\n"
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+ end
data/recipes/deploy.rb ADDED
@@ -0,0 +1,17 @@
1
+ # Override default deploy tasks here (using Monit).
2
+ # If not using monit, use service start/stop, #sudo "/sbin/service mongrel_cluster_#{application} restart"
3
+ namespace :deploy do
4
+
5
+ task :restart, :roles => :web do
6
+ sudo "/usr/local/bin/monit -g mongrel_cluster_#{application} restart all"
7
+ end
8
+
9
+ task :start, :roles => :web do
10
+ sudo "/usr/local/bin/monit -g mongrel_cluster_#{application} start all"
11
+ end
12
+
13
+ task :stop, :roles => :web do
14
+ sudo "/usr/local/bin/monit -g mongrel_cluster_#{application} stop all"
15
+ end
16
+
17
+ end
data/recipes/gems.rb ADDED
@@ -0,0 +1,8 @@
1
+ namespace :gems do
2
+
3
+ desc "Install gems"
4
+ task :install do
5
+ gem_install(gem_list) if gem_list
6
+ end
7
+
8
+ end
@@ -0,0 +1,9 @@
1
+ namespace :imagemagick do
2
+
3
+ task :install do
4
+ # Dependencies: "libjpeg-devel", "libpng-devel", "glib2-devel", "fontconfig-devel", "zlib-devel",
5
+ # "libwmf-devel", "freetype-devel", "libtiff-devel"
6
+ script_install("imagemagick/install.sh")
7
+ end
8
+
9
+ end
@@ -0,0 +1,13 @@
1
+ namespace :install do
2
+
3
+ task :default do
4
+ # Choose profile, and load capistrano settings
5
+ fetch(:profile)
6
+
7
+ # These run after install task and install all the apps
8
+ install_tasks.each do |task_name|
9
+ after "install", task_name
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,15 @@
1
+ namespace :memcached do
2
+
3
+ desc "Install memcached"
4
+ task :install do
5
+ put load_template("memcached/memcached.initd.centos.erb", binding), "/tmp/memcached.initd"
6
+ script_install("memcached/install.sh")
7
+ end
8
+
9
+ desc "Install memcached monit hooks"
10
+ task :install_monit do
11
+ put load_template("memcached/memcached.monitrc.erb", binding), "/tmp/memcached.monitrc"
12
+ script_install("memcached/install_monit.sh")
13
+ end
14
+
15
+ end
@@ -0,0 +1,49 @@
1
+ # Create init script
2
+ namespace :mongrel_cluster do
3
+
4
+ after "mongrel_cluster:setup", "mongrel_cluster:setup_monit"
5
+
6
+ desc "Create mongrel cluster"
7
+ task :setup do
8
+ run "mkdir -p #{shared_path}/config"
9
+
10
+ # Mongrel cluster config needs its own config directory
11
+ mongrel_config_path = "#{shared_path}/config/mongrel"
12
+ run "mkdir -p #{mongrel_config_path}"
13
+
14
+ pid_path = "#{shared_path}/pids"
15
+
16
+ put load_template("mongrel/mongrel_cluster.initd.erb", binding), "/tmp/mongrel_cluster_#{application}.initd"
17
+ put load_template("mongrel/mongrel_cluster.yml.erb", binding), "#{mongrel_config_path}/mongrel_cluster.yml"
18
+
19
+ # Setup the mongrel_cluster init script
20
+ sudo "install -o root /tmp/mongrel_cluster_#{application}.initd /etc/init.d/mongrel_cluster_#{application}"
21
+
22
+ sudo "/sbin/chkconfig --level 345 mongrel_cluster_#{application} on"
23
+ end
24
+
25
+ desc "Create monit configuration for mongrel cluster"
26
+ task :setup_monit do
27
+
28
+ # see http://www.igvita.com/2006/11/07/monit-makes-mongrel-play-nice/
29
+
30
+ # TODO: For depends on memcached setting
31
+ # see http://blog.labratz.net/articles/2007/5/1/monit-for-your-uptime
32
+
33
+ processes = []
34
+ ports = (0...mongrel_size).collect { |i| mongrel_port + i }
35
+ ports.each do |port|
36
+
37
+ pid_path = "#{shared_path}/pids/mongrel.#{port}.pid"
38
+ start_options = "-d -e production -a 127.0.0.1 -c #{current_path} --user #{user} --group #{user} -p #{port} -P #{pid_path} -l log/mongrel.#{port}.log"
39
+ stop_options = "-p #{port} -P #{pid_path}"
40
+
41
+ processes << { :port => port, :start_options => start_options, :stop_options => stop_options, :name => "/usr/bin/mongrel_rails", :pid_path => pid_path }
42
+ end
43
+
44
+ put load_template("mongrel/mongrel_cluster.monitrc.erb", binding), "/tmp/mongrel_cluster_#{application}.monitrc"
45
+
46
+ sudo "install -o root /tmp/mongrel_cluster_#{application}.monitrc /etc/monit/mongrel_cluster_#{application}.monitrc"
47
+ end
48
+
49
+ end
data/recipes/monit.rb ADDED
@@ -0,0 +1,16 @@
1
+ namespace :monit do
2
+
3
+ desc "Install monit"
4
+ task :install do
5
+ # Dependencies: "flex", "byacc"
6
+
7
+ put load_template("monit/monit.initd.centos.erb", binding), "/tmp/monit.initd"
8
+ put load_template("monit/monitrc.erb", binding), "/tmp/monitrc"
9
+ put load_file("monit/monit.cnf"), "/tmp/monit.cnf"
10
+
11
+ script_install("monit/install.sh")
12
+ script_install("monit/patch_inittab.sh")
13
+ script_install("monit/cert.sh")
14
+ end
15
+
16
+ end
data/recipes/mysql.rb ADDED
@@ -0,0 +1,24 @@
1
+ # Mysql recipes
2
+ namespace :mysql do
3
+
4
+ desc "Install mysql"
5
+ task :install do
6
+ script_install("mysql/install.sh.erb")
7
+ end
8
+
9
+ desc "Install mysql monit hooks"
10
+ task :install_monit do
11
+ put load_template("mysql/mysql.monitrc.erb", binding), "/tmp/mysql.monitrc"
12
+ script_install("mysql/install_monit.sh")
13
+ end
14
+
15
+ desc "Create database user, and database with appropriate permissions"
16
+ task :setup do
17
+ # Add localhost to grant locations
18
+ locations_for_grant = [ "localhost", web_host ]
19
+
20
+ put load_template("mysql/install_db.sql.erb", binding), "/tmp/install_db_#{application}.sql"
21
+ run "mysql -u root -p#{mysql_admin_password} < /tmp/install_db_#{application}.sql"
22
+ end
23
+
24
+ end
data/recipes/nginx.rb ADDED
@@ -0,0 +1,42 @@
1
+ # Nginx recipes
2
+ namespace :nginx do
3
+
4
+ # Callbacks
5
+ after "nginx:setup", "nginx:restart"
6
+
7
+ desc "Install nginx, conf, initscript, nginx user and service"
8
+ task :install do
9
+ # Dependencies: "pcre-devel", "openssl", "openssl-devel"
10
+
11
+ put(load_template("nginx/nginx.initd.erb", binding), "/tmp/nginx.initd")
12
+ put(load_template("nginx/nginx.conf.erb", binding), "/tmp/nginx.conf")
13
+
14
+ script_install("nginx/install.sh.erb")
15
+ end
16
+
17
+ desc "Install nginx monit hooks"
18
+ task :install_monit do
19
+ put load_template("nginx/nginx.monitrc.erb", binding), "/tmp/nginx.monitrc"
20
+ script_install("nginx/install_monit.sh")
21
+ end
22
+
23
+
24
+ desc "Create and update the nginx vhost include"
25
+ task :setup do
26
+
27
+ ports = (0...mongrel_size).collect { |i| mongrel_port + i }
28
+ public_path = current_path + "/public"
29
+
30
+ run "mkdir -p #{shared_path}/config"
31
+ put load_template("nginx/nginx_vhost.conf.erb", binding), "/tmp/nginx_#{application}.conf"
32
+
33
+ sudo "install -o root /tmp/nginx_#{application}.conf /etc/nginx/vhosts/#{application}.conf"
34
+ end
35
+
36
+ # Restart nginx
37
+ task :restart do
38
+ # TODO: Monit
39
+ sudo "/sbin/service nginx restart"
40
+ end
41
+
42
+ end
@@ -0,0 +1,65 @@
1
+ set :namespace, "centos"
2
+ set :description, "Install based on default centos 5.1 image"
3
+ set :packager_type, "yum"
4
+ set :packages_to_remove, [ "openoffice.org-*", "ImageMagick" ]
5
+ set :packages_to_add, [
6
+ "gcc", "kernel-devel", "libevent-devel", "libxml2-devel",
7
+ "openssl", "openssl-devel",
8
+ "aspell", "aspell-devel", "aspell-en", "aspell-es",
9
+ "zlib", "zlib-devel",
10
+ "gcc-c++",
11
+ "pcre-devel",
12
+ "mysql", "mysql-devel", "mysql-server",
13
+ "flex", "byacc",
14
+ "libjpeg-devel", "libpng-devel", "glib2-devel", "fontconfig-devel", "libwmf-devel", "freetype-devel",
15
+ "libtiff-devel"
16
+ ]
17
+
18
+ set :install_tasks, [
19
+ "centos:setup",
20
+ "packages:install",
21
+ "ruby:install",
22
+ "nginx:install",
23
+ "nginx:install_monit",
24
+ "mysql:install",
25
+ "mysql:install_monit",
26
+ "sphinx:install",
27
+ "monit:install",
28
+ "imagemagick:install",
29
+ "memcached:install",
30
+ "memcached:install_monit",
31
+ "gems:install",
32
+ "centos:cleanup"
33
+ ]
34
+
35
+ set :gem_list, [
36
+ "rake",
37
+ "mysql -- --with-mysql-include=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql --with-mysql-config",
38
+ "raspell", "rmagick", "mongrel", "mongrel_cluster"
39
+ ]
40
+
41
+ # Monit
42
+ set :monit_port, 2812 # Capistrano::CLI.ui.ask('Monit port: ')
43
+ set :monit_password, Capistrano::CLI.ui.ask('Monit admin password (to set): ')
44
+
45
+ # For nginx
46
+ set :nginx_bin_path, "/sbin/nginx"
47
+ set :nginx_conf_path, "/etc/nginx/nginx.conf"
48
+ set :nginx_pid_path, "/var/run/nginx.pid"
49
+ set :nginx_prefix_path, "/var/nginx"
50
+
51
+ # Mysql
52
+ set :mysql_admin_password, Capistrano::CLI.ui.ask('Mysql admin password (to set): ')
53
+ set :mysql_pid_path, "/var/run/mysqld/mysqld.pid"
54
+ set :db_port, 3306 # Capistrano::CLI.ui.ask('Mysql port: ')
55
+
56
+ # Sphinx
57
+ set :sphinx_prefix, "/usr/local/sphinx"
58
+
59
+ # Memcached
60
+ set :memcached_pid_path, "/var/run/memcached.pid"
61
+ set :memcached_memory, 64
62
+ set :memcached_port, 11211
63
+
64
+
65
+
data/recipes/rails.rb ADDED
@@ -0,0 +1,14 @@
1
+ # Rails recipes
2
+ namespace :rails do
3
+
4
+ desc "Create database yaml in shared path"
5
+ task :setup do
6
+ run "mkdir -p #{shared_path}/config"
7
+ put load_template("rails/database.yml.erb", binding), "#{shared_path}/config/database.yml"
8
+ end
9
+
10
+ desc "Make symlink for database yaml"
11
+ task :update_code do
12
+ run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
13
+ end
14
+ end
data/recipes/ruby.rb ADDED
@@ -0,0 +1,14 @@
1
+ namespace :ruby do
2
+
3
+ desc "Install ruby and rubygems"
4
+ task :install do
5
+ # Dependencies: zlib, zlib-devel
6
+
7
+ # Install ruby 1.8.6
8
+ script_install("ruby/ruby_install.sh")
9
+
10
+ # Install rubygems
11
+ script_install("ruby/rubygems_install.sh")
12
+ end
13
+
14
+ end
data/recipes/sphinx.rb ADDED
@@ -0,0 +1,62 @@
1
+ # Sphinx recipes
2
+ namespace :sphinx do
3
+
4
+ after "sphinx:setup", "sphinx:setup_monit"
5
+
6
+ desc "Install sphinx"
7
+ task :install do
8
+ # Dependencies: gcc-c++
9
+ script_install("sphinx/install.sh.erb")
10
+ end
11
+
12
+ desc "Setup sphinx for application"
13
+ task :setup do
14
+
15
+ sphinx_bin_path = "#{sphinx_prefix}/bin"
16
+ sphinx_conf_path = "#{shared_path}/config/sphinx.conf"
17
+ sphinx_pid_path = "#{shared_path}/pids/searchd.pid"
18
+
19
+ put load_template("sphinx/sphinx_app.initd.centos.erb", binding), "/tmp/sphinx.initd"
20
+
21
+ sudo "install -o root /tmp/sphinx.initd /etc/init.d/sphinx_#{application}"
22
+
23
+ sudo "/sbin/chkconfig --level 345 sphinx_#{application} on"
24
+
25
+ run "mkdir -p #{shared_path}/var/index"
26
+ end
27
+
28
+ desc "Create monit configuration for sphinx"
29
+ task :setup_monit do
30
+ sphinx_pid_path = "#{shared_path}/pids/searchd.pid"
31
+ put load_template("sphinx/sphinx.monitrc.erb", binding), "/tmp/sphinx_#{application}.monitrc"
32
+
33
+ sudo "install -o root /tmp/sphinx_#{application}.monitrc /etc/monit/sphinx_#{application}.monitrc"
34
+ end
35
+
36
+ desc "Update sphinx for application"
37
+ task :update_code do
38
+
39
+ rails_root = current_path
40
+ index_root = "#{shared_path}/var/index";
41
+ log_root = "#{shared_path}/log"
42
+ pid_root = "#{shared_path}/pids"
43
+
44
+ put load_project_template("config/templates/sphinx.conf.erb", binding), "#{shared_path}/config/sphinx.conf"
45
+ end
46
+
47
+ desc "Rotate sphinx index for application"
48
+ task :rotate_all do
49
+ run "#{sphinx_prefix}/bin/indexer --config #{shared_path}/config/sphinx.conf --rotate --all"
50
+ end
51
+
52
+ desc "Build sphinx indexes for application"
53
+ task :index_all do
54
+ run "#{sphinx_prefix}/bin/indexer --config #{shared_path}/config/sphinx.conf --all"
55
+ end
56
+
57
+ desc "Start sphinx"
58
+ task :start do
59
+ # TODO: Monit
60
+ sudo "/sbin/service monit restart sphinx_#{application}"
61
+ end
62
+ end
data/script/destroy ADDED
@@ -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, :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.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/capigen/version.rb'
15
+
16
+ version = Capigen::VERSION::STRING
17
+ download = 'http://rubyforge.org/projects/capigen'
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)