Class: Hanber::Generators::ScaffoldGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
GeneratorHelpers
Defined in:
lib/generators/hanber/scaffold_generator.rb

Instance Method Summary collapse

Methods included from GeneratorHelpers

#application_name, #ember_path

Instance Method Details

#create_modelObject



16
17
18
19
20
21
# File 'lib/generators/hanber/scaffold_generator.rb', line 16

def create_model
  unless options.skip_model?
    generate("hanber:model", "#{file_name} #{puts attributes}")
  end
  #template 'model.js', File.join('app/assets/javascripts/models', class_path, "#{file_name}.js")
end

#create_resourceful_routeObject

template ‘model.js’, File.join(‘app/assets/javascripts/models’, class_path, “#file_name.js”)



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/generators/hanber/scaffold_generator.rb', line 22

def create_resourceful_route

  insert_into_file "app/assets/javascripts/router.js", after: ".map(function(match) {\n" do
    %Q(  
  match("/#{file_name.pluralize}").to("#{file_name.pluralize}", function(match) {
    match("/").to("#{file_name.pluralize}Index");
    match("/new").to("#{file_name}New");
    match("/:#{file_name.underscore}_id").to("#{file_name}", function(match) {
match('/').to("#{file_name}Show")
match("/content").to("#{file_name}Edit");
    });
  });
    )
  end
end

#create_route_handlersObject



37
38
39
40
41
42
43
# File 'lib/generators/hanber/scaffold_generator.rb', line 37

def create_route_handlers
  resource_hash = {show: "#{file_name}Show", index: "#{file_name.pluralize}Index", new: "#{file_name}New", edit: "#{file_name}Edit"}
  resource_hash.each do |restful_action, restful_name|
    @rest_action = restful_name
    template('scaffolded_route.js', File.join("app/assets/javascripts/route_handlers/#{file_name}_routes", class_path, "#{restful_action.to_s}.js"))
  end
end