Package damsel provides html outlining via css-selectors and common template functionality.

Overview

Damsel GoDoc Build Status

Markup language featuring html outlining via css-selectors, extensible via pkg html/template and others.

Library

This package expects to exist at $GOPATH/src/dasa.cc/damsel and can be installed with:

go get dasa.cc/damsel

Command Line

A command line utility can be installed with:

go get dasa.cc/damsel/cmd/damsel

View help with:

damsel -h

Documentation

http://godoc.org/dasa.cc/damsel

Package damsel provides html outlining via css-selectors and common template functionality.

Tags

Tags are specified with %tag, #id, .class where #id and .class become a div if no %tag is specified. Multiple classes can be specified but only one #id tag should be specified for an element. It's also important that an #id tag is unique in the document as damsel facilitates overriding content of a document via an #id tag.

%html %body
  #content.border Hello, World
  %div.one.two.three

Attributes

Attributes can be inlined, line-breaked, or a combination of such. Provide quotes around the attribute value to escape brackets.

%html %body

  %div[a=1][b=2]

  #foo
    [a="1[1]"]
    [b="2[2]"]

  #bar[a=1][b=2]
      [c=3][d=4]

  %span[a][b] Attributes do not require values

Text and Whitespace

Whitespace can be manipulated as described below, but it's worth pointing out that large amounts of content are simply not suitable for such document types (Damsel, Haml, etc).

%p One
  \ Two
  \ Three

%p    One Two Three

Both paragraphs will be rendered the same. Use of a backslash controls whitespace, including inlined text.

%p \ One Two Three

This would insert a space before One.

Whitespace can be preserved using `

%p `this is some
text and all whitespace
    is preserved as-is`

HTML Comments

Supports commenting out blocks of code via html comments with optional text and browser specfic IFs. This also includes DOCTYPE declarations.

!DOCTYPE html
%html %body
  ! %ul
    %li 1
    %li 2

The use of ! as a block element, causing %ul to become inlined, will cause the entire block to become commented out. The ! could also be placed after the body tag in this case. You can also nest items under a comment.

%html %body
  ! here's a comment though it's not required
    %h1 Hello World

  %div
    ! this comment doesn't enclose any tags
    %span Hello World

  ![if IE] %p Internet Explorer

Actions

There is basic support for actions. An action is just another way of calling a function while also preserving indention of the inner content lines, making this suitable for parsing other indention based markup. Once an action has been processed, the lexer will parse the result as though it was part of the original document.

In time, this package will facilitate custom functions. Currently included actions are js, css, include, and extends.

%html %head
  :css /css/
    main.css
    extra.css

This would generate the following document.

%html %head
  %link[type=text/css][rel=stylesheet][href=/css/main.css]
  %link[type=text/css][rel=stylesheet][href=/css/extra.css]

Reusable Templates

Damsel allows any element with an id specified to be overridden. Also required is at least one root node that will serve as the main document output. Additional root nodes are checked against the first for overridable content.

%html %body
  #content
    %p Hello

#content OVERRIDE

The would produce the following output.

<html><body>
  <div id="content">OVERRIDE</div>
</body></html>

This functionality is also facilitated with the action extends.

:extends overlay.dmsl

#content OVERRIDE

If you wish to append child nodes instead of overriding the original content, specify a super attribute.

:extends overlay.dmsl

#content[super]
  %p A second paragraph

The action include uses the whitespace preceding its declaration to insert content from a separate document into the current. For example, given the following document:

%ul
  %li One
  %li Two

included in the following document:

%html %body
  #content
    %h1 My Numbers
    :include numbers.dmsl

would produce the following document:

%html %body
  #content
    %h1 My Numbers
    %ul
      %li One
      %li Two

Other Template Integration

This package should be ok for use with most text templating options. Helpers that provide integration with html/template take the following steps.

- Call dmsl/parse.ActionParse(b []byte)
- Pass the result to package html/template and execute
- Call dmsl/parse.DocParse(b []byte)
- Display result

Calling dmsl.NewHtmlTemplate will return an instance that parses actions and passes the result to html/template.Template. Call Execute(interface{}) to produce the final result. For example, given [10][10]int:

%html %body
  %table {range .}
    %tr {range .}
      %td {.}
{end}{end}

At one-point the {end} was optional with deeper integration of html/template, but in practice this created confusion and errors except for the most trivial of examples (above).

Here's another example.

%html %body
  %table
  {range .}

    {if .}

    %tr
    {range .}
      %td {.}
    {end}

    {else}
    %tr %td None
    {end}

    %p some trailing text
  {end}
You might also like...
Templating system for HTML and other text documents - go implementation

FAQ What is Kasia.go? Kasia.go is a Go implementation of the Kasia templating system. Kasia is primarily designed for HTML, but you can use it for any

A strongly typed HTML templating language that compiles to Go code, and has great developer tooling.
A strongly typed HTML templating language that compiles to Go code, and has great developer tooling.

A language, command line tool and set of IDE extensions that makes it easier to write HTML user interfaces and websites using Go.

Safe HTML for Go

Safe HTML for Go safehtml provides immutable string-like types that wrap web types such as HTML, JavaScript and CSS. These wrappers are safe by constr

mold your templated to HTML/ TEXT/ PDF easily.
mold your templated to HTML/ TEXT/ PDF easily.

mold mold your templated to HTML/ TEXT/ PDF easily. install go get github.com/mayur-tolexo/mold Example 1 //Todo model type Todo struct { Title stri

Simple and fast template engine for Go

fasttemplate Simple and fast template engine for Go. Fasttemplate performs only a single task - it substitutes template placeholders with user-defined

A handy, fast and powerful go template engine.
A handy, fast and powerful go template engine.

Hero Hero is a handy, fast and powerful go template engine, which pre-compiles the html templates to go code. It has been used in production environme

A sane and simple Go REST API template.

Gosane 🧘‍♀️ A sane and simple Go REST API template. Clone me and edit me to fit your usecase. What is Gosane? Gosane is a cloneable API template to g

A general purpose golang CLI template for Github and Gitlab

golang-cli-template A general purpose project template for golang CLI applications This template serves as a starting point for golang commandline app

⚗ The most advanced CLI template on earth! Featuring automatic releases, website generation and a custom CI-System out of the box.
⚗ The most advanced CLI template on earth! Featuring automatic releases, website generation and a custom CI-System out of the box.

cli-template ✨ ⚗ A template for beautiful, modern, cross-platform compatible CLI tools written with Go! Getting Started | Wiki This template features

Comments
  • compile problem

    compile problem

    cd github.com/dskinner/damsel/ go install main.go:7:2: import "dasa.cc/damsel/dmsl": cannot find package main.go:8:2: import "dasa.cc/damsel/dmsl/parse": cannot find package

    opened by rif 2
  • is % really necessary?

    is % really necessary?

    In the py project, it certainly was for differentiating a line of python from html.

    x = 5
    %p {x}
    

    It also enabled inlined tags

    %html %body %h1 Hello World
    

    The three options in my mind worth considering are

    Remove From First Element

    Due to how plain text works right now, the line contained by the element needs no special notation, but multiline plain text requires a back slash, mostly to properly control whitespace. It is feasible to not require % except for inlining

    html
      body
        div %h1 Hello World
        div a b c d
          \ e f g
    

    I feel this is a bit hard to distinguish whats going on though. Which brings me to the other option

    Swap control needs from elements to text

    Essentially, remove the need for % and require something for all text. The example below uses \

    html body
      div \ a b c d
        \ e f g h
    

    Considering the use case of damsel (discussed below) this wouldn't be a bad option, but I do feel it might become more burdensome to seemingly arbitrarily insert a character to start text mid declaration versus the somewhat easy habit of starting a new line with %. A % also gives each element a distinct look, such %div #id .class

    Finally, this brings me back to

    Leave it alone

    Something like damsel suits a particular need of development, and that need is not for large content writeups. It's ideal for stubbing out an interface that will have most of its content insert by variables, and heavily scripted by javascript, making it easy to reference the dom you've created. I already feel the syntax accomplishes that through my use of it on multiple projects. If the constraints I worked under at the time just happen to produce the best results I can come up with, then it may be best to simply leave it alone.

    question 
    opened by dskinner 1
Owner
Daniel Skinner
despiteallobjections return
Daniel Skinner
Wrapper package for Go's template/html to allow for easy file-based template inheritance.

Extemplate Extemplate is a small wrapper package around html/template to allow for easy file-based template inheritance. File: templates/parent.tmpl <

Danny van Kooten 51 Dec 6, 2022
Goview is a lightweight, minimalist and idiomatic template library based on golang html/template for building Go web application.

goview Goview is a lightweight, minimalist and idiomatic template library based on golang html/template for building Go web application. Contents Inst

foolin 314 Dec 25, 2022
A template to build dynamic web apps quickly using Go, html/template and javascript

gomodest-template A modest template to build dynamic web apps in Go, HTML and sprinkles and spots of javascript. Why ? Build dynamic websites using th

Adnaan Badr 85 Dec 29, 2022
Fast, powerful, yet easy to use template engine for Go. Optimized for speed, zero memory allocations in hot paths. Up to 20x faster than html/template

quicktemplate A fast, powerful, yet easy to use template engine for Go. Inspired by the Mako templates philosophy. Features Extremely fast. Templates

Aliaksandr Valialkin 2.7k Dec 26, 2022
Golang Echo and html template.

golang-website-example Golang Echo and html template. move GitHub repository for hello to golang-website-example Visual Studio Code Run and Debug: lau

Ocki Bagus Pratama 0 Feb 4, 2022
HTML template engine for Go

Ace - HTML template engine for Go Overview Ace is an HTML template engine for Go. This is inspired by Slim and Jade. This is a refinement of Gold. Exa

Keiji Yoshida 827 Jan 4, 2023
Made from template temporalio/money-transfer-project-template-go

Temporal Go Project Template This is a simple project for demonstrating Temporal with the Go SDK. The full 20 minute guide is here: https://docs.tempo

MarkGorewicz 0 Jan 6, 2022
Go-project-template - Template for a golang project

This is a template repository for golang project Usage Go to github: https://git

KyberNetwork 4 Oct 25, 2022
Go-api-template - A rough template to give you a starting point for your API

Golang API Template This is only a rough template to give you a starting point f

Only Tunes Radio 3 Jan 14, 2022
Api-go-template - A simple Go API template that uses a controller-service based model to build its routes

api-go-template This is a simple Go API template that uses a controller-service

Pedro Espíndula 1 Feb 18, 2022