simple_generators 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Michael van Rooijen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,110 @@
1
+ = Simple Generators
2
+
3
+ To get you up and running just a little bit faster!
4
+
5
+ == Installation
6
+
7
+ === Add Repository Source(s)
8
+
9
+ gem sources -a http://gemcutter.org
10
+ gem sources -a http://gems.github.com
11
+
12
+ === Gem
13
+
14
+ # Gem Cutter
15
+ sudo gem install simple_generators
16
+
17
+ # GitHub
18
+ sudo gem install meskyanichi-simple_generators
19
+
20
+ === Plugin
21
+
22
+ ./script/plugin install git://github.com/meskyanichi/simple_generators.git
23
+
24
+
25
+ == Simple Capistrano Recipe
26
+
27
+ This generator will generate a simple capistrano template. You can supply some arguments to let the generate fill in the deployment recipe for you as well. This generator is currently made specifically for Ruby on Rails with Phusion Passenger and Git Repository. Of course, you can still generate the deployment recipe and alter the sections within it to get it to deploy to your liking!
28
+
29
+ ==== To generate a dry Capistrano Deployment Recipe, run the following command:
30
+ script/generate simple_capistrano_recipe
31
+
32
+ ==== You can also provide arguments to generate an already filled in recipe:
33
+ script/generate simple_capistrano_recipe domain:example.com user:root deploy_path:/var/rails/example.com
34
+ repository_type:git repository_url:ssh://root@example.com/var/git/example.git reeip:/opt/ruby-enterprise-1.8.6-20090610
35
+ ssh_address:xxx.xx.xxx.xx crontab_id:a_crontab_id
36
+
37
+ After generating the deployment recipe (RAILS_ROOT/config/deploy.rb), you might want to double check if everything is set up correctly before you actually try to deploy.
38
+
39
+
40
+
41
+
42
+ == Simple Git Template
43
+
44
+ This is a very small generator that just generates a .gitignore file in the RAILS_ROOT with a couple of predefined ignore lines.
45
+ ==== No arguments can be supplied here:
46
+ script/generate simple_git_template
47
+
48
+
49
+
50
+
51
+ == Simple Paperclip Model
52
+
53
+ Now, I always tend to forget all the settings I usually need for my Paperclip model, hence why I created the gem and added this generators as well.
54
+
55
+ ==== To generate a Paperclip Model you are required to supply 2 of the 3 arguments:
56
+ script/generate simple_paperclip_model model:user attachment:avatar [optional: type:image] bucket:my_bucket
57
+
58
+ The optional type:image argument will generate example "styles" for Paperclip.
59
+
60
+
61
+
62
+
63
+ == Simple Tasks
64
+
65
+ At the moment, there is only one Task Generator available.
66
+
67
+
68
+ === Simple Repository Tasks
69
+
70
+ This generator will generate 3 rake tasks that can help with creating and destroying your applications remote repository using SSH on your own server.
71
+
72
+ ==== To generates these Repository Rake Tasks, run the following command:
73
+ script/generate simple_repository_tasks
74
+
75
+ If you do it this way, you will manually have to open the rake tasks, located in the lib/tasks/simple_tasks/repository.rake file, and add your server settings in there.
76
+
77
+ ==== If you wish to, like I do, let the generator insert these settings in for you, execute the following command:
78
+ script/generate simple_repository_tasks domain:example.com path:/var/git/example.git
79
+ user:root password:mys3cr3tp4ssw0rd
80
+
81
+ ==== Now, when you run the following command:
82
+ rake -T
83
+
84
+ You will see a list of all your available rake tasks, including the Repository Rake Tasks and their description.
85
+
86
+ These rake tasks allow your to quickly, without manually SSH'ing to your server, create and destroy your git repository for a specific Ruby on Rails application. Additionally, if you haven't already, you can run a simple command (rake simple_tasks:repository:add_to_git) to add your remote repository location (origin) to your local repository.
87
+
88
+ ==== These are the commands that are currently available for the Simple Repository Tasks:
89
+
90
+ rake simple_tasks:repository:add_to_git
91
+ rake simple_tasks:repository:create
92
+ rake simple_tasks:repository:destroy
93
+
94
+
95
+
96
+
97
+ == Simple Admin Data Setup
98
+
99
+ This generator will generate a single file, containing some ruby code that will ensure security over the Admin Data Interface. The file will be generated inside the RAILS_ROOT/config/initializers directory. You will want to open this
100
+ file to see if the methods that are added are the ones you desire and use to check whether the logged in user has privileges to view the interface.
101
+
102
+ ==== To generate the Admin Data file, run the following command:
103
+ script/generate simple_admin_data_setup
104
+
105
+ * There are no available arguments.
106
+
107
+
108
+ == Copyright
109
+
110
+ Copyright (c) 2009 Michael van Rooijen. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "simple_generators"
8
+ gem.summary = "A couple of generators that supply you with some common templates to speed up the development process."
9
+ gem.description = "A couple of generators that supply you with some common templates to speed up the development process."
10
+ gem.email = "meskyan@gmail.com"
11
+ gem.homepage = "http://github.com/meskyanichi/simple_generators"
12
+ gem.authors = ["Michael van Rooijen"]
13
+ gem.files.include 'generators/**/*'
14
+ end
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+ task :test => :check_dependencies
40
+
41
+ task :default => :test
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ if File.exist?('VERSION')
46
+ version = File.read('VERSION')
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "simple_generators #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
@@ -0,0 +1,7 @@
1
+ This generator will generate a single file, containing some ruby code that will ensure security over the Admin Data Interface. The file will be generated inside the RAILS_ROOT/config/initializers directory. You will want to open this
2
+ file to see if the methods that are added are the ones you desire and use to check whether the logged in user has privileges to view the interface.
3
+
4
+ ==== To generate the Admin Data file, run the following command:
5
+ script/generate simple_admin_data_setup
6
+
7
+ * There are no available arguments.
@@ -0,0 +1,53 @@
1
+ class SimpleAdminDataSetupGenerator < Rails::Generator::Base
2
+
3
+ # This method gets initialized when the generator gets run.
4
+ # It will receive an array of arguments inside @args
5
+ def initialize(runtime_args, runtime_options = {})
6
+ super
7
+ extract_args
8
+ set_defaults
9
+ confirm_input
10
+ end
11
+
12
+ # Processes the file generation/templating
13
+ # This will automatically be run after the initialize method
14
+ def manifest
15
+ record do |m|
16
+ m.directory "config/initializers"
17
+ m.file "admin_data_setting.rb", "config/initializers/admin_data_setting.rb"
18
+ end
19
+ end
20
+
21
+ # Creates a new Hash Object containing the user input
22
+ # The user input will be available through @input and input
23
+ def extract_args
24
+ @input = Hash.new
25
+ @args.each do |arg|
26
+ if arg.include?(":") then
27
+ @input[:"#{arg.slice(0, arg.index(":"))}"] = arg.slice((arg.index(":") + 1)..-1)
28
+ end
29
+ end
30
+ end
31
+
32
+ # Input Method that's available inside the generated templates
33
+ # because instance variable are not available, so we access them through methods
34
+ def input
35
+ @input
36
+ end
37
+
38
+ # Sets defaults for user input when left blank by the user
39
+ # for each parameter
40
+ def set_defaults
41
+ end
42
+
43
+ # Confirms whether the model and attachment arguments were passed in
44
+ # Raises an error if not
45
+ def confirm_input
46
+ end
47
+
48
+ private
49
+
50
+ def input_error
51
+ end
52
+
53
+ end
@@ -0,0 +1,20 @@
1
+ # AdminDate Plugin/Gem Download On Github:
2
+ # http://github.com/neerajdotname/admin_data
3
+ #
4
+ # Public Git Clone: git://github.com/neerajdotname/admin_data.git
5
+ # script/plugin install git://github.com/neerajdotname/admin_data.git
6
+ #
7
+ # Be sure to install this plugin/gem for the interface.
8
+
9
+ # Define the two methods that should be invoked when checking whether the logged in user has privelleges to either:
10
+ # * View Data From the Database
11
+ # * Update Data from the Database
12
+ #
13
+ # You may change the two methods "logged_in?" and "admin_logged_in?" to methods you've defined.
14
+ # Usually you don't want any non-admin viewing any data from the admin-data interface. If this is what you
15
+ # desire, then create a method, for example, "admin_logged_in?" and let both the
16
+ # :view_security_check and :update_security_check invoke it.
17
+ AdminDataConfig.set = {
18
+ :view_security_check => lambda {|controller| controller.send('logged_in?') },
19
+ :update_security_check => lambda {|controller| controller.send('admin_logged_in?') }
20
+ }
@@ -0,0 +1,11 @@
1
+ This generator will generate a simple capistrano template. You can supply some arguments to let the generate fill in the deployment recipe for you as well. This generator is currently made specifically for Ruby on Rails with Phusion Passenger and Git Repository. Of course, you can still generate the deployment recipe and alter the sections within it to get it to deploy to your liking!
2
+
3
+ ==== To generate a dry Capistrano Deployment Recipe, run the following command:
4
+ script/generate simple_capistrano_recipe
5
+
6
+ ==== You can also provide arguments to generate an already filled in recipe:
7
+ script/generate simple_capistrano_recipe domain:example.com user:root deploy_path:/var/rails/example.com
8
+ repository_type:git repository_url:ssh://root@example.com/var/git/example.git reeip:/opt/ruby-enterprise-1.8.6-20090610
9
+ ssh_address:xxx.xx.xxx.xx crontab_id:a_crontab_id
10
+
11
+ After generating the deployment recipe (RAILS_ROOT/config/deploy.rb), you might want to double check if everything is set up correctly before you actually try to deploy.
@@ -0,0 +1,51 @@
1
+ class SimpleCapistranoRecipeGenerator < Rails::Generator::Base
2
+
3
+ # This method gets initialized when the generator gets run.
4
+ # It will receive an array of arguments inside @args
5
+ def initialize(runtime_args, runtime_options = {})
6
+ super
7
+ extract_args
8
+ set_defaults
9
+ end
10
+
11
+ # Processes the file generation/templating
12
+ # This will automatically be run after the initialize method
13
+ def manifest
14
+ system "capify #{RAILS_ROOT}" unless File.exist? "#{RAILS_ROOT}/Capfile"
15
+ record do |m|
16
+ m.directory "config"
17
+ m.template "capistrano_recipe.rb", "config/deploy.rb"
18
+ end
19
+ end
20
+
21
+ # Creates a new Hash Object containing the user input
22
+ # The user input will be available through @input and input
23
+ def extract_args
24
+ @input = Hash.new
25
+ @args.each do |arg|
26
+ if arg.include?(":") then
27
+ @input[:"#{arg.slice(0, arg.index(":"))}"] = arg.slice((arg.index(":") + 1)..-1)
28
+ end
29
+ end
30
+ end
31
+
32
+ # Sets defaults for user input when left blank by the user
33
+ # for each parameter
34
+ def set_defaults
35
+ @input[:domain] ||= "example.com"
36
+ @input[:user] ||= "root"
37
+ @input[:deploy_path] ||= "/var/rails/example.com"
38
+ @input[:repository_type] ||= "git"
39
+ @input[:repository_url] ||= "ssh://root@example.com/var/git/example.git"
40
+ @input[:reeip] ||= "/opt/ruby-enterprise-1.8.6-20090610"
41
+ @input[:ssh_address] ||= nil
42
+ @input[:crontab_id] ||= nil
43
+ end
44
+
45
+ # Input Method that's available inside the generated templates
46
+ # because instance variable are not available, so we access them through methods
47
+ def input
48
+ @input
49
+ end
50
+
51
+ end
@@ -0,0 +1,156 @@
1
+ # Author: Michael van Rooijen
2
+ # Description:
3
+ # This recipe is designed to work for people using Phusion Passenger,
4
+ # Git as your repository.
5
+ #
6
+ # The script (initially) does the following:
7
+ # - It first (after you run cap:deploy setup) will set up the capistrano environment on your remote machine
8
+ # - After that, it will sync your current database.yml file to the "shared" location on the remote machine
9
+ # - You are now basically ready to deploy.
10
+ # - Once you run "cap:deploy" it will start the deployment
11
+ # - First, it will reach for your remote repository and pull out the files
12
+ # - The application will be placed in a new revision folder
13
+ # - The "current" symlink will be updated upon completion of the transfer above
14
+ # - It will then set up the symlinks from the current application to the "shared"
15
+ # section for the database.yml, production.sqlite3 and the "assets" directory.
16
+ # - Once this is done, Capistrano will initiallize the Passenger Instance and your application should be up and running!
17
+ # - One last task will be performed right after this, and that is that Capistrano will give Rails specific "rights" (www-data:www-data)
18
+ # to the whole application. This will make sure that nothing that should be writed/modified will kill the application, such as:
19
+ # stylesheets/javascripts when :cache => true, writing to sqlite3 database, using upload gems such as paperclip.
20
+ #
21
+ # So, now your application is up and running. Long Story Short:
22
+ #
23
+ # Create a new Rails App. Create a Git Repository. Add your remote repository to it.
24
+ # Push all your data to the remote repository. Configure this file. Run "cap:deploy setup" to setup the remote machine's environment.
25
+ # Run "cap:deploy" and your web application should be running in a matter of seconds.
26
+ #
27
+ # If you are not using sqlite3 and get a (500)error right off the bat, first place to look is whether your database exists on the remote server
28
+ # ( I always forget this part ;) )
29
+ #
30
+ # This Capistrano Recipe is just a base awaiting to be expanded!
31
+ # So feel free to do so.
32
+
33
+
34
+
35
+
36
+ # SETTINGS
37
+ # Application Domain (example.domain.com)
38
+ # Be sure to fill in the correct domain name for your web application!
39
+ set :application, "<%= input[:domain] %>"
40
+
41
+ # Set server where the application is going to be uploaded to.
42
+ # Automatically filled in with the application variable.
43
+ role :web, application
44
+ role :app, application
45
+ role :db, application
46
+
47
+ # Crontab
48
+ # Change "application" to whatever you want if you wish to use a different identifier
49
+ # to reduce the chance it might conflict with another application.
50
+ <% if input[:crontab_id] -%>
51
+ set :crontab_id, "<%= input[:crontab_id] %>"
52
+ <% else -%>
53
+ set :crontab_id, application
54
+ <% end -%>
55
+
56
+ # SSH Address
57
+ # Change "application" to whatever you want if you wish to use a dfferent address to connect to.
58
+ # This can either be an IP or a URL that points at the same IP.
59
+ <% if input[:ssh_address] -%>
60
+ set :ssh_address, "<%= input[:ssh_address] %>"
61
+ <% else -%>
62
+ set :ssh_address, application
63
+ <% end -%>
64
+
65
+ # Set the user
66
+ # :user => Set the user that will attempt to access the remote repository
67
+ # :deploy_to => Set the deployment location (destination) on the remote server
68
+ # :use_sudo => Set to false
69
+ set :user, "<%= input[:user] %>"
70
+ set :deploy_to, "<%= input[:deploy_path] %>"
71
+ set :use_sudo, false
72
+
73
+ # Git Repository Location
74
+ # :scm => Specify the source code management tool you want to use (default is git)
75
+ # :repository => Assign the repository location where the application resides
76
+ # :branch => Select the branch that capistrano should fetch from (default is master)
77
+ set :scm, "<%= input[:repository_type] %>"
78
+ set :repository, "<%= input[:repository_url] %>"
79
+ set :branch, "master"
80
+
81
+ # Ruby Enterprise Edition
82
+ set :ruby_enterprise_edition_installation_path, "<%= input[:reeip] %>"
83
+
84
+ # Required: default_run_options[:pty] - This will allow the user to connect to protected repository after
85
+ # logging in when the system prompts for the server's root password
86
+ # default_run_options => (default is true)
87
+ default_run_options[:pty] = true
88
+
89
+
90
+ # TASKS
91
+ # You can add additional deployment tasks, or alter the ones below.
92
+
93
+ namespace :deploy do
94
+
95
+ desc "Restart Application with Passenger and make the application writable."
96
+ task :restart do
97
+ run "touch #{current_path}/tmp/restart.txt"
98
+ run "chown -R www-data:www-data #{deploy_to}"
99
+ end
100
+
101
+ desc "Setup the shared folder structure."
102
+ task :setup_shared do
103
+ run "touch #{shared_path}/log/production.log"
104
+ run "mkdir #{shared_path}/db #{shared_path}/assets #{shared_path}/config"
105
+ end
106
+
107
+ desc "Syncs the database.yml to the server"
108
+ task :sync_database_yaml do
109
+ system "rsync -vr --exclude='.DS_Store' config/database.yml #{user}@#{ssh_address}:#{shared_path}/config/"
110
+ end
111
+
112
+ desc "Syncs the backup.sqlite3 to the server"
113
+ task :sync_backup_database do
114
+ system "rsync -vr --exclude='.DS_Store' db/backup.sqlite3 #{user}@#{ssh_address}:#{shared_path}/db/"
115
+ end
116
+
117
+ desc "Sets up symbolic links."
118
+ task :setup_symlinks do
119
+ run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
120
+ run "ln -nfs #{shared_path}/db/production.sqlite3 #{release_path}/db/production.sqlite3"
121
+ run "ln -nfs #{shared_path}/db/backup.sqlite3 #{release_path}/db/backup.sqlite3"
122
+ run "ln -nfs #{shared_path}/assets #{release_path}/public/assets"
123
+ end
124
+
125
+ desc "Reset remote rails environment."
126
+ task :reset_rails_environment do
127
+ run "rm -rf #{deploy_to}"
128
+ system "cap deploy:setup"
129
+ end
130
+
131
+ desc "Installs any 'not-yet-installed' gems on the production server."
132
+ task :install_gems do
133
+ run "cd #{current_path}; #{ruby_enterprise_edition_installation_path}/bin/rake gems:install RAILS_ENV=production"
134
+ run "cd #{current_path}; rake gems:install RAILS_ENV=production"
135
+ end
136
+
137
+ desc "Update the crontab file"
138
+ task :update_crontab, :roles => :db do
139
+ run "cd #{release_path} && whenever --update-crontab #{crontab_id}"
140
+ end
141
+
142
+ end
143
+
144
+
145
+ # CALLBACKS
146
+ # By adding more tasks, you might want to add more callbacks.
147
+ # Just append more callbacks to the existing ones below.
148
+
149
+ after 'deploy:setup', 'deploy:setup_shared'
150
+ after 'deploy:setup', 'deploy:sync_database_yaml'
151
+ after 'deploy:update_code', 'deploy:setup_symlinks'
152
+
153
+ # Javan-Whenever RubyGem
154
+ # If you're using this gem and want to update the cron on the server after every deployment
155
+ # then simply uncomment the line below:
156
+ #after 'deploy:symlink', 'deploy:update_crontab'
@@ -0,0 +1,3 @@
1
+ This is a very small generator that just generates a .gitignore file in the RAILS_ROOT with a couple of predefined ingore lines.
2
+ ==== No arguments can be supplied here:
3
+ script/generate simple_git_template
@@ -0,0 +1,17 @@
1
+ class SimpleGitTemplateGenerator < Rails::Generator::Base
2
+
3
+ # This method gets initialized when the generator gets run.
4
+ # It will receive an array of arguments inside @args
5
+ def initialize(runtime_args, runtime_options = {})
6
+ super
7
+ end
8
+
9
+ # Processes the file generation/templating
10
+ # This will automatically be run after the initialize method
11
+ def manifest
12
+ record do |m|
13
+ m.file "git_ignore", ".gitignore"
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,8 @@
1
+ .DS_Store
2
+ log/*.log
3
+ tmp/**/*
4
+ config/database.yml
5
+ db/*.sqlite3
6
+ public/assets
7
+ public/javascripts/all.js
8
+ public/stylesheets/all.css
@@ -0,0 +1,6 @@
1
+ Now, I always tend to forget all the settings I usually need for my Paperclip model, hence why I created the gem and added this generators as well.
2
+
3
+ ==== To generate a Paperclip Model you are required to supply 2 of the 3 arguments:
4
+ script/generate simple_paperclip_model model:user attachment:avatar [optional: type:image] bucket:my_bucket
5
+
6
+ The optional type:image argument will generate example "styles" for Paperclip.
@@ -0,0 +1,68 @@
1
+ class SimplePaperclipModelGenerator < Rails::Generator::Base
2
+
3
+ # This method gets initialized when the generator gets run.
4
+ # It will receive an array of arguments inside @args
5
+ def initialize(runtime_args, runtime_options = {})
6
+ super
7
+ extract_args
8
+ set_defaults
9
+ confirm_input
10
+ end
11
+
12
+ # Processes the file generation/templating
13
+ # This will automatically be run after the initialize method
14
+ def manifest
15
+ record do |m|
16
+ m.directory "app/models"
17
+ m.directory "config"
18
+ m.template "paperclip.rb", "app/models/#{input[:model]}.rb"
19
+ m.template "s3.yml", "config/s3.yml"
20
+ end
21
+ end
22
+
23
+ # Creates a new Hash Object containing the user input
24
+ # The user input will be available through @input and input
25
+ def extract_args
26
+ @input = Hash.new
27
+ @args.each do |arg|
28
+ if arg.include?(":") then
29
+ @input[:"#{arg.slice(0, arg.index(":"))}"] = arg.slice((arg.index(":") + 1)..-1)
30
+ end
31
+ end
32
+ end
33
+
34
+ # Input Method that's available inside the generated templates
35
+ # because instance variable are not available, so we access them through methods
36
+ def input
37
+ @input
38
+ end
39
+
40
+ # Sets defaults for user input when left blank by the user
41
+ # for each parameter
42
+ def set_defaults
43
+ @input[:type] ||= "image"
44
+ @input[:bucket] ||= "my_bucket"
45
+ end
46
+
47
+ # Confirms whether the model and attachment arguments were passed in
48
+ # Raises an error if not
49
+ def confirm_input
50
+ if @input[:model].nil? or @input[:attachment].nil?
51
+ raise input_error
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ def input_error
58
+ <<-eos
59
+
60
+ A model and attachment must be specified!
61
+
62
+ Example:
63
+ script/generate simple_paperclip_model model:user attachment:avatar
64
+
65
+ eos
66
+ end
67
+
68
+ end
@@ -0,0 +1,38 @@
1
+ class <%= input[:model].camelcase.singularize %> < ActiveRecord::Base
2
+
3
+ # Generated with Simple Generators: Simple Paperclip Model
4
+ # Choose one of the two storage methods below..
5
+
6
+ # Add <%= input[:attachment].singularize.underscore %> attribute
7
+ # Configuration For Filesystem Storage
8
+ has_attached_file :<%= input[:attachment].singularize.underscore %>,
9
+ :url => "/assets/<%= input[:attachment].pluralize %>/:style/:id.:basename.:extension",
10
+ :path => ":rails_root/public/assets/<%= input[:attachment].pluralize %>/:style/:id.:basename.:extension",
11
+ :styles => {
12
+ <% if input[:type].eql?("image") -%>
13
+ :small => '50x45#',
14
+ :medium => '150x150',
15
+ :large => '300x300'
16
+ <% end -%>
17
+ }
18
+
19
+ # Add <%= input[:attachment].singularize.underscore %> attribute
20
+ # Configuration For Amazon S3 Storage
21
+ has_attached_file :<%= input[:attachment].singularize.underscore %>,
22
+ :storage => :s3,
23
+ :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
24
+ :path => "<%= input[:attachment].pluralize %>/:style/:id.:basename.:extension",
25
+ :styles => {
26
+ <% if input[:type].eql?("image") -%>
27
+ :small => '50x45#',
28
+ :medium => '150x150',
29
+ :large => '300x300'
30
+ <% end -%>
31
+ }
32
+
33
+ # Validation
34
+ validates_attachment_presence :<%= input[:attachment].singularize.underscore %>, :message => "You are required to select an <%= input[:attachment].singularize %>."
35
+ validates_attachment_size :<%= input[:attachment].singularize.underscore %>, :less_than => 2.megabytes, :message => "must be less than 500 kilobytes."
36
+ validates_attachment_content_type :<%= input[:attachment].singularize.underscore %>, :content_type => ['image/jpg', 'image/jpeg','image/gif','image/png','image/pjpeg','image/x-png'], :message => "Must be JPG PNG or GIF."
37
+
38
+ end
@@ -0,0 +1,14 @@
1
+ development:
2
+ access_key_id: ACCESS_KEY_ID
3
+ secret_access_key: SECRET_ACCESS_KEY
4
+ bucket: <%= input[:bucket] %>
5
+
6
+ production:
7
+ access_key_id: ACCESS_KEY_ID
8
+ secret_access_key: SECRET_ACCESS_KEY
9
+ bucket: <%= input[:bucket] %>
10
+
11
+ test:
12
+ access_key_id: ACCESS_KEY_ID
13
+ secret_access_key: SECRET_ACCESS_KEY
14
+ bucket: <%= input[:bucket] %>
@@ -0,0 +1,25 @@
1
+ === Simple Repository Tasks
2
+
3
+ This generator will generate 3 rake tasks that can help with creating and destroying your applications remote repository using SSH on your own server.
4
+
5
+ ==== To generates these Repository Rake Tasks, run the following command:
6
+ script/generate simple_repository_tasks
7
+
8
+ If you do it this way, you will manually have to open the rake tasks, located in the lib/tasks/simple_tasks/repository.rake file, and add your server settings in there.
9
+
10
+ ==== If you wish to, like I do, let the generator insert these settings in for you, execute the following command:
11
+ script/generate simple_repository_tasks domain:example.com path:/var/git/example.git
12
+ user:root password:mys3cr3tp4ssw0rd
13
+
14
+ ==== Now, when you run the following command:
15
+ rake -T
16
+
17
+ You will see a list of all your available rake tasks, including the Repository Rake Tasks and their description.
18
+
19
+ These rake tasks allow your to quickly, without manually SSH'ing to your server, create and destroy your git repository for a specific Ruby on Rails application. Additionally, if you haven't already, you can run a simple command (rake simple_tasks:repository:add_to_git) to add your remote repository location (origin) to your local repository.
20
+
21
+ ==== These are the commands that are currently available for the Simple Repository Tasks:
22
+
23
+ rake simple_tasks:repository:add_to_git
24
+ rake simple_tasks:repository:create
25
+ rake simple_tasks:repository:destroy
@@ -0,0 +1,46 @@
1
+ class SimpleRepositoryTasksGenerator < Rails::Generator::Base
2
+
3
+ # This method gets initialized when the generator gets run.
4
+ # It will receive an array of arguments inside @args
5
+ def initialize(runtime_args, runtime_options = {})
6
+ super
7
+ extract_args
8
+ set_defaults
9
+ end
10
+
11
+ # Processes the file generation/templating
12
+ # This will automatically be run after the initialize method
13
+ def manifest
14
+ record do |m|
15
+ m.directory "lib/tasks/simple_tasks"
16
+ m.template "repository.rake", "lib/tasks/simple_tasks/repository.rake"
17
+ end
18
+ end
19
+
20
+ # Creates a new Hash Object containing the user input
21
+ # The user input will be available through @input and input
22
+ def extract_args
23
+ @input = Hash.new
24
+ @args.each do |arg|
25
+ if arg.include?(":") then
26
+ @input[:"#{arg.slice(0, arg.index(":"))}"] = arg.slice((arg.index(":") + 1)..-1)
27
+ end
28
+ end
29
+ end
30
+
31
+ # Sets defaults for user input when left blank by the user
32
+ # for each parameter
33
+ def set_defaults
34
+ @input[:domain] ||= "example.com"
35
+ @input[:path] ||= "/var/git/example.git"
36
+ @input[:user] ||= "root"
37
+ @input[:password] ||= "mys3cr3tp4ssw0rd"
38
+ end
39
+
40
+ # Input Method that's available inside the generated templates
41
+ # because instance variable are not available, so we access them through methods
42
+ def input
43
+ @input
44
+ end
45
+
46
+ end
@@ -0,0 +1,43 @@
1
+ require 'net/ssh'
2
+
3
+ namespace :simple_tasks do
4
+
5
+ namespace :repository do
6
+
7
+ repository_domain = "<%= input[:domain] %>"
8
+ repository_path = "<%= input[:path] %>"
9
+ repository_user = "<%= input[:user] %>"
10
+ repository_password = "<%= input[:password] %>"
11
+
12
+ desc "Creates a remote repository for the Rails application."
13
+ task :create => :filter do
14
+ puts "Creating remote repository.."
15
+ Net::SSH.start(repository_domain, repository_user, :password => repository_password) do |ssh|
16
+ ssh.exec "mkdir -p #{repository_path}; git --bare --git-dir=#{repository_path} init"
17
+ end
18
+ end
19
+
20
+ desc "Removes a remote repository for the Rails application."
21
+ task :destroy => :filter do
22
+ puts "Removing remote repository.."
23
+ Net::SSH.start(repository_domain, repository_user, :password => repository_password) do |ssh|
24
+ ssh.exec "rm -rf #{repository_path}"
25
+ end
26
+ end
27
+
28
+ desc "Adds the remote repository as origin to git."
29
+ task :add_to_git do
30
+ system "git remote rm origin"
31
+ system "git remote add origin ssh://#{repository_user}@#{repository_domain}/#{repository_path}"
32
+ puts "ssh://#{repository_user}@#{repository_domain}/#{repository_path}"
33
+ puts "was successfully added as remote repository (origin)."
34
+ end
35
+
36
+ desc "Filters anything that might cause an error."
37
+ task :filter do
38
+ # => no filters added at the moment
39
+ end
40
+
41
+ end
42
+
43
+ end
File without changes
@@ -0,0 +1,82 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{simple_generators}
8
+ s.version = "0.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Michael van Rooijen"]
12
+ s.date = %q{2009-10-09}
13
+ s.description = %q{A couple of generators that supply you with some common templates to speed up the development process.}
14
+ s.email = %q{meskyan@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "generators/simple_admin_data_setup/USAGE",
27
+ "generators/simple_admin_data_setup/USAGE",
28
+ "generators/simple_admin_data_setup/simple_admin_data_setup_generator.rb",
29
+ "generators/simple_admin_data_setup/simple_admin_data_setup_generator.rb",
30
+ "generators/simple_admin_data_setup/templates/admin_data_setting.rb",
31
+ "generators/simple_admin_data_setup/templates/admin_data_setting.rb",
32
+ "generators/simple_capistrano_recipe/USAGE",
33
+ "generators/simple_capistrano_recipe/USAGE",
34
+ "generators/simple_capistrano_recipe/simple_capistrano_recipe_generator.rb",
35
+ "generators/simple_capistrano_recipe/simple_capistrano_recipe_generator.rb",
36
+ "generators/simple_capistrano_recipe/templates/capistrano_recipe.rb",
37
+ "generators/simple_capistrano_recipe/templates/capistrano_recipe.rb",
38
+ "generators/simple_git_template/USAGE",
39
+ "generators/simple_git_template/USAGE",
40
+ "generators/simple_git_template/simple_git_template_generator.rb",
41
+ "generators/simple_git_template/simple_git_template_generator.rb",
42
+ "generators/simple_git_template/templates/git_ignore",
43
+ "generators/simple_git_template/templates/git_ignore",
44
+ "generators/simple_paperclip_model/USAGE",
45
+ "generators/simple_paperclip_model/USAGE",
46
+ "generators/simple_paperclip_model/simple_paperclip_model_generator.rb",
47
+ "generators/simple_paperclip_model/simple_paperclip_model_generator.rb",
48
+ "generators/simple_paperclip_model/templates/paperclip.rb",
49
+ "generators/simple_paperclip_model/templates/paperclip.rb",
50
+ "generators/simple_paperclip_model/templates/s3.yml",
51
+ "generators/simple_paperclip_model/templates/s3.yml",
52
+ "generators/simple_tasks/simple_repository_tasks/USAGE",
53
+ "generators/simple_tasks/simple_repository_tasks/USAGE",
54
+ "generators/simple_tasks/simple_repository_tasks/simple_repository_tasks_generator.rb",
55
+ "generators/simple_tasks/simple_repository_tasks/simple_repository_tasks_generator.rb",
56
+ "generators/simple_tasks/simple_repository_tasks/templates/repository.rake",
57
+ "generators/simple_tasks/simple_repository_tasks/templates/repository.rake",
58
+ "lib/simple_generators.rb",
59
+ "simple_generators.gemspec",
60
+ "test/simple_generators_test.rb",
61
+ "test/test_helper.rb"
62
+ ]
63
+ s.homepage = %q{http://github.com/meskyanichi/simple_generators}
64
+ s.rdoc_options = ["--charset=UTF-8"]
65
+ s.require_paths = ["lib"]
66
+ s.rubygems_version = %q{1.3.5}
67
+ s.summary = %q{A couple of generators that supply you with some common templates to speed up the development process.}
68
+ s.test_files = [
69
+ "test/simple_generators_test.rb",
70
+ "test/test_helper.rb"
71
+ ]
72
+
73
+ if s.respond_to? :specification_version then
74
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
75
+ s.specification_version = 3
76
+
77
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
78
+ else
79
+ end
80
+ else
81
+ end
82
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class SimpleGeneratorsTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'simple_generators'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_generators
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael van Rooijen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-09 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A couple of generators that supply you with some common templates to speed up the development process.
17
+ email: meskyan@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - generators/simple_admin_data_setup/USAGE
33
+ - generators/simple_admin_data_setup/simple_admin_data_setup_generator.rb
34
+ - generators/simple_admin_data_setup/templates/admin_data_setting.rb
35
+ - generators/simple_capistrano_recipe/USAGE
36
+ - generators/simple_capistrano_recipe/simple_capistrano_recipe_generator.rb
37
+ - generators/simple_capistrano_recipe/templates/capistrano_recipe.rb
38
+ - generators/simple_git_template/USAGE
39
+ - generators/simple_git_template/simple_git_template_generator.rb
40
+ - generators/simple_git_template/templates/git_ignore
41
+ - generators/simple_paperclip_model/USAGE
42
+ - generators/simple_paperclip_model/simple_paperclip_model_generator.rb
43
+ - generators/simple_paperclip_model/templates/paperclip.rb
44
+ - generators/simple_paperclip_model/templates/s3.yml
45
+ - generators/simple_tasks/simple_repository_tasks/USAGE
46
+ - generators/simple_tasks/simple_repository_tasks/simple_repository_tasks_generator.rb
47
+ - generators/simple_tasks/simple_repository_tasks/templates/repository.rake
48
+ - lib/simple_generators.rb
49
+ - simple_generators.gemspec
50
+ - test/simple_generators_test.rb
51
+ - test/test_helper.rb
52
+ has_rdoc: true
53
+ homepage: http://github.com/meskyanichi/simple_generators
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --charset=UTF-8
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.5
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: A couple of generators that supply you with some common templates to speed up the development process.
80
+ test_files:
81
+ - test/simple_generators_test.rb
82
+ - test/test_helper.rb