beego_assets

package module
v0.0.0-...-8051e60 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2017 License: MIT Imports: 18 Imported by: 5

README

Build Status

Description

Rails-style assets for golang beego web framework

Installation

To install library, create config in ./conf/asset-pipeline.conf and enter into the console:

go get github.com/saturn4er/beego-assets

Usage

Add following lines to your main file

import (
	_ "github.com/saturn4er/beego-assets"
)

Put basic config to ./conf/asset-pipeline.conf

Use functions javascript_include_tag and stylesheet_include_tag in your templates

{{ asset_js "application" }}
{{ asset_css "application" }}

Preprocessors

Library support preprocessors, like sass, less, scss and coffeescript. It use Node.js and corresponding libraries, so, you should install them before using it.

Installation

First, install corresponding node modules

Less: npm install less -g
Scss/Sass: npm install node-sass -g
Coffeescript: npm install coffee-script -g

After that you can use less by adding following line to your imports

Less: import _ "github.com/saturn4er/beego-assets/less"
Sass: import _ "github.com/saturn4er/beego-assets/sass"
Scss: import _ "github.com/saturn4er/beego-assets/scss"
Coffeescript: import _ "github.com/saturn4er/beego-assets/coffee"

Asset format

Asset extension sholud be .js or .css. Depends on include_tag function
Current version of library support only "require" method.

CSS asset example

/*= require css/file1
/*= require css/file1

JS asset example

//= require js/file1
//= require js/file2

Config

The configuration file is ./conf/asset-pipeline.conf have basic INI format.

Root params

  • assets_dir - paths to assets files(You can specify many directories, separated by commas)
  • public_dirs - paths, where library will search for files for assets.(You can specify many directories, separated by commas)
  • temp_dir - path to store compiled asset files.

Sections

You can define different parameters for different runmodes, which are defined in ./conf/app.conf. Name of section is the value of runmode. If there is no such section, all the parameters will be false

Parameters
  • minify_js - Flag to minify javascript assets
  • minify_css - Flag to minify stylesheet assets
  • combine_js - Flag to combine multiple javascript files into one file
  • combine_css - Flag to combine multiple stylesheet files into one file
  • production_mode - It this flag is FALSE, assets will be recompiled each page request

Config example:

#paths where assets stored(Devided by comma)
assets_dirs = assets/javascripts,assets/stylesheets
#path to js/css
public_dirs = static
#where to put compiled assets files
temp_dir = static/assets

[production]
minify_js = true
minify_css = true

combine_js = true
combine_css = true

production_mode = false

[dev]
minify_js = false
minify_css = false

combine_js = false
combine_css = false

production_mode = false

API

  • SetAssetFileExtension - add your own extension to files finder

    • extension string - Extension name, with point.(Ex. ".js")
    • asset_type AssetType - beego_assets.ASSET_STYLESHEET / beego_assets.ASSET_JAVASCRIPT
  • SetPreLoadCallback - define pre-load callback for assets. "cb" will be executed before loading assets files to memory.

    • asset_type AssetType
    • cb preLoadCallback - callback, which will be executed before asset compilation
  • SetPreBuildCallback - define pre-build callback for assets. "cb" will be executed before building of asset

    • asset_type AssetType
    • cb pre_afterBuildCallback - callback, which will be executed before asset compilation
  • SetAfterBuildCallback - define after-build callback for assets. "cb" will be executed after asset was built

    • asset_type AssetType
    • cb pre_afterBuildCallback - callback, which will be executed after asset compilation

Documentation

Index

Constants

View Source
const CSS_EXTENSION = ".css"
View Source
const CSS_EXTENSION_LEN = len(CSS_EXTENSION)
View Source
const JS_EXTENSION = ".js"
View Source
const JS_EXTENSION_LEN = len(JS_EXTENSION)
View Source
const PREFIX = "[ ASSET_PIPELINE ] "

Variables

View Source
var Config assetPipelineConfig
View Source
var Logger = logs.NewLogger(10000)

Functions

func Error

func Error(format string, v ...interface{})

func GetAssetFileHash

func GetAssetFileHash(body *string) string

func MinifyJavascript

func MinifyJavascript(body string) (string, error)

func MinifyStylesheet

func MinifyStylesheet(body string) (string, error)

func SetAfterBuildCallback

func SetAfterBuildCallback(asset_type AssetType, cb pre_afterBuildCallback)

func SetAssetFileExtension

func SetAssetFileExtension(extension string, asset_type AssetType)

func SetMinifyCallback

func SetMinifyCallback(extension string, cb minifyFileCallback)

func SetPreBuildCallback

func SetPreBuildCallback(asset_type AssetType, cb pre_afterBuildCallback)

func SetPreLoadCallback

func SetPreLoadCallback(asset_type AssetType, cb preLoadCallback)

func Warning

func Warning(format string, v ...interface{})

Types

type Asset

type Asset struct {
	Include_files []string
	// contains filtered or unexported fields
}

type AssetType

type AssetType byte
const (
	ASSET_JAVASCRIPT AssetType = iota
	ASSET_STYLESHEET
)

func (*AssetType) String

func (this *AssetType) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL