module SimpleAddressGenerator module Generators class SimpleAddressGeneratorGenerator < Rails::Generators::Base source_root File.expand_path('../templates', __FILE__) def create_address_model generate("model", "address address_line_1:string address_line_2:string city:string state:string postal_code:string country:string telephone_number:string latitude:float longitude:float category_id:integer") rake("db:migrate") end def generate_everything_else directory "gmaps4rails", "app/assets/javascripts/gmaps4rails/" directory "addresses", "app/views/addresses/" copy_file "addresses_controller.rb", "app/controllers/addresses_controller.rb" copy_file "address.rb", "app/models/address.rb" copy_file "icon-1.png", "app/assets/images/icon-1.png" end def insert_code_application inject_into_file "app/views/layouts/application.html.erb", after: "<%= yield %>" do a = "<%= yield:scripts %>" a end end def insert_to_model inject_into_file "app/models/address.rb", after: "attr_accessible :address_line_1, :address_line_2, :category_id, :city, :country, :latitude, :longitude, :postal_code, :state, :telephone_number" do a = "\n\n attr_accessor :gmaps" b = "\n\n geocoded_by :full_address" c = "\n\n after_validation :geocode" d = "\n\n acts_as_gmappable" e = "\n\n def full_address" f = "\n [self.address_line_1, self.address_line_2, self.city, self.state, self.country, self.postal_code].compact.join(", ")" g = "\n end" h = "\n\n def gmaps4rails_address" i = "\n full_address" j = "\n end" k = "\n\n def gmaps4rails_marker_picture" l = "\n {" m = "\n 'picture' => '/assets/icon-1.png'," n = "\n 'width => 30," o = "\n height' => 30," p = "\n 'marker_anchor => [ 5, 10]," q = "\n 'picture' => '/assets/icon-1.png'," r = "\n 'picture' => '/assets/icon-1.png'," s = "\n 'picture' => '/assets/icon-1.png'," t = "\n }" u = "\n end" a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+s+t+u end end def insert_routes route("resources :addresses") end def add_gems gem("geocoder") gem("gmaps4rails") end end end end