Esempio n. 1
0
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)
		}
	})
}
Esempio n. 2
0
func (s *Server) HandleCheckout(w http.ResponseWriter, r *http.Request) {
	// POST /reservations/checkout
	if r.Method != "POST" {
		http.Error(w, "Method must be POST", http.StatusBadRequest)
		return
	}
	if err := r.ParseForm(); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	var vars CheckoutVars
	if err := s.decoder.Decode(&vars, r.PostForm); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	var tourIDs []int32
	for _, item := range vars.Items {
		tourIDs = append(tourIDs, item.TourID)
	}
	tourDetails, err := s.store.GetTourDetailsByID(tourIDs)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	var checkoutItems []*CheckoutItem
	for _, item := range vars.Items {
		tourDetail, ok := tourDetails[item.TourID]
		if !ok {
			http.Error(w, fmt.Sprintf("Invalid tour ID: %d", item.TourID), http.StatusBadRequest)
			return
		}
		checkoutItems = append(checkoutItems, &CheckoutItem{
			Quantity:   item.Quantity,
			TourDetail: tourDetail,
		})
	}

	data := &CheckoutData{
		Items:                checkoutItems,
		StripePublishableKey: template.JSStr(s.stripePublishableKey),
	}
	tmpl, err := template.ParseFiles(path.Join(s.templatesDir, "checkout.html"))
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if err := tmpl.Execute(w, data); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}
Esempio n. 3
0
File: index.go Progetto: zqzca/back
// The CSS Assets to inject into the page.
func templateData(host string) map[string]interface{} {
	css := []string{
		"login", "menu", "registration", "table", "authentication",
		"uploader", "upload_file", "style", "alerts", "dashboard",
		"header", "footer", "file_list_component", "file_view",
	}
	js := []string{
		"new/xhr", "ws",
		"lib/dominate", "lib/filesize", "helpers", "alerts", "table_component",
		"authentication_component", "router", "login", "login_component", "menu",
		"header_component", "footer_component", "app",
	}

	nakedHost := strings.Split(host, ":")[0]
	var liveReloadStr string
	if config.LiveReload {
		liveReloadStr = "http://" + nakedHost + ":35729/livereload.js?snipver=1"
	}

	var wsPath string
	if config.Secure {
		wsPath = fmt.Sprintf("wss://%s/ws", host)
	} else {
		wsPath = fmt.Sprintf("ws://%s/ws", host)
	}

	return map[string]interface{}{
		"Title":      "zqz.ca",
		"LiveReload": liveReloadStr,
		"Cdn":        template.JSStr(config.CDNURL),
		"WSPath":     template.JSStr(wsPath),

		"Assets": map[string]interface{}{
			"Js":  js,
			"Css": css,
		},
	}
}
Esempio n. 4
0
File: init.go Progetto: kdada/tinygo
func init() {
	//初始化基本模板函数
	//until(start, end int) []int:生成一个从start到end的数组
	//time(t time.Time) string:返回时间字符串2006-01-02 15:04:05
	//date(t time.Time) string:返回日期字符串2006-01-02
	//tocss(s string) template.CSS:转换字符串为CSS
	//tohtml(s string) template.HTML:转换字符串为HTML
	//toattr(s string) template.HTMLAttr:转换字符串为HTMLAttr
	//tojs(s string) template.JS:转换字符串为JS
	//tojsstr(s string) template.JSStr:转换字符串为JSStr
	//tourl(s string) template.URL:转换字符串为URL
	commonFuncMap = template.FuncMap{
		"until": func(start, end int) []int {
			if end >= start {
				var length = end - start + 1
				var result = make([]int, length)
				for i := 0; i < length; i++ {
					result[i] = start + i
				}
				return result
			}
			return []int{}
		},
		"time": func(t time.Time) string {
			return t.Format("2006-01-02 15:04:05")
		},
		"date": func(t time.Time) string {
			return t.Format("2006-01-02")
		},
		"tocss": func(s string) template.CSS {
			return template.CSS(s)
		},
		"tohtml": func(s string) template.HTML {
			return template.HTML(s)
		},
		"toattr": func(s string) template.HTMLAttr {
			return template.HTMLAttr(s)
		},
		"tojs": func(s string) template.JS {
			return template.JS(s)
		},
		"tojsstr": func(s string) template.JSStr {
			return template.JSStr(s)
		},
		"tourl": func(s string) template.URL {
			return template.URL(s)
		},
	}
}
Esempio n. 5
0
func rawJSStr(text string) template.JSStr {
	return template.JSStr(text)
}
Esempio n. 6
0
/*
Reads a post and gets all details from it.
*/
func read_post(filename string, conf Configuration) Post {
	var buffer bytes.Buffer
	var p Post
	var err error = nil
	var onlyonce bool = true
	var titleline, dateline, tagline, authorline, line string
	flag := false
	f, err := os.Open(filename)
	if err != nil {
		fmt.Println(err)
		return p
	}
	defer f.Close()
	r := bufio.NewReader(f)
	for err == nil {
		line, err = r.ReadString('\n')
		buffer.WriteString(line)
		if onlyonce && strings.HasPrefix(line, "<!--") {
			onlyonce = false
			flag = true
			continue
		}
		if !onlyonce && strings.HasPrefix(line, "-->") {
			flag = false
			continue
		}
		if flag {
			i := strings.Index(line, ".. title:")
			if i != -1 {
				titleline = line[i+9:]
				continue
			}
			i = strings.Index(line, ".. date:")
			if i != -1 {
				dateline = line[i+8:]
				continue
			}
			i = strings.Index(line, ".. tags:")
			if i != -1 {
				tagline = strings.TrimSpace(line[i+8:])
				if tagline == "" {
					tagline = "Uncategorized"
				}
				continue
			}
			i = strings.Index(line, ".. author:")
			if i != -1 {
				authorline = line[i+10:]
				continue
			}
		}
	}

	if err == io.EOF {
		if authorline == "" {
			authorline = conf.Author
		}
		title := strings.TrimSpace(titleline)
		date := strings.TrimSpace(dateline)
		author := strings.TrimSpace(authorline)
		tagsnonstripped := strings.Split(tagline, ",")
		tags := make(map[string]string, 0)
		for i := range tagsnonstripped {
			word := strings.TrimSpace(tagsnonstripped[i])
			tags[get_slug(word)] = word
		}

		p.Title = title
		slug := filepath.Base(filename)
		length := len(slug)
		p.Slug = slug[:length-3]
		body := MD(buffer.Bytes())
		p.Body = template.HTML(string(body))
		p.Date = get_time(date)
		p.S_Date = date
		p.Tags = tags
		p.Changed = false
		p.Url = fmt.Sprintf("%sposts/%s.html", conf.URL, p.Slug)
		p.Durl = template.JSStr(p.Url)
		p.Logo = conf.Logo
		p.Links = conf.Links
		p.Disqus = conf.Disqus
		p.Author = author

		// Let us add any extra data for the themes.
		var edata ExtraData
		edata.BrokenDate = p.Date.Format("Jan 02, 2006")
		edata.BrokenTime = p.Date.Format("15:04")
		p.EData = edata
		p.Conf = conf

	}
	return p
}
Esempio n. 7
0
func (c App) getMenuLi(sessionId int) []interface{} {
	line1 := []map[string]interface{}{
		map[string]interface{}{"name": "收款单", "image": "40174.gif"},
		map[string]interface{}{"name": "付款单", "image": "40171.gif"},
		map[string]interface{}{"name": "资金汇总表", "image": "40153.gif"},
		map[string]interface{}{"name": "现金账户初始化", "image": "40170.gif"},
	}
	line2 := []map[string]interface{}{
		map[string]interface{}{"name": "银行账户初始化", "image": "40138.gif"},
		map[string]interface{}{"name": "系统参数", "image": "6.gif"},
		map[string]interface{}{"name": "单据类型参数", "image": "11.gif"},
		map[string]interface{}{"name": "会计期", "image": "69.gif"},
	}
	line3 := []map[string]interface{}{
		map[string]interface{}{"name": "银行账户", "image": "53.gif"},
		map[string]interface{}{"name": "现金账户", "image": "42.gif"},
		map[string]interface{}{"name": "客户", "image": "7.gif"},
		map[string]interface{}{"name": "银行资料", "image": "68.gif"},
	}

	nameLi := []string{}
	for _, item := range line1 {
		nameLi = append(nameLi, item["name"].(string))
	}
	for _, item := range line2 {
		nameLi = append(nameLi, item["name"].(string))
	}
	for _, item := range line3 {
		nameLi = append(nameLi, item["name"].(string))
	}

	_, db := global.GetConnection(sessionId)
	menuLi := []map[string]interface{}{}
	err := db.C("Menu").Find(map[string]interface{}{
		"name": map[string]interface{}{
			"$in": nameLi,
		},
		"isLeaf": 1,
	}).All(&menuLi)
	if err != nil {
		panic(err)
	}

	for i, item := range line1 {
		line1[i] = item
		for _, menu := range menuLi {
			if item["name"].(string) == fmt.Sprint(menu["name"]) {
				item["url"] = template.JSStr(fmt.Sprint(menu["url"]))
				break
			}
		}
	}
	for i, item := range line2 {
		line2[i] = item
		for _, menu := range menuLi {
			if item["name"].(string) == fmt.Sprint(menu["name"]) {
				item["url"] = template.JSStr(fmt.Sprint(menu["url"]))
				break
			}
		}
	}
	for i, item := range line3 {
		line3[i] = item
		for _, menu := range menuLi {
			if item["name"].(string) == fmt.Sprint(menu["name"]) {
				item["url"] = template.JSStr(fmt.Sprint(menu["url"]))
				break
			}
		}
	}
	return []interface{}{
		line1,
		line2,
		line3,
	}
}