Giter Club home page Giter Club logo

martini-fis-app's Introduction

martini-fis-app

在go语言的martini-framwork环境下使用fis

安装

安装gois

$ npm install -g gois

gois 扩展自fis,包含FIS的全部功能,包括添加md5、cdn、打包等等,详细请见FIS。

安装fis的martini-middleware

$ go get github.com/go-martini/martini
$ go get github.com/xiangshouding/martini-middleware/fis

martini-middleware/fis 修改并重新发布了render,并包含所有render的方法。其中 添加了一些模板函数。

下载demo

git clone https://github.com/xiangshouding/martini-fis-app.git

使用

➜  martini-fis-app git:(master) ✗ tree -L 1
.
├── README.md
├── app.go
├── public
├── src
└── template

编译发布

src 目录下是FIS项目源码,编译后产出到public和template两个目录下。

$ cd src
$ gois release -d remote

  • url加md5

    $ gois release -md remote
  • 合并静态资源(打包)

    $ gois release -pd remote
  • 静态资源压缩

    $ gois release -od remote
  • 静态资源加CDN

    $ gois release -Dd remote
  • md5 + 打包 + 压缩 + CDN

    $ gois release -ompDd remote
    

app.go

app.go 是使用martini写的web程序;

package main

import (
    "github.com/go-martini/martini"
    "github.com/xiangshouding/martini-middleware/fis" //引入FIS
)

func main() {
    m := martini.Classic()
    m.Use(martini.Static("public"))     //设置静态资源目录

    //martini使用FIS martini-middleware
    m.Use(fis.Renderer(fis.Options{
        Directory:  "template",         //设置模板目录
        Extensions: []string{".tpl"},   //设置模板扩展
    }))

    m.Get("/", func(r fis.Render) {
        r.HTML(200, "page/index", "")   //渲染模板
    })

    m.Run()
}

运行

$ go run app.go

访问

浏览器访问 http://127.0.0.1:3000 查看效果

开发

javascript

widget 目录下的js都会被组件化;

源码 编译后
console.log('test'); define('widget/test.js', function(require, exports, module){console.log('test');});

tpl

{{framework "mod.js"}} //引入组件化库
{{require "widget/test.js"}} //页面加载test.js

<script>
var testjs = "{{uri `widget/test.js`}}" //获得test.js的线上路径
</script>
widget
<!-- widget/header/header.tpl -->
{{define "widget/header/header.tpl"}}
    <script>
        //blabla
    </script>
    {{require "widget/header/header.tpl"}} <!-- load widget使用到的静态资源 -->
{{end}}

<!-- page/index.tpl -->
{{template "widget/header/header.tpl"}} <!-- use widget `widget/header/header.tpl` -->

静态资源在</head>前加载

扩展阅读

martini-fis-app's People

Contributors

oxund avatar

Watchers

 avatar  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.