Class: AppGenerator

Inherits:
VraptorScaffold::Base show all
Defined in:
lib/vraptor-scaffold/generators/app/app_generator.rb

Constant Summary collapse

ORMS =
%w( jpa hibernate )

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, opts = []) ⇒ AppGenerator

Returns a new instance of AppGenerator.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 30

def initialize(args, opts=[])
  super([args], opts)
  validate
  self.destination_root=(project_path)
  @project_name = project_path.split("/").last
  @dependency_manager = DependencyManager.new(options)
  @javascripts = Configuration::JAVASCRIPTS
  @stylesheets = Configuration::STYLESHEETS
  @images = Configuration::IMAGES
  @img = File.join Configuration::WEB_APP, "img"
end

Class Method Details



26
27
28
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 26

def self.banner
  "vraptor new #{self.arguments.map(&:usage).join(' ')} [options]"
end

.source_rootObject



22
23
24
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 22

def self.source_root
  File.join File.dirname(__FILE__), "templates"
end

Instance Method Details

#configure_mavenObject



47
48
49
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 47

def configure_maven
  template("pom.erb", "pom.xml") 
end

#configure_ormObject



83
84
85
86
87
88
89
90
91
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 83

def configure_orm
  if (orm == "hibernate")
    copy_file("orm/hibernate.cfg.xml", (File.join Configuration::MAIN_RESOURCES, "hibernate.cfg.xml"))
  else
    metainf = File.join Configuration::MAIN_RESOURCES, 'META-INF'
    empty_directory metainf
    copy_file("orm/persistence.xml", (File.join metainf, "persistence.xml"))
  end
end

#configure_scaffold_propertiesObject



101
102
103
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 101

def configure_scaffold_properties
  template("vraptor-scaffold.erb", Configuration::FILENAME)
end

#configure_vraptor_packagesObject



51
52
53
54
55
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 51

def configure_vraptor_packages
  vraptor_util_package = "br.com.caelum.vraptor"
  @vraptor_packages = []
  @vraptor_packages += ["#{vraptor_util_package}.util.#{orm}"] if orm == "jpa" or orm == "hibernate"
end

#create_angular_filesObject



127
128
129
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 127

def create_angular_files
  copy_file("angular/angular.js", "#{@javascripts}/angular.js")
end

#create_bootstrap_filesObject



118
119
120
121
122
123
124
125
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 118

def create_bootstrap_files
  empty_directory @img
  copy_file("bootstrap/bootstrap.js", "#{@javascripts}/bootstrap.js")
  copy_file("bootstrap/bootstrap.css", "#{@stylesheets}/bootstrap.css")
  copy_file("bootstrap/bootstrap-responsive.css", "#{@stylesheets}/bootstrap-responsive.css")
  copy_file("bootstrap/glyphicons-halflings-white.png", "#{@img}/glyphicons-halflings-white.png")
  copy_file("bootstrap/glyphicons-halflings.png", "#{@img}/glyphicons-halflings.png")
end

#create_controllers_directoryObject



63
64
65
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 63

def create_controllers_directory
  empty_directory File.join @src, options[:controllers_package]
end

#create_eclipse_filesObject



139
140
141
142
143
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 139

def create_eclipse_files
  template("eclipse/classpath.erb", ".classpath")
  template("eclipse/project.erb", ".project")
  directory("eclipse/settings", ".settings")
end

#create_frontend_directoryObject



135
136
137
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 135

def create_frontend_directory
  empty_directory Configuration::FRONTEND
end

#create_javascriptsObject



97
98
99
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 97

def create_javascripts
  create_file File.join @javascripts, "application.js"
end

#create_jquery_filesObject



114
115
116
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 114

def create_jquery_files
  copy_file("jquery/jquery.min.js", "#{@javascripts}/jquery.min.js")
end

#create_main_javaObject



57
58
59
60
61
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 57

def create_main_java
  empty_directory Configuration::MAIN_SRC
  @src = File.join(Configuration::MAIN_SRC, options[:package].gsub(".", File::Separator))
  copy_file("heroku/Main.java", "#{Configuration::MAIN_SRC}/Main.java")
end

#create_main_resourcesObject



79
80
81
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 79

def create_main_resources
  directory("resources", Configuration::MAIN_RESOURCES)
end

#create_models_directoryObject



67
68
69
70
71
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 67

def create_models_directory
  models_folder = File.join @src, options[:models_package]
  empty_directory models_folder
  template("models/Entity.erb", "#{models_folder}/Entity.java") 
end

#create_repositories_directoryObject



73
74
75
76
77
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 73

def create_repositories_directory
  repositories_folder = File.join @src, options[:repositories_package]
  empty_directory repositories_folder
  template("orm/Repository-#{orm}.java.tt", "#{repositories_folder}/Repository.java")
end

#create_root_folderObject



42
43
44
45
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 42

def create_root_folder
  empty_directory "."
  copy_file("heroku/Procfile", "Procfile")
end

#create_testObject



105
106
107
108
109
110
111
112
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 105

def create_test
  empty_directory Configuration::TEST_SRC
  test_src = File.join(Configuration::TEST_SRC, options[:package].gsub(".", File::Separator))
  empty_directory File.join test_src, options[:controllers_package]
  empty_directory File.join test_src, options[:models_package]
  empty_directory File.join test_src, options[:repositories_package]
  directory("resources-test", Configuration::TEST_RESOURCES)
end

#create_underscore_filesObject



131
132
133
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 131

def create_underscore_files
  copy_file("underscore/underscore.min.js", "#{@javascripts}/underscore.min.js")
end

#create_webappObject



93
94
95
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 93

def create_webapp
  directory("webapp", Configuration::WEB_APP)
end