Permalink
Browse files

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
kai.huang committed Nov 2, 2009
1 parent 637921b commit a3c26dd4eb33b757ff987a32f8b970473b724b4d
Showing 514 changed files with 2,248 additions and 1,035 deletions.
@@ -16,7 +16,7 @@
'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 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
A simple Soy file.
@@ -16,13 +16,24 @@
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.CmdLineParser;
import org.kohsuke.args4j.OptionDef;
import org.kohsuke.args4j.spi.OptionHandler;
import org.kohsuke.args4j.spi.Parameters;
import org.kohsuke.args4j.spi.Setter;
import java.util.List;
import javax.annotation.Nullable;
/**
* Private utils for classes with a main() method.
@@ -123,4 +134,55 @@ public static void exitWithError(
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);
}
}
}
@@ -17,9 +17,7 @@
package com.google.template.soy;
import com.google.common.collect.Lists;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.template.soy.base.SoySyntaxException;
import com.google.template.soy.msgs.SoyMsgBundle;
import com.google.template.soy.msgs.SoyMsgBundleHandler;
@@ -115,15 +113,7 @@ private void execMain(String[] args) throws IOException, SoySyntaxException {
MainClassUtils.exitWithError("Must provide output file path.", cmdLineParser, USAGE_PREFIX);
}
Module msgPluginModuleInstance;
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);
Injector injector = MainClassUtils.createInjector(messagePluginModule, null);
SoyFileSet.Builder sfsBuilder = injector.getInstance(SoyFileSet.Builder.class);
String inputPrefixStr = inputPrefix;
@@ -19,9 +19,7 @@
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import com.google.common.io.Files;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.template.soy.base.SoySyntaxException;
import com.google.template.soy.javasrc.SoyJavaSrcOptions;
import com.google.template.soy.javasrc.SoyJavaSrcOptions.CodeStyle;
@@ -111,6 +109,11 @@ private SoyToJavaSrcCompilerExperimental() {}
" the XliffMsgPlugin.")
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. */
@Argument
private List<String> arguments = Lists.newArrayList();
@@ -128,15 +131,7 @@ private void execMain(String[] args) throws IOException, SoySyntaxException {
MainClassUtils.exitWithError("Must provide list of Soy files.", cmdLineParser, USAGE_PREFIX);
}
Module msgPluginModuleInstance;
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);
Injector injector = MainClassUtils.createInjector(messagePluginModule, pluginModules);
// Create SoyJavaSrcOptions.
SoyJavaSrcOptions javaSrcOptions = new SoyJavaSrcOptions();
@@ -17,9 +17,7 @@
package com.google.template.soy;
import com.google.common.collect.Lists;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.template.soy.base.SoySyntaxException;
import com.google.template.soy.jssrc.SoyJsSrcOptions;
import com.google.template.soy.jssrc.SoyJsSrcOptions.CodeStyle;
@@ -140,6 +138,11 @@
" the XliffMsgPlugin.")
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. */
@Argument
private List<String> arguments = Lists.newArrayList();
@@ -171,15 +174,7 @@ private void execMain(String[] args) throws IOException, SoySyntaxException {
"Must provide the output path format.", cmdLineParser, USAGE_PREFIX);
}
Module msgPluginModuleInstance;
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);
Injector injector = MainClassUtils.createInjector(messagePluginModule, pluginModules);
// Create SoyJsSrcOptions.
SoyJsSrcOptions jsSrcOptions = new SoyJsSrcOptions();
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
Oops, something went wrong.

0 comments on commit a3c26dd

Please sign in to comment.