rocketstarter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,232 @@
1
+ require 'optparse'
2
+ require "yaml"
3
+ require "readline"
4
+
5
+
6
+ class Rocket_starter_options < Hash
7
+ @@version = [ 0, 0, 1 ]
8
+ @@product_name = "rocket_starter"
9
+
10
+ @@command_line_params = {}
11
+
12
+ def initialize
13
+ super()
14
+
15
+ # default values
16
+ self[:project] = ""
17
+ self[:rocket_starter_conf_path] = ""
18
+ self[:rocket_starter_conf_path] = ENV['ROCKET_STARTER_CONF'] unless ENV['ROCKET_STARTER_CONF'].nil?
19
+ self[:init] = false
20
+ self.merge(Rocket_starter_options::static_default_values)
21
+
22
+ end
23
+
24
+
25
+ def parse
26
+
27
+
28
+ @@opts = OptionParser.new do |opts|
29
+ opts.banner = "Usage: #{@@product_name} project-name [options]"
30
+ opts.separator "Usage: #{@@product_name} --init [options]"
31
+ opts.separator "Usage: #{@@product_name} --check [options]"
32
+ opts.separator "version #{@@version.join('.')}"
33
+
34
+ opts.separator ""
35
+ opts.separator "Useful Options:"
36
+ opts.separator ""
37
+
38
+ opts.on( '--conf=/path/to/conffile', 'change conf file path(static < conf < command line params)' ) do |p|
39
+ self[:rocket_starter_conf_path] = p
40
+ end
41
+
42
+ opts.on( '--scmtype=[svn|git]', 'choose SCM type. default is svn' ) do |p|
43
+ @@command_line_params[:scmtype] = p
44
+ end
45
+
46
+ opts.on( '--scmuri=URI', 'use provided URI for SCM(if need, use with "username@")' ) do |p|
47
+ @@command_line_params[:scmuri] = p
48
+ end
49
+
50
+ opts.on( '--scmpassword=PASSWORD', 'use supplied password for SCM' ) do |p|
51
+ @@command_line_params[:scmpassword] = p
52
+ end
53
+
54
+ opts.on( '--database=name', 'paramater for rails. default is ""' ) do |p|
55
+ @@command_line_params[:database] = p
56
+ end
57
+
58
+ opts.on( '--ignoredatabase', 'set ingore for database.yml') do
59
+ @@command_line_params[:ignoredatabase] = true
60
+ end
61
+
62
+ opts.on( '--verbose', 'provide extra output while running') do
63
+ @@command_line_params[:verbose] = true
64
+ end
65
+
66
+ opts.on( '--sudo', 'use sudo command') do
67
+ @@command_line_params[:sudo] = true
68
+ end
69
+
70
+ opts.on( '--log', 'create a log of command activity' ) do
71
+ @@command_line_params[:logging] = true
72
+ end
73
+
74
+ opts.on( '--logfile=/path/to/logfile', 'Set path to logfile' ) do |p|
75
+ @@command_line_params[:log_file] = p
76
+ end
77
+
78
+ opts.on( '--skip-netbeans', 'skip to setup propset for netbeans ide' ) do
79
+ @@command_line_params[:skip_netbeans] = true
80
+ end
81
+
82
+ opts.on( '--listpath=/path/to/listfile', 'plugin url list path for setup' ) do |p|
83
+ @@command_line_params[:pluginlist_path] = p
84
+ end
85
+
86
+ opts.on( '--skip-plugins', 'skip to setup plugins' ) do
87
+ @@command_line_params[:skip_plugins] = true
88
+ end
89
+
90
+ opts.on( '--rapt', 'use RaPT gem for plugins' ) do
91
+ @@command_line_params[:rapt] = true
92
+ end
93
+
94
+ opts.on( '--externals', 'use svn:externals for plugins' ) do
95
+ @@command_line_params[:external] = true
96
+ end
97
+
98
+ opts.on( '--emulate', 'enable emulation mode' ) do
99
+ @@command_line_params[:emulate] = true
100
+ end
101
+
102
+ opts.separator ""
103
+ opts.separator "General Options:"
104
+ opts.separator ""
105
+
106
+ opts.on( '-h', '--help', 'display this information' ) do
107
+ puts opts
108
+ exit
109
+ end
110
+
111
+ opts.on( '-v', '--version', 'display version information' ) do
112
+ puts "Ruby on Rails environment setup tool: #{@@product_name} version #{@@version.join('.')}"
113
+ exit
114
+ end
115
+
116
+ opts.on( '--init', 'setup a template of conf file' ) do
117
+ self[:init] = true
118
+ end
119
+
120
+ self[:check] = false
121
+ opts.on( '--check', 'check current variables' ) do
122
+ self[:check] = true
123
+ end
124
+
125
+ opts.separator ""
126
+ opts.separator "Notice:"
127
+ opts.separator ""
128
+ opts.separator "Paramater priority: static < conf < command line"
129
+ opts.separator "You can use a environment variable ROCKET_STARTER_CONF for a rocket_starter_conf_file"
130
+ opts.separator "conf path priority: env < command line"
131
+
132
+ end
133
+
134
+ validate_project_name
135
+ @@opts.parse!
136
+ marge_values
137
+ if self[:check] or "--check" == self[:project]
138
+ puts "current variables"
139
+ self.each_pair do |key, value| puts "#{key}:#{value}" end
140
+ exit
141
+ end
142
+ if self[:init] or "--init" == self[:project]
143
+ put_conf_file
144
+ exit
145
+ end
146
+ self
147
+ end
148
+
149
+ # write a template conf file to rocket_starter_conf_path
150
+ def put_conf_file
151
+ # check put path
152
+ Rocket_starter_options::error_with_show_usage "conf path is empty. set ROCKET_STARTER_CONF environment variable or use --conf paramater." if self[:rocket_starter_conf_path].empty?
153
+
154
+ unless "y" == Readline.readline("would a template file put to #{self[:rocket_starter_conf_path]}? [y/N] > ").downcase
155
+ puts "Set your conf path to ROCKET_STARTER_CONF environment variable or use --conf paramater."
156
+ exit
157
+ end
158
+
159
+ begin
160
+ File.open(self[:rocket_starter_conf_path]) do |yamlfile|
161
+ # check overwrite?
162
+ exit unless "y" == Readline.readline("Overwrite? [y/N]").downcase
163
+ end
164
+ rescue
165
+ end
166
+
167
+ begin
168
+ File.open(self[:rocket_starter_conf_path], "w") do |yamlfile|
169
+ yamlfile.puts "# Rocket_starter conf file"
170
+ yamlfile.puts ""
171
+ yamlfile.puts Rocket_starter_options::static_default_values.to_yaml
172
+ end
173
+ puts "Put template yaml file to #{self[:rocket_starter_conf_path]}"
174
+ rescue
175
+ puts "Warning:Could not open for writing. check parmitions."
176
+ end
177
+ end
178
+
179
+ def self.error_with_show_usage(message)
180
+ puts "Error:" + message
181
+ Rocket_starter_options::show_usage
182
+ exit(1)
183
+ end
184
+
185
+ def self.show_usage
186
+ puts @@opts
187
+ end
188
+
189
+ def validate_project_name
190
+ temp = ARGV.first
191
+ unless temp.nil? or temp.empty?
192
+ @@command_line_params[:project] = temp.chomp
193
+ else
194
+ Rocket_starter_options::error_with_show_usage("Need project name.")
195
+ end
196
+ end
197
+
198
+ # default values if not use .rocket_starter file
199
+ def Rocket_starter_options.static_default_values
200
+ defaults = {}
201
+ defaults[:scmtype] = "svn"
202
+ defaults[:scmuri] = ""
203
+ defaults[:scmpassword] = ""
204
+ defaults[:database] = ""
205
+ defaults[:ignoredatabase] = false
206
+ defaults[:verbose] = false
207
+ defaults[:sudo] = false
208
+ defaults[:logging] = false
209
+ defaults[:log_file] = "./rocket_starter.log"
210
+ defaults[:skip_netbeans] = false
211
+ defaults[:pluginlist_path] = "./useful_plugins"
212
+ defaults[:skip_plugins] = false
213
+ defaults[:rapt] = false
214
+ defaults[:external] = false
215
+ defaults[:emulate] = false
216
+ defaults
217
+ end
218
+
219
+ # priority static < conf < command line params
220
+ def marge_values
221
+ conf_params = {}
222
+ # can open?
223
+ begin
224
+ File::open(self[:rocket_starter_conf_path]) do |conf_file|
225
+ conf_params = YAML.load(conf_file.read)
226
+ end
227
+ rescue
228
+ end
229
+ self.merge!(conf_params.merge!(@@command_line_params))
230
+ end
231
+
232
+ end
@@ -0,0 +1,9 @@
1
+ module Rocketstarter
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,9 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require File.dirname(__FILE__) + "/rocketstarter/rocket_starter_core"
5
+ require File.dirname(__FILE__) + "/rocketstarter/rocket_starter_options"
6
+
7
+ module Rocket_starter
8
+
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/rocketstarter.rb'}"
9
+ puts "Loading rocketstarter 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 = 'rocketstarter' # what ppl will type to install your gem
4
+ RUBYFORGE_PROJECT = 'rocketstarter'
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 = Rocketstarter::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)