initial commits
parent
d706d012a4
commit
ff1cb9f370
|
@ -0,0 +1,32 @@
|
||||||
|
package frameproto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// WriteFrameImageAspectRatio will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:image:aspect_ratio" name-value pair.
|
||||||
|
//
|
||||||
|
// For example, this call:
|
||||||
|
//
|
||||||
|
// var aspectRatio string = "1.91:1"
|
||||||
|
//
|
||||||
|
// frameproto.WriteFrameImageAspectRatio(writer, aspectRatio)
|
||||||
|
//
|
||||||
|
// Would write this HTML <meta/> element:
|
||||||
|
//
|
||||||
|
// <meta property="fc:frame:image:aspect_ratio" content="1.91:1" />
|
||||||
|
//
|
||||||
|
// Note that this package provides some constants to use with WriteFrameImageAspectRatio.
|
||||||
|
// Namely: AspectRatioOnePointNineOneToOne (for "1.91:1") and AspectRatioOneToOne (for "1:1").
|
||||||
|
//
|
||||||
|
// Which in code would be used at:
|
||||||
|
//
|
||||||
|
// frameproto.WriteFrameImageAspectRatio(writer, frameproto.AspectRatioOnePointNineOneToOne)
|
||||||
|
//
|
||||||
|
// And:
|
||||||
|
//
|
||||||
|
// frameproto.WriteFrameImageAspectRatio(writer, frameproto.AspectRatioOneToOne)
|
||||||
|
func WriteFrameImageAspectRatio(writer io.Writer, label string) {
|
||||||
|
const property string = MetaPropertyFrameImageAspectRatio
|
||||||
|
writeMetaPropertyContent(writer, property, label)
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
package frameproto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestWriteFrameImageAspectRatio(t *testing.T) {
|
||||||
|
|
||||||
|
tests := []struct{
|
||||||
|
AspectRatio string
|
||||||
|
Expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
AspectRatio: "",
|
||||||
|
Expected: `<meta property="fc:frame:image:aspect_ratio" content="" />`+"\n",
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
AspectRatio: "something",
|
||||||
|
Expected: `<meta property="fc:frame:image:aspect_ratio" content="something" />`+"\n",
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
AspectRatio: "Hello world! 🙂",
|
||||||
|
Expected: `<meta property="fc:frame:image:aspect_ratio" content="Hello world! 🙂" />`+"\n",
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
AspectRatio: "1.91:1",
|
||||||
|
Expected: `<meta property="fc:frame:image:aspect_ratio" content="1.91:1" />`+"\n",
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
AspectRatio: "1:1",
|
||||||
|
Expected: `<meta property="fc:frame:image:aspect_ratio" content="1:1" />`+"\n",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for testNumber, test := range tests {
|
||||||
|
|
||||||
|
var buffer strings.Builder
|
||||||
|
|
||||||
|
WriteFrameImageAspectRatio(&buffer, test.AspectRatio)
|
||||||
|
|
||||||
|
expected := test.Expected
|
||||||
|
actual := buffer.String()
|
||||||
|
|
||||||
|
if expected != actual {
|
||||||
|
t.Errorf("For test #%d, the actual written meta-tag is not what was expected." ,testNumber)
|
||||||
|
t.Logf("EXPECTED: %s", expected)
|
||||||
|
t.Logf("ACTUAL: %s", actual)
|
||||||
|
t.Logf("EXPECTED: %q", expected)
|
||||||
|
t.Logf("ACTUAL: %q", actual)
|
||||||
|
t.Logf("AspectRatio: %q", test.AspectRatio)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue