Class: Kablam::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/kablam/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#basic_setupObject

argument :name, :type => :string, :default => “en”



9
10
11
12
13
14
15
16
# File 'lib/generators/kablam/install_generator.rb', line 9

def basic_setup
  # Change ApplicationRecord's inheritence
  gsub_file 'app/models/application_record.rb', 'class ApplicationRecord < ActiveRecord::Base', 'class ApplicationRecord < Kablam::KablamRecord'

  # Setup Initializer
  template "kablam.rb", "config/initializers/kablam.rb"
  copy_file "_sample_target_item.html.erb", "app/views/kablam/models/_sample_target_item.html.erb"
end

#setup_assetsObject



24
25
26
27
28
29
# File 'lib/generators/kablam/install_generator.rb', line 24

def setup_assets
  inject_into_file 'app/assets/javascripts/application.js', before: "//= require_tree ." do
    "//= require kablam/ajax \n//= require kablam/forms\n"
  end
  prepend_file 'app/assets/stylesheets/application.css.scss', "@import 'kablam';\n"
end

#setup_routesObject



17
18
19
20
21
22
# File 'lib/generators/kablam/install_generator.rb', line 17

def setup_routes
  inject_into_file 'config/routes.rb', before: "end" do
    "  # KABLAM! form/create/update/destroy/undo for all models\n  # Note: Make sure Kablam engine is at the BOTTOM of routes\n  # helpers to use KABLAM! [examples w/ 'posts' model)\n  # --->  kablam.form_path('posts')\n  #  (if edit form, must add '?id=\#\{@post.id\}' to path)\n  # --->  kablam.create_path('posts')\n  # --->  kablam.delete_path('posts', @post)\n  # --->  kablam.update_path('posts', @post)\n  # --->  kablam.undo_path('posts', @post)\n  mount Kablam::Engine => '/kablam', as: 'kablam'\n"
  end

end