GitXplorerGitXplorer
m

go-leansite

public
32 stars
3 forks
0 issues

Commits

List of commits on branch master.
Unverified
208c0ae0d0828c324ed78e66279d631ccaa990f5

[autopush] «If there are epigrams, there must be meta-epigrams.»

committed 7 years ago
Unverified
2df09f16a2f5f5e4cd7cc1d393fb802956410b40

[autocommit] «Hire the morally handicapped.»

committed 8 years ago
Unverified
8fd676b8d19648e4d18d9a10acf204dbb50a3643

[autocommit] «I'll never get off this planet. -- Luke Skywalker»

committed 8 years ago
Unverified
c6ee261104fc16eba08116ac8e2d8a8d24b8b9cc

import paths updated-not-fixed (ie now self-fixable)

committed 8 years ago
Unverified
4d2ccc37728f504fa2bb78c3b3a5ef13c166b656

jQuery 2.0.3

committed 12 years ago
Unverified
701422caac02507018c4a863eec1360843bdad06

..

committed 12 years ago

README

The README file for this repository.

leansite

-- import "github.com/metaleap/go-leansite"

A super-minimalistic "dynamic-web-page" server written in Go, just to explore the net/http, html/template, and Gorilla web packages.

The folder helloworld represents a sample LeanSite and can be used as a seed site:

  • run it standalone via go run $GOPATH/src/github.com/metaleap/go-leansite/helloworld/go-leansite-helloworld/main.go

  • run it on your Google App Engine SDK via dev_appserver.py $GOPATH/src/github.com/metaleap/go-leansite/helloworld

  • see it in action running on Google App Engine at http://go-leansite-helloworld.appspot.com/

Usage

var (
	//	To be set via Init(), see func Init() docs
	DirPath string

	//	Various file-system watchers, initialized by Init()
	DirWatch *ufs.Watcher

	//	Our request router, initialized by Init()
	Router *mux.Router

	//	Some site-specific data loaded from DirPath
	SiteData struct {
		//	Top-level navigation links loaded from contents/top.nav JSON file
		TopNav NavItems

		//	A map of blogs. Populated by PageContext.GetBlogArchive(), which is called from a template
		Blogs map[string]BlogNav
	}
)

func Init

func Init(dirPath string) (err error)

Stand-alone: call this in your main() before calling ListenAndServe().

App Engine: call this in your init() and DON'T call ListenAndServe().

dirPath: the site's base directory which contains folders "static", "contents" and "templates".

func ListenAndServe

func ListenAndServe(addr string) (err error)

addr: see http.Server.Addr

type BlogNav

type BlogNav struct {
	//	A chronological listing of blog entries
	Nav BlogNavItems
}

A chronological listing of blog entries

func (*BlogNav) ShowYear

func (me *BlogNav) ShowYear(year string) (dif bool)

Returns true if year is different than the value passed when this method was last called

type BlogNavItem

type BlogNavItem struct {
	//	Embedded navigation info (Href, Caption)
	NavItem

	//	Date posted
	Year, Month, Day string
}

Represents a blog entry

type BlogNavItems

type BlogNavItems []BlogNavItem

A collection of blog entries

func (BlogNavItems) Len

func (me BlogNavItems) Len() int

Implements sort.Interface.Len()

func (BlogNavItems) Less

func (me BlogNavItems) Less(i, j int) bool

Implements sort.Interface.Less()

func (BlogNavItems) Swap

func (me BlogNavItems) Swap(i, j int)

Implements sort.Interface.Swap()

type NavItem

type NavItem struct {
	//	Link attributes
	CssClass, Href, Caption, Desc string
}

A navigation link such as used in the sample site's top-navbar

func (*NavItem) IsActive

func (me *NavItem) IsActive(pc *PageContext) bool

Returns true if this NavItem points to the resource represented by pc, or an ancestor resource.

type NavItems

type NavItems []NavItem

A collection of navigation links

type PageContext

type PageContext struct {
	//	The underlying http.Request
	R *http.Request

	//	Host-relative Request URL path
	Path string

	//	Extracted from either SiteData.TopNav or the first <h2> occurence in the final HTML output
	PageTitle string

	//	Final HTML output
	HtmlContent template.HTML

	//	Always equivalent to SiteData.TopNav
	TopNav NavItems

	//	Contains the current year, for auto-updating copyright notices
	Year int
}

Represents a single page request, used as pipeline in main template

func NewPageContext

func NewPageContext(r *http.Request, path string) (me *PageContext)

Creates a new PageContext for the specified http.Request and host-relative request URL path

func (*PageContext) GetBlogArchive

func (me *PageContext) GetBlogArchive(path string) *BlogNav

Returns a BlogNav for the specified path. For example, GetBlogArchive("blog") maps to "contents/blog/"

-- godocdown http://github.com/robertkrimen/godocdown