Exemple #1
0
func (e *Entry) SummaryRender() string {
	if len(e.SummaryRendered) > 0 && !conf.Config.Debug {
		return e.SummaryRendered
	}
	var ret string
	var data obj
	b := []byte(e.Data)
	json.Unmarshal(b, &data)

	template_name := fmt.Sprintf("blog/stream/%s-summary.mandira", e.Type)

	if e.Type == "twitter" {
		ret = template.Render(template_name, obj{"Entry": e, "Tweet": data["tweet"]})
	} else if e.Type == "github" {
		event := data["event"].(map[string]interface{})
		var hash string
		if event["id"] != nil {
			hash = event["id"].(string)[:8]
		} else if event["sha"] != nil {
			hash = event["sha"].(string)[:8]
		} else {
			hash = "unknown"
		}
		eventType := event["event"].(string)
		isCommit := eventType == "commit"
		isCreate := eventType == "create"
		isFork := eventType == "fork"
		ret = template.Render(template_name, obj{
			"Entry":    e,
			"Event":    event,
			"Hash":     hash,
			"IsCommit": isCommit,
			"IsCreate": isCreate,
			"IsFork":   isFork,
		})
	} else if e.Type == "bitbucket" {
		// TODO: check username (author) against configured bitbucket username
		update := data["update"].(map[string]interface{})
		revision := fmt.Sprintf("#%d", update["revision"].(float64))
		var repository obj
		if data["repository"] != nil {
			repository = data["repository"].(obj)
		}
		ret = template.Render(template_name, obj{
			"Entry":      e,
			"Data":       data,
			"Update":     update,
			"Repository": repository,
			"Revision":   revision})
	}
	e.SummaryRendered = ret
	if !conf.Config.Debug {
		db.Upsert(e)
	}
	return ret
}
Exemple #2
0
func (pp *PagesPanel) Render() string {
	var pages []Page
	db.Find(&Page{}, nil).Limit(indexListSize).All(&pages)
	return template.Render("blog/admin/pages-panel.mandira", M{
		"pages": pages,
	})
}
Exemple #3
0
func (up *UnpublishedPanel) Render() string {
	var posts []Post
	db.Latest(&Post{}, M{"published": 0}).Limit(indexListSize).All(&posts)
	return template.Render("blog/admin/unpublished-panel.mandira", M{
		"posts": posts,
	})
}
Exemple #4
0
/* given a maximum number of items, render pagination */
func (p *Paginator) Render(objCount int) string {
	if p.Begin > objCount {
		return ""
	}
	if p.Page > 1 {
		p.HasPrev = true
	}
	if p.End < objCount {
		p.HasNext = true
	}
	p.NumPages = int(math.Ceil(float64(objCount) / float64(p.PerPage)))
	if p.Page > p.NumPages {
		return ""
	}
	context := p.Context(p.NumPages)
	links := []Link{}
	for _, c := range context {
		v, _ := strconv.Atoi(c)
		if c == "..." {
			links = append(links, Link{Num: p.Inter, Inter: true})
		} else if v == p.Page {
			links = append(links, Link{Num: c})
		} else {
			links = append(links, Link{Num: c, Url: p.Link + c, HasUrl: true})
		}
	}
	return template.Render("paginator.mandira", M{"Pages": links}, p,
		M{
			"NextPageUrl": p.Link + itoa(p.Page+1),
			"PrevPageUrl": p.Link + itoa(p.Page-1),
		})
}
Exemple #5
0
// A Flatpage view.  Attach it via web.Get wherever you want flatpages to be available
func Flatpage(ctx *web.Context, url string) string {
	p := GetPage(url)
	if p == nil {
		ctx.Abort(404, "Page not found")
		return ""
	}

	return template.Render("base.mandira", M{
		"body":        p.ContentRendered,
		"title":       "jmoiron.net",
		"description": "Blog and assorted media from Jason Moiron.",
	})
}
Exemple #6
0
// A Flatpage view.  Attach it via web.Get wherever you want flatpages to be available
func Flatpage(ctx *web.Context, url string) string {
	p := GetPage(url)
	fmt.Printf("Got page %v for url %s\n", p, url)
	if p == nil {
		ctx.Abort(404, "Page not found")
		return ""
	}

	return template.Render("base.mandira", M{
		"body":        p.ContentRendered,
		"title":       "Jamil Seaidoun",
		"description": "Blog and assorted media from Jamil Seaidoun.",
	})
}
Exemple #7
0
func blogDetail(ctx *web.Context, slug string) string {
	var post = new(Post)
	err := db.Find(post, M{"slug": slug}).One(&post)
	if err != nil {
		fmt.Println(err)
		ctx.Abort(404, "Page not found")
		return ""
	}

	return template.Render("base.mandira", M{
		"body":        RenderPost(post),
		"title":       post.Title,
		"description": post.Summary})
}
Exemple #8
0
// Render the post, using the cached ContentRendered if available, or generating
// and re-saving it to the database if not
func RenderPost(post *Post) string {
	if len(post.ContentRendered) == 0 {
		db.Upsert(post)
	}
	return template.Render("blog/post.mandira", post)
}