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

Perch CMS Template Engine

Drew McLellan
September 10, 2013

Perch CMS Template Engine

How we wrote a template engine for Perch CMS

Drew McLellan

September 10, 2013
Tweet

More Decks by Drew McLellan

Other Decks in Technology

Transcript

  1. Drew McLellan
    Perch CMS
    grabaperch.com
    -HOW WE WROTE A-
    TEMPLATE
    ENGINE
    RDG Geek Night
    10th September 2013

    View full-size slide

  2. L I G H T W E I G H T
    PHP CMS
    FOR SMALL WEBSITES

    View full-size slide

  3. WE NEEDED A
    REALLY GOOD
    TEMPLATE LANGUAGE

    View full-size slide

  4. -SO-
    W H A T W A S
    ALREADY
    OUT THERE?

    View full-size slide

  5. SMARTY
    (NOT SO SMART)

    View full-size slide

  6. TWIG
    (NOT SO MATURE)

    View full-size slide

  7. JUST PHP
    -WITH A-
    DIFFERENT
    S Y N T A X

    View full-size slide

  8. !!!!type=”text”
    !!!id=”heading”
    !!!label=”Main heading”
    !!!required=”true” />

    View full-size slide

  9. type="text" label="Heading"
    required="true" title="true" />
    type="date" label="Date" format="%d %B
    %Y" />
    label="Body" textile="true"
    editor="markitup" required="true" />

    View full-size slide

  10. HTML IS LIKE
    X M L
    RIGHT?

    View full-size slide

  11. label="Photo" />" />

    View full-size slide

  12. xkcd.com/208

    View full-size slide

  13. stackoverflow.com/questions/1732348/

    View full-size slide

  14. ! ! ! id=”heading” label=”Main heading”
    ! ! required=”true” />
    #]*/>#

    View full-size slide

  15. $Tag = new PerchXMLTag(
    '');
    echo $Tag->bar; // baz

    View full-size slide

  16. #([a-z-]*)="([^"]*)"#

    View full-size slide

  17. #([a-z-]+)=[\"]([^\"\\
    \\]*(?:\\\\.[^\"\\\
    \]*)*)[\"]#

    View full-size slide

  18. -WAIT-
    REGULAR
    EXPRESSIONS
    ARE SLOW,
    RIGHT?

    View full-size slide

  19. REGEX ARE
    SLOW
    UNLESS YOU
    NEED
    THEM

    View full-size slide

  20. #(]*>)(((?!
    perch:if).)*)#
    !
    ! ! ... loadsamarkup ...
    !

    View full-size slide

  21. -WE NEEDED-
    A NEW WAY
    -TO PARSE-
    TAG PAIRS

    View full-size slide


  22. !
    ! !
    ! ! ! Hello, world.
    ! !
    !

    !
    ! ! Goodbye, cruel world.
    !

    View full-size slide


  23. !
    ! !
    ! ! ! Hello, world.
    ! !
    !

    !
    ! ! Goodbye, cruel world.
    !

    View full-size slide


  24. !
    ! !
    ! ! ! Hello, world.
    ! !
    !

    !
    ! ! Goodbye, cruel world.
    !

    View full-size slide


  25. !
    ! !
    ! ! ! Hello, world.
    ! !
    !

    !
    ! ! Goodbye, cruel world.
    !

    View full-size slide


  26. !
    ! !
    ! ! ! Hello, world.
    ! !
    !

    !
    ! ! Goodbye, cruel world.
    !

    View full-size slide


  27. !
    ! !
    ! ! ! Hello, world.
    ! !
    !

    !
    ! ! Goodbye, cruel world.
    !

    View full-size slide


  28. !
    ! !
    ! ! ! Hello, world.
    ! !
    !

    !
    ! ! Goodbye, cruel world.
    !

    View full-size slide


  29. !
    ! !
    ! ! ! Hello, world.
    ! !
    !

    !
    ! ! Goodbye, cruel world.
    !

    View full-size slide

  30. CLOSING TAGS
    -ARE -
    EASY

    View full-size slide

  31. NO MORE
    WINDOWS
    CRASHES

    View full-size slide

  32. MAYBE
    - WE WILL -
    REWRITE IT

    View full-size slide

  33. THANK YOU
    Perch is at grabaperch.com
    On most things, I’ am @
    drewm

    View full-size slide