Class: Ingoweiss::ScaffoldViewsGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Rails::Generators::ResourceHelpers, ScopeHelpers
Defined in:
lib/generators/ingoweiss/scaffold_views/scaffold_views_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ScopeHelpers

#instance_variable_scope, #scope, #scope_prefix, #scoped?, #scoped_controller_class_name, #scoped_controller_plural_name, #singleton?, #unscoped?

Class Method Details

.source_rootObject



14
15
16
# File 'lib/generators/ingoweiss/scaffold_views/scaffold_views_generator.rb', line 14

def self.source_root
  @source_root ||= File.expand_path('../templates', __FILE__)
end

Instance Method Details

#generate_viewsObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/generators/ingoweiss/scaffold_views/scaffold_views_generator.rb', line 18

def generate_views
  template 'index.html.erb',    "app/views/#{scoped_controller_plural_name}/index.html.erb" unless options[:singleton]
  template '_entry.html.erb',   "app/views/#{scoped_controller_plural_name}/_#{singular_name}.html.erb"
  template 'new.html.erb',      "app/views/#{scoped_controller_plural_name}/new.html.erb"
  template 'edit.html.erb',     "app/views/#{scoped_controller_plural_name}/edit.html.erb"
  template '_fields.html.erb',  "app/views/#{scoped_controller_plural_name}/_fields.html.erb"
  template 'show.html.erb',     "app/views/#{scoped_controller_plural_name}/show.html.erb"
  template 'layout.html.erb',   "app/views/layouts/scaffold.html.erb" unless File.exists?(File.join(destination_root, 'app/views/layouts/scaffold.html.erb'))
  invoke :stylesheets
end


29
30
31
32
33
# File 'lib/generators/ingoweiss/scaffold_views/scaffold_views_generator.rb', line 29

def inject_link_to_children_index
  return if singleton? || unscoped?
  parent_resource_view_folder = (scope[0..-2].collect(&:singularize) << scope.last).join('_')
  append_file "app/views/#{parent_resource_view_folder}/show.html.erb", "<%= link_to 'Show #{plural_name}', #{scope_prefix}#{plural_name}_path(#{instance_variable_scope}) %>\n"
end