Пример #1
0
func get_specific_id(ctx *web.Context, id string) {
	log.Printf("get_specific_id %s\n", id)
	if e, err := Load(id); err == nil {
		t := entry_template
		m := map[string]interface{}{"Id": e.Id, "Date": e.Date, "Body": e.Body}
		s := mustache.Render(t, m)
		ctx.WriteString(page(s))
	} else {
		ctx.WriteString(page(fmt.Sprintf("<p>Invalid ID</p> <!--%v-->", err)))
	}
}
Пример #2
0
func get_from(ctx *web.Context, id string) {
	log.Printf("get_root\n")
	p := `{{#entries}}` + entry_template + `{{/entries}}` + footer_template
	t := page(p)
	m := make(map[string]interface{})
	entries, _ := LoadRange(id, *max_entries)
	m["entries"] = entries
	m["id"] = id
	if len(entries) == *max_entries {
		m["from_id"] = entries[len(entries)-1].Id
	}
	s := mustache.Render(t, m)
	ctx.WriteString(s)
}
Пример #3
0
func edit_form(action, id, date, body, button_label string) string {
	t := edit_form_template
	m := make(map[string]interface{})
	m["action"] = action
	m["id"] = id
	if len(date) > 0 {
		m["date"] = date
	} else {
		m["date"] = time.LocalTime().Format(NCTIME)
	}
	m["body"] = body
	m["button_label"] = button_label
	s := mustache.Render(t, m)
	return s
}
Пример #4
0
func main() {
	var rendered_content string
	var template []uint8
	var error os.Error
	var inode *os.Dir

	flag.Usage = usage
	flag.Parse()
	if flag.NArg() == 0 {
		fmt.Fprintf(os.Stderr, "no template rules defined\n")
		os.Exit(ERROR)
	}

	rules := make(Dictionary)
	for i := 0; i < flag.NArg(); i++ {
		rules.define(flag.Args()[i])
	}

	if *input_file == "" {
		if template, error = ioutil.ReadAll(os.Stdin); error == nil {
			rendered_content, error = mustache.Render(string(template), rules)
		}
	} else {
		switch inode, error = os.Stat(*input_file); {
		case error != nil:
		case inode.IsRegular():
			rendered_content, error = mustache.RenderFile(*input_file, rules)
		default:
		}
	}
	if error != nil {
		os.Exit(ERROR)
	} else {
		if *write {
			error = ioutil.WriteFile(*input_file, []byte(rendered_content), 0)
		} else {
			_, error = os.Stdout.Write([]byte(rendered_content))
		}
		if error != nil {
			os.Exit(ERROR)
		}
	}
	os.Exit(0)
}
Пример #5
0
func get_rss(ctx *web.Context) {
	log.Printf("get_rss\n")
	ctx.SetHeader("Content-Type", "application/rss+xml", false)
	t := rss_template
	m := map[string]interface{}{"title": *title, "url": *url}
	if entries, err := LoadRange("", *max_entries); err == nil {
		type RSSEntry struct {
			Entry
			Guid    string
			RssDate string
		}
		rss_entries := make([]RSSEntry, len(entries))
		for i, _ := range entries {
			re := RSSEntry{entries[i], fmt.Sprintf("%s/%s", *url, entries[i].Id), nctime_to_rsstime(entries[i].Date)}
			rss_entries[i] = re
		}
		m["entries"] = rss_entries
		m["most_recent_date"] = nctime_to_rsstime(entries[0].Date)
		s := mustache.Render(t, m)
		ctx.WriteString(s)
	} else {
		ctx.WriteString(page(fmt.Sprintf("<p>Error generating RSS: %s</p>", err)))
	}
}