Git Product home page Git Product logo

beego-assets's Introduction

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

beego-assets's People

Contributors

saturn4er avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.