zen0wu / topcoder-greed

greedy editor for topcoder arena
Apache License 2.0
229 stars 48 forks source link

Code folder #82

Closed vexorian closed 10 years ago

vexorian commented 10 years ago

Nowadays we have plenty of templates and it is likely we'll get more and more. Each are supposed to be created in the problem's code folder.

What if the coder wants to change this folder? Doesn't like ${Contest.Name}, wants just ".", or wants a folder per problem, or etc? Currently the user has to change the output file location in each of the templates he is using.

Although it is great to allow templates to be saved in different folders, I think that having a ${OutputFolder} variable would be great.

Example default.conf under this idea:

greed {
    codeRoot    = "."
    outputFolder = "${Contest.Name}" #default location for all templates

    logging {
        logLevel    = OFF
        logToStderr = true
        logFolder   = Logs
    }

    shared {
        templateDef {
            test {
                override = false
                outputKey = TestCode
                transformers = [ empty-block, cont-blank-line ]
            }
            filetest {
                override = false
                outputKey = TestCode
                transformers = [ empty-block, cont-blank-line ]
            }
            source {
                override = false
                outputFileName = "${outputFolder}/${Problem.Name}"
                transformers = [ empty-block, cont-blank-line ]
            }
            unittest {
                override = false
                templateFile = None
                outputFileName = "${outputFolder}/${Problem.Name}Test"
                transformers = [ empty-block, cont-blank-line ]
            }
            testcase {
                override = false
                outputFile = "${outputFolder}/${Problem.Name}.sample"
                templateFile = "builtin testcase/testcases.tmpl"
            }
            problem-desc {
                override = false
                outputFile = "${outputFolder}/${Problem.Name}.html"
                templateFile = "builtin problem/desc.html.tmpl"
            }
        }

        defaultLanguage {
            templates = [ filetest, source, testcase, problem-desc ]
            submitTemplate = source
        }

        cstyleLanguage = ${greed.shared.defaultLanguage} {
            cutBegin = "// CUT begin"
            cutEnd = "// CUT end"
        }
    }

    language {
        cpp = ${greed.shared.cstyleLanguage} {
            longIntTypeName = long long

            templateDef = ${greed.shared.templateDef} {
                filetest.templateFile = "builtin filetest/cpp.tmpl"
                test.templateFile = "builtin test/cpp.tmpl"
                source.templateFile = "builtin source/cpp.tmpl"
                source.outputFileExtension = cpp
            }
        }

        java = ${greed.shared.cstyleLanguage} {
            templateDef = ${greed.shared.templateDef} {
                filetest.templateFile = "builtin filetest/java.tmpl"
                test.templateFile = "builtin test/java.tmpl"
                source.templateFile = "builtin source/java.tmpl"
                source.outputFileExtension = java
                unittest.templateFile = "builtin unittest/junit.java.tmpl"
            }
        }

        csharp = ${greed.shared.cstyleLanguage}  {
            templateDef = ${greed.shared.templateDef} {
                filetest.templateFile = "builtin filetest/cs.tmpl"
                test.templateFile = "builtin test/cs.tmpl"
                source.templateFile = "builtin source/cs.tmpl"
                source.outputFileExtension = cs
                unittest.templateFile = "builtin unittest/nunit.cs.tmpl"
            }
        }

        python = ${greed.shared.defaultLanguage}  {
            cutBegin = "# CUT begin"
            cutEnd = "# CUT end"

            templateDef = ${greed.shared.templateDef} {
                filetest.templateFile = "builtin filetest/py.tmpl"
                test.templateFile = "builtin test/py.tmpl"
                source.templateFile = "builtin source/py.tmpl"
                source.outputFileExtension = py
            }

        }
    }
}

If user changes outputfolder, all templates will output to the new location.

zen0wu commented 10 years ago

Awesome! You read my mind! I was considering this feature too.

I do think a config like contestDirectory is needed, to set a root for an individual contest, which make perfect sense. But what I'm really considering is this, if we have contestDirectory, do we really need the codeRoot? I don't see any necessity. If we have, it's just ${codeRoot}/${ContestDir} instead of ${contestDir}, seems useless and redundant.

zen0wu commented 10 years ago

Oh, I see a little difference. What I mean was that we don't need to reference ${outputDir} in the definition, all the files in one contest are put into a specific directory.

vexorian commented 10 years ago

What if we just made codeRoot = ${Contest.name} and removed ${Contest.name} from outputFile ? As long as people can put absolute paths it would work.

For the record. Some people might prefer to save all files in the same folder, without organizing by contest.

zen0wu commented 10 years ago

That sounds good, let's do that.

vexorian commented 10 years ago

Sorry, I used the site to turn issue into pull request wrongly and I accidentally turned this issue into a PR. But if you agree with the idea to turn coderoot into ${Contest.Name}, that's great.