Class: Mizugumo::ViewGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Rails::Generators::ResourceHelpers
Defined in:
lib/generators/rails/mizugumo/view_generator.rb

Direct Known Subclasses

ErbGenerator, HamlGenerator

Constant Summary collapse

JS_VIEWS =
%w(create destroy edit new update)
HTML_VIEWS =
%w(index edit show new _form)

Instance Method Summary collapse

Instance Method Details

#add_javascriptObject

in Rails 3.0, this gets injected into application.js. in Rails 3.1, it’s handled by overriding the JS Assets Generator



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/generators/rails/mizugumo/view_generator.rb', line 30

def add_javascript
  return if Mizugumo::RAILS_31 
  js_content = <<ADDITIONAL_JS
  Ninja.behavior({
// Generated by the mizugumo scaffold
// AJAX behavior for edit, new, and delete actions; applies to both forms and links
'.new_#{singular_table_name}': Ninja.submitsAsAjax,
'.edit_#{singular_table_name}': Ninja.submitsAsAjax,
'.delete_#{singular_table_name}': Ninja.submitsAsAjax
  });
  
ADDITIONAL_JS
 file = File.join("public", "javascripts", "application.js")
 insert_into_file(file, :before => '  Ninja.go();') { js_content }
 
end

#copy_js_filesObject



21
22
23
24
25
26
# File 'lib/generators/rails/mizugumo/view_generator.rb', line 21

def copy_js_files
  JS_VIEWS.each do |view|
    filename = "#{view}.js.erb"
    template filename, File.join("app/views", controller_file_path, filename)
  end
end

#create_root_folderObject



17
18
19
# File 'lib/generators/rails/mizugumo/view_generator.rb', line 17

def create_root_folder
  empty_directory File.join("app/views", controller_file_path)
end