templates

package
v0.0.0-...-8fa4d24 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2013 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecTemplate

func ExecTemplate(t *template.Template, args interface{}) (string,
	error)

ExecTemplate calls the Execute function on the given template and saves the results to the string. The given set of args should be a map of arguments within the template and their values. 将 args 中的数据变量,赋值到 template中的变量,然后保存在 bytes.Buffer中,最后返回字符串

Types

type SiteData

type SiteData struct {
	Title       string
	Description string
	Author      string
	Content     string
	Languages   []string
	AtHome      bool
	AtTags      bool
	AtArchives  bool
	AtAbout     bool
}

SiteData is a struct that contains all of the information necessary for generating a site page.

type Templates

type Templates map[string]*template.Template

Templates is a set of goblog templates.

func LoadTemplates

func LoadTemplates(dir string) (Templates, error)

func (Templates) MakeAbout

func (t Templates) MakeAbout(dir string) error

MakeAbout creates a complleted about HTML page and puts it into the given directory. It uses the template from about.html and will fill in the following values:

.CDate - The date the page was created.

The results of that templating are then used as the content for calling MakeWebPage.

func (Templates) MakeArchive

func (t Templates) MakeArchive(dir string, a []*archives.YearEntries) error

MakeArchive creates a completed archives HTML page and puts it into the given directory. It uses the template from tags.html and will fill in the following values:

     .CDate   - The date the page was created.
     .Years   - A slice of Years that contain blog entries. Each one
	               contains:
       .Year   - The name of the Year (e.g. 2013).
       .Months - A slice of months for this year that contains blog
                 entries. Each one contains:
         .Month   - The name of the month (e.g. January).
         .Entries - A slice of blog entries for the given month of
                    the given year. Each one contains:
           .CDate   - The date of the blog entry.
           .Url     - The url of the blog entry.
           .Title   - The title of the blog entry.

The results of that templating are then used as the content for calling MakeWebPage.

func (Templates) MakeBlogEntry

func (t Templates) MakeBlogEntry(dir string, blog *blogs.BlogEntry,
	contents string) error

MakeBlogEntry creates a completed HTML page of the given blog entry and puts it in the given directory. It uses the template from entry.html and will fill in the following values:

.CDate - The date the entry was created.
.Title   - The title of the entry.
.UDate   - If the entry has changed since it's original
           creation, this will be the most recent update
           date.
.Content - The HTML formated Content of blog entry.
.Tags    - A list of tags (strings) for the blog entry.

The results of that templating are then used as the content for calling MakeWebPage. 调用 template 文件夹下的 entry.html 模板,根据 BlogEntry和 contents信息, 在 dir 文件夹下生成 html 文件

func (Templates) MakeIndex

func (t Templates) MakeIndex(dir string, b []*blogs.BlogEntry) error

MakeIndex creates a completed index HTML page and puts it into the given directory. It uses the template from tags.html and will fill in the following values:

.Entries - A list of entries to display. Each one contains:
  .CDate   - The date the entry was created.
  .Title   - The title of the entry.
  .UDate   - If the entry has changed since it's original
             creation, this will be the most recent update
             date.
  .Content - The HTML formated Content of blog entry.
  .Tags    - A list of tags (strings) for the blog entry.

The results of that templating are then used as the content for calling MakeWebPage.

func (Templates) MakeTags

func (t Templates) MakeTags(dir string, ta []*tags.TagEntry) error

MakeTags creates a completed tags HTML page and puts it into the given directory. It uses the template from tags.html and will fill in the following values:

.CDate - The date the page was created.
.Tags - A list of tags for the blog entry. Each one contains:
   .Name - The name of the tag.
   .Entries - A slice of blog entries for with the given tag.
              Each one contains:
      .Url   - The url of the blog entry.
      .Title - The title of the blog entry.

The results of that templating are then used as the content for calling MakeWebPage.

func (Templates) MakeWebPage

func (t Templates) MakeWebPage(file string, sd *SiteData) error

MakeWebPage write the resutls of using the site template on the given SiteData to the given file. This is the main function that makes complete web pages. It uses site.html to render the page and passes the following values:

.Title       - The title to use for this page.
.Description - The description of this page.
.Author      - The author of this page.
.Content     - The pages content.
.Languages   - A list of languages (string) used by the page.
.AtHome      - If true, the page is the index.html page.
.AtTags      - If true, the page is the index.html page.
.AtArchives  - If true, the page is the index.html page.
.AtAbout     - If true, the page is the index.html page.

渲染 SiteData数据到 site.html中。

Jump to

Keyboard shortcuts

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