本文整理汇总了Golang中html/template.CSS函数的典型用法代码示例。如果您正苦于以下问题:Golang CSS函数的具体用法?Golang CSS怎么用?Golang CSS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了CSS函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng