GithubHelp home page GithubHelp logo

khaf / gohaml Goto Github PK

View Code? Open in Web Editor NEW

This project forked from realistschuckle/gohaml

0.0 2.0 0.0 341 KB

An implementation of the popular XHTML Abstraction Markup Language using the Go language.

License: MIT License

Go 100.00%

gohaml's Introduction

What is it?

You can find out more about HAML at haml-lang.com
You can find out more about GO at golang.org

I’ve tried to remain diligent about reproducing the output from the canonical Ruby-based parser, so if you feel familiar with the one, then you should feel familiar with the other.

This branch compiles with 6g/8g “go version go1.0.3.”

Is it done?

I think so. It has…

  • Tags with
    • empty content;
    • attributes of the form {:attr => "value"};
    • id moniker using “#” (#divId); and,
    • class moniker using “.” (.divClass).
  • Tag nesting
  • Scope lookup
    • Arbitrary number of keys as specified by struct (someKeyInScope.Subkey1.Subkey2)
    • Valid as tag content (%p= someKeyInScope)
    • Valid as tag attribute value (%p{:attr => someKeyInScope})
    • Valid as tag attribute name (%p{someKeyInScope => "value"})
  • Engine-level autoclose option (<br /> vs. <br>)
  • Tag-specific close option (%br/ becomes <br /> regardless of autoclose setting)
  • Whitespace removal with the < operator
  • Simple scripting
    • Declaration and assignment of strings, floats, and ints (- varname := “value”)
    • Range looping construct (- for i, v := range scopeVar)
  • Error messages for badly-formed templates

If you would like another feature added, just log an issue and I’ll review it forthright.

How can I install this?

To install the library for use in your project, you can use goinstall.

go get "github.com/realistschuckle/gohaml"

How can I install this from source?

In a Go workspace, create a directory for gohaml.

mkdir -p src/github.com/realistschuckle/gohaml

Clone the gohaml repository into that newly created directory.
git clone git://github.com/realistschuckle/gohaml.git src/github.com/realistschuckle/gohaml

Now build and install it.
go install github.com/realistschuckle/gohaml

How can I use it?

How about something like this? Save it, compile it, link it, and run it!

package main

import (
	"github.com/realistschuckle/gohaml"
	"fmt"
)

func main() {
	var scope = make(map[string]interface{})
	scope["lang"] = "HAML"
	content := "I love <\n=lang<\n!"
	engine, _ := gohaml.NewEngine(content)
	output := engine.Render(scope)
	fmt.Println(output) // Prints "I love HAML!"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.