Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Misc changes including doc.
git-svn-id: http://closure-templates.googlecode.com/svn/trunk@8 ba6e359a-b4f9-11de-880b-11b4e8d67c75
  • Loading branch information
kai.huang committed Nov 2, 2009
1 parent 637921b commit a3c26dd
Show file tree
Hide file tree
Showing 514 changed files with 2,248 additions and 1,035 deletions.
2 changes: 1 addition & 1 deletion examples/README_FOR_EXAMPLES
Expand Up @@ -16,7 +16,7 @@
'examples' 'examples'
This directory contains example Soy files shared by both the JS and Java usage examples. This directory contains example Soy files shared by both the JS and Java usage examples.
For the JavaScript usage examples, see 'javascript/examples'. For the JavaScript usage examples, see 'javascript/examples'.
For the Java usage examples, see 'src/com/google/template/soy/examples'. For the Java usage examples, see 'java/src/com/google/template/soy/examples'.


+ simple.soy + simple.soy
A simple Soy file. A simple Soy file.
Expand Down
62 changes: 62 additions & 0 deletions java/src/com/google/template/soy/MainClassUtils.java
Expand Up @@ -16,13 +16,24 @@


package com.google.template.soy; package com.google.template.soy;


import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;

import org.kohsuke.args4j.CmdLineException; import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser; import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.OptionDef; import org.kohsuke.args4j.OptionDef;
import org.kohsuke.args4j.spi.OptionHandler; import org.kohsuke.args4j.spi.OptionHandler;
import org.kohsuke.args4j.spi.Parameters; import org.kohsuke.args4j.spi.Parameters;
import org.kohsuke.args4j.spi.Setter; import org.kohsuke.args4j.spi.Setter;


import java.util.List;

import javax.annotation.Nullable;



/** /**
* Private utils for classes with a main() method. * Private utils for classes with a main() method.
Expand Down Expand Up @@ -123,4 +134,55 @@ public static void exitWithError(
System.exit(1); System.exit(1);
} }



/**
* Creates a Guice injector that includes the SoyModule, a message plugin module, and maybe
* additional plugin modules.
*
* @param msgPluginModuleName The full class name of the message plugin module. Required.
* @param pluginModuleNames Comma-delimited list of full class names of additional plugin modules
* to include. Optional.
* @return A Guice injector that includes the SoyModule, the given message plugin module, and the
* given additional plugin modules (if any).
*/
public static Injector createInjector(
String msgPluginModuleName, @Nullable String pluginModuleNames) {

List<Module> guiceModules = Lists.newArrayListWithCapacity(2);

guiceModules.add(new SoyModule());

checkArgument(msgPluginModuleName != null && msgPluginModuleName.length() > 0);
guiceModules.add(instantiatePluginModule(msgPluginModuleName));

if (pluginModuleNames != null && pluginModuleNames.length() > 0) {
for (String pluginModuleName : Splitter.on(',').split(pluginModuleNames)) {
guiceModules.add(instantiatePluginModule(pluginModuleName));
}
}

return Guice.createInjector(guiceModules);
}


/**
* Private helper for createInjector().
*
* @param moduleName The name of the plugin module to instantiate.
* @return A new instance of the specified plugin module.
*/
private static Module instantiatePluginModule(String moduleName) {

try {
return (Module) Class.forName(moduleName).newInstance();

} catch (ClassNotFoundException e) {
throw new RuntimeException("Cannot find plugin module \"" + moduleName + "\".", e);
} catch (IllegalAccessException e) {
throw new RuntimeException("Cannot access plugin module \"" + moduleName + "\".", e);
} catch (InstantiationException e) {
throw new RuntimeException("Cannot instantiate plugin module \"" + moduleName + "\".", e);
}
}

} }
12 changes: 1 addition & 11 deletions java/src/com/google/template/soy/SoyMsgExtractor.java
Expand Up @@ -17,9 +17,7 @@
package com.google.template.soy; package com.google.template.soy;


import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.template.soy.base.SoySyntaxException; import com.google.template.soy.base.SoySyntaxException;
import com.google.template.soy.msgs.SoyMsgBundle; import com.google.template.soy.msgs.SoyMsgBundle;
import com.google.template.soy.msgs.SoyMsgBundleHandler; import com.google.template.soy.msgs.SoyMsgBundleHandler;
Expand Down Expand Up @@ -115,15 +113,7 @@ private void execMain(String[] args) throws IOException, SoySyntaxException {
MainClassUtils.exitWithError("Must provide output file path.", cmdLineParser, USAGE_PREFIX); MainClassUtils.exitWithError("Must provide output file path.", cmdLineParser, USAGE_PREFIX);
} }


Module msgPluginModuleInstance; Injector injector = MainClassUtils.createInjector(messagePluginModule, null);
try {
msgPluginModuleInstance = (Module) Class.forName(messagePluginModule).newInstance();
} catch (Exception e) {
throw new RuntimeException(
"Failed to instantiate message plugin module \"" + messagePluginModule + "\".", e);
}

Injector injector = Guice.createInjector(new SoyModule(), msgPluginModuleInstance);


SoyFileSet.Builder sfsBuilder = injector.getInstance(SoyFileSet.Builder.class); SoyFileSet.Builder sfsBuilder = injector.getInstance(SoyFileSet.Builder.class);
String inputPrefixStr = inputPrefix; String inputPrefixStr = inputPrefix;
Expand Down
Expand Up @@ -19,9 +19,7 @@
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.io.Files; import com.google.common.io.Files;
import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.template.soy.base.SoySyntaxException; import com.google.template.soy.base.SoySyntaxException;
import com.google.template.soy.javasrc.SoyJavaSrcOptions; import com.google.template.soy.javasrc.SoyJavaSrcOptions;
import com.google.template.soy.javasrc.SoyJavaSrcOptions.CodeStyle; import com.google.template.soy.javasrc.SoyJavaSrcOptions.CodeStyle;
Expand Down Expand Up @@ -111,6 +109,11 @@ private SoyToJavaSrcCompilerExperimental() {}
" the XliffMsgPlugin.") " the XliffMsgPlugin.")
private String messagePluginModule = XliffMsgPluginModule.class.getName(); private String messagePluginModule = XliffMsgPluginModule.class.getName();


@Option(name = "--pluginModules",
usage = "Specifies the full class names of Guice modules for function plugins and" +
" print directive plugins (comma-delimited list).")
private String pluginModules = "";

/** The remaining arguments after parsing command-line flags. */ /** The remaining arguments after parsing command-line flags. */
@Argument @Argument
private List<String> arguments = Lists.newArrayList(); private List<String> arguments = Lists.newArrayList();
Expand All @@ -128,15 +131,7 @@ private void execMain(String[] args) throws IOException, SoySyntaxException {
MainClassUtils.exitWithError("Must provide list of Soy files.", cmdLineParser, USAGE_PREFIX); MainClassUtils.exitWithError("Must provide list of Soy files.", cmdLineParser, USAGE_PREFIX);
} }


Module msgPluginModuleInstance; Injector injector = MainClassUtils.createInjector(messagePluginModule, pluginModules);
try {
msgPluginModuleInstance = (Module) Class.forName(messagePluginModule).newInstance();
} catch (Exception e) {
throw new RuntimeException(
"Failed to instantiate message plugin module \"" + messagePluginModule + "\".", e);
}

Injector injector = Guice.createInjector(new SoyModule(), msgPluginModuleInstance);


// Create SoyJavaSrcOptions. // Create SoyJavaSrcOptions.
SoyJavaSrcOptions javaSrcOptions = new SoyJavaSrcOptions(); SoyJavaSrcOptions javaSrcOptions = new SoyJavaSrcOptions();
Expand Down
17 changes: 6 additions & 11 deletions java/src/com/google/template/soy/SoyToJsSrcCompiler.java
Expand Up @@ -17,9 +17,7 @@
package com.google.template.soy; package com.google.template.soy;


import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.template.soy.base.SoySyntaxException; import com.google.template.soy.base.SoySyntaxException;
import com.google.template.soy.jssrc.SoyJsSrcOptions; import com.google.template.soy.jssrc.SoyJsSrcOptions;
import com.google.template.soy.jssrc.SoyJsSrcOptions.CodeStyle; import com.google.template.soy.jssrc.SoyJsSrcOptions.CodeStyle;
Expand Down Expand Up @@ -140,6 +138,11 @@ public final class SoyToJsSrcCompiler {
" the XliffMsgPlugin.") " the XliffMsgPlugin.")
private String messagePluginModule = XliffMsgPluginModule.class.getName(); private String messagePluginModule = XliffMsgPluginModule.class.getName();


@Option(name = "--pluginModules",
usage = "Specifies the full class names of Guice modules for function plugins and" +
" print directive plugins (comma-delimited list).")
private String pluginModules = "";

/** The remaining arguments after parsing command-line flags. */ /** The remaining arguments after parsing command-line flags. */
@Argument @Argument
private List<String> arguments = Lists.newArrayList(); private List<String> arguments = Lists.newArrayList();
Expand Down Expand Up @@ -171,15 +174,7 @@ private void execMain(String[] args) throws IOException, SoySyntaxException {
"Must provide the output path format.", cmdLineParser, USAGE_PREFIX); "Must provide the output path format.", cmdLineParser, USAGE_PREFIX);
} }


Module msgPluginModuleInstance; Injector injector = MainClassUtils.createInjector(messagePluginModule, pluginModules);
try {
msgPluginModuleInstance = (Module) Class.forName(messagePluginModule).newInstance();
} catch (Exception e) {
throw new RuntimeException(
"Failed to instantiate message plugin module \"" + messagePluginModule + "\".", e);
}

Injector injector = Guice.createInjector(new SoyModule(), msgPluginModuleInstance);


// Create SoyJsSrcOptions. // Create SoyJsSrcOptions.
SoyJsSrcOptions jsSrcOptions = new SoyJsSrcOptions(); SoyJsSrcOptions jsSrcOptions = new SoyJsSrcOptions();
Expand Down
25 changes: 25 additions & 0 deletions java/src/com/google/template/soy/base/package.html
@@ -0,0 +1,25 @@
<!--
Copyright 2009 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
Base classes.

Mostly Soy-internal except for {@code SoySyntaxException}.
</body>
</html>
23 changes: 23 additions & 0 deletions java/src/com/google/template/soy/basetree/package.html
@@ -0,0 +1,23 @@
<!--
Copyright 2009 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
Classes shared by Soy parse trees and expression parse trees.
</body>
</html>
23 changes: 23 additions & 0 deletions java/src/com/google/template/soy/basicdirectives/package.html
@@ -0,0 +1,23 @@
<!--
Copyright 2009 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
Plugin package for basic print directives.
</body>
</html>
23 changes: 23 additions & 0 deletions java/src/com/google/template/soy/basicfunctions/package.html
@@ -0,0 +1,23 @@
<!--
Copyright 2009 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
Plugin package for basic functions.
</body>
</html>
23 changes: 23 additions & 0 deletions java/src/com/google/template/soy/bididirectives/package.html
@@ -0,0 +1,23 @@
<!--
Copyright 2009 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
Plugin package of print directives for bidi (bidirectional text).
</body>
</html>
23 changes: 23 additions & 0 deletions java/src/com/google/template/soy/bidifunctions/package.html
@@ -0,0 +1,23 @@
<!--
Copyright 2009 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
Plugin package of functions for bidi (bidirectional text).
</body>
</html>
23 changes: 23 additions & 0 deletions java/src/com/google/template/soy/coredirectives/package.html
@@ -0,0 +1,23 @@
<!--
Copyright 2009 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
Plugin package for core print directives.
</body>
</html>
23 changes: 23 additions & 0 deletions java/src/com/google/template/soy/data/package.html
@@ -0,0 +1,23 @@
<!--
Copyright 2009 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
Java representation of Soy data types.
</body>
</html>

0 comments on commit a3c26dd

Please sign in to comment.