diff --git a/writeframeimageaspectratio.go b/writeframeimageaspectratio.go new file mode 100644 index 0000000..6f8a4c5 --- /dev/null +++ b/writeframeimageaspectratio.go @@ -0,0 +1,32 @@ +package frameproto + +import ( + "io" +) + +// WriteFrameImageAspectRatio will write the HTML 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 element: +// +// +// +// 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) +} diff --git a/writeframeimageaspectratio_test.go b/writeframeimageaspectratio_test.go new file mode 100644 index 0000000..cd131c4 --- /dev/null +++ b/writeframeimageaspectratio_test.go @@ -0,0 +1,68 @@ +package frameproto + +import ( + "testing" + + "strings" +) + +func TestWriteFrameImageAspectRatio(t *testing.T) { + + tests := []struct{ + AspectRatio string + Expected string + }{ + { + AspectRatio: "", + Expected: ``+"\n", + }, + + + + { + AspectRatio: "something", + Expected: ``+"\n", + }, + + + + { + AspectRatio: "Hello world! 🙂", + Expected: ``+"\n", + }, + + + + { + AspectRatio: "1.91:1", + Expected: ``+"\n", + }, + + + + { + AspectRatio: "1:1", + Expected: ``+"\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 + } + } +}