예제 #1
0
func (r *reCaptcha) FieldAddOns(ctx *app.Context, field *form.Field) []*form.AddOn {
	if field.Name == "Recaptcha" {
		style := &html.Node{
			Tag:      "style",
			Attrs:    html.Attrs{"type": "text/css"},
			Children: html.Text(css),
		}
		theme := &html.Node{
			Tag:      "script",
			Attrs:    html.Attrs{"type": "text/javascript"},
			Children: html.Text(fmt.Sprintf("var RecaptchaOptions = {theme : '%s'};", r.theme)),
		}
		src := fmt.Sprintf("//www.google.com/recaptcha/api/challenge?k=%s", r.publicKey)
		if r.msg != "" {
			src += fmt.Sprintf("&error=%s", r.msg)
		}
		script := &html.Node{
			Tag:   "script",
			Attrs: html.Attrs{"type": "text/javascript", "src": src},
		}
		return []*form.AddOn{
			&form.AddOn{
				Node: html.Div(style, theme, script),
			},
		}
	}
	return nil
}
예제 #2
0
func (p *Paginator) appendNode(parent *html.Node, page int, flags PageFlags) {
	if page == p.Current {
		flags |= PageCurrent
	}
	node := p.Renderer.Node(page, flags)
	var text string
	switch {
	case flags&PageSeparator != 0:
		text = p.Separator
		if text == "" {
			text = defaultSeparator
		}
	case flags&PagePrevious != 0:
		text = p.Previous
		if text == "" {
			text = defaultPrevious
		}
	case flags&PageNext != 0:
		text = p.Next
		if text == "" {
			text = defaultNext
		}
	default:
		text = strconv.Itoa(page)
	}
	anchor := node.Find(html.TypeAny, "a", nil)
	if anchor == nil {
		panic(fmt.Errorf("no anchor found in ElementRenderer's element %s", node))
	}
	anchor.Children = html.Text(text)
	if page > 0 && page != p.Current && page <= p.Count {
		anchor.SetAttr("href", p.Pager.URL(page))
	}
	parent.AppendChild(node)
}
예제 #3
0
func (s *mathCaptcha) FieldAddOns(ctx *app.Context, field *form.Field) []*form.AddOn {
	if field.Name == "CaptchaResult" {
		return []*form.AddOn{
			&form.AddOn{
				Node:     html.Text(fmt.Sprintf("%d+%d =", s.MathCaptchaA, s.MathCaptchaB)),
				Position: form.AddOnPositionBefore,
			},
		}
	}
	return nil
}
예제 #4
0
파일: form.go 프로젝트: rainycape/gondola
func (r *FormRenderer) WriteHelp(w io.Writer, field *form.Field, help string) error {
	span := html.Span(html.Text(help))
	span.Attrs = html.Attrs{"class": "help-block"}
	_, err := span.WriteTo(w)
	return err
}
예제 #5
0
파일: form.go 프로젝트: rainycape/gondola
func (r *FormRenderer) WriteError(w io.Writer, field *form.Field, err error) error {
	span := html.Span(html.Text(err.Error()))
	span.Attrs = html.Attrs{"class": "help-block"}
	_, werr := span.WriteTo(w)
	return werr
}