当前位置: 首页>>代码示例>>Golang>>正文


Golang IndentingWriter.Printf方法代码示例

本文整理汇总了Golang中github.com/travissimon/formatting.IndentingWriter.Printf方法的典型用法代码示例。如果您正苦于以下问题:Golang IndentingWriter.Printf方法的具体用法?Golang IndentingWriter.Printf怎么用?Golang IndentingWriter.Printf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/travissimon/formatting.IndentingWriter的用法示例。


在下文中一共展示了IndentingWriter.Printf方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: processNodes2

func (w *ViewWriter) processNodes2(htmlWriter, srcWriter, patternWriter *formatting.IndentingWriter) {
	// initialise opening quote for htmlArray
	htmlWriter.Print("`")

	// initialise starting indent for src
	srcWriter.IncrIndent()

	// initialise starting indent and openning quote
	patternWriter.IncrIndent()

	htmlIndex := 0
	patternIndex := 0
	for n := w.rootNode.children.Front(); n != nil; n = n.Next() {
		htmlIndex, _ = w.writeNode(n, htmlWriter, srcWriter, patternWriter, htmlIndex, patternIndex)
	}

	// close quote for html Array
	htmlWriter.Print("`,")

	// Ensure final html is written
	srcWriter.Printf("fmt.Fprint(w, %sHtml[%d])\n", w.viewName, htmlIndex)

	// if our last op was writing code, we need to close pattern string
	if w.writingCodeOutput {
		patternWriter.Println("`,")
	}
}
开发者ID:rickb777,项目名称:ghaml,代码行数:27,代码来源:view_writer.go

示例2: writeCodeExecution

func (w *ViewWriter) writeCodeExecution(nd *Node, haml *formatting.IndentingWriter, src *formatting.IndentingWriter, currentHtmlIndex int) int {
	// end most recent haml output
	haml.Println("`,")
	// start next haml output (which will follow this code output
	haml.Println("`")

	// All call to write html from array
	src.Printf("fmt.Fprint(w, %sHtml[%d])\n", w.destinationName, currentHtmlIndex)
	currentHtmlIndex++

	// attempt to keep formatting across user code.
	// Here we're checking to see if this is the end of a block statement
	// if so, we need to decrease indent
	first := getFirstChar(nd.text)
	if first == '}' {
		src.DecrIndent()
	}

	// add user's code
	src.Printf("%s\n", nd.text)

	// If user code ends in {, incr indent as they started a block statement
	last := getLastChar(nd.text)
	if last == '{' {
		src.IncrIndent()
	}

	for n := nd.children.Front(); n != nil; n = n.Next() {
		currentHtmlIndex = w.writeNode(n.Value.(*Node), haml, src, currentHtmlIndex)
	}

	return currentHtmlIndex
}
开发者ID:rayleyva,项目名称:ghaml,代码行数:33,代码来源:view_writer.go

示例3: writeCodeOutput

func (w *ViewWriter) writeCodeOutput(nd *Node, haml *formatting.IndentingWriter, src *formatting.IndentingWriter, currentHtmlIndex int) int {
	// end most recent haml output
	haml.Println("`,")
	// start next haml output (which will follow this code output
	haml.Println("`")

	// All call to write html from array
	src.Printf("fmt.Fprint(w, %sHtml[%d])\n", w.destinationName, currentHtmlIndex)
	currentHtmlIndex++

	// add call to print output
	src.Printf("fmt.Fprint(w, %s)\n", nd.text)

	for n := nd.children.Front(); n != nil; n = n.Next() {
		currentHtmlIndex = w.writeNode(n.Value.(*Node), haml, src, currentHtmlIndex)
	}

	return currentHtmlIndex
}
开发者ID:rayleyva,项目名称:ghaml,代码行数:19,代码来源:view_writer.go

示例4: writeNode

// Recursive function to write parsed HAML Nodes
func (w *ViewWriter) writeNode(nd *Node, haml *formatting.IndentingWriter, src *formatting.IndentingWriter, currentHtmlIndex int) int {

	if nd.name == "code_output" {
		return w.writeCodeOutput(nd, haml, src, currentHtmlIndex)
	} else if nd.name == "code_execution" {
		return w.writeCodeExecution(nd, haml, src, currentHtmlIndex)
	}

	haml.Printf("<%s", nd.name)
	if nd.id != nil {
		w.writeAttribute(nd.id, haml)
	}
	if nd.class != nil {
		w.writeAttribute(nd.class, haml)
	}

	for attrEl := nd.attributes.Front(); attrEl != nil; attrEl = attrEl.Next() {
		attr := attrEl.Value.(*nameValueStr)
		w.writeAttribute(attr, haml)
	}

	if nd.selfClosing {
		haml.Println(" />`)")
		return currentHtmlIndex
	} else {
		haml.Print(">")
	}

	// Outputting text.

	// If tag only contains short text, add it on same line
	if w.canChildContentFitOnOneLine(nd) {
		haml.Printf("%s</%s>\n", nd.text, nd.name)
		return currentHtmlIndex
	}

	// We either have long text, child tags or both
	// so we add it as indented child content
	haml.Println("")
	haml.IncrIndent()

	if len(nd.text) > 0 {
		w.writeLongText(nd.text, haml)
	}

	for n := nd.children.Front(); n != nil; n = n.Next() {
		currentHtmlIndex = w.writeNode(n.Value.(*Node), haml, src, currentHtmlIndex)
	}

	haml.DecrIndent()
	haml.Printf("</%s>\n", nd.name)

	return currentHtmlIndex
}
开发者ID:rayleyva,项目名称:ghaml,代码行数:55,代码来源:view_writer.go

示例5: writeCodeOutput

func (w *ViewWriter) writeCodeOutput(el *list.Element, haml, src, pattern *formatting.IndentingWriter,
	currentHtmlIndex, currentPatternIndex int, nodeType CodeOutputType) (htmlIndex, patternIndex int) {

	nd := el.Value.(*Node)

	htmlIndex = currentHtmlIndex
	patternIndex = currentPatternIndex

	if !w.writingCodeOutput {
		// First code output node - close off haml node output:

		// end most recent haml output
		haml.Println("`,")
		// start next haml output (which will follow this code output
		haml.Println("`")

		// Add call to write html from array
		src.Printf("fmt.Fprint(w, %sHtml[%d])\n", w.viewName, currentHtmlIndex)

		if nodeType == Literal || nodeType == EscapedValue {
			// Add calls to execute template. However, we need to know which
			// object to inject into template. Usually this will be 'data', but
			// can be something else inside a loop, for example, so we take the
			// object from the first dynamic element
			objectToInject := "data"
			if nodeType == EscapedValue {
				objectToInject = getObjectName(nd.text)
			} else {
			LookaheadLoop:
				for n := el; n != nil; n = n.Next() {
					node := n.Value.(*Node)
					switch node.name {
					case "code_output_dynamic":
						objectToInject = getObjectName(node.text)
						break LookaheadLoop
					}
				}
			}
			src.Printf("err = wr.templates[%d].Execute(w, %s)\n", currentPatternIndex, objectToInject)
			src.Printf("handle%sError(err)\n", w.properViewName)
			// start a new pattern string
			pattern.Print("`")

			w.writingCodeOutput = true
			patternIndex++
		}

		htmlIndex++
	}

	// These stop writing patterns, so we need to close off pattern strings
	if w.writingCodeOutput && (nodeType == RawValue || nodeType == Execution) {
		pattern.Println("`,")
		w.writingCodeOutput = false
	}

	// add call to print output
	switch nodeType {
	case Literal:
		pattern.Print(nd.text)
	case EscapedValue:
		// print the path to the desired object for the template pattern
		patternStr := "."
		index := strings.Index(nd.text, ".")
		if index > 0 {
			patternStr = nd.text[index:]
		}
		pattern.Printf("{{%s}}", patternStr)
	case RawValue:
		src.Printf("fmt.Fprint(w, %s)\n", nd.text)
	case Execution:
		// attempt to keep formatting across user code.
		// Here we're checking to see if this is the end of a block statement
		// if so, we need to decrease indent
		first := getFirstChar(nd.text)
		if first == '}' {
			src.DecrIndent()
		}

		// add user's code
		src.Printf("%s\n", nd.text)

		// If user code ends in {, incr indent as they started a block statement
		last := getLastChar(nd.text)
		if last == '{' {
			src.IncrIndent()
		}
	}

	for n := nd.children.Front(); n != nil; n = n.Next() {
		htmlIndex, patternIndex = w.writeNode(n, haml, src, pattern, htmlIndex, patternIndex)
	}

	return
}
开发者ID:rickb777,项目名称:ghaml,代码行数:95,代码来源:view_writer.go

示例6: writeAttribute

func (w *ViewWriter) writeAttribute(attribute *nameValueStr, haml *formatting.IndentingWriter) {
	haml.Printf(" %s=\"%s\"", attribute.name, attribute.value)
}
开发者ID:rickb777,项目名称:ghaml,代码行数:3,代码来源:view_writer.go

示例7: writeNode

// Recursive function to write parsed HAML Nodes
// We have to return a bool indicating if we have escaped any HTML (XSS protection)
// so that we know if we need to include the templating library for that function
func (w *ViewWriter) writeNode(el *list.Element,
	haml, src, pattern *formatting.IndentingWriter,
	currentHtmlIndex, currentPatternIndex int) (htmlIndex, patternIndex int) {

	nd := el.Value.(*Node)

	htmlIndex = currentHtmlIndex
	patternIndex = currentPatternIndex

	switch nd.name {
	case "code_output_literal":
		return w.writeCodeOutput(el, haml, src, pattern, htmlIndex, patternIndex, Literal)
	case "code_output_value":
		return w.writeCodeOutput(el, haml, src, pattern, htmlIndex, patternIndex, EscapedValue)
	case "code_output_raw":
		return w.writeCodeOutput(el, haml, src, pattern, htmlIndex, patternIndex, RawValue)
	case "code_execution":
		return w.writeCodeOutput(el, haml, src, pattern, htmlIndex, patternIndex, Execution)
	}

	if w.writingCodeOutput {
		// we've finished writing code output and we're back to haml
		// so close off our pattern string
		pattern.Println("`,")
	}
	w.writingCodeOutput = false

	if nd.name != "" {
		haml.Printf("<%s", nd.name)
		if nd.id != nil {
			w.writeAttribute(nd.id, haml)
		}
		if nd.class != nil {
			w.writeAttribute(nd.class, haml)
		}

		for attrEl := nd.attributes.Front(); attrEl != nil; attrEl = attrEl.Next() {
			attr := attrEl.Value.(*nameValueStr)
			w.writeAttribute(attr, haml)
		}

		if nd.selfClosing {
			haml.Print(" />")
			if nd.text != "" {
				haml.Printf(" %s", nd.text)
			}
			haml.Println("")
			return
		} else {
			haml.Print(">")
		}
	}

	// Outputting text.

	// If tag only contains short text, add it on same line
	if w.canChildContentFitOnOneLine(nd) {
		if nd.name == "" {
			haml.Printf("%s\n", nd.text)
		} else {
			haml.Printf("%s</%s>\n", nd.text, nd.name)
		}
		return
	}

	// We either have long text, child tags or both
	// so we add it as indented child content
	haml.Println("")
	haml.IncrIndent()

	if len(nd.text) > 0 {
		w.writeLongText(nd.text, haml)
	}

	for n := nd.children.Front(); n != nil; n = n.Next() {
		htmlIndex, patternIndex = w.writeNode(n, haml, src, pattern, htmlIndex, patternIndex)
	}

	haml.DecrIndent()
	if nd.name != "" {
		haml.Printf("</%s>\n", nd.name)
	}

	return
}
开发者ID:rickb777,项目名称:ghaml,代码行数:88,代码来源:view_writer.go


注:本文中的github.com/travissimon/formatting.IndentingWriter.Printf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。