當前位置: 首頁>>代碼示例>>Golang>>正文


Golang template.CSS函數代碼示例

本文整理匯總了Golang中html/template.CSS函數的典型用法代碼示例。如果您正苦於以下問題:Golang CSS函數的具體用法?Golang CSS怎麽用?Golang CSS使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了CSS函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: RenderTemplate

func RenderTemplate(path string, input []byte, metadata map[string]interface{}) []byte {
	R := func(relativeFilename string) string {
		filename := filepath.Join(filepath.Dir(path), relativeFilename)
		return string(RenderTemplate(filename, Read(filename), metadata))
	}
	importhtml := func(relativeFilename string) template.HTML {
		return template.HTML(R(relativeFilename))
	}
	importcss := func(relativeFilename string) template.CSS {
		return template.CSS(R(relativeFilename))
	}
	importjs := func(relativeFilename string) template.JS {
		return template.JS(R(relativeFilename))
	}

	templateName := Relative(*sourceDir, path)
	funcMap := template.FuncMap{
		"importhtml": importhtml,
		"importcss":  importcss,
		"importjs":   importjs,
		"sorted":     SortedValues,
	}

	tmpl, err := template.New(templateName).Funcs(funcMap).Parse(string(input))
	if err != nil {
		Fatalf("Render Template %s: Parse: %s", path, err)
	}

	output := bytes.Buffer{}
	if err = tmpl.Execute(&output, metadata); err != nil {
		Fatalf("Render Template %s: Execute: %s", path, err)
	}

	return output.Bytes()
}
開發者ID:moochi,項目名稱:grender,代碼行數:35,代碼來源:main.go

示例2: init

func init() {
	HtmlFuncBoot.Register(func(w *Web) {
		// HTML Marksafe
		w.HtmlFunc["html"] = func(str string) html.HTML {
			return html.HTML(str)
		}

		// HTML Attr MarkSafe
		w.HtmlFunc["htmlattr"] = func(str string) html.HTMLAttr {
			return html.HTMLAttr(str)
		}

		// JS Marksafe
		w.HtmlFunc["js"] = func(str string) html.JS {
			return html.JS(str)
		}

		// JS String Marksafe
		w.HtmlFunc["jsstr"] = func(str string) html.JSStr {
			return html.JSStr(str)
		}

		// CSS Marksafe
		w.HtmlFunc["css"] = func(str string) html.CSS {
			return html.CSS(str)
		}
	})
}
開發者ID:venliong,項目名稱:webby,代碼行數:28,代碼來源:html.go

示例3: colors

// colors generates the CSS rules for coverage colors.
func colors() template.CSS {
	var buf bytes.Buffer
	for i := 0; i < 11; i++ {
		fmt.Fprintf(&buf, ".cov%v { color: %v }\n", i, rgb(i))
	}
	return template.CSS(buf.String())
}
開發者ID:Harvey-OS,項目名稱:go,代碼行數:8,代碼來源:html.go

示例4: renderArticle

func renderArticle(c interface{}, path string, arg string) {
	// inject content
	stylePath := resolveFilename("style.css")
	coverPath := resolveFilename("_cover")

	styleContent, _ := ioutil.ReadFile(stylePath)
	coverJSON, _ := ioutil.ReadFile(coverPath)

	article := readArticle(path)

	data := gin.H{
		"title":      filepath.Base(path),
		"article":    template.JS(article.data),
		"useMathjax": article.useMathjax,
		"style":      template.CSS(styleContent),
		"cover":      template.JS(coverJSON),
	}

	switch target := c.(type) {
	case *gin.Context:
		// arg is the template used
		target.HTML(http.StatusOK, arg, data)
	case *template.Template:
		// arg is the file to be written to
		w, err := createFile(arg)
		if err != nil {
			panic(err.Error())
		}
		target.Execute(w, data)
	}
}
開發者ID:kenpu,項目名稱:presently,代碼行數:31,代碼來源:util.go

示例5: ForegroundColor

// ForegroundColor calculates the text color for labels based
// on their background color.
func (l *Label) ForegroundColor() template.CSS {
	if strings.HasPrefix(l.Color, "#") {
		if color, err := strconv.ParseUint(l.Color[1:], 16, 64); err == nil {
			r := float32(0xFF & (color >> 16))
			g := float32(0xFF & (color >> 8))
			b := float32(0xFF & color)
			luminance := (0.2126*r + 0.7152*g + 0.0722*b) / 255

			if luminance < 0.5 {
				return template.CSS("#fff")
			}
		}
	}

	// default to black
	return template.CSS("#000")
}
開發者ID:CarloQ,項目名稱:gogs,代碼行數:19,代碼來源:issue_label.go

示例6: colorNick

func colorNick(s string) template.CSS {
	hue := uint(0)
	for _, c := range s {
		hue *= 17
		hue += uint(c)
	}
	style := fmt.Sprintf("color: hsl(%d, 40%%, 50%%)", hue%360)
	return template.CSS(style)
}
開發者ID:lyuyun,項目名稱:loggregator,代碼行數:9,代碼來源:irc.go

示例7: TemplateHandler

// An example http.Handler that serves a template
func TemplateHandler(w http.ResponseWriter, r *http.Request) {
	// The JS() and CSS() functions will safely escape the given string
	// according to the requested format.
	attrs := map[string]interface{}{
		"Title": "I am a Title from Attributes",
		"JS":    template.JS("console.log('I am safely injected JavaScript!');"),
		"CSS":   template.CSS("p { color: blue; border: 1px solid #aaa }"),
	}
	example.Execute(w, attrs)
}
開發者ID:aodin,項目名稱:go-http-tutorials,代碼行數:11,代碼來源:js_and_css_variables.go

示例8: CSS

func (c *Chart) CSS() template.CSS {
	h, w := c.Height, c.Width
	if h == 0 {
		h = 150
	}
	if w == 0 {
		w = 300
	}
	return template.CSS(fmt.Sprintf("width:%dpx;height:%dpx", w, h))
}
開發者ID:ibmendoza,項目名稱:dgtk,代碼行數:10,代碼來源:chart.go

示例9: newInvitationEmailHTMLContent

func newInvitationEmailHTMLContent(title, inlineStyles, name, company, invitedBy, link string) (string, error) {
	// Layout
	layoutContents, err := ioutil.ReadFile(htmlEmailLayout)
	if err != nil {
		return "", err
	}
	layoutTmpl, err := htmlTemplate.New(htmlEmailLayout).Parse(string(layoutContents))
	if err != nil {
		return "", err
	}

	// Content
	templateContents, err := ioutil.ReadFile(invitationEmailTemplateHTML)
	if err != nil {
		return "", err
	}
	tmpl, err := htmlTemplate.New(invitationEmailTemplateHTML).Parse(string(templateContents))
	if err != nil {
		return "", err
	}

	var (
		inventory                   map[string]interface{}
		parsedContent, parsedLayout bytes.Buffer
	)

	// Parse the content template
	inventory = map[string]interface{}{
		"name":          name,
		"company":       company,
		"invitedBy":     invitedBy,
		"invitationURL": link,
	}
	if err := tmpl.Execute(&parsedContent, inventory); err != nil {
		return "", err
	}

	// Insert the content into the layout
	inventory = map[string]interface{}{
		"title":        title,
		"inlineStyles": htmlTemplate.CSS(inlineStyles),
		"content":      htmlTemplate.HTML(parsedContent.String()),
		"company":      company,
	}
	if err := layoutTmpl.Execute(&parsedLayout, inventory); err != nil {
		return "", err
	}

	return parsedLayout.String(), nil
}
開發者ID:RichardKnop,項目名稱:example-api,代碼行數:50,代碼來源:email_factory.go

示例10: init

func init() {
	//初始化基本模板函數
	//until(start, end int) []int:生成一個從start到end的數組
	//time(t time.Time) string:返回時間字符串2006-01-02 15:04:05
	//date(t time.Time) string:返回日期字符串2006-01-02
	//tocss(s string) template.CSS:轉換字符串為CSS
	//tohtml(s string) template.HTML:轉換字符串為HTML
	//toattr(s string) template.HTMLAttr:轉換字符串為HTMLAttr
	//tojs(s string) template.JS:轉換字符串為JS
	//tojsstr(s string) template.JSStr:轉換字符串為JSStr
	//tourl(s string) template.URL:轉換字符串為URL
	commonFuncMap = template.FuncMap{
		"until": func(start, end int) []int {
			if end >= start {
				var length = end - start + 1
				var result = make([]int, length)
				for i := 0; i < length; i++ {
					result[i] = start + i
				}
				return result
			}
			return []int{}
		},
		"time": func(t time.Time) string {
			return t.Format("2006-01-02 15:04:05")
		},
		"date": func(t time.Time) string {
			return t.Format("2006-01-02")
		},
		"tocss": func(s string) template.CSS {
			return template.CSS(s)
		},
		"tohtml": func(s string) template.HTML {
			return template.HTML(s)
		},
		"toattr": func(s string) template.HTMLAttr {
			return template.HTMLAttr(s)
		},
		"tojs": func(s string) template.JS {
			return template.JS(s)
		},
		"tojsstr": func(s string) template.JSStr {
			return template.JSStr(s)
		},
		"tourl": func(s string) template.URL {
			return template.URL(s)
		},
	}
}
開發者ID:kdada,項目名稱:tinygo,代碼行數:49,代碼來源:init.go

示例11: render

// openDiffs diffs the given files and writes the result to a tempfile,
// then opens it in the gui.
func render(d *delta.DiffSolution, pathFrom, pathTo, pathBase string, config Config) (*bytes.Buffer, error) {
	change := changeModified
	if pathTo == "/dev/null" {
		change = changeDeleted
	} else if pathFrom == "/dev/null" {
		change = changeAdded
	}

	// normalize paths so we don't have tmp on the path
	tmpFrom := strings.HasPrefix(pathFrom, os.TempDir())
	tmpTo := strings.HasPrefix(pathTo, os.TempDir())
	if tmpFrom && !tmpTo {
		pathFrom = pathTo
	} else if !tmpFrom && tmpTo {
		pathTo = pathFrom
	}

	wd, _ := os.Getwd()
	html := formatter.HTML(d)
	m := &Metadata{
		From:      pathFrom,
		To:        pathTo,
		Merged:    pathBase,
		Dir:       wd,
		Change:    change,
		Hash:      md5sum(html),
		DirHash:   md5sum(wd),
		Timestamp: time.Now().UnixNano() / 1000000, // convert to millis
	}
	meta, _ := json.Marshal(m)
	cfg, _ := json.Marshal(config)
	tmpl := template.Must(template.New("compare").Parse(getAsset("compare.html")))
	buf := &bytes.Buffer{}
	err := tmpl.Execute(buf, map[string]interface{}{
		"metadata": template.JS(string(meta)),
		"config":   template.JS(cfg),
		"content":  template.HTML(html),
		"CSS":      template.CSS(getAsset("app.css")),
		"JS": map[string]interface{}{
			"mithril":   template.JS(getAsset("vendor/mithril.min.js")),
			"mousetrap": template.JS(getAsset("vendor/mousetrap.min.js")),
			"highlight": template.JS(getAsset("vendor/highlight.min.js")),
			"pouchdb":   template.JS(getAsset("vendor/pouchdb.min.js")),
			"app":       template.JS(getAsset("app.js")),
		},
	})
	return buf, err
}
開發者ID:joydo,項目名稱:delta,代碼行數:50,代碼來源:delta.go

示例12: TestToString

func TestToString(t *testing.T) {
	var foo interface{} = "one more time"
	assert.Equal(t, ToString(8), "8")
	assert.Equal(t, ToString(int64(16)), "16")
	assert.Equal(t, ToString(8.12), "8.12")
	assert.Equal(t, ToString([]byte("one time")), "one time")
	assert.Equal(t, ToString(template.HTML("one time")), "one time")
	assert.Equal(t, ToString(template.URL("http://somehost.foo")), "http://somehost.foo")
	assert.Equal(t, ToString(template.JS("(1+2)")), "(1+2)")
	assert.Equal(t, ToString(template.CSS("a")), "a")
	assert.Equal(t, ToString(template.HTMLAttr("a")), "a")
	assert.Equal(t, ToString(foo), "one more time")
	assert.Equal(t, ToString(nil), "")
	assert.Equal(t, ToString(true), "true")
	assert.Equal(t, ToString(false), "false")
}
開發者ID:rawlingsj,項目名稱:gofabric8,代碼行數:16,代碼來源:cast_test.go

示例13: Init

// Must be called after flag.Parse()
func Init(tlsCertPath, tlsKeyPath, staticPath string) {
	loadTemplates()
	b, err := ioutil.ReadFile(filepath.Join(staticPath, "critical.min.css"))
	if err != nil {
		log.Fatal(err)
	}
	CriticalCss = template.CSS(string(b))
	addrs := strings.Split(*sourceBackends, ",")
	SourceBackendStubs = make([]proto.SourceBackendClient, len(addrs))
	for idx, addr := range addrs {
		conn, err := grpcutil.DialTLS(addr, tlsCertPath, tlsKeyPath)
		if err != nil {
			log.Fatalf("could not connect to %q: %v", addr, err)
		}
		SourceBackendStubs[idx] = proto.NewSourceBackendClient(conn)
	}
}
開發者ID:Debian,項目名稱:dcs,代碼行數:18,代碼來源:common.go

示例14: Init

func (m middlewareView) Init(app *App) error {
	app.requestMiddlewares = append(app.requestMiddlewares, requestMiddlewareView)

	templates := template.New("")
	templateFuncs := template.FuncMap{}

	templateFuncs["Plain"] = func(data string) template.HTML {
		return template.HTML(data)
	}

	templateFuncs["CSS"] = func(data string) template.CSS {
		return template.CSS(data)
	}

	templates = templates.Funcs(templateFuncs)

	app.data["templates"] = templates
	app.data["templateFuncs"] = templateFuncs
	return nil
}
開發者ID:hypertornado,項目名稱:prago,代碼行數:20,代碼來源:view.go

示例15: AddFile

func (doc *Content) AddFile(f string) error {
	switch path.Ext(f) {
	case ".js":
		data, err := ioutil.ReadFile(f)
		if err != nil {
			return err
		}
		doc.JS = append(doc.JS, template.JS(data))
	case ".css":
		data, err := ioutil.ReadFile(f)
		if err != nil {
			return err
		}
		doc.CSS = append(doc.CSS, template.CSS(data))
	case ".html":
		data, err := ioutil.ReadFile(f)
		if err != nil {
			return err
		}
		doc.HTML = append(doc.HTML, template.HTML(data))
	}

	return nil
}
開發者ID:swdunlop,項目名稱:livefire,代碼行數:24,代碼來源:livefire.go


注:本文中的html/template.CSS函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。