@Bean ScriptTemplateConfigurer configureScript() { ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer(); configurer.setEngineName("nashorn"); configurer.setRenderFunction("render"); configurer.setScripts( "/META-INF/resources/webjars/react/15.1.0/react.min.js", "/META-INF/resources/webjars/react/15.1.0/react-dom-server.min.js", "/build/react-templating.jsx", "/static/js/doms.js", "/static/js/playfield.js" ); logger.trace(" ScriptTemplateConfigurer configureScript()"); return configurer; }
@Bean public ScriptTemplateConfigurer reactConfigurer() { ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer(); configurer.setEngineName("nashorn"); configurer.setScripts("static/polyfill.js", "static/lib/js/ejs.min.js", "/META-INF/resources/webjars/react/0.13.1/react.js", // "/META-INF/resources/webjars/react/0.13.1/JSXTransformer.js", "static/render.js", "static/output/comment.js", "static/output/comment-form.js", "static/output/comment-list.js"); configurer.setRenderFunction("render"); configurer.setSharedEngine(false); return configurer; }
/** * Register a script template view resolver with an empty default view name prefix and suffix. * @since 4.2 */ public UrlBasedViewResolverRegistration scriptTemplate() { if (this.applicationContext != null && !hasBeanOfType(ScriptTemplateConfigurer.class)) { throw new BeanInitializationException("In addition to a script template view resolver " + "there must also be a single ScriptTemplateConfig bean in this web application context " + "(or its parent): ScriptTemplateConfigurer is the usual implementation. " + "This bean may be given any name."); } ScriptRegistration registration = new ScriptRegistration(); this.viewResolvers.add(registration.getViewResolver()); return registration; }
@Before public void setUp() { StaticWebApplicationContext context = new StaticWebApplicationContext(); context.registerSingleton("freeMarkerConfigurer", FreeMarkerConfigurer.class); context.registerSingleton("velocityConfigurer", VelocityConfigurer.class); context.registerSingleton("tilesConfigurer", TilesConfigurer.class); context.registerSingleton("groovyMarkupConfigurer", GroovyMarkupConfigurer.class); context.registerSingleton("scriptTemplateConfigurer", ScriptTemplateConfigurer.class); this.registry = new ViewResolverRegistry(); this.registry.setApplicationContext(context); this.registry.setContentNegotiationManager(new ContentNegotiationManager()); }
@Bean public ScriptTemplateConfigurer scriptTemplateConfigurer() throws IOException { final ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer(); configurer.setRenderFunction("render"); configurer.setSharedEngine(true); ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn"); configurer.setEngine(engine); addScripts(configurer); return configurer; }
private void addScripts(ScriptTemplateConfigurer configurer) throws IOException { List<String> scripts = new ArrayList<>(); scripts.add("/static/dust.js"); scripts.add("/static/polyfill.js"); scripts.add("/META-INF/resources/webjars/dustjs-linkedin/2.7.2/dust-full.js"); // TODO we needs refactoring if add STV.setScripts("folder") final ClassPathResource dir = new ClassPathResource("/static/templates/compiled"); for (File f : dir.getFile().listFiles()) { scripts.add("/static/templates/compiled/" + f.getName()); } configurer.setScripts(scripts.toArray(new String[scripts.size()])); }
@Bean public ScriptTemplateConfigurer handlebarsConfigurer() { ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer(); configurer.setEngineName("nashorn"); configurer.setScripts("/static/polyfill.js", "/META-INF/resources/webjars/handlebars/3.0.0-1/handlebars.js", "/static/render.js"); configurer.setRenderFunction("render"); configurer.setSharedEngine(false); return configurer; }