Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/rsniezynski/go-asset-helper

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/rsniezynski/go-asset-helper

  • v0.0.0-20150405181857-38e753e5e853
  • Source
  • Go
  • Socket score

Version published
Created
Source

go-asset-helper

Package asset helps using static assets (scripts, stylesheets, other files) prepared by external asset pipelines in Go (Golang) templates. It provides template functions that insert references to (optionally) minified and versioned files.

The idea behind this package is that in some cases creating asset bundles is best left to external tools such as grunt or gulp. The default configuration relies on a presence of a JSON file describing a mapping from original to minified assets. Such file can be prepared e.g. by gulp-rev.

Example of a manifest file:

{
    "js/main.min.js": "js/main.min-da89a0c4.js",
    "css/style.min.css": "css/style.min-16680603.css"
}

Example usage in template:

<head>
    {{ linktag "css/style.css" }}
    {{ scripttag "js/main.js" }}

    <!-- Additional attributes can be passed using an even number of arguments: -->
    {{ scripttag "js/main.js" "charset" "UTF-8" }}
</head>
<body>
    <!-- Inserts URL prefix to avoid hardcoding it -->
    <img src="{{ static }}/img/logo.jpg"/>
</body>

Example initialization:

import (
    "github.com/rsniezynski/go-asset-helper"
    "html/template"
)

func main() {
    static, err := asset.NewStatic("/static/", "/path/to/manifest.json")
    if err != nil {
        // Manifest file doesn't exist or is not a valid JSON
    }
    tmpl := template.Must(template.ParseFiles("template_name.html"))

    // Attach helper functions with the template:
    static.Attach(tmpl)
    // Alternatively:
    tmpl.Funcs(static.FuncMap())

    // Use minified versions if available:
    static, err = asset.NewStatic("/static/", "/path/to/manifest.json", asset.WithUseMinified(true))

    // Use minified versions and load the manifest file using go-bindata (Asset is a go-bindata class).
    // The loader is a func(string) ([]byte, error)
    static, err = asset.NewStatic(
        "/static/", "/path/to/manifest.json",
        asset.WithUseMinified(true),
        asset.WithManifestLoader(Asset),
    )

    // There's also WithMappingBuilder option to create the asset mapper without
    // using the manifest file.
}

FAQs

Package last updated on 05 Apr 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc