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 Slide

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

    View Slide

  3. Reading

    View Slide

  4. Usage

    View Slide

  5. 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 Slide

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

    View Slide

  7. Correctness

    View Slide

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

    View Slide

  9. Seven Types of Ambiguity
    - William Empson, 1930

    View Slide

  10. Efficiency

    View Slide

  11. // 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 Slide

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

    View Slide

  13. Extend

    View Slide

  14. html/template

    View Slide

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

    View Slide

  16. History

    View Slide

  17. 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 Slide

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

    View Slide

  19. View Slide