Ejemplo n.º 1
0
// Renders the example content including support for context sensitive
// text substitution.
func (c *exampleContent) Write(w io.Writer) (int, error) {
	e := c.Example
	wwwURL := fburl.URL{
		Env: c.Context.Env,
	}
	tpl, err := template.New("example-" + e.URL).Parse(string(e.Content))
	if err != nil {
		// if template parsing fails, we ignore it. it's probably malformed html
		return w.Write(e.Content)
	}
	countingW := counting.NewWriter(w)
	err = tpl.Execute(countingW,
		struct {
			Rand     string // a random token
			RellFBNS string // the OG namespace
			RellURL  string // local http://www.fbrell.com/ URL
			WwwURL   string // server specific http://www.facebook.com/ URL
		}{
			Rand:     randString(10),
			RellFBNS: c.Context.AppNamespace(),
			RellURL:  context.Default().AbsoluteURL("/").String(),
			WwwURL:   wwwURL.String(),
		})
	if err != nil {
		// if template execution fails, we ignore it. it's probably malformed html
		return w.Write(e.Content)
	}
	return countingW.Count(), err
}
Ejemplo n.º 2
0
func TestParseBase64(t *testing.T) {
	t.Parallel()
	const song1 = "W1sib2c6dGl0bGUiLCJzb25nMSJdLFsib2c6dHlwZSIsInNvbmciXV0"
	expected := &Object{Pairs: []Pair{
		{"og:title", "song1"},
		{"og:type", "song"},
		{"og:url", "http://www.fbrell.com/rog/" + song1},
		{"og:image", "http://www.fbrell.com/public/images/" + stockImages[8]},
		{"og:description", stockDescriptions[0]},
	}}

	object, err := NewFromBase64(context.Default(), song1)
	if err != nil {
		t.Fatal(err)
	}
	assertSubset(t, expected, object)
}
Ejemplo n.º 3
0
func TestParseValues(t *testing.T) {
	t.Parallel()
	const ogType = "article"
	const ogTitle = "foo"
	values := url.Values{}
	values.Set("og:type", ogType)
	values.Set("og:title", ogTitle)
	expected := &Object{Pairs: []Pair{
		{"og:type", ogType},
		{"og:title", ogTitle},
		{"og:url", "http://www.fbrell.com/og/" + ogType + "/" + ogTitle},
		{"og:image", "http://www.fbrell.com/public/images/" + stockImages[8]},
		{"og:description", stockDescriptions[6]},
	}}

	object, err := NewFromValues(context.Default(), values)
	if err != nil {
		t.Fatal(err)
	}
	assertSubset(t, expected, object)
}
Ejemplo n.º 4
0
func TestDefaultContext(t *testing.T) {
	t.Parallel()
	ctx := fromValues(t, url.Values{})
	subset.Assert(t, context.Default(), ctx)
}