adminpage_scaffold_generator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data.tar.gz.sig +0 -0
  2. data/History.txt +4 -0
  3. data/License.txt +20 -0
  4. data/Manifest.txt +73 -0
  5. data/PostInstall.txt +8 -0
  6. data/README.txt +48 -0
  7. data/Rakefile +4 -0
  8. data/USAGE +27 -0
  9. data/adminpage_scaffold_generator.rb +87 -0
  10. data/config/hoe.rb +73 -0
  11. data/config/requirements.rb +15 -0
  12. data/lib/adminpage.rb +6 -0
  13. data/lib/adminpage/version.rb +9 -0
  14. data/script/console +10 -0
  15. data/script/destroy +14 -0
  16. data/script/generate +14 -0
  17. data/script/txt2html +82 -0
  18. data/setup.rb +1585 -0
  19. data/spec/adminpage_spec.rb +11 -0
  20. data/spec/spec.opts +1 -0
  21. data/spec/spec_helper.rb +10 -0
  22. data/tasks/deployment.rake +34 -0
  23. data/tasks/environment.rake +7 -0
  24. data/tasks/rspec.rake +21 -0
  25. data/tasks/website.rake +17 -0
  26. data/templates/adminpage.css +344 -0
  27. data/templates/controller.rb +85 -0
  28. data/templates/functional_test.rb +45 -0
  29. data/templates/helper.rb +2 -0
  30. data/templates/images/add-icon.gif +0 -0
  31. data/templates/images/arrow.gif +0 -0
  32. data/templates/images/bg-center-column.jpg +0 -0
  33. data/templates/images/bg-dotted.gif +0 -0
  34. data/templates/images/bg-footer.gif +0 -0
  35. data/templates/images/bg-header.gif +0 -0
  36. data/templates/images/bg-left-header.gif +0 -0
  37. data/templates/images/bg-left-link.gif +0 -0
  38. data/templates/images/bg-middle.gif +0 -0
  39. data/templates/images/bg-orange-button.gif +0 -0
  40. data/templates/images/bg-select.gif +0 -0
  41. data/templates/images/bg-th-left.gif +0 -0
  42. data/templates/images/bg-th-right.gif +0 -0
  43. data/templates/images/delete.png +0 -0
  44. data/templates/images/edit-icon.gif +0 -0
  45. data/templates/images/exclamation.png +0 -0
  46. data/templates/images/hr.gif +0 -0
  47. data/templates/images/info.png +0 -0
  48. data/templates/images/login-icon.gif +0 -0
  49. data/templates/images/logo.gif +0 -0
  50. data/templates/images/logo_1.gif +0 -0
  51. data/templates/images/magnifier.png +0 -0
  52. data/templates/images/msg_Info.png +0 -0
  53. data/templates/images/msg_error.png +0 -0
  54. data/templates/images/msg_success.png +0 -0
  55. data/templates/images/msg_validation.png +0 -0
  56. data/templates/images/msg_warning.png +0 -0
  57. data/templates/images/save-icon.gif +0 -0
  58. data/templates/images/tab-active-left.gif +0 -0
  59. data/templates/images/tab-active-right.gif +0 -0
  60. data/templates/images/tab-active.gif +0 -0
  61. data/templates/images/tab-left.gif +0 -0
  62. data/templates/images/tab-right.gif +0 -0
  63. data/templates/images/tab.gif +0 -0
  64. data/templates/layout.html.erb +56 -0
  65. data/templates/messagebox.css +34 -0
  66. data/templates/view_edit.html.erb +35 -0
  67. data/templates/view_index.html.erb +42 -0
  68. data/templates/view_new.html.erb +35 -0
  69. data/templates/view_show.html.erb +30 -0
  70. data/website/index.html +153 -0
  71. data/website/index.txt +85 -0
  72. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  73. data/website/stylesheets/screen.css +138 -0
  74. data/website/template.html.erb +48 -0
  75. metadata +170 -0
  76. metadata.gz.sig +0 -0
data.tar.gz.sig ADDED
Binary file
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-07-14
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Yusuke Ohmichi(Maimuzo)
2
+
3
+ This code is free to use under the terms of the GPL version 3 license.
4
+ See:
5
+ http://www.gnu.org/licenses/gpl.html
6
+
7
+ Small(16x16) icons are licensed under a Creative Commons Attribution 2.5 License.
8
+ http://creativecommons.org/licenses/by/2.5/
9
+ and
10
+ http://www.famfamfam.com/lab/icons/silk/
11
+
12
+ Middle(32x32) icons are free to use under the Free License.
13
+ See:
14
+ http://itweek.deviantart.com/art/Knob-Buttons-Toolbar-icons-73463960
15
+
16
+ This template files (layout, index, add, edit, show, CSS and more) are free to use under the Free License.
17
+ See:
18
+ http://www.webresourcesdepot.com/
19
+
20
+
data/Manifest.txt ADDED
@@ -0,0 +1,73 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ PostInstall.txt
5
+ README.txt
6
+ Rakefile
7
+ USAGE
8
+ adminpage_scaffold_generator.rb
9
+ config/hoe.rb
10
+ config/requirements.rb
11
+ lib/adminpage.rb
12
+ lib/adminpage/version.rb
13
+ script/console
14
+ script/destroy
15
+ script/generate
16
+ script/txt2html
17
+ setup.rb
18
+ spec/adminpage_spec.rb
19
+ spec/spec.opts
20
+ spec/spec_helper.rb
21
+ tasks/deployment.rake
22
+ tasks/environment.rake
23
+ tasks/rspec.rake
24
+ tasks/website.rake
25
+ templates/adminpage.css
26
+ templates/controller.rb
27
+ templates/functional_test.rb
28
+ templates/helper.rb
29
+ templates/images/add-icon.gif
30
+ templates/images/arrow.gif
31
+ templates/images/bg-center-column.jpg
32
+ templates/images/bg-dotted.gif
33
+ templates/images/bg-footer.gif
34
+ templates/images/bg-header.gif
35
+ templates/images/bg-left-header.gif
36
+ templates/images/bg-left-link.gif
37
+ templates/images/bg-middle.gif
38
+ templates/images/bg-orange-button.gif
39
+ templates/images/bg-select.gif
40
+ templates/images/bg-th-left.gif
41
+ templates/images/bg-th-right.gif
42
+ templates/images/delete.png
43
+ templates/images/edit-icon.gif
44
+ templates/images/exclamation.png
45
+ templates/images/hr.gif
46
+ templates/images/info.png
47
+ templates/images/login-icon.gif
48
+ templates/images/logo.gif
49
+ templates/images/logo_1.gif
50
+ templates/images/magnifier.png
51
+ templates/images/msg_Info.png
52
+ templates/images/msg_error.png
53
+ templates/images/msg_success.png
54
+ templates/images/msg_validation.png
55
+ templates/images/msg_warning.png
56
+ templates/images/save-icon.gif
57
+ templates/images/tab-active-left.gif
58
+ templates/images/tab-active-right.gif
59
+ templates/images/tab-active.gif
60
+ templates/images/tab-left.gif
61
+ templates/images/tab-right.gif
62
+ templates/images/tab.gif
63
+ templates/layout.html.erb
64
+ templates/messagebox.css
65
+ templates/view_edit.html.erb
66
+ templates/view_index.html.erb
67
+ templates/view_new.html.erb
68
+ templates/view_show.html.erb
69
+ website/index.html
70
+ website/index.txt
71
+ website/javascripts/rounded_corners_lite.inc.js
72
+ website/stylesheets/screen.css
73
+ website/template.html.erb
data/PostInstall.txt ADDED
@@ -0,0 +1,8 @@
1
+
2
+ (YOUR_RAILS_ROOT)$ script/generate adminpage_scaffold model [column:type [column:type]]
3
+
4
+ See more options:
5
+ (YOUR_RAILS_ROOT)$ script/generate adminpage_scaffold --help
6
+
7
+ For more information on adminpage_scaffold_generator, see http://adminpage.rubyforge.org
8
+
data/README.txt ADDED
@@ -0,0 +1,48 @@
1
+ = adminpage
2
+
3
+ * http://adminpage.rubyforge.org/
4
+
5
+ == DESCRIPTION:
6
+
7
+ You can generate template files easy and beautiful by this scaffold generator for Ruby on Rails.
8
+ These templates are based on:
9
+ http://www.webresourcesdepot.com/free-admin-template-for-web-applications/
10
+
11
+ == FEATURES/PROBLEMS:
12
+
13
+ * You can create admin-pages easily.
14
+
15
+ == SYNOPSIS:
16
+
17
+ $ cd (YOUR_RAILS_ROOT)
18
+ $ scirpt/generate adminpage_scaffold (MODEL NAME) [(COLUMN NAME):(TYPE) [(COLUMN NAME):(TYPE)]]
19
+
20
+ == REQUIREMENTS:
21
+
22
+ * rails ver 2.1.0
23
+
24
+ == INSTALL:
25
+
26
+ * sudo gem install adminpage
27
+
28
+ == LICENSE:
29
+
30
+ Copyright (c) 2008 Yusuke Ohmichi(Maimuzo)
31
+
32
+ This code is free to use under the terms of the GPL version 3 license.
33
+ See:
34
+ http://www.gnu.org/licenses/gpl.html
35
+
36
+ Small(16x16) icons are licensed under a Creative Commons Attribution 2.5 License.
37
+ http://creativecommons.org/licenses/by/2.5/
38
+ and
39
+ http://www.famfamfam.com/lab/icons/silk/
40
+
41
+ Middle(32x32) icons are free to use under the Free License.
42
+ See:
43
+ http://itweek.deviantart.com/art/Knob-Buttons-Toolbar-icons-73463960
44
+
45
+ This template files (layout, index, add, edit, show, CSS and more) are free to use under the Free License.
46
+ See:
47
+ http://www.webresourcesdepot.com/
48
+
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 }
data/USAGE ADDED
@@ -0,0 +1,27 @@
1
+ Description:
2
+ This logic is same as the default scaffold generator.
3
+ I changed erb files only.
4
+ So, you can use it like default scaffold parameters.
5
+
6
+ This code is free to use under the terms of the GPL version 3 license.
7
+ See:
8
+ http://www.gnu.org/licenses/gpl.html
9
+
10
+ Small(16x16) icons are licensed under a Creative Commons Attribution 2.5 License.
11
+ http://creativecommons.org/licenses/by/2.5/
12
+ and
13
+ http://www.famfamfam.com/lab/icons/silk/
14
+
15
+ Middle(32x32) icons are free to use under the Free License.
16
+ See:
17
+ http://itweek.deviantart.com/art/Knob-Buttons-Toolbar-icons-73463960
18
+
19
+ This template files (layout, index, add, edit, show, CSS and more) are free to use under the Free License.
20
+ See:
21
+ http://www.webresourcesdepot.com/
22
+
23
+ Example:
24
+ `./script/generate adminpage_scaffold post` # no attributes, view will be anemic
25
+ `./script/generate adminpage_scaffold post title:string body:text published:boolean`
26
+ `./script/generate adminpage_scaffold purchase order_id:integer amount:decimal`
27
+
@@ -0,0 +1,87 @@
1
+ class AdminpageScaffoldGenerator < ScaffoldGenerator
2
+ def manifest
3
+ record do |m|
4
+ # Check for class naming collisions.
5
+ m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
6
+ m.class_collisions(class_path, "#{class_name}")
7
+
8
+ # Controller, helper, views, test and stylesheets directories.
9
+ m.directory(File.join('app/models', class_path))
10
+ m.directory(File.join('app/controllers', controller_class_path))
11
+ m.directory(File.join('app/helpers', controller_class_path))
12
+ m.directory(File.join('app/views', controller_class_path, controller_file_name))
13
+ m.directory(File.join('app/views/layouts', controller_class_path))
14
+ m.directory(File.join('test/functional', controller_class_path))
15
+ m.directory(File.join('test/unit', class_path))
16
+ m.directory(File.join('public/stylesheets', class_path))
17
+ m.directory(File.join('public/stylesheets/adminpage', class_path))
18
+ m.directory(File.join('public/images/adminpage', class_path))
19
+
20
+ for action in scaffold_views
21
+ m.template(
22
+ "view_#{action}.html.erb",
23
+ File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.erb")
24
+ )
25
+ end
26
+
27
+ # Layout and stylesheet.
28
+ m.template('layout.html.erb', File.join('app/views/layouts', controller_class_path, "#{controller_file_name}.html.erb"))
29
+ # m.template('style.css', 'public/stylesheets/scaffold.css')
30
+
31
+ # CSS for adminpage
32
+ m.template('adminpage.css', 'public/stylesheets/adminpage/adminpage.css')
33
+ m.template('messagebox.css', 'public/stylesheets/adminpage/messagebox.css')
34
+
35
+ # Images for adminpage
36
+ m.file('images/logo.gif', 'public/images/adminpage/logo.gif')
37
+ m.file('images/add-icon.gif', 'public/images/adminpage/add-icon.gif')
38
+ m.file('images/arrow.gif', 'public/images/adminpage/arrow.gif')
39
+ m.file('images/bg-center-column.jpg', 'public/images/adminpage/bg-center-column.jpg')
40
+ m.file('images/bg-dotted.gif', 'public/images/adminpage/bg-dotted.gif')
41
+ m.file('images/bg-footer.gif', 'public/images/adminpage/bg-footer.gif')
42
+ m.file('images/bg-header.gif', 'public/images/adminpage/bg-header.gif')
43
+ m.file('images/bg-left-header.gif', 'public/images/adminpage/bg-left-header.gif')
44
+ m.file('images/bg-left-link.gif', 'public/images/adminpage/bg-left-link.gif')
45
+ m.file('images/bg-middle.gif', 'public/images/adminpage/bg-middle.gif')
46
+ m.file('images/bg-orange-button.gif', 'public/images/adminpage/bg-orange-button.gif')
47
+ m.file('images/bg-select.gif', 'public/images/adminpage/bg-select.gif')
48
+ m.file('images/bg-th-left.gif', 'public/images/adminpage/bg-th-left.gif')
49
+ m.file('images/bg-th-right.gif', 'public/images/adminpage/bg-th-right.gif')
50
+ m.file('images/edit-icon.gif', 'public/images/adminpage/edit-icon.gif')
51
+ m.file('images/hr.gif', 'public/images/adminpage/hr.gif')
52
+ m.file('images/login-icon.gif', 'public/images/adminpage/login-icon.gif')
53
+ m.file('images/save-icon.gif', 'public/images/adminpage/save-icon.gif')
54
+ m.file('images/tab-active-left.gif', 'public/images/adminpage/tab-active-left.gif')
55
+ m.file('images/tab-active-right.gif', 'public/images/adminpage/tab-active-right.gif')
56
+ m.file('images/tab-active.gif', 'public/images/adminpage/tab-active.gif')
57
+ m.file('images/tab-left.gif', 'public/images/adminpage/tab-left.gif')
58
+ m.file('images/tab-right.gif', 'public/images/adminpage/tab-right.gif')
59
+ m.file('images/tab.gif', 'public/images/adminpage/tab.gif')
60
+ m.file('images/magnifier.png', 'public/images/adminpage/magnifier.png')
61
+ m.file('images/exclamation.png', 'public/images/adminpage/exclamation.png')
62
+ m.file('images/delete.png', 'public/images/adminpage/delete.png')
63
+ m.file('images/msg_error.png', 'public/images/adminpage/msg_error.png')
64
+ m.file('images/msg_info.png', 'public/images/adminpage/msg_info.png')
65
+ m.file('images/msg_success.png', 'public/images/adminpage/msg_success.png')
66
+ m.file('images/msg_validation.png', 'public/images/adminpage/msg_validation.png')
67
+ m.file('images/msg_warning.png', 'public/images/adminpage/msg_warning.png')
68
+
69
+
70
+ m.template(
71
+ 'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
72
+ )
73
+
74
+ m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
75
+ m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
76
+
77
+ m.route_resources controller_file_name
78
+
79
+ m.dependency 'model', [name] + @args, :collision => :skip
80
+ end
81
+ end
82
+ protected
83
+ # Override with your own usage banner.
84
+ def banner
85
+ "Usage: #{$0} adminpage_scaffold ModelName [field:type, field:type]"
86
+ end
87
+ end
data/config/hoe.rb ADDED
@@ -0,0 +1,73 @@
1
+ require 'adminpage/version'
2
+
3
+ AUTHOR = 'Yusuke Ohmichi(Maimuzo)' # can also be an array of Authors
4
+ EMAIL = "maimuzo@gmail.com"
5
+ DESCRIPTION = "You can generate template files easy and beautiful by this scaffold generator for Ruby on Rails. These templates are based on http://www.webresourcesdepot.com/free-admin-template-for-web-applications/"
6
+ GEM_NAME = 'adminpage_scaffold_generator' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'adminpage' # 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
+ ['rails', '>= 2.1.0']
12
+ ] # An array of rubygem dependencies [name, version]
13
+
14
+ @config_file = "~/.rubyforge/user-config.yml"
15
+ @config = nil
16
+ RUBYFORGE_USERNAME = "maimuzo"
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 = Adminpage::VERSION::STRING + (REV ? ".#{REV}" : "")
38
+ RDOC_OPTS = ['--quiet', '--title', 'adminpage 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]))
data/lib/adminpage.rb ADDED
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module Adminpage
5
+
6
+ end
@@ -0,0 +1,9 @@
1
+ module Adminpage
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ 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/adminpage.rb'}"
9
+ puts "Loading adminpage 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 = 'adminpage' # what ppl will type to install your gem
4
+ RUBYFORGE_PROJECT = 'adminpage'
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 = Adminpage::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)