kickstart 0.2

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 ADDED
@@ -0,0 +1,6 @@
1
+ == 0.1.0 / 2007-04-13
2
+
3
+ * First Commit!
4
+ * basic idea works. works well for generating a basic project
5
+ * svn stuff works too. pretty cool.
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,22 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/kickstart
6
+ lib/filebase.rb
7
+ lib/kickstart.rb
8
+ lib/keywords.rb
9
+ lib/scripting.rb
10
+ lib/plugins.rb
11
+ lib/rails_elements.rb
12
+ lib/cli_tools.rb
13
+ lib/repository.rb
14
+ lib/extentions/class.rb
15
+ lib/extentions/array.rb
16
+ lib/extentions/string.rb
17
+ kickstart_home/defaults.rb
18
+ kickstart_home/plugin_helper.rb
19
+ kickstart_home/samples/portfolio.rails
20
+ kickstart_home/samples/blahg.rails
21
+ kickstart_home/samples/twirp.rails
22
+
data/README.txt ADDED
@@ -0,0 +1,85 @@
1
+ kickstart
2
+ by Evan Short
3
+
4
+ == DESCRIPTION:
5
+
6
+ This project aims to take out some of the overhead of creating a
7
+ rails project, primarily by attacking initial design of a project,
8
+ plugin usage, and subversion preparation.
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ =features
13
+ * Prepare a project with the plugins you use most
14
+ * Create rspec models and resources with a new DSL
15
+ * define relationships
16
+ * setup plugins within models
17
+ * Starter maintenence on repo (removing logs, ignoring database.yml, etc) is already done
18
+
19
+ =problems
20
+ * does not yet set up databases
21
+ * cannot run the svn import script by itself
22
+
23
+ == SYNOPSIS:
24
+
25
+ first create a file project_name.rails
26
+
27
+ use_plugin :file_column
28
+
29
+ Repository.define "http://svn.whatever.com/project", {
30
+ :comment => 'adding for the first time',
31
+ :user => 'who'
32
+ }
33
+
34
+ resource(:post){ |post|
35
+ post.attrs :title => 'string', :body => 'text', :added_on => 'date'
36
+ post.has_many :categories, :through => :categorization
37
+ }
38
+
39
+ resource(:categorization){ |cat|
40
+ cat.belongs_to :post
41
+ cat.belongs_to :category
42
+ }
43
+
44
+ resource(:category){ |cat|
45
+ cat.attrs :name => 'string'
46
+ cat.has_many :posts, :through => :categorization
47
+ }
48
+
49
+ then run <tt>kickstart project_name.rails</tt>. Your resources will be created with the appropriate
50
+ migrations (belongs_to adds a key). once the script is finished you will need to edit database.yml
51
+ and migrate. your project and its repository are ready.
52
+
53
+ == REQUIREMENTS:
54
+
55
+ * Rails
56
+ * Rspec
57
+
58
+ == INSTALL:
59
+
60
+ * sudo gem install kickstart
61
+
62
+ == LICENSE:
63
+
64
+ (The MIT License)
65
+
66
+ Copyright (c) 2007 FIX
67
+
68
+ Permission is hereby granted, free of charge, to any person obtaining
69
+ a copy of this software and associated documentation files (the
70
+ 'Software'), to deal in the Software without restriction, including
71
+ without limitation the rights to use, copy, modify, merge, publish,
72
+ distribute, sublicense, and/or sell copies of the Software, and to
73
+ permit persons to whom the Software is furnished to do so, subject to
74
+ the following conditions:
75
+
76
+ The above copyright notice and this permission notice shall be
77
+ included in all copies or substantial portions of the Software.
78
+
79
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
80
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
81
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
82
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
83
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
84
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
85
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/kickstart.rb'
6
+
7
+ Hoe.new('kickstart', Kickstart::VERSION) do |p|
8
+ p.rubyforge_name = 'kickstart'
9
+ p.summary = 'this project is intended to give the initial steps of the rails process a nice kick in the pants, allowing you to define the initial parameters of a project in a unified way.'
10
+ # p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
11
+ # p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
12
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
13
+ end
14
+
15
+ # vim: syntax=Ruby
data/bin/kickstart ADDED
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ require File.dirname(__FILE__)+'/../lib/kickstart'
5
+
6
+ include FileBase
7
+ include Flagger
8
+ include CliTools
9
+ include Kickstart
10
+ include Kickstart::Keywords
11
+ include Kickstart::Plugins
12
+ include Kickstart::Scripting
13
+
14
+ flag(:sample => 's'){ |value|
15
+ @remaining_argument << "#{ENV['HOME']}/.kickstart/samples/#{value}.rails" if exists?(:folder, "#{ENV['HOME']}/.kickstart")
16
+ }
17
+
18
+ flag(:config => 'c'){
19
+ puts "\npreparing the ~/.kickstart folder\n"
20
+ copy "#{File.dirname(__FILE__)}/../kickstart_home/", "#{ENV['HOME']}/.kickstart" unless exists?(:folder, "#{ENV['HOME']}/.kickstart")
21
+ puts "\nvi #{ENV['HOME']}/.kickstart/plugin_helper.rb\n"
22
+ system "vi #{ENV['HOME']}/.kickstart/plugin_helper.rb"
23
+ puts "\nvi #{ENV['HOME']}/.kickstart/defaults.rb"
24
+ system "vi #{ENV['HOME']}/.kickstart/defaults.rb"
25
+ exit unless not remaining_argument.empty?
26
+ }
27
+
28
+ flag(:name => 'n'){ |value|
29
+ @project_name = (value || request_value('what name would you like this project to have?'))
30
+ }
31
+
32
+ seperate_arguments_from ARGV
33
+
34
+ process_command_line_input
35
+
36
+ if exists? :folder, "#{ENV['HOME']}/.kickstart"
37
+ $LOAD_PATH.unshift("#{ENV['HOME']}/.kickstart")
38
+ load 'defaults.rb'
39
+ end
40
+
41
+ before_setup
42
+ setup_project remaining_argument.first
43
+ goto_project @project_name+'_tmp'
44
+ after_setup
45
+
46
+ before_required_plugins
47
+ use_plugins required_plugins
48
+ after_required_plugins
49
+
50
+ before_kicking
51
+ kick_it!(@kickstarter)
52
+ after_kicking
53
+
54
+ separator
55
+
56
+ copy "config/database.yml", "config/database.example" if Repository.defined?
57
+
58
+ edit_db_config
59
+
60
+ before_create_databases
61
+ create_databases
62
+ after_create_databases
63
+
64
+ before_migrate
65
+ migrate
66
+ after_migrate
67
+
68
+ separator
69
+
70
+ before_edit_routes
71
+ edit_routes
72
+ after_edit_routes
73
+
74
+ delete_rails_index
75
+
76
+ if Repository.defined?
77
+ Repository.import
78
+ puts "moving out of the temporary directory\n\n"
79
+ Dir.chdir('../')
80
+ Repository.checkout @project_name
81
+ puts "\n\n"
82
+ goto_project
83
+ condition_repository
84
+ else
85
+ no_repository_defined
86
+ end
87
+
88
+ separator
89
+
90
+ before_start_server
91
+ start_server
92
+ finish
93
+ after_all
@@ -0,0 +1,17 @@
1
+
2
+ # this file is about to be executed.
3
+ # feel free to do with it as you see fit
4
+
5
+ require 'plugin_helper'
6
+
7
+ rspec_version = '0_7_5_1'
8
+
9
+ mysqladmin_user 'root'
10
+ request_mysqladmin_pass? false
11
+ edit_db_config? true
12
+ edit_routes? true
13
+ delete_rails_index? true
14
+
15
+ default_plugins << :spider_test
16
+
17
+ use_plugins default_plugins
@@ -0,0 +1,28 @@
1
+
2
+ # add plugins to be used or define sets of plugins to use
3
+ # either in the defaults or in a particular project
4
+
5
+ # e.g. use_plugins optional_plugins
6
+
7
+ module Kickstart
8
+ module Plugins
9
+
10
+ def plugin_bank
11
+ {
12
+ :file_column => 'http://opensvn.csie.org/rails_file_column/plugins/file_column/trunk',
13
+ :rspec_on_rails => "svn://rubyforge.org/var/svn/rspec/tags/REL_#{rspec_version}/rspec_on_rails/vendor/plugins/rspec_on_rails",
14
+ :resource_fu => 'http://svn.protocool.com/public/plugins/resource_fu/',
15
+ :exception_notification => 'http://svn.rubyonrails.org/rails/plugins/exception_notification',
16
+ :spider_test => 'svn://caboo.se/plugins/court3nay/spider_test',
17
+ :annotate_models => 'http://svn.pragprog.com/Public/plugins/annotate_models',
18
+ :restful_authentication => 'http://svn.techno-weenie.net/projects/plugins/restful_authentication/',
19
+ :attachment_fu => 'http://svn.techno-weenie.net/projects/plugins/attachment_fu/'
20
+ }
21
+ end
22
+
23
+ def optional_plugins
24
+ [ :exception_notification, :resource_fu,
25
+ :restful_authentication, :spider_test, :annotate_models ]
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+
2
+ Repository.define 'http://svn.newqdev.com/testttwoo',{
3
+ :user => 'what',
4
+ :comment => 'first commit of this here blahgthing'
5
+ }
6
+
7
+ resource(:post){|post|
8
+ post.has_many :comments
9
+ post.has_many :categories, :through => :categorization
10
+ post.attrs :title => 'string', :body => 'text', :created_at => 'datetime'
11
+ }
12
+
13
+ resource(:comment){|comment|
14
+ comment.belongs_to :post
15
+ comment.attrs { :handle => 'string', :title => 'string',
16
+ :email => 'string', :body => 'text' }
17
+ }
18
+
19
+ resource(:category){|cat|
20
+ cat.has_many :posts, :through => :categorization
21
+ cat.attrs :name => 'string'
22
+ }
23
+
24
+ resource(:categorization){|cat|
25
+ cat.belongs_to :post
26
+ cat.belongs_to :category
27
+ }
@@ -0,0 +1,38 @@
1
+
2
+ #use_plugin :file_column
3
+
4
+ Repository.define "http://svn.newqdev.com/testarif", {
5
+ :comment => 'adding for the first time',
6
+ :user => 'what'
7
+ }
8
+
9
+ resource(:category){ |cat|
10
+ cat.attrs :name => 'string', :type => 'text'
11
+ cat.has_many :posts, :through => :categorization
12
+ cat.has_many :photos, :through => :categorization
13
+ }
14
+
15
+ resource(:post){ |post|
16
+ post.attrs :title => 'string', :body => 'text', :added_on => 'date', :hello_mom => 'string'
17
+ post.has_many :categories, :through => :categorization
18
+ }
19
+
20
+ resource(:categorization){ |cat|
21
+ cat.belongs_to :item
22
+ cat.belongs_to :category
23
+ }
24
+
25
+ resource(:project){ |proj|
26
+ proj.attrs :name => 'string', :description => 'text', :icon => 'string'
27
+ proj.uses :file_column, :on => 'icon'
28
+ }
29
+
30
+ resource(:photo){ |photo|
31
+ photo.has_many :tags, :through => :categorization
32
+ photo.attrs :image => 'string', :description => 'text', :title => 'string'
33
+ photo.uses :file_column, :on => 'image'
34
+ }
35
+
36
+ resource(:thingie){ |thing|
37
+ thing.attrs :name => 'string'
38
+ }
@@ -0,0 +1,23 @@
1
+
2
+ Repository.define 'http://svn.newqdev.com/testttwoo',{
3
+ :user => 'what',
4
+ :comment => 'first commit'
5
+ }
6
+
7
+ use_plugin :file_column
8
+
9
+ resource(:post){|post|
10
+ post.attrs :title => 'string', :body => 'text'
11
+ post.has_one :thingie
12
+ post.actions :example
13
+ }
14
+
15
+ model(:thingie){|thing|
16
+ thing.belongs_to :post
17
+ thing.attrs :face => 'string', :name => 'string'
18
+ thing.uses :file_column, :on => 'face'
19
+ }
20
+
21
+ controller(:gateway){|gate|
22
+ gate.actions :index, :login, :logout
23
+ }
data/lib/cli_tools.rb ADDED
@@ -0,0 +1,114 @@
1
+ require File.dirname(__FILE__)+'/extentions/string'
2
+ require File.dirname(__FILE__)+'/extentions/array'
3
+
4
+ module CliTools
5
+ def request_value words=nil
6
+ puts words if words
7
+ $stdin.gets.chop
8
+ end
9
+ end
10
+
11
+ module Flagger
12
+ def seperate_arguments_from(args)
13
+ @active_keys = {}
14
+ @remaining_argument = []
15
+ args = args.duplicate
16
+ while !args.empty? and !args.first.flag?
17
+ if @potential_keywords && @potential_keywords.include?(args.first.to_sym) then
18
+ @active_keys.merge! args.shift.to_sym => nil
19
+ else
20
+ @remaining_argument << args.shift
21
+ end
22
+ end
23
+ @flags = args
24
+ end
25
+
26
+ def process_command_line_input
27
+ flags = parse_flags(@flags)
28
+ run_flags @active_keys
29
+ run_flags flags
30
+ end
31
+
32
+ def trip_flag which, with_value=nil
33
+ start_flag_checking
34
+ @active_flags.merge!({which => (with_value || true)})
35
+ end
36
+
37
+ def start_flag_checking
38
+ @active_flags ||= {}
39
+ end
40
+
41
+ def parse_flags(args)
42
+ start_flag_checking
43
+ while not args.empty?
44
+ flag_set = args.shift
45
+ flag_set.shift
46
+ unless flag_set.flag?
47
+ while not flag_set.empty?
48
+ @active_flags.merge!({flag_key_for(flag_set.shift) => (flag_set.empty? && args.first) ? (args.first.flag? or args.shift ) : true})
49
+ end
50
+ else
51
+ flag_set.shift
52
+ @active_flags.merge!({flag_key_for(flag_set) => (args.first ? (args.first.flag? or args.shift) : true) })
53
+ end
54
+ end
55
+ @active_flags
56
+ end
57
+
58
+ def flag_key_for(which)
59
+ return which.to_sym if @potential_flags.member? which.to_sym
60
+ try = @potential_flags.invert
61
+ return try[which] if try.member? which
62
+ return nil
63
+ end
64
+
65
+ def flag option, &blk
66
+ set_flag option
67
+ set_block option, blk
68
+ end
69
+ alias key flag
70
+
71
+ def flag_and_key option, &blk
72
+ flag option, &blk
73
+ option.each { |k, v| flag k, &blk }
74
+ end
75
+
76
+ def set_flag(option)
77
+ if option.respond_to? :merge!
78
+ @potential_flags ||= {}
79
+ @potential_flags.merge! option
80
+ else
81
+ @potential_keywords ||= []
82
+ @potential_keywords << option
83
+ end
84
+ end
85
+
86
+ def set_block(option, blk=nil)
87
+ @associated_blocks||= {}
88
+ blk ||= lambda{}
89
+ tmp = {}
90
+ if option.kind_of? Symbol
91
+ tmp[option] = blk
92
+ else
93
+ option.each {|key, value| tmp[key] = blk}
94
+ end
95
+ @associated_blocks.merge! tmp
96
+ end
97
+
98
+ def run_flags(options)
99
+ options.each { |key, value|
100
+ @associated_blocks[key.to_sym][value]
101
+ }
102
+ end
103
+
104
+ def active_options
105
+ flags = @active_flags || {}
106
+ keys = @active_keys || {}
107
+ flags.merge keys
108
+ end
109
+ def remaining_argument
110
+ @remaining_argument||[]
111
+ end
112
+
113
+ end
114
+
@@ -0,0 +1,3 @@
1
+ class Array
2
+ def duplicate; *copy = *self.map{|a|a.dup} end
3
+ end
@@ -0,0 +1,43 @@
1
+
2
+ class Class # :nodoc:
3
+ def cattr_reader(*syms)
4
+ syms.flatten.each do |sym|
5
+ class_eval(<<-EOS, __FILE__, __LINE__)
6
+ unless defined? @@#{sym}
7
+ @@#{sym} = nil
8
+ end
9
+
10
+ def self.#{sym}
11
+ @@#{sym}
12
+ end
13
+
14
+ def #{sym}
15
+ @@#{sym}
16
+ end
17
+ EOS
18
+ end
19
+ end
20
+
21
+ def cattr_writer(*syms)
22
+ syms.flatten.each do |sym|
23
+ class_eval(<<-EOS, __FILE__, __LINE__)
24
+ unless defined? @@#{sym}
25
+ @@#{sym} = nil
26
+ end
27
+
28
+ def self.#{sym}=(obj)
29
+ @@#{sym} = obj
30
+ end
31
+
32
+ def #{sym}=(obj)
33
+ @@#{sym} = obj
34
+ end
35
+ EOS
36
+ end
37
+ end
38
+
39
+ def cattr_accessor(*syms)
40
+ cattr_reader(*syms)
41
+ cattr_writer(*syms)
42
+ end
43
+ end
@@ -0,0 +1,4 @@
1
+ class String
2
+ def flag?; self[0,1]=='-' end
3
+ def shift; self.slice! 0,1 end
4
+ end
data/lib/filebase.rb ADDED
@@ -0,0 +1,76 @@
1
+ require 'fileutils'
2
+
3
+ class String
4
+ def as_file; self.gsub(/([!?,]|[^a-zA-Z0-9]$)/, '').gsub(/[^a-zA-Z0-9\/\.]/, '_').downcase end
5
+ def as_folder; (self=~/^[\. \/]{1,2}$/ ? './' : (self.as_file+((self.as_file=~/\/$/||self=='') ? '' : '/'))) end
6
+ def as_ext; self[0,0]='.' unless self[0,1]=='.'|| self==''; self end
7
+ def as_file_title; self.as_file.gsub /_/, ' ' end
8
+ def as_symbol; self.as_file.to_sym end
9
+ end
10
+
11
+ module FileBase
12
+ include FileUtils
13
+
14
+ Home = ''
15
+ def home; (@home||Home).as_folder end
16
+ def set_home(here)
17
+ mkdir here unless exists? :folder, here
18
+ @home=here
19
+ end
20
+
21
+ def location; (@location||'').as_folder end
22
+ def set_location where; @location=where end
23
+ def reset_location; @location='' end
24
+ def has_location?; location!='' end
25
+
26
+ def path; home+location end
27
+ def file_path; home+location+filename end
28
+
29
+ def exists? type, item
30
+ return false unless File.exist? item
31
+ truth = case type
32
+ when :folder
33
+ File.directory? item
34
+ when :file
35
+ !File.directory? item
36
+ else
37
+ true
38
+ end
39
+ end
40
+
41
+ def write(contents, where)
42
+ File.open(where, 'w'){ |f| f << contents }
43
+ end
44
+
45
+ def move(from, to=home)
46
+ FileUtils.mv from, to
47
+ end
48
+
49
+ def copy(from, to=home)
50
+ FileUtils.cp_r from, to
51
+ end
52
+
53
+ def mkdir where, force=false
54
+ begin
55
+ Dir.mkdir where
56
+ rescue
57
+ raise $! unless force
58
+ destroy where
59
+ mkdir where
60
+ end
61
+ end
62
+
63
+ def make_dir path, force=false
64
+ mkdir path, force
65
+ puts 'creating '+path
66
+ end
67
+
68
+ def destroy what
69
+ FileUtils.rm_rf what
70
+ puts 'destroying '+what
71
+ end
72
+
73
+ alias loc location
74
+ alias loc= set_location
75
+ end
76
+
data/lib/keywords.rb ADDED
@@ -0,0 +1,30 @@
1
+
2
+ # These are the words used in a .rails file.
3
+ # you can also do basically any ruby in there,
4
+ # and very likely all of the kickstart sub-
5
+ # module methods would be available anyway
6
+
7
+ module Kickstart
8
+ module Keywords
9
+ # call to create a resource
10
+ def resource(name, *args, &blk)
11
+ resource = Resource.new(name)
12
+ yield(resource)
13
+ resource.generate
14
+ end
15
+
16
+ # call to create a controller
17
+ def controller(name, *args, &blk)
18
+ controller = Controller.new(name)
19
+ yield(controller)
20
+ controller.generate
21
+ end
22
+
23
+ # call to create a model
24
+ def model(name, *args, &blk)
25
+ model = Model.new(name)
26
+ yield(model)
27
+ model.generate
28
+ end
29
+ end
30
+ end
data/lib/kickstart.rb ADDED
@@ -0,0 +1,14 @@
1
+
2
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'rails_elements'
5
+ require 'repository'
6
+ require 'keywords'
7
+ require 'scripting'
8
+ require 'plugins'
9
+ require 'filebase'
10
+ require 'cli_tools'
11
+
12
+ module Kickstart
13
+ VERSION = '0.2'
14
+ end
data/lib/plugins.rb ADDED
@@ -0,0 +1,54 @@
1
+ module Kickstart
2
+ module Plugins
3
+ # define the version of rspec that you are using. formatted as it would be in the rspec_on_rails url
4
+ def rspec_version
5
+ value = request_value 'please enter the version of rspec on your computer [default: 0_7_5_1]'
6
+ value = '0_7_5_1' if value == ''
7
+ value
8
+ end
9
+
10
+ # set the rspec version
11
+ def rspec_version= what
12
+ @rspec_version = what
13
+ end
14
+
15
+ # install a plugin
16
+ def use_plugin(plugin)
17
+ puts "\n\n+ installing #{plugin} +"
18
+ puts `script/plugin install #{ plugin_bank.include?(plugin) ? plugin_bank[plugin] : plugin }`
19
+ end
20
+
21
+ # define a list of plugins to install
22
+ def use_plugins(*args)
23
+ args=args.flatten
24
+ args.each{|arg| use_plugin(arg)}
25
+ end
26
+
27
+ # list of plugins that can be downloaded by name.
28
+ # this list is expandable in the <tt>~/.kickstart</tt> folder
29
+ def plugin_bank
30
+ {
31
+ :rspec_on_rails => "svn://rubyforge.org/var/svn/rspec/tags/REL_#{rspec_version}/rspec_on_rails/vendor/plugins/rspec_on_rails",
32
+ }
33
+ end
34
+
35
+ # list of plugins required by kickstart and, therefore, will be installed in the course of running kickstart
36
+ # this list is expandable in the <tt>~/.kickstart</tt> folder
37
+ def required_plugins
38
+ [ :rspec_on_rails ]
39
+ end
40
+
41
+ # a callback for some plugins you would like to install in every project. can be dealt with in the home folder
42
+ def default_plugins
43
+ []
44
+ end
45
+
46
+ # installs all necessary plugins
47
+ def install_plugins
48
+ puts "\n\n+ installing plugins +" unless default_plugins.empty?
49
+ default_plugins.each do |plugin|
50
+ use_plugin plugin
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,157 @@
1
+
2
+ require 'rubygems'
3
+ require 'active_support'
4
+ require 'filebase'
5
+ include ActiveSupport::CoreExtensions::String::Inflections
6
+
7
+
8
+ class DomainElement
9
+ attr_accessor :name, :file_loc
10
+ def initialize name
11
+ @name = name
12
+ end
13
+
14
+ def insert_after(filename, regex, new_content)
15
+ contents = ''
16
+ file = File.read(filename)
17
+ file.each { |line|
18
+ contents << line
19
+ contents << new_content if line =~ regex
20
+ }
21
+ write contents, filename
22
+ end
23
+
24
+ def generate
25
+ end
26
+ end
27
+
28
+ class Model < DomainElement
29
+ include FileBase
30
+ include ActiveSupport::CoreExtensions::String::Inflections
31
+
32
+ attr_accessor :associations, :plugin_methods, :attributes, :methods
33
+
34
+ def initialize(name)
35
+ @file_loc = "app/models/#{name.underscore}.rb"
36
+ @associations=[]
37
+ @attributes=[]
38
+ @plugin_methods=[]
39
+ super
40
+ end
41
+
42
+ # defining types and names of attributes for a model
43
+ def attrs(args={})
44
+ args.each { |ident, type| attributes << "#{ident}:#{type}" }
45
+ end
46
+
47
+ def attribute_string
48
+ attributes.join ' '
49
+ end
50
+
51
+ def uses(what, *opts)
52
+ opts = opts.first
53
+ plugin_methods << "\t#{what.to_s} :#{opts[:on]}\n"
54
+ end
55
+
56
+ def has_many what, args=nil
57
+ has_many(args[:through]) if args && args[:through]
58
+ associations << "\thas_many :#{what}"+ (args ? ", #{args.inspect.gsub(/[{}]/, '')}" : '')
59
+ end
60
+
61
+ def has_one what, args=nil
62
+ associations << "\thas_one :#{what}"+(args ? ", #{args.inspect.gsub(/[{}]/, '')}" : '')
63
+ end
64
+
65
+ def belongs_to what, args=nil
66
+ associations << "\tbelongs_to :#{what}"+ (args ? ", #{args.inspect.gsub(/[{}]/, '')}" : '')
67
+ attrs "#{what}_id".to_sym => 'integer'
68
+ end
69
+
70
+ def print_associations
71
+ "#{associations.join("\n")}\n\n"
72
+ end
73
+ def print_plugin_methods
74
+ "#{plugin_methods.join("\n")}\n\n"
75
+ end
76
+
77
+ def write_plugin_methods
78
+ puts "#{name}: preparing plugins for use" unless plugin_methods.empty?
79
+ insert_after(file_loc, /^$/, print_plugin_methods)
80
+ end
81
+
82
+ def write_associations
83
+ puts "#{name}: recording associations" unless associations.empty?
84
+ insert_after(file_loc, /^class/, print_associations)
85
+ end
86
+
87
+ def generate
88
+ puts "\ngenerating #{name} model with specs"
89
+ puts(`script/generate rspec_model #{name} #{attribute_string}\n`)
90
+ end
91
+ end
92
+
93
+ class Controller < DomainElement
94
+ def initialize(name)
95
+ @file_loc = "app/controllers/#{name.pluralize}_controller.rb"
96
+ @actions = []
97
+ super
98
+ end
99
+
100
+ def actions *args
101
+ @actions << args.flatten
102
+ end
103
+
104
+ def actions_list
105
+ @actions.join(' ')
106
+ end
107
+
108
+ def print_actions
109
+ tmp = []
110
+ @actions.flatten.each{|a| tmp << "\n\tdef #{a}\n\n\tend\n\n"}
111
+ tmp.join("\n")
112
+ end
113
+
114
+ def write_actions
115
+ puts "#{name}: recording actions" unless actions.empty?
116
+ insert_after(file_loc, /^class/, print_actions)
117
+ end
118
+
119
+ def generate
120
+ puts "\ngenerating #{name} controller with specs"
121
+ system "script/generate rspec_controller #{name} #{actions_list}"
122
+ end
123
+ end
124
+
125
+ class Resource < DomainElement
126
+ include FileBase
127
+
128
+ attr_accessor :model, :controller
129
+
130
+ def initialize(name)
131
+ super
132
+ @model = Model.new name
133
+ @controller = Controller.new name
134
+ end
135
+
136
+ def generate
137
+ puts "\n#- - - - - - - - - - - - - - - - - - -#\n"
138
+ puts "generating #{name} resource with specs\n"
139
+ system "script/generate rspec_resource #{name} #{attribute_string}\n"
140
+ model.write_associations
141
+ model.write_plugin_methods
142
+ controller.write_actions
143
+ end
144
+
145
+ def method_missing(method, *args, &blk)
146
+ case
147
+ when model.respond_to?(method) then
148
+ model.send(method, *args, &blk)
149
+ when controller.respond_to?(method) then
150
+ controller.send(method, *args, &blk)
151
+ else
152
+ super
153
+ end
154
+ end
155
+ end
156
+
157
+
data/lib/repository.rb ADDED
@@ -0,0 +1,62 @@
1
+ require 'singleton'
2
+ require 'extentions/class'
3
+ require 'filebase'
4
+
5
+ module Kickstart
6
+ class Repository
7
+ include Singleton
8
+ include FileBase
9
+ cattr_accessor :address, :username, :import_command, :comment, :project_name
10
+
11
+ def self.define where, args
12
+ self.address = where
13
+ self.username = args[:user]
14
+ self.comment = args[:comment]
15
+ raise 'repository needs an address' unless where
16
+ self.import_command = "svn import . #{where}/trunk"
17
+ self.import_command << " -m '#{args[:comment]}'" if args[:comment]
18
+ self.import_command << " --username #{args[:user]}" if args[:user]
19
+ end
20
+
21
+ def self.checkout(where=nil)
22
+ where||='.'
23
+ puts "checking out the trunk of the application into #{where}"
24
+ system "svn co #{self.address}/trunk #{where}"
25
+ end
26
+
27
+ def self.defined?
28
+ self.address
29
+ end
30
+
31
+ def self.import
32
+ puts "committing the application to your repository\n"
33
+ puts import_command
34
+ system import_command
35
+ end
36
+
37
+ def self.remove what
38
+ puts "\nsvn remove #{what}"
39
+ system "svn remove #{what}"
40
+ end
41
+
42
+ def self.commit message
43
+ puts "\nsvn commit -m '#{message}'"
44
+ system "svn commit -m '#{message}'"
45
+ end
46
+
47
+ def self.ignore what, where
48
+ puts "\nsvn propset svn:ignore '#{what}' #{where}"
49
+ system "svn propset svn:ignore '#{what}' #{where}"
50
+ end
51
+
52
+ def self.update what
53
+ puts "\nsvn update #{what}"
54
+ system "svn update #{what}"
55
+ end
56
+
57
+ def self.move what, where
58
+ puts "\nsvn move #{what} #{where}"
59
+ system "svn move #{what} #{where}"
60
+ end
61
+ end
62
+ end
data/lib/scripting.rb ADDED
@@ -0,0 +1,168 @@
1
+
2
+ require "yaml"
3
+ require 'erb'
4
+
5
+ module Kickstart
6
+ module Scripting
7
+
8
+ def use_repo_first
9
+ @repo_first_template = ERB.new <<-EOF
10
+
11
+ Repository.define '<%=@repo_address%>',{
12
+ :user => '',
13
+ :comment => 'first commit'
14
+ }
15
+
16
+ resource(:foo){|foo|
17
+ foo.attrs :name => 'string'
18
+ }
19
+
20
+ EOF
21
+ end
22
+
23
+ def setup_project(arg)
24
+ if arg =~ /^(http:\/\/|svn\+ssh:\/\/)/
25
+ @repo_address = arg
26
+ @project_name ||= arg.gsub(/^.+\//, '')
27
+ @kickstarter = "#{@project_name}.rails"
28
+ use_repo_first
29
+ write @repo_first_template.result, @kickstarter
30
+ system "vi #{@kickstarter}"
31
+ else
32
+ @kickstarter = arg
33
+ @project_name ||= arg.gsub(/^.+\//, '').gsub(/\..+$/, '')
34
+ end
35
+ puts("rails #{@project_name}")
36
+ system("rails #{@project_name}")
37
+ puts "\n moving project to a temporary folder to make way for the repository \n"
38
+ move @project_name, "#{@project_name}_tmp"
39
+ end
40
+
41
+ def goto_project(where=nil)
42
+ where ||=@project_name
43
+ puts "\n\n+ entering #{where} +"
44
+ Dir.chdir(where)
45
+ end
46
+ def separator
47
+ puts "\n#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#\n"
48
+ end
49
+ def kick_it!(huh)
50
+ begin
51
+ load("#{huh}")
52
+ rescue MissingSourceFile
53
+ load "../#{huh}"
54
+ end
55
+ end
56
+
57
+ def edit_db_config
58
+ @edit_db = request_value "would you like to edit database.yml file? default values will be used otherwise. [Y/n]" if(@edit_db == :ask || @edit_db.nil?)
59
+ system 'vi config/database.yml' if @edit_db && @edit_db != 'n'
60
+ File.open('config/database.yml') { |yf| @dbconfig = YAML::load(yf) }
61
+ end
62
+
63
+ def create_databases
64
+ create_database('test')
65
+ create_database('development')
66
+ end
67
+
68
+ def migrate
69
+ puts 'migrating up to start of project'
70
+ system "rake db:migrate"
71
+ end
72
+
73
+ def edit_db_config? bool = nil
74
+ bool.nil? ? @edit_db : @edit_db = bool
75
+ puts "@edit_db is now #{@edit_db}"
76
+ end
77
+
78
+ def mysqladmin_user who = nil
79
+ who ? @mysqladmin_user = who : @mysqladmin_user
80
+ puts "@mysqladmin_user is now #{@mysqladmin_user}"
81
+ end
82
+
83
+ def request_mysqladmin_pass? bool = nil
84
+ bool.nil? ? @mysqladmin_pass : @mysqladmin_pass = bool
85
+ puts "@mysqladmin_pass is now #{@mysqladmin_pass}"
86
+ end
87
+
88
+ def create_database(which)
89
+ mysqladmin_user(request_value('please enter mysqladmin username [default: root]')) if @mysqladmin_user.nil?
90
+ puts "creating mysql database for #{which}"
91
+ puts "mysqladmin create #{@dbconfig[which]['database']} -u #{@mysqladmin_user == '' ? 'root' : @mysqladmin_user } #{'-p' if @mysqladmin_pass} "
92
+ system "mysqladmin create #{@dbconfig[which]['database']} -u #{@mysqladmin_user == '' ? 'root' : @mysqladmin_user } #{'-p' if @mysqladmin_pass} "
93
+ end
94
+
95
+ def edit_routes? bool
96
+ @edit_routes = bool
97
+ end
98
+ def edit_routes
99
+ @edit_routes = request_value "would you like to edit routes.rb? default values will be used otherwise. [Y/n]" if(@edit_routes == :ask || @edit_routes.nil?)
100
+ system "vi config/routes.rb"
101
+ end
102
+
103
+ def delete_rails_index? bool
104
+ @delete_index = bool
105
+ puts 'public/index.html will be deleted'
106
+ end
107
+
108
+ def delete_rails_index
109
+ @delete_index = request_value 'delete the rails index page? [Y/n]' if @delete_index.nil?
110
+ destroy 'public/index.html' unless @delete_index.to_s.downcase=='n' if @delete_index && @delete_index != 'n'
111
+ end
112
+
113
+ def start_server
114
+ puts "\nmongrel_rails start -d"
115
+ system "mongrel_rails start -d"
116
+ end
117
+
118
+ def finish
119
+ puts "\nyour project is now running at http://localhost:3000. use mongrel_rails stop to kill the server.\n\n"
120
+ end
121
+ def condition_repository
122
+ Repository.remove "log/*"
123
+ Repository.commit "removing logs from repository"
124
+ Repository.ignore "*.log", "log/"
125
+ Repository.update "log/"
126
+ Repository.commit "ignoring all .log files in log/"
127
+ Repository.ignore "*", "tmp/sessions"
128
+ Repository.ignore "*", "tmp/cache"
129
+ Repository.ignore "*", "tmp/sockets"
130
+ Repository.commit "ignoring all files in tmp/"
131
+ Repository.remove "config/database.yml"
132
+ Repository.ignore "database.yml", "config/"
133
+ Repository.update "config/"
134
+ Repository.commit "ignoring database.yml"
135
+ puts "\ncopying database.yml back in place\n"
136
+ copy "../#{@project_name}_tmp/config/database.yml", 'config/'
137
+ Repository.remove "tmp/*"
138
+ Repository.ignore "*", "tmp/"
139
+ Repository.update "tmp/"
140
+ Repository.commit "ignoring all tmp/ content"
141
+ destroy '../'+@project_name+'_tmp'
142
+ end
143
+ def no_repository_defined
144
+ puts "moving out of the temporary directory\n\n"
145
+ Dir.chdir('../')
146
+ puts 'you have not defined a subversion repository'
147
+ move "#{@project_name}_tmp".as_folder, @project_name.as_folder
148
+ Dir.chdir @project_name
149
+ end
150
+
151
+ def before_setup; end
152
+ def after_setup; end
153
+ def before_required_plugins; end
154
+ def after_required_plugins; end
155
+ def before_kicking; end
156
+ def after_kicking; end
157
+ def before_create_databases; end
158
+ def after_create_databases; end
159
+ def before_migrate; end
160
+ def after_migrate; end
161
+ def before_edit_routes; end
162
+ def after_edit_routes; end
163
+ def before_start_server; end
164
+ def after_all; end
165
+ end
166
+ end
167
+
168
+
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: kickstart
5
+ version: !ruby/object:Gem::Version
6
+ version: "0.2"
7
+ date: 2007-04-15 00:00:00 -04:00
8
+ summary: this project is intended to give the initial steps of the rails process a nice kick in the pants, allowing you to define the initial parameters of a project in a unified way.
9
+ require_paths:
10
+ - lib
11
+ email: ryand-ruby@zenspider.com
12
+ homepage: http://www.zenspider.com/ZSS/Products/kickstart/
13
+ rubyforge_project: kickstart
14
+ description: The author was too lazy to write a description
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Ryan Davis
31
+ files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ - Rakefile
36
+ - bin/kickstart
37
+ - lib/filebase.rb
38
+ - lib/kickstart.rb
39
+ - lib/keywords.rb
40
+ - lib/scripting.rb
41
+ - lib/plugins.rb
42
+ - lib/rails_elements.rb
43
+ - lib/cli_tools.rb
44
+ - lib/repository.rb
45
+ - lib/extentions/class.rb
46
+ - lib/extentions/array.rb
47
+ - lib/extentions/string.rb
48
+ - kickstart_home/defaults.rb
49
+ - kickstart_home/plugin_helper.rb
50
+ - kickstart_home/samples/portfolio.rails
51
+ - kickstart_home/samples/blahg.rails
52
+ - kickstart_home/samples/twirp.rails
53
+ test_files: []
54
+
55
+ rdoc_options: []
56
+
57
+ extra_rdoc_files: []
58
+
59
+ executables:
60
+ - kickstart
61
+ extensions: []
62
+
63
+ requirements: []
64
+
65
+ dependencies:
66
+ - !ruby/object:Gem::Dependency
67
+ name: hoe
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Version::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 1.2.0
74
+ version: