Class: AppGenerator

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

Constant Summary

TEMPLATE_ENGINES =
%w( jsp ftl )
BUILD_TOOLS =
%w( ant mvn gradle )
ORMS =
%w( jpa hibernate objectify )
IVY_JAR =
"ivy-2.2.0.jar"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of AppGenerator



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

def initialize(args, opts=[])
  super([args], opts)
  validate
  self.destination_root=(project_path)
  @project_name = project_path.split("/").last
  @dependencies = DependencyManager.new(options).dependencies
end

Class Method Details



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

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

.source_rootObject



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

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

Instance Method Details

#configure_antObject



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

def configure_ant
  if build_tool == "ant"
    create_eclipse_files unless options[:skip_eclipse]
    copy_file("build.xml")
    template("build.properties.erb", "build.properties")
    template("ivy.erb", "ivy.xml")
    copy_file(IVY_JAR)
  end
end

#configure_gradleObject



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

def configure_gradle
  template("build.gradle.erb", "build.gradle") if build_tool == "gradle"
end

#configure_mavenObject



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

def configure_maven
  template("pom.erb", "pom.xml") if build_tool == "mvn"
end

#configure_ormObject



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

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



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

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

#configure_template_engineObject



145
146
147
148
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 145

def configure_template_engine
  templates = {"jsp" => JspTemplateEngine, "ftl" => FreemarkerTemplateEngine}
  templates[options[:template_engine]].new(project_path, @options).configure if templates[options[:template_engine]]
end

#configure_vraptor_packagesObject



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

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_controllers_directoryObject



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

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

#create_javascriptsObject



132
133
134
135
136
137
138
139
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 132

def create_javascripts
  javascripts = File.join Configuration::WEB_APP, "javascripts"
  create_file File.join javascripts, "application.js"
  unless options[:skip_jquery]
    jquery = get_jquery
    add_file (File.join javascripts, "jquery.min.js"), jquery.body if jquery
  end
end

#create_main_javaObject



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

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

#create_main_resourcesObject



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

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

#create_models_directoryObject



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

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



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

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



59
60
61
62
63
64
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 59

def create_root_folder
  empty_directory "."
  if @options[:heroku]
    copy_file("heroku/Procfile", "Procfile")
  end
end

#create_testObject



150
151
152
153
154
155
156
157
158
159
# File 'lib/vraptor-scaffold/generators/app/app_generator.rb', line 150

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_webappObject



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

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