Class: Chapter10::Generators::BeginGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/chapter10/begin/begin_generator.rb

Instance Method Summary collapse

Instance Method Details

#augment_gemfileObject



10
11
12
13
# File 'lib/generators/chapter10/begin/begin_generator.rb', line 10

def augment_gemfile
  gem 'faker',         '~> 0.9.5'
  gem 'will_paginate', '~> 3.0.pre2'
end

#copy_app_treeObject



6
7
8
# File 'lib/generators/chapter10/begin/begin_generator.rb', line 6

def copy_app_tree
  directory(self.class.source_root, Rails.root)
end

#generate_instructionsObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/chapter10/begin/begin_generator.rb', line 27

def generate_instructions
  require 'rdiscount'
  
  instr_md = File.expand_path('../instructions.md',self.class.source_root)
  return unless File.exists?(instr_md)
  dest = File.join(Rails.root,'doc','chapter10.html')
  copy_file(instr_md, dest, :force => true) do |content|
    RDiscount.new(content).to_html
  end
  say_status('Note',"Now open file://#{dest} in your web browser for instructions", :cyan)
end

#insert_cssObject



15
16
17
18
19
# File 'lib/generators/chapter10/begin/begin_generator.rb', line 15

def insert_css
  src  = File.expand_path("../snippets/custom.css", __FILE__)
  dest = File.join(Rails.root,'public','stylesheets','custom.css')
  insert_into_file(dest, File.binread(src), :before => /\Z/) # insert before end
end

#insert_factoriesObject



21
22
23
24
25
# File 'lib/generators/chapter10/begin/begin_generator.rb', line 21

def insert_factories
  src  = File.expand_path("../snippets/factories.rb", __FILE__)
  dest = File.join(Rails.root,'spec','factories.rb')
  insert_into_file(dest, File.binread(src), :before => /\Z/) # insert before end
end