Created
November 17, 2017 00:31
-
-
Save crackcomm/00d5afd70b79e0335fd004d4b1510f35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
"github.com/crackcomm/flex" | |
) | |
func fooHandler(w http.ResponseWriter, r *http.Request) { | |
printer := flex.NewNodePrinter(w, flex.PrintOptionsLayout|flex.PrintOptionsStyle|flex.PrintOptionsChildren) | |
config := flex.NewConfig() | |
config.Context = "test" | |
fmt.Fprintf(w, `<html><head> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.0.0/normalize.min.css"> | |
<style> | |
body { | |
margin: 0; | |
} | |
div { | |
box-sizing: border-box; | |
position: relative; | |
display: flex; | |
flex-direction: column; | |
align-items: stretch; | |
flex-shrink: 0; | |
align-content: flex-start; | |
border-width: 0px; | |
margin: 0px; | |
padding: 0px; | |
min-width: 0px; | |
} | |
body > div:nth-child(1) > div:nth-child(1) { | |
background-color: #1A237E; | |
color: white; | |
} | |
body > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) { | |
background-color: #607D8B; | |
color: white; | |
} | |
</style></head><body>`) | |
root := flex.NewNodeWithConfig(config) | |
root.StyleSetFlexDirection(flex.FlexDirectionColumn) | |
root.StyleSetHeightPercent(100) | |
navigation := flex.NewNodeWithConfig(config) | |
navigation.StyleSetHeight(60) | |
navigation.StyleSetPadding(flex.EdgeAll, 20) | |
navigation.StyleSetFlexDirection(flex.FlexDirectionRow) | |
for index := 0; index < 5; index++ { | |
child := flex.NewNodeWithConfig(config) | |
child.StyleSetPadding(flex.EdgeAll, 20) | |
navigation.InsertChild(child, index) | |
} | |
root.InsertChild(navigation, 0) | |
container := flex.NewNodeWithConfig(config) | |
container.StyleSetFlexGrow(1) | |
container.StyleSetFlexDirection(flex.FlexDirectionRow) | |
root.StyleSetHeightPercent(100) | |
root.InsertChild(container, 1) | |
sidebar := flex.NewNodeWithConfig(config) | |
sidebar.StyleSetFlexGrow(1) | |
container.InsertChild(sidebar, 0) | |
content := flex.NewNodeWithConfig(config) | |
content.StyleSetFlexGrow(5) | |
container.InsertChild(content, 1) | |
flex.CalculateLayout(root, flex.Undefined, flex.Undefined, flex.DirectionLTR) | |
printer.Print(root) | |
// // log.Printf("%s") | |
// fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path)) | |
fmt.Fprintf(w, `</body></html>`) | |
} | |
func main() { | |
http.HandleFunc("/", fooHandler) | |
log.Println("starting") | |
log.Fatal(http.ListenAndServe("127.0.0.1:8088", nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment