initial commits
parent
f469e7fbff
commit
c35c7c2e0c
|
@ -0,0 +1,28 @@
|
||||||
|
package frameproto
|
||||||
|
|
||||||
|
// StringFrameImageAspectRatio will return 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"
|
||||||
|
//
|
||||||
|
// str := frameproto.StringFrameImageAspectRatio(aspectRatio)
|
||||||
|
//
|
||||||
|
// Would return 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 StringFrameImageAspectRatio.
|
||||||
|
// Namely: AspectRatioOnePointNineOneToOne (for "1.91:1") and AspectRatioOneToOne (for "1:1").
|
||||||
|
//
|
||||||
|
// Which in code would be used at:
|
||||||
|
//
|
||||||
|
// str := frameproto.StringFrameImageAspectRatio(frameproto.AspectRatioOnePointNineOneToOne)
|
||||||
|
//
|
||||||
|
// And:
|
||||||
|
//
|
||||||
|
// str := frameproto.StringFrameImageAspectRatio(frameproto.AspectRatioOneToOne)
|
||||||
|
func StringFrameImageAspectRatio(label string) string {
|
||||||
|
const property string = MetaPropertyFrameImageAspectRatio
|
||||||
|
return stringMetaPropertyContent(property, label)
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
package frameproto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestStringFrameImageAspectRatio(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 {
|
||||||
|
|
||||||
|
actual := StringFrameImageAspectRatio(test.AspectRatio)
|
||||||
|
|
||||||
|
expected := test.Expected
|
||||||
|
|
||||||
|
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