{"id":15394294,"url":"https://github.com/xyproto/onthefly","last_synced_at":"2025-05-05T22:20:49.671Z","repository":{"id":5363873,"uuid":"6550407","full_name":"xyproto/onthefly","owner":"xyproto","description":":link: Generate HTML and CSS together, on the fly","archived":false,"fork":false,"pushed_at":"2024-11-08T19:57:45.000Z","size":2375,"stargazers_count":45,"open_issues_count":0,"forks_count":6,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-31T00:13:41.260Z","etag":null,"topics":["angularjs","css","diskless","dom","generate","html","server-side-rendering","ssr","threejs","xml"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xyproto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-11-05T19:37:10.000Z","updated_at":"2024-11-08T19:57:49.000Z","dependencies_parsed_at":"2025-01-10T12:01:01.088Z","dependency_job_id":"2ed270cc-7a12-4ea8-955e-73ad297e4248","html_url":"https://github.com/xyproto/onthefly","commit_stats":null,"previous_names":["xyproto/browserspeak"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fonthefly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fonthefly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fonthefly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fonthefly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xyproto","download_url":"https://codeload.github.com/xyproto/onthefly/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252584472,"owners_count":21771970,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angularjs","css","diskless","dom","generate","html","server-side-rendering","ssr","threejs","xml"],"created_at":"2024-10-01T15:23:04.095Z","updated_at":"2025-05-05T22:20:49.653Z","avatar_url":"https://github.com/xyproto.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"On The Fly\n==========\n\n[![Build](https://github.com/xyproto/onthefly/actions/workflows/test.yml/badge.svg)](https://github.com/xyproto/onthefly/actions/workflows/test.yml)\n[![GoDoc](https://godoc.org/github.com/xyproto/onthefly?status.svg)](http://godoc.org/github.com/xyproto/onthefly)\n[![License](http://img.shields.io/badge/license-BSD-blue.svg?style=flat)](https://raw.githubusercontent.com/xyproto/onthefly/master/LICENSE)\n[![Report Card](https://img.shields.io/badge/go_report-A+-brightgreen.svg?style=flat)](http://goreportcard.com/report/xyproto/onthefly)\n\n* Package for generating HTML and CSS together, on the fly.\n* Can also be used for generating HTML, XML or CSS (or templates).\n* HTML and CSS can be generated together, but be presented as two seperate (but linked) files.\n* Could be used to set up a diskless webserver that generates all the content on the fly\n  (something similar could also be achieved by using templates that are not stored on disk).\n\nNew/experimental features:\n\n* Generate WebGL graphics with Three.JS on the fly.\n* Generate AngularJS applications on the fly.\n\nThe SVG related code has been refactored out, optimized and moved to the [tinysvg](https://github.com/xyproto/tinysvg) package.\n\nOnline API Documentation\n------------------------\n\n[godoc.org](http://godoc.org/github.com/xyproto/onthefly)\n\nGenerate HTML, CSS and SVG in one go\n------------------------------------\n\u003cimg src=\"img/onthefly.png\"\u003e\n\nCreate hardware accelerated 3D-graphics with [three.js](http://threejs.org/)\n-----------------------------------------------------\n\u003cimg src=\"img/threejs.png\"\u003e\n\nExperiment with [AngularJS](https://angularjs.org/)\n-----------------------\n\u003cimg src=\"img/angular.png\"\u003e\n\nExample for [Negroni](https://github.com/urfave/negroni)\n--------------------\n\n~~~go\npackage main\n\nimport (\n    \"fmt\"\n    \"net/http\"\n\n    \"github.com/urfave/negroni\"\n    \"github.com/xyproto/onthefly\"\n    \"github.com/xyproto/tinysvg\"\n)\n\n// Generate a new SVG image\nfunc svgImage() []byte {\n    document, svg := tinysvg.NewTinySVG(128, 64)\n    svg.Describe(\"Hello SVG\")\n\n    // x, y, radius, color\n    svg.Circle(30, 10, 5, \"red\")\n    svg.Circle(110, 30, 2, \"green\")\n    svg.Circle(80, 40, 7, \"blue\")\n\n    // x, y, font size, font family, text and color\n    svg.Text(3, 60, 6, \"Courier\", \"There will be cake\", \"#394851\")\n\n    return document.Bytes()\n}\n\n// Generate a new onthefly Page (HTML5 and CSS combined)\nfunc indexPage(svgurl string) *onthefly.Page {\n\n    // Create a new HTML5 page, with CSS included\n    page := onthefly.NewHTML5Page(\"Demonstration\")\n\n    // Add some text\n    page.AddContent(fmt.Sprintf(\"onthefly %.1f\", onthefly.Version))\n\n    // Change the margin (em is default)\n    page.SetMargin(4)\n\n    // Change the font family\n    page.SetFontFamily(\"serif\") // or: sans-serif\n\n    // Change the color scheme\n    page.SetColor(\"black\", \"#d0d0d0\")\n\n    // Include the generated SVG image on the page\n    body, err := page.GetTag(\"body\")\n    if err == nil {\n        // CSS attributes for the body tag\n        body.AddStyle(\"font-size\", \"2em\")\n        body.AddStyle(\"font-family\", \"sans-serif\")\n\n        // Paragraph\n        p := body.AddNewTag(\"p\")\n\n        // CSS style\n        p.AddStyle(\"margin-top\", \"2em\")\n\n        // Image tag\n        img := p.AddNewTag(\"img\")\n\n        // HTML attributes\n        img.AddAttrib(\"src\", svgurl)\n        img.AddAttrib(\"alt\", \"Three circles\")\n\n        // CSS style\n        img.AddStyle(\"width\", \"60%\")\n        img.AddStyle(\"border\", \"4px solid white\")\n    }\n\n    return page\n}\n\n// Set up the paths and handlers then start serving.\nfunc main() {\n    fmt.Println(\"onthefly \", onthefly.Version)\n\n    // Create a Negroni instance and a ServeMux instance\n    n := negroni.Classic()\n    mux := http.NewServeMux()\n\n    // Publish the generated SVG as \"/circles.svg\"\n    svgurl := \"/circles.svg\"\n    mux.HandleFunc(svgurl, func(w http.ResponseWriter, req *http.Request) {\n        w.Header().Add(\"Content-Type\", \"image/svg+xml\")\n        w.Write(svgImage())\n    })\n\n    // Generate a Page that includes the svg image\n    page := indexPage(svgurl)\n    // Publish the generated Page in a way that connects the HTML and CSS\n    page.Publish(mux, \"/\", \"/style.css\", false)\n\n    // Handler goes last\n    n.UseHandler(mux)\n\n    // Listen for requests at port 3000\n    n.Run(\":3000\")\n}\n~~~\n\nExample for `net/http`\n--------------------\n\n~~~go\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"\n    \"net/http\"\n    \"time\"\n\n    \"github.com/xyproto/onthefly\"\n    \"github.com/xyproto/tinysvg\"\n)\n\n// Generate a new SVG image\nfunc svgImage() []byte {\n    document, svg := tinysvg.NewTinySVG(128, 64)\n    svg.Describe(\"Hello SVG\")\n\n    // x, y, radius, color\n    svg.Circle(30, 10, 5, \"red\")\n    svg.Circle(110, 30, 2, \"green\")\n    svg.Circle(80, 40, 7, \"blue\")\n\n    // x, y, font size, font family, text and color\n    svg.Text(3, 60, 6, \"Courier\", \"There will be cake\", \"#394851\")\n\n    return document.Bytes()\n}\n\n// Generate a new onthefly Page (HTML5 and CSS combined)\nfunc indexPage(svgurl string) *onthefly.Page {\n\n    // Create a new HTML5 page, with CSS included\n    page := onthefly.NewHTML5Page(\"Demonstration\")\n\n    // Add some text\n    page.AddContent(fmt.Sprintf(\"onthefly %.1f\", onthefly.Version))\n\n    // Change the margin (em is default)\n    page.SetMargin(4)\n\n    // Change the font family\n    page.SetFontFamily(\"serif\") // or: sans-serif\n\n    // Change the color scheme\n    page.SetColor(\"black\", \"#d0d0d0\")\n\n    // Include the generated SVG image on the page\n    body, err := page.GetTag(\"body\")\n    if err == nil {\n\n        // CSS attributes for the body tag\n        body.AddStyle(\"font-size\", \"2em\")\n        body.AddStyle(\"font-family\", \"sans-serif\")\n\n        // Paragraph\n        p := body.AddNewTag(\"p\")\n\n        // CSS style\n        p.AddStyle(\"margin-top\", \"2em\")\n\n        // Image tag\n        img := p.AddNewTag(\"img\")\n\n        // HTML attributes\n        img.AddAttrib(\"src\", svgurl)\n        img.AddAttrib(\"alt\", \"Three circles\")\n\n        // CSS style\n        img.AddStyle(\"width\", \"60%\")\n        img.AddStyle(\"border\", \"4px solid white\")\n    }\n\n    return page\n}\n\n// Set up the paths and handlers then start serving.\nfunc main() {\n    fmt.Println(\"onthefly \", onthefly.Version)\n\n    // Create a mux\n    mux := http.NewServeMux()\n\n    // Publish the generated SVG as \"/circles.svg\"\n    svgurl := \"/circles.svg\"\n    mux.HandleFunc(svgurl, func(w http.ResponseWriter, req *http.Request) {\n        w.Header().Add(\"Content-Type\", \"image/svg+xml\")\n        w.Write(svgImage())\n    })\n\n    // Generate a Page that includes the svg image\n    page := indexPage(svgurl)\n\n    // Publish the generated Page in a way that connects the HTML and CSS\n    page.Publish(mux, \"/\", \"/style.css\", false)\n\n    // Configure the HTTP server and permissionHandler struct\n    s := \u0026http.Server{\n        Addr:           \":3000\",\n        Handler:        mux,\n        ReadTimeout:    10 * time.Second,\n        WriteTimeout:   10 * time.Second,\n        MaxHeaderBytes: 1 \u003c\u003c 20,\n    }\n    log.Println(\"Listening for requests on port 3000\")\n\n    // Start listening\n    log.Fatal(s.ListenAndServe())\n}\n~~~\n\nAdditional screenshots\n----------------------\n\nScreenshots from version 0.8:\n\n\u003cimg src=\"img/svg_dark.png\"\u003e\n\n\u003cimg src=\"img/svg_light.png\"\u003e\n\n\nVersion, license and author\n---------------------------\n\n* Version: 1.2.3\n* Alexander F Rødseth \u0026lt;xyproto@archlinux.org\u0026gt;\n* License: BSD-3\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxyproto%2Fonthefly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxyproto%2Fonthefly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxyproto%2Fonthefly/lists"}