Class: LoadbehindGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/loadbehind/loadbehind_generator.rb

Constant Summary collapse

IMAGES =
["error", "growl_bottom", "growl_repeat", "growl_top", "info"]
JAVASCRIPTS =
["loadbehind", "jquery.growl", "jquery.ajax.enhance"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#action_nameObject

Returns the value of attribute action_name.



46
47
48
# File 'lib/generators/loadbehind/loadbehind_generator.rb', line 46

def action_name
  @action_name
end

Instance Method Details

#generate_loadbehindObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/generators/loadbehind/loadbehind_generator.rb', line 7

def generate_loadbehind
  view_dir = "app/views/#{plural_name}"

  JAVASCRIPTS.each do |js|
    copy_file "#{js}.js", "public/javascripts/#{js}.js"
  end

  IMAGES.each do |image|
    copy_file "images/#{image}.png", "public/images/growl/#{image}.png"
  end

  ["index", "show"].each do |act|
    self.action_name = act
    template "view.js.haml", "#{view_dir}/#{action_name}.js.haml"
  end
  self.action_name = "show"
  template "view.js.haml", "#{view_dir}/update.js.haml"
  template "view.js.haml", "#{view_dir}/create.js.haml"

  ["edit", "new"].each do |act|
    self.action_name = 'form'
    template "edit.js.haml", "#{view_dir}/#{act}.js.haml"
  end

  ["destroy.js"].each do |file|
    template "#{file}.haml", "#{view_dir}/#{file}.haml"
  end

  puts "Add the following code to your layout..."
  JAVASCRIPTS.each do |j|
    puts "  = javascript_include_tag \"#{j}.js\""
  end

  puts "**** Remember to add loadbehind.js and jquery.growl.js to the
  javascript tags, or add it to your own js files.
  You'll also need to add handling to see that all your
  events are reconnected each time you reload. "
end