Upgrade to Pro — share decks privately, control downloads, hide ads and more …

text/template

 text/template

We deal with text every day. I'll show you how to use text/template to convert your data into whatever representation you'd like, but I'd also like to talk about how we read code, using text/template as a source text.

More Decks by Joseph Anthony Pasquale Holsten

Other Decks in Programming

Transcript

  1. text/template

    View full-size slide

  2. /*
    Package template implements data-
    driven templates for generating
    textual output.

    View full-size slide

  3. type Inventory struct {
    Material string
    Count uint
    }
    sweaters := Inventory{"wool", 17}
    tmpl, _ := template.New(“test").
    Parse("{{.Count}} items are made of {{.Material}}")
    tmpl.Execute(os.Stdout, sweaters)

    View full-size slide

  4. - C K Ogden &
    I A Richards, 1923
    The gostak destims the doshes

    View full-size slide

  5. if!
    with!
    range!
    index!
    len
    call!
    printf!
    js!
    urlquery
    eq!
    ne!
    gt!
    le!
    !
    and!
    not!
    or

    View full-size slide

  6. Seven Types of Ambiguity
    - William Empson, 1930

    View full-size slide

  7. // lex creates a new scanner for the input string.!
    func lex(name, input, left, right string) *lexer {!
    if left == "" {!
    left = leftDelim!
    }!
    if right == "" {!
    right = rightDelim!
    }!
    l := &lexer{!
    name: name,!
    input: input,!
    leftDelim: left,!
    rightDelim: right,!
    items: make(chan item),!
    }!
    go l.run()!
    return l!
    }

    View full-size slide

  8. • Referential
    • Aesthetic
    • Emotive
    • Conative
    • Phatic
    • Metalingual
    - Roman Jacobson, 1960

    View full-size slide

  9. html/template

    View full-size slide

  10. Structure, Sign & Play
    - Jaques Derrida, 1966

    View full-size slide

  11. 2014-02: 1!
    2013-12: 1!
    2013-09: 4!
    2013-08: 6!
    2013-07: 3!
    2013-05: 1!
    2013-03: 5!
    2013-01: 2!
    2012-10: 4!
    2012-09: 3!
    2012-08: 6!
    2012-07: 4!
    2012-06: 1!
    2012-05: 1!
    2012-09: 4!
    2012-04: 3!
    2012-06: 1!
    2012-04: 6!
    2012-03: 6!
    2012-02: 10!
    2012-01: 6!
    2011-12: 5!
    2011-11: 12
    64 [email protected]!
    4 [email protected]!
    3 [email protected]!
    3 [email protected]!
    2 [email protected]!
    2 [email protected]!
    2 [email protected]!
    2 [email protected]!
    2 [email protected]!
    2 [email protected]!
    2 [email protected]!
    1 [email protected]!
    1 [email protected]!
    1 [email protected]!
    1 [email protected]!
    1 [email protected]!
    1 [email protected]!
    1 [email protected]

    View full-size slide

  12. Qu’est-ce qu’un auteur?
    - Michel Foucault, 1967

    View full-size slide