Skip to content

Commit

Permalink
Update generators for new layout.
Browse files Browse the repository at this point in the history
Get rid of copying kara and kotlin runtimes to an app. Use $KARA_HOME path variable instead to reference original jars in Kara distribution.
  • Loading branch information
shafirov committed Jan 25, 2013
1 parent b1d1171 commit 64728b6
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 322 deletions.
1 change: 1 addition & 0 deletions .idea/ant.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion samples/KaraDemo/KaraDemo.iml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/bin" />
<output-test url="file://$MODULE_DIR$/../../out/test/KaraDemo" />
<output-test url="file://$KARA_HOME$/out/test/KaraDemo" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
Expand Down
2 changes: 0 additions & 2 deletions src/KaraExec/src/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ Generators:
Currently supports: 'idea' for IntelliJ IDEA
update Updates the application's Kara dependency to the latest version
route <name> Generates a new route with the given name.
view <route> <view> Generate a new view for the given route. ('View' will be automatically appended to the name)
Expand Down Expand Up @@ -100,7 +99,6 @@ fun main(args: Array<String>) {
"s", "server" -> startServer = true
"g", "generate" -> runGenerator = true
"h", "help" -> showHelp = true
"update" -> generatorTask = GeneratorTask.update
"project" -> generatorTask = GeneratorTask.project
"route" -> generatorTask = GeneratorTask.route
"view" -> generatorTask = GeneratorTask.view
Expand Down
54 changes: 10 additions & 44 deletions src/KaraExec/src/generators/Generator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.google.common.io.Files
enum class GeneratorTask(val name : String) {
project: GeneratorTask("project")
route: GeneratorTask("route")
update: GeneratorTask("update")
view: GeneratorTask("view")
fun toString() : String {
return name
Expand Down Expand Up @@ -46,7 +45,7 @@ class Generator(val appConfig : AppConfig, val task : GeneratorTask, val args :

var stylesheetName : String = ""

var ide = ""
var ide = "default"

var projectName = ""

Expand Down Expand Up @@ -76,9 +75,6 @@ class Generator(val appConfig : AppConfig, val task : GeneratorTask, val args :
for (arg in args)
execRoute(arg)
}
GeneratorTask.update -> {
execUpdate()
}
GeneratorTask.view -> {
// ensure there's a route name and a view name
if (args.size != 2)
Expand Down Expand Up @@ -151,16 +147,12 @@ class Generator(val appConfig : AppConfig, val task : GeneratorTask, val args :
createDir("tmp")

createIDEFiles(ide)
// copy the necessary libraries
copyFile("lib/kotlin-runtime.jar", "lib/kotlin-runtime.jar")
copyFile("out/jars/KaraLib.jar", "lib/KaraLib.jar")

// render the templates
renderTemplate(moduleImlTemplate(this), "${appConfig.appPackage}.iml")
renderTemplate(buildxmlTemplate(this), "build.xml")
renderTemplate(appconfigTemplate(this), "config/appconfig.json")
renderTemplate(appconfigDevelopmentTemplate(this), "config/appconfig.development.json")
renderTemplate(applicationTemplate(this), "src/$appPackagePath/Application.kt")
renderTemplate(buildxmlTemplate(), "build.xml")
renderTemplate(appconfigTemplate(), "config/appconfig.json")
renderTemplate(appconfigDevelopmentTemplate(), "config/appconfig.development.json")
renderTemplate(applicationTemplate(), "src/$appPackagePath/Application.kt")

// make the default routes and view
execRoute("Home")
Expand All @@ -178,7 +170,7 @@ class Generator(val appConfig : AppConfig, val task : GeneratorTask, val args :

ensureDir("src/$appPackagePath/routes")

renderTemplate(routeTemplate(this), "src/$appPackagePath/routes/${routeClassName}.kt")
renderTemplate(routeTemplate(), "src/$appPackagePath/routes/${routeClassName}.kt")
execLayout("Default")
execView(routeName, "Index")
}
Expand All @@ -192,8 +184,8 @@ class Generator(val appConfig : AppConfig, val task : GeneratorTask, val args :
ensureDir("src/$appPackagePath/views")
ensureDir("src/$appPackagePath/styles")

renderTemplate(layoutTemplate(this), "src/$appPackagePath/views/${viewName}.kt")
renderTemplate(stylesheetTemplate(this), "src/$appPackagePath/styles/${stylesheetName}.kt")
renderTemplate(layoutTemplate(), "src/$appPackagePath/views/${viewName}.kt")
renderTemplate(stylesheetTemplate(), "src/$appPackagePath/styles/${stylesheetName}.kt")
}


Expand All @@ -210,13 +202,7 @@ class Generator(val appConfig : AppConfig, val task : GeneratorTask, val args :

val outPath = "src/$appPackagePath/views/$routeSlug/${viewName}.kt"
var isLanding = routeName == "Home" && vName == "Index"
renderTemplate(viewTemplate(this, outPath, isLanding), outPath)
}


/** Updates the target project's Kara dependency to the latest version. */
fun execUpdate() {
copyFile("out/jars/KaraLib.jar", "lib/KaraLib.jar")
renderTemplate(viewTemplate(outPath, isLanding), outPath)
}


Expand Down Expand Up @@ -265,31 +251,11 @@ class Generator(val appConfig : AppConfig, val task : GeneratorTask, val args :

fun createIDEFiles(ide: String) {
when (ide) {
"idea" -> createIDEAFiles()
"default", "idea" -> createIDEAFiles()
else -> {
throw RuntimeException("$ide not supported")
}
}
}

fun createIDEAFiles() {
// TODO: .idea works on Windows too?
ensureDir(".idea")
ensureDir(".idea/scopes")
ensureDir(".idea/copyright")
ensureDir(".idea/libraries")
renderTemplate(gradleTemplate(this), ".idea/gradle.xml")
renderTemplate(compilerTemplate(this), ".idea/compiler.xml")
renderTemplate(encodingsTemplate(this), ".idea/encodings.xml")
renderTemplate(uiDesignerTemplate(this), ".idea/uiDesigner.xml")
renderTemplate(vcsTemplate(this), ".idea/vcs.xml")
renderTemplate(miscTemplate(this), ".idea/misc.xml")
renderTemplate(scopeTemplate(this), ".idea/scopes/scope_settings.xml")
renderTemplate(nameTemplate(this), ".idea/.name")
renderTemplate(copyrightTemplate(this), ".idea/copyright/profile_settings.xml")
renderTemplate(modulesTemplate(this), ".idea/modules.xml")
renderTemplate(libraryKaraTemplate(this), ".idea/libraries/KaraLib.xml")
}

}

22 changes: 11 additions & 11 deletions src/KaraExec/src/generators/templates/GeneralTemplates.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import kara.generators.Generator
*/


fun appconfigTemplate(gen : Generator) : String {
fun Generator.appconfigTemplate() : String {
return """
{
"kara": {
"appPackage": "${gen.appPackage}",
"appPackage": "${appPackage}",
"publicDir": "public",
"stylesheetDir": "stylesheets",
"sessionDir": "tmp/sessions"
Expand All @@ -20,7 +20,7 @@ fun appconfigTemplate(gen : Generator) : String {
"""
}

fun appconfigDevelopmentTemplate(gen : Generator) : String {
fun Generator.appconfigDevelopmentTemplate() : String {
return """
{
"kara": {
Expand All @@ -31,7 +31,7 @@ fun appconfigDevelopmentTemplate(gen : Generator) : String {
}


fun buildxmlTemplate(gen : Generator) : String {
fun Generator.buildxmlTemplate() : String {
return """
<project>
<target name="restart">
Expand All @@ -44,9 +44,9 @@ fun buildxmlTemplate(gen : Generator) : String {
}


fun applicationTemplate(gen : Generator) : String {
fun Generator.applicationTemplate() : String {
return """
package ${gen.appPackage}
package ${appPackage}
import kara.config.*
Expand All @@ -67,15 +67,15 @@ public class Application(config: AppConfig) : kara.app.Application(config) {
"""
}

fun routeTemplate(gen : Generator) : String {
fun Generator.routeTemplate() : String {
return """
package ${gen.appPackage}.routes
package ${appPackage}.routes
import ${gen.appPackage}.views.*
import ${gen.appPackage}.views.${gen.routeSlug}.*
import ${appPackage}.views.*
import ${appPackage}.views.${routeSlug}.*
import kara.controllers.*
object ${gen.routeClassName} {
object ${routeClassName} {
val layout = DefaultLayout()
Get("/") class Index() : Request({
IndexView()
Expand Down
Loading

0 comments on commit 64728b6

Please sign in to comment.