FAQ
Reviewers: campoy, rsc,

Message:
Hello campoy, rsc (cc: golang-dev@googlegroups.com),

I'd like you to review this change to
https://code.google.com/p/go.talks


Description:
go.talks/pkg/present: add Time field to Document

Please review this at https://codereview.appspot.com/6868048/

Affected files:
M 2012/simple.slide
M pkg/present/doc.go
M pkg/present/parse.go
M present/templates/slides.tmpl


Index: 2012/simple.slide
===================================================================
--- a/2012/simple.slide
+++ b/2012/simple.slide
@@ -1,5 +1,7 @@
Go: a simple programming environment

+9 Nov 2012
+
# Go is a general-purpose language that bridges the gap between efficient
# statically typed languages and productive dynamic language. But it’s not
just
# the language that makes Go special – Go has broad and consistent standard
Index: pkg/present/doc.go
===================================================================
--- a/pkg/present/doc.go
+++ b/pkg/present/doc.go
@@ -10,6 +10,7 @@

Title of document
Subtitle of document
+ 15:04 2 Jan 2006
<blank line>
Author Name
Job title, Company
@@ -17,6 +18,10 @@
http://url/
@twitter_name

+The date line is optional, and may be written without a time as just:
+ 2 Jan 2006
+in which case it will be interpreted as 10am UTC for that date.
+
The author section may contain a mixture of text, twitter names, and links.
For slide presentations, only the plain text lines will be displayed on the
first slide.
Index: pkg/present/parse.go
===================================================================
--- a/pkg/present/parse.go
+++ b/pkg/present/parse.go
@@ -14,6 +14,7 @@
"log"
"net/url"
"strings"
+ "time"
"unicode"
"unicode/utf8"
)
@@ -48,6 +49,7 @@
type Doc struct {
Title string
Subtitle string
+ Time time.Time
Authors []Author
Sections []Section
Template *template.Template
@@ -217,6 +219,13 @@
if !ok {
return nil, errors.New("no subtitle")
}
+ text, ok := lines.next()
+ if !ok {
+ return nil, errors.New("unexpected EOF")
+ }
+ if t, ok := parseTime(text); ok {
+ doc.Time = t
+ }
if mode&TitlesOnly > 0 {
return doc, nil
}
@@ -411,3 +420,17 @@
}
return Link{URL: u}
}
+
+func parseTime(text string) (t time.Time, ok bool) {
+ t, err := time.Parse("15:04 2 Jan 2006", text)
+ if err == nil {
+ return t, true
+ }
+ t, err = time.Parse("2 Jan 2006", text)
+ if err == nil {
+ // at 11am UTC it is the same date everywhere
+ t = t.Add(time.Hour * 11)
+ return t, true
+ }
+ return time.Time{}, false
+}
Index: present/templates/slides.tmpl
===================================================================
--- a/present/templates/slides.tmpl
+++ b/present/templates/slides.tmpl
@@ -16,6 +16,7 @@
<article>
<h1>{{.Title}}</h1>
{{with .Subtitle}}<h3>{{.}}</h3>{{end}}
+ {{with .Time}}<h3>{{.Format "2 January 2006"}}</h3>{{end}}
{{range .Authors}}
<div class="presenter">
{{range .TextElem}}{{.HTML $.Template}}{{end}}

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedDec 2, '12 at 9:15p
activeDec 2, '12 at 9:15p
posts1
users1
websitegolang.org

1 user in discussion

Adg: 1 post

People

Translate

site design / logo © 2022 Grokbase