Skip to content

Instantly share code, notes, and snippets.

@TMorgan99
Created October 14, 2009 08:46
Show Gist options
  • Save TMorgan99/209898 to your computer and use it in GitHub Desktop.
Save TMorgan99/209898 to your computer and use it in GitHub Desktop.
### This is a template file for generating the GVMP rails-application
# ================
log '== PATCH '
# ================
FileUtils.rm 'public/index.html' rescue nil
gsub_file 'app/controllers/application_controller.rb', /#\s*(filter_parameter_logging :password)/, '\1'
# layout, with the active_scaffold included.
file 'app/views/layouts/application.html.erb', <<-'__ERB'
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>GVMP</title>
<%= javascript_include_tag :defaults %>
<%= active_scaffold_includes %>
</head>
<body>
<p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
</body>
</html>
__ERB
append_file 'config/environment.rb', <<-'__ENV'
# still no newline?
# remove hobo methods
class ActiveRecord::Base
class << self
def hobo_model; end
def fields &block; end
end
end
__ENV
# ================
log '== GEM '
# ================
gem :hobo, :env => 'test'
gem :cucumber, :env => 'test'
gem :rspec, :env => 'test', :lib => false
gem :'rspec-rails', :env => 'test', :lib => false
gem :webrat, :env => 'test'
rake 'gems:install', :env => 'test'
rake 'gems:install gems:unpack'
# ================
log '== PLUGIN '
# ================
#
# # plugin does not recoginse options for --revision!
plugins = %w[active_scaffold]
if true # copy from cache
FileUtils.cp_r plugins.map { |plug| File.join ENV['HOME'], '/.rails/plugins/', plug }, 'vendor/plugins/'
else # download fresh, and update cache
plugin :active_scaffold, :git => 'git://github.com/activescaffold/active_scaffold.git'
FileUtils.cp_r 'vendor/plugins/', File.join( ENV['HOME'], '/.rails/plugins/' )
end
# ================
log '== GENERATE '
# ================
generate :rspec
generate :session_migration
# generate 'authenticated', 'user session --include-activation --aasm --include-password-reset'
# route 'map.resources :users, :member => { :suspend => :put, :unsuspend => :put, :purge => :delete }'
#
# authenticated_patches
# ================
log '== RESOURCES'
# ================
generate :resource, "clippings", 'date_sequence:date author:string date_text:string source:string source_url:string title:string title_url:string description:text'
generate :resource, "colleagues", 'sequence:float email:string family_name:string given_name:string photo:string role:string description:text'
generate :resource, "communities", 'delta:boolean adder_ip:string category:string city:string country:string creator_ip:string name:string official_url:string prov_state:string scope:string short_name:string wiki_url:string add_to_description:text description:text'
generate :resource, "faqs", 'importance:float sequence:float category:string question:string answer:text'
generate :resource, "presentations", 'pdate:date host:string place:string'
generate :resource, "proposals", 'in_proxy:boolean date_agm:date date_submitted:date yes_percent:float company:string company_url:string proposal_type:string proposal_url:string proxy_url:string ticker:string correspondence:text'
generate :resource, "pubs", 'date_sequence:date country:string date_text:string journal:string title:string'
generate :resource, "rankings", 'count0:float count1:float rank:float share:float community:belongs_to sequence:integer website:belongs_to'
generate :resource, "users", 'remember_token_expires_at:datetime permission:decimal crypted_password:string email:string login:string name:string remember_token:string salt:string'
generate :resource, "votes", 'support:float ballot_type:integer community:belongs_to website:belongs_to ip_address:string'
generate :resource, "websites", 'creator_ip:string title:string url:string'
route 'map.root :controller => \'communities\''
# ================
log '== ASSOCIATE '
# ================
#
# tag=/(^\s*## == VALIDATIONS)/m
#
# gsub_file 'app/models/community.rb', tag, "#{ <<-_RUBY_ }\\1\n#{ <<-__RUBY }"
#
# has_many :rankings do
# def with_websites
# map { |r| {
# :rank => r.rank,
# :created_at => r.created_at,
# :website => r.website,
# :share => r.share,
# :count0 => r.count0,
# :count1 => r.count1 }
# }.sort_by { |r| [r[:share], r[:count1] ]
# }.reverse
# end
# end
#
# has_many :websites, :through => :rankings
#
# ## == SCOPES
# default_scope :order => 'country, category, name'
# # How to substitute this order when called from communities/manage ? Done crudely below by defining filter_manage.
# # default_scope :order => 'created_at DESC'. This works on my Mac but not at RailsPlayground!
# _RUBY_
# validates_presence_of :name, :short_name
# validates_presence_of :category, :message => "(Type) can't be blank"
#
# validates_length_of :name, :maximum => 50
# validates_length_of :short_name, :maximum => 20, :message => ": please shorten to 20 characters or less"
# validates_length_of :category, :maximum => 20
# validates_length_of :country, :maximum => 30
# validates_length_of :prov_state, :maximum => 30
# validates_length_of :city, :maximum => 30
#
# __RUBY
#
# # -- supply empty featured method ( just before end)
# gsub_file 'app/models/community.rb', /^(end)$/, "#{ <<-__RUBY }\n\\1"
#
# class << self
# def featured
# []
# end
# end
# __RUBY
#
# gsub_file 'app/models/website.rb', tag, "#{ <<-_RUBY_ }\\1\n#{ <<-__RUBY }"
# has_many :votes
# has_many :rankings
# has_many :communities, :through => :rankings
#
# ## == SCOPES
# default_scope :order => "id DESC"
# _RUBY_
# validates_presence_of :url
# __RUBY
# ================
log '== MIGRATE '
# ================
# need to ensure all migrations are current before hobo
rake 'db:migrate'
# need to use the shell here to pipe a yes-stream of newlines
run 'yes "" |generate hobo_migration --generate'
rake 'db:migrate db:test:prepare db:fixtures:load'
log '** ((SUCCESS)) **'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment