Class: Datagrid::Scaffold

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/datagrid/scaffold.rb

Instance Method Summary collapse

Instance Method Details

#create_scaffoldObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/datagrid/scaffold.rb', line 6

def create_scaffold
  template "grid.rb.erb", "app/grids/#{grid_class_name.underscore}.rb"
  template "controller.rb.erb", "app/controllers/#{grid_controller_name.underscore}.rb"
  template "index.html.erb", "app/views/#{grid_controller_short_name}/index.html.erb"
  route("resources :#{grid_controller_short_name}")
  unless defined?(::Kaminari) || defined?(::WillPaginate)
    gem 'kaminari'
  end
  in_root do
    {
      "css" => " *= require datagrid",
      "css.sass" => " *= require datagrid",
      "css.scss" => " *= require datagrid",
    }.each do |extension, string|
      file = "app/assets/stylesheets/application.#{extension}"
      if File.exists?(Rails.root.join(file))
        inject_into_file file, string + "\n", {:before => %r{.*require_self}} # before all
      end
    end
  end
end

#grid_class_nameObject



28
29
30
# File 'lib/datagrid/scaffold.rb', line 28

def grid_class_name
  file_name.camelize.pluralize + "Grid"
end

#grid_controller_nameObject



32
33
34
# File 'lib/datagrid/scaffold.rb', line 32

def grid_controller_name
  grid_controller_short_name.camelize + "Controller"
end

#grid_controller_short_nameObject



36
37
38
# File 'lib/datagrid/scaffold.rb', line 36

def grid_controller_short_name
  file_name.underscore.pluralize
end

#grid_ivar_nameObject



44
45
46
# File 'lib/datagrid/scaffold.rb', line 44

def grid_ivar_name
  grid_class_name.underscore
end

#grid_model_nameObject



40
41
42
# File 'lib/datagrid/scaffold.rb', line 40

def grid_model_name
  file_name.camelize.singularize
end

#grid_route_nameObject



62
63
64
# File 'lib/datagrid/scaffold.rb', line 62

def grid_route_name
  grid_controller_short_name + "_path"
end

#paginate_codeObject



48
49
50
# File 'lib/datagrid/scaffold.rb', line 48

def paginate_code
  "page(params[:page])"
end

#pagination_helper_codeObject



52
53
54
55
56
57
58
59
60
# File 'lib/datagrid/scaffold.rb', line 52

def pagination_helper_code
  if defined?(::WillPaginate)
    "will_paginate(@grid.assets)"
  else
    # Kaminari is default
    "paginate(@grid.assets)"
  end

end