本文整理匯總了Java中com.samskivert.mustache.Mustache類的典型用法代碼示例。如果您正苦於以下問題:Java Mustache類的具體用法?Java Mustache怎麽用?Java Mustache使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Mustache類屬於com.samskivert.mustache包,在下文中一共展示了Mustache類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testMustasche
import com.samskivert.mustache.Mustache; //導入依賴的package包/類
@Test
@SuppressWarnings("unchecked")
public void testMustasche() throws IOException {
Yaml yaml = new Yaml();
Map model = (Map) yaml.load(valuesResource.getInputStream());
String templateAsString = StreamUtils.copyToString(nestedMapResource.getInputStream(),
Charset.defaultCharset());
Template mustacheTemplate = Mustache.compiler().compile(templateAsString);
String resolvedYml = mustacheTemplate.execute(model);
Map map = (Map) yaml.load(resolvedYml);
logger.info("Resolved yml = " + resolvedYml);
assertThat(map).containsKeys("apiVersion", "deployment");
Map deploymentMap = (Map) map.get("deployment");
assertThat(deploymentMap).contains(entry("name", "time"))
.contains(entry("count", 10));
Map applicationProperties = (Map) deploymentMap.get("applicationProperties");
assertThat(applicationProperties).contains(entry("log.level", "DEBUG"), entry("server.port", 8089));
Map deploymentProperties = (Map) deploymentMap.get("deploymentProperties");
assertThat(deploymentProperties).contains(entry("app.time.producer.partitionKeyExpression", "payload"),
entry("app.log.spring.cloud.stream.bindings.input.consumer.maxAttempts", 5));
}
示例2: mustacheCompiler
import com.samskivert.mustache.Mustache; //導入依賴的package包/類
@Bean
public Mustache.Compiler mustacheCompiler(Mustache.TemplateLoader mustacheTemplateLoader, Map<String, Mustache.Lambda> lambdas) {
MustacheApplicationCollector collector = new MustacheApplicationCollector();
collector.addVariable("static_base", staticBase);
collector.addVariable("dev", env.acceptsProfiles("dev"));
for (Map.Entry<String, Mustache.Lambda> lambda : lambdas.entrySet()) {
String name = lambda.getKey();
if (name.indexOf('_') == -1) {
name = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name);
}
collector.addVariable(name, lambda.getValue());
}
String defaultValue = env.acceptsProfiles("dev") ? "!!!!MISSING VALUE!!!!" : "";
return Mustache.compiler().withFormatter(new MustacheFormatter()).defaultValue(defaultValue).withLoader(mustacheTemplateLoader)
.withCollector(collector);
}
示例3: partial
import com.samskivert.mustache.Mustache; //導入依賴的package包/類
@Test
public void partial() {
Formatter formatter=value -> value.toString();
TemplateLoader loader=name -> new StringReader(">{{foo.bar}}<");
// Mustache.VariableFetcher;
String result = Mustache.compiler()
.emptyStringIsFalse(true)
.withFormatter(formatter)
.withLoader(loader)
.compile("Huii {{> sub}}")
.execute(ImmutableMap.of("foo", ImmutableMap.of("bar",17)));
System.out.println(result);
}
示例4: getObject
import com.samskivert.mustache.Mustache; //導入依賴的package包/類
@Override
public Mustache.Compiler getObject() throws Exception {
this.compiler = Mustache.compiler();
if (this.delims != null) {
this.compiler = this.compiler.withDelims(this.delims);
}
if (this.templateLoader != null) {
this.compiler = this.compiler.withLoader(this.templateLoader);
}
if (this.formatter != null) {
this.compiler = this.compiler.withFormatter(this.formatter);
}
if (this.escaper != null) {
this.compiler = this.compiler.withEscaper(this.escaper);
}
if (this.collector != null) {
this.compiler = this.compiler.withCollector(this.collector);
}
if (this.defaultValue != null) {
this.compiler = this.compiler.defaultValue(this.defaultValue);
}
if (this.emptyStringIsFalse != null) {
this.compiler = this.compiler.emptyStringIsFalse(this.emptyStringIsFalse);
}
return this.compiler;
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:27,代碼來源:MustacheCompilerFactoryBean.java
示例5: logout
import com.samskivert.mustache.Mustache; //導入依賴的package包/類
public void logout(String apiSessionId) {
Resource resource = resourceLoader.getResource("classpath:request_templates/" + SIGN_OUT_TEMPLATE_PATH);
InputStream inputStream = null;
try {
inputStream = resource.getInputStream();
} catch (IOException e) {
throw new RuntimeException("Problem reading request template: " + SIGN_OUT_TEMPLATE_PATH, e);
}
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
Template tmpl = Mustache.compiler().compile(inputStreamReader);
Map<String, String> messageParams = new HashMap<>();
messageParams.put("apiSessionId", apiSessionId);
String messageId = UUID.randomUUID().toString();
messageParams.put("messageUUID", messageId);
messageParams.put("serviceAddress", serviceAddressUser);
String messageBody = tmpl.execute(messageParams);
httpClient.post(serviceAddressUser, messageBody, messageId);
}
示例6: gatherReferencedFields
import com.samskivert.mustache.Mustache; //導入依賴的package包/類
/**
* Gather fields that are referenced in the mustache template.
*
* @return the collection
*/
private Collection<String> gatherReferencedFields() {
Collection<String> fields = new ArrayList<>();
Collector collector = new DefaultCollector() {
@Override
public VariableFetcher createFetcher(Object ctx, String name) {
fields.add(name);
return super.createFetcher(ctx, name);
}
};
Compiler compiler = Mustache.compiler().defaultValue("").withCollector(collector);
Template mockTemplate = compiler.compile(mustacheTemplate);
mockTemplate.execute(new HashMap<>());
return fields;
}
示例7: NotificationService
import com.samskivert.mustache.Mustache; //導入依賴的package包/類
public NotificationService(ConfigurationRepository configurationRepository, UserRepository userRepository,
CardDataRepository cardDataRepository, CardRepository cardRepository,
BoardColumnRepository boardColumnRepository, MessageSource messageSource, NamedParameterJdbcTemplate jdbc,
NotificationQuery queries) {
this.configurationRepository = configurationRepository;
this.userRepository = userRepository;
this.cardDataRepository = cardDataRepository;
this.cardRepository = cardRepository;
this.boardColumnRepository = boardColumnRepository;
this.messageSource = messageSource;
this.jdbc = jdbc;
this.queries = queries;
com.samskivert.mustache.Mustache.Compiler compiler = Mustache.compiler().escapeHTML(false).defaultValue("");
try {
emailTextTemplate = compiler.compile(new InputStreamReader(
new ClassPathResource("/io/lavagna/notification/email.txt")
.getInputStream(), StandardCharsets.UTF_8));
emailHtmlTemplate = compiler
.compile(new InputStreamReader(new ClassPathResource(
"/io/lavagna/notification/email.html")
.getInputStream(), StandardCharsets.UTF_8));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
示例8: loginPageGenerator
import com.samskivert.mustache.Mustache; //導入依賴的package包/類
private LoginPageGenerator loginPageGenerator() {
return new LoginPageGenerator() {
@Override
public void generate(HttpServletRequest req, HttpServletResponse resp, Map<String, LoginHandler> handlers) throws IOException {
Map<String, Object> model = new HashMap<>();
model.put("version", Version.version());
for (LoginHandler lh : handlers.values()) {
model.putAll(lh.modelForLoginPage(req));
}
resp.setStatus(HttpServletResponse.SC_OK);
resp.setContentType("text/html");
resp.setCharacterEncoding("UTF-8");
model.put("json", Json.GSON.toJson(model));
try (InputStream is = req.getServletContext().getResourceAsStream("/WEB-INF/views/login.html")) {
Mustache.compiler().escapeHTML(false).defaultValue("").compile(new InputStreamReader(is, StandardCharsets.UTF_8)).execute(model, resp.getWriter());
}
}
};
}
示例9: compileMustache
import com.samskivert.mustache.Mustache; //導入依賴的package包/類
/**
* Compiles a mustache template with a given scope (map of fields and values).
* @param context a map of fields and values
* @param template a Mustache template
* @return the compiled template string
*/
public static String compileMustache(Map<String, Object> context, String template) {
if (context == null || StringUtils.isBlank(template)) {
return "";
}
Writer writer = new StringWriter();
try {
Mustache.compiler().escapeHTML(false).emptyStringIsFalse(true).compile(template).execute(context, writer);
} finally {
try {
writer.close();
} catch (IOException e) {
logger.error(null, e);
}
}
return writer.toString();
}
示例10: TemplateManager
import com.samskivert.mustache.Mustache; //導入依賴的package包/類
@Autowired
public TemplateManager(JMustacheTemplateLoader templateLoader,
MessageSource messageSource,
UploadedResourceManager uploadedResourceManager) {
this.messageSource = messageSource;
this.uploadedResourceManager = uploadedResourceManager;
Formatter dateFormatter = (o) -> {
return (o instanceof ZonedDateTime) ? DateTimeFormatter.ISO_ZONED_DATE_TIME
.format((ZonedDateTime) o) : String.valueOf(o);
};
this.compilers = new EnumMap<>(TemplateOutput.class);
this.compilers.put(TemplateOutput.TEXT, Mustache.compiler()
.escapeHTML(false)
.standardsMode(false)
.defaultValue("")
.nullValue("")
.withFormatter(dateFormatter)
.withLoader(templateLoader));
this.compilers.put(TemplateOutput.HTML, Mustache.compiler()
.escapeHTML(true)
.standardsMode(false)
.defaultValue("")
.nullValue("")
.withFormatter(dateFormatter)
.withLoader(templateLoader));
}
示例11: setUp
import com.samskivert.mustache.Mustache; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
this.model = new HashMap<String, Object>();
this.model.put("name", "foo");
this.model.put("zero", 0);
this.model.put("emptyString", "");
writer = new StringWriter();
when(response.getWriter()).thenReturn(new PrintWriter(writer));
ResourceLoader resourceLoader = new DefaultResourceLoader();
templateLoader = new DefaultTemplateLoader(resourceLoader);
Compiler compiler = Mustache.compiler()
.zeroIsFalse(true)
.emptyStringIsFalse(true);
MustacheCompiler mustacheCompiler = new JMustacheCompiler(compiler, templateLoader);
mustacheView = new MustacheView();
mustacheView.setCompiler(mustacheCompiler);
}
示例12: it_should_create_object
import com.samskivert.mustache.Mustache; //導入依賴的package包/類
@Test
public void it_should_create_object() throws Exception {
MustacheTemplateLoader templateLoader = mock(MustacheTemplateLoader.class);
Mustache.Compiler compiler = mock(Mustache.Compiler.class);
Handlebars handlebars = mock(Handlebars.class);
when(applicationContext.getBean(MustacheTemplateLoader.class)).thenReturn(templateLoader);
when(applicationContext.getBean(Mustache.Compiler.class)).thenReturn(compiler);
when(applicationContext.getBean(Handlebars.class)).thenReturn(handlebars);
factoryBean.afterPropertiesSet();
MustacheCompiler mustacheCompiler = factoryBean.getObject();
assertThat(mustacheCompiler).isNotNull();
verify(applicationContext).getBean(MustacheTemplateLoader.class);
}
示例13: it_should_not_create_twice
import com.samskivert.mustache.Mustache; //導入依賴的package包/類
@Test
public void it_should_not_create_twice() throws Exception {
MustacheTemplateLoader templateLoader = mock(MustacheTemplateLoader.class);
Mustache.Compiler compiler = mock(Mustache.Compiler.class);
Handlebars handlebars = mock(Handlebars.class);
when(applicationContext.getBean(MustacheTemplateLoader.class)).thenReturn(templateLoader);
when(applicationContext.getBean(Mustache.Compiler.class)).thenReturn(compiler);
when(applicationContext.getBean(Handlebars.class)).thenReturn(handlebars);
factoryBean.afterPropertiesSet();
MustacheCompiler mustacheCompiler1 = factoryBean.getObject();
MustacheCompiler mustacheCompiler2 = factoryBean.getObject();
assertThat(mustacheCompiler1).isNotNull();
assertThat(mustacheCompiler2).isNotNull();
assertThat(mustacheCompiler1).isSameAs(mustacheCompiler2);
}
示例14: setUp
import com.samskivert.mustache.Mustache; //導入依賴的package包/類
@Before
public void setUp() {
applicationContext = mock(ApplicationContext.class);
MustacheTemplateLoader templateLoader = mock(MustacheTemplateLoader.class);
when(applicationContext.getBean(MustacheTemplateLoader.class)).thenReturn(templateLoader);
Mustache.Compiler jmustache = mock(Mustache.Compiler.class);
when(applicationContext.getBean(Mustache.Compiler.class)).thenReturn(jmustache);
Handlebars handlebars = mock(Handlebars.class);
when(applicationContext.getBean(Handlebars.class)).thenReturn(handlebars);
MustacheEngine mustacheEngine = mock(MustacheEngine.class);
when(applicationContext.getBean(MustacheEngine.class)).thenReturn(mustacheEngine);
mockStatic(ClassUtils.class);
mockStatic(JavaUtils.class);
mockStatic(NashornUtils.class);
}
示例15: it_should_create_target_object_with_custom_settings
import com.samskivert.mustache.Mustache; //導入依賴的package包/類
@Test
public void it_should_create_target_object_with_custom_settings() throws Exception {
factoryBean.setEmptyStringIsFalse(false);
factoryBean.setZeroIsFalse(false);
factoryBean.setEscapeHTML(false);
factoryBean.setStandardsMode(true);
factoryBean.setStrictSections(true);
factoryBean.setNullValue("foo");
factoryBean.setDefaultValue("foo");
factoryBean.afterPropertiesSet();
Mustache.Compiler compiler = factoryBean.getObject();
assertThat(compiler).isNotNull();
assertThat(compiler.nullValue).isEqualTo("foo");
assertThat(compiler.emptyStringIsFalse).isFalse();
assertThat(compiler.zeroIsFalse).isFalse();
assertThat(compiler.escaper).isEqualTo(Escapers.NONE);
assertThat(compiler.standardsMode).isTrue();
assertThat(compiler.strictSections).isTrue();
}