simpleform

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2020 License: MIT Imports: 4 Imported by: 1

README ¶

🔷 SimpleForm

Build Status GoDoc Go Report Card

SimpleForm is a language for constructing HTML forms out of very little text.

Here is an example login form:

Login

Welcome dear user!

Username: {{ username }}
Password: {{ password }}

[Login](/login)
  • The first line is recognized as the title, and is used both for the title (like this: <title>Login</title> and as a title in the body, like this: <h2>Login</h2>.
  • The lines with {{ and }} are recognized as single line input fields, where the label is the word before :.
  • The [Login](/login) is recognized as a button that can submit the contents of the form as a POST request to /login.
  • The syntax is inspired by Jinja2 and Markdown.

Here's the generated HTML from the login form above:

<!doctype html>
<html lang="en">
  <head>
    <title>Login</title>
  </head>
  <body>
    <h2>Login</h2>
    <p>Welcome dear user!</p>
    <form method="POST">
      <label for="username">Username:</label><input type="text" id="username" name="username"><br><br>
      <label for="password">Password:</label><input type="password" id="password" name="password"><br><br>
      <input type="submit" formaction="/login" value="Login"><br><br>
    </form>
  </body>
</html>

Unstyled, it looks like this:

loginform

When styled with MVP.CSS, this is how it looks:

loginform_styled

Features and limitations

  • If the input ID starts with password or pwd, then the input type "password" is used.
  • Multiple buttons can be provided on a single line.
  • All text that is not recognized as either the title or as form elements is combined and returned in a <p> tag.
  • If [[ and ]] are used instead of {{ and }}, then a multi-line text input box is created instead.

TODO

  • Formal spec (or at least a PDF describing the language).
  • Radio button support, with options separated by |.
  • Support for required fields, by using the exclamation mark.
  • Spport all available form elements, while keeping complexity low.

General Info

Documentation ¶

Index ¶

Constants ¶

View Source
const VersionString = "SimpleForm 0.2.0"

VersionString is the current name and version of this package

Variables ¶

View Source
var (
	// MultilineColumns is the number of columns that multiline input text should have
	MultilineColumns = 80
	// MultilineRows is the number of rows that multiline input text should have
	MultilineRows = 25
)

Functions ¶

func HTML ¶

func HTML(frmContents string, entireDocument bool, options ...string) (string, error)

HTML transforms the contents of a .frm file to a HTML form

Example use:

Return a full HTML document:
  HTML(frmContents, true, "en", "/style.css, "/favicon.ico")

Return just the body of the HTML document, using the default values of the rest:
  HTML(frmContents, false)

Return HTML styled by MPV.CSS:
  HTML(frmContents, true, "en", "https://unpkg.com/mvp.css")

If entireDocument is true, doctype + html + head + body is returned, and not just the body contents.

The optional parameter can be from 0 to 3 strings with: - The language of the document, default is "en" - The CSS URL of the document, no default, example: "/css/style.css" - The favicon URL of the document, no default, example: "/img/favicon.ico"

Types ¶

This section is empty.

Directories ¶

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL