bham

package module
v0.0.0-...-4266bd4 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2013 License: BSD-2-Clause Imports: 9 Imported by: 1

README

bham - Blocky Hypertext Abstraction Markup

bham is a similar language to something like haml, but it implements a subset of what haml does in order to keep the language neat and tidy.


Working Markup Examples

For a web page with the title set to 'Example Page' and an h1 tag with the content 'Whatever' you would do the following.

<!DOCTYPE html>
%html
  %head
    %title Example Page
  %body
    %h1 Whatever

If I wanted to display a default title if there wasn't a PageTitle attibute in the Render Arguments when Rendering the template, and otherwise to use the PageTitle argument, then you would do the following. I'm not sure that the {{ }} bit works yet...

<!DOCTYPE html>
%html
  %head
    = if .PageTitle
      %title
        = .PageTitle
    = else
      %title No Title Set

And the big one, that shows off pretty much all the features...

<!DOCTYPE html>
%html(ng-app)
  %head
    = $current := .Current.Page.Name
    = javascript_include_tag "jquery" "angular"
    %title Web Introduction: {{ $current }}
    = if .ExtraJsFiles
      = javascript_include_tag .ExtraJsFiles
    = stylesheet_link_tag "ui-bootstrap"
    = with $current := .Current.Variables
      = template "Layouts/CurrentJs.html" $current
  %body
    %div(class="header {{ .HeaderType }}")
    .hello Welcome to the web {{ .User.Name }}
      You are in section {{ $current }}.

    .row-fluid
      .span3
        = template "Layouts/Navigation.html" .
      .span9
        = yield .
    .row-fluid
      .span10.offset1
        = range $index, $sponsor := .Sponsors
          .sponsor-mini(data-bg-image="sponsor-{{ $sponsor.Img }}")
            = link_to $sponsor.Name $sponsor.Url "class='name'"

Implemented Features

  • Plaintext passthrough
  • %tag expansion
  • If/Else Statements
  • Tag Nesting
  • Range statements for collection data structures
  • = ... for Lines with pipelines on them
  • Parentheses for HTML-like attributes
  • Class and ID shorthand
  • With statement for limited visibility variables
  • Template Variables
  • {{ }} For embedded pipeline output

To Be Implemented Features

  • Code Quality
  • More Documentation

Unlikely To Be Implemented Features

  • Curly branch hashrocket syntax for attributes
  • Multiple line prefixes for different visibility/escaping

Documentation

Overview

bham or the "blocky hypertext abstraction markup" is an attempt to take what is good about languages like haml, jade, slim, etc. and port it to Go, but not blindly. It will take into account the capabilities of Go's template libraries to parse directly into the internal template structures that the stdlib template libraries use to provide both speed and interoperability with standard Go templates.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Strict determines whether only tabs will be considered
	// as indentation operators (Strict == true) or whether
	// two spaces can be counted as an indentation operator
	// (Strict == false), this is included for haml
	// semi-comapibility
	Strict bool

	// To add multiple id declarations, the outputter puts them together
	// with a join string, by default this is an underscore
	IdJoin = "_"

	// Like the template library, you need to be able to set code delimeters
	LeftDelim  = "{{"
	RightDelim = "}}"
)
View Source
var Doctypes = map[string]string{
	"":             `<!DOCTYPE html>`,
	"Transitional": `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">`,
	"Strict":       `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">`,
	"Frameset":     `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">`,
	"5":            `<!DOCTYPE html>`,
	"1.1":          `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">`,
	"Basic":        `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">`,
	"Mobile":       `<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">`,
	"RDFa":         `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">`,
}
View Source
var Filters = []FilterHandler{
	FilterHandler{
		Trigger: ":javascript",
		Open:    `<script type="text/javascript">`,
		Close:   "</script>",
		Handler: Transformer(func(s string) string { return s }),
	},
	FilterHandler{
		Trigger: ":css",
		Open:    `<style>`,
		Close:   "</style>",
		Handler: Transformer(func(s string) string { return s }),
	},
}

Functions

func Parse

func Parse(name, text string) (map[string]*parse.Tree, error)

parse will return a parse tree containing a single

Types

type FilterHandler

type FilterHandler struct {
	Trigger     string
	Open, Close string
	Handler     Transformer
}

type Transformer

type Transformer func(string) string

Jump to

Keyboard shortcuts

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