@Override public Renderer setIjData(Map<String, ?> ijData) { this.ijData = (ijData == null) ? null : new SoyMapData(ijData); return this; }
@Override public Renderer setData(Map<String, ?> data) { this.data = (data == null) ? null : new SoyMapData(data); return this; }
@Override public Optional<SoyMapData> toSoyMap(final Object model) throws Exception { return Optional.of(new SoyMapData()); }
protected SoyMapData objectToSoyDataMap(Object obj) throws Exception { if (obj == null) { return new SoyMapData(); } if (obj instanceof SoyMapData) { return (SoyMapData) obj; } return new SoyMapData(toSoyCompatibleMap(obj)); }
@Override public Optional<SoyMapData> resolveData() { if (data == null || data.isEmpty()) { return Optional.absent(); } return Optional.of(new SoyMapData(data)); }
/** * Convert (at least attempt) any object to a SoyMapData instance. * @param obj The object to convert. * @return The created SoyMapData. */ public static SoyMapData objectToSoyDataMap(Object obj) { if (obj == null) { return new SoyMapData(); } if (obj instanceof SoyMapData) { return (SoyMapData) obj; } return new SoyMapData(toSoyCompatibleMap(obj)); }
@Inject SimplifyExprVisitor(PreevalVisitorFactory preevalVisitorFactory) { this.preevalVisitor = preevalVisitorFactory.create(new SoyMapData(), EMPTY_ENV); }
@Deprecated @Override public String render(String templateName, @Nullable Map<String, ?> data, @Nullable SoyMsgBundle msgBundle) { return renderMain( templateName, (data == null) ? null : new SoyMapData(data), null, null, msgBundle, null, true); }
@Deprecated @SuppressWarnings({"deprecation"}) @Override public String render(String templateName, @Nullable Map<String, ?> data, @Nullable SoyMsgBundle msgBundle) { return render(templateName, (data == null) ? null : new SoyMapData(data), msgBundle); }
public SoyMapData resolveGlobals(HttpServletRequest request) { Object globals = request.getAttribute(globalsKey); if (globals == null) { return null; } if (globals instanceof SoyMapData) { return (SoyMapData) globals; } Map<String, ?> globalsMap = Utils.toSoyCompatibleMap(globals); return new SoyMapData(globalsMap); }
public SoyMapData resolveModel(HttpServletRequest request) { Object model = request.getAttribute(modelKey); if (model == null) { return null; } if (model instanceof SoyMapData) { return (SoyMapData) model; } Map<String, ?> modeMap = Utils.toSoyCompatibleMap(model); return new SoyMapData(modeMap); }
@Deprecated @Override public String render(SoyTemplateInfo templateInfo, @Nullable Map<String, ?> data, @Nullable SoyMsgBundle msgBundle) { return renderMain( templateInfo.getName(), (data == null) ? null : new SoyMapData(data), null, null, msgBundle, null, true); }
public <K, V> SoyMapData convertToSoyMapData(Map<K, V> map) { SoyMapData soyMapData = new SoyMapData(); for (Map.Entry<K, V> entry : map.entrySet()) { String key = entry.getKey().toString(); Object value = entry.getValue(); Object soyValue = convertObject(value); soyMapData.put(key, soyValue); } return soyMapData; }
@Override public Optional<SoyMapData> resolveData(final HttpServletRequest request, final HttpServletResponse response, final Map<String, ? extends Object> model) { final SoyMapData root = new SoyMapData(); for (final RuntimeDataResolver runtimeDataResolver : resolvers) { logger.debug("resolving:{}", runtimeDataResolver); runtimeDataResolver.resolveData(request, response, model, root); } for (final RuntimeDataResolver runtimeDataResolver : userResolvers) { logger.debug("user data resolving:{}", runtimeDataResolver); runtimeDataResolver.resolveData(request, response, model, root); } return Optional.of(root); }
private File doccoIndex(SoyListData index, File baseOutputPath, SoyTofu tofu) throws IOException { SoyMapData soyData = new SoyMapData("basePath",".","title",title,"groups",index); String rendered = tofu.newRenderer(".indexPage").setData(soyData).render(); File indexFile = new File(baseOutputPath,indexFilename); FileUtils.touch(indexFile); FileUtils.writeStringToFile(indexFile, rendered); return indexFile; }
private File writeHtml(File sourceFile, String syntax, Header header, List<Section> sections, SoyListData index, File baseOutputPath, SoyTofu tofu) throws IOException { String relativeName = getRelativeName(sourceFile); File htmlFile = new File(baseOutputPath, relativeName); FileUtils.forceMkdir(htmlFile.getParentFile()); String relativeBase = getRelativeBase(htmlFile,baseOutputPath); Map<String,String> replaceMap = ImmutableMap.<String,String> builder().put("${basePath}",relativeBase).build(); SanitizedContent headerHtml = new SanitizedContent(header.getDocWithTokenReplacement(replaceMap), SanitizedContent.ContentKind.HTML); SoyMapData soyData = new SoyMapData("title", StringUtils.substringBeforeLast(htmlFile.getName(), "."),"nameWithoutExtension", StringUtils.substringBeforeLast(sourceFile.getName(), "."),"syntax", syntax, "groups", index, "basePath", relativeBase, "myPath", relativeName, "header", headerHtml, "sections", Docco.getSoySectionDataWithTokenReplacement(sections, replaceMap)); String rendered = tofu.newRenderer(".batchPage").setData(soyData).render(); FileUtils.writeStringToFile(htmlFile, rendered); return htmlFile; }
@Override public Map<String, SoyData> asMap() { SoyMapData combinedMapData = new SoyMapData(); addMapDataHelper(combinedMapData, "", baseData.asMap()); addMapDataHelper(combinedMapData, "", super.asMap()); return Collections.unmodifiableMap(combinedMapData.asMap()); }
@Override protected SoyData visitMapLiteralNode(MapLiteralNode node) { Map<String, SoyData> map = Maps.newHashMap(); for (int i = 0, n = node.numChildren(); i < n; i += 2) { SoyData key = visit(node.getChild(i)); if (! (key instanceof StringData)) { throw new RenderException( "Maps must have string keys (key \"" + node.getChild(i).toSourceString() + "\"" + " in map " + node.toSourceString() + " does not evaluate to a string)."); } SoyData value = visit(node.getChild(i + 1)); map.put(key.stringValue(), value); } return new SoyMapData(map); }
public static SoyListData getSoySectionData(List<Section> sections) throws IOException { SoyListData soyList = new SoyListData(); for(Section section : sections) { SanitizedContent doc = new SanitizedContent(section.getDoc(), SanitizedContent.ContentKind.HTML); SanitizedContent code = new SanitizedContent(section.getCode(), SanitizedContent.ContentKind.HTML); SoyMapData soyMap = new SoyMapData("doc",doc,"code",section.getCode(),"hidden", section.isHidden(),"title",section.getTitle()); soyList.add(soyMap); } return soyList; }
public static SoyListData getSoySectionDataWithTokenReplacement(List<Section> sections,Map<String,String> replaceMap) throws IOException { SoyListData soyList = new SoyListData(); for(Section section : sections) { SanitizedContent doc = new SanitizedContent(section.getDocWithTokenReplacement(replaceMap), SanitizedContent.ContentKind.HTML); SanitizedContent code = new SanitizedContent(section.getCode(), SanitizedContent.ContentKind.HTML); SoyMapData soyMap = new SoyMapData("doc",doc,"code",section.getCode(),"hidden", section.isHidden(),"title",section.getTitle()); soyList.add(soyMap); } return soyList; }