Refresh Austin - Intro to Dexy

1,223 views

Published on

Slides for my Refreshing Documentation talk at Refresh Austin on July 12, 2011. Sources and handouts available from bitbucket: http://bit.ly/qXU3yP

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,223
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Refresh Austin - Intro to Dexy

  1. 1. Refreshing Documentation An Introduction to Dexy Ana Nelson dexy.it July 12, 2011
  2. 2. Dexy for Web Apps• Install Guide
  3. 3. Dexy for Web Apps• Install Guide• User Guide
  4. 4. Dexy for Web Apps• Install Guide• User Guide• Developer Docs
  5. 5. The Big IdeaNo Dead Code • Any code you show comes from a live, runnable file. • Any images or output you show comes from running live code.
  6. 6. Benefits• Correctness• Maintainability• Workflow
  7. 7. Tool for the jobDexy • Open Source (mostly MIT, some AGPL) • Written in Python • Command Line, Text Based • * Agnostic • My Day Job and my Mission in Life
  8. 8. DemoWhat we want to create: • Install Guide • User Guide • Developer DocsWhat we need: • An App! • Install Script • Watir Script
  9. 9. An Appweb.py todo list app http://webpy.org/src/todo-list/0.3
  10. 10. DB SchemaCREATE TABLE todo ( id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT);
  11. 11. model.pyimport webdb = web.database(dbn= ’ sqlite ’ , db= ’ todo.sqlite3 ’ )def get_todos(): return db.select( ’ todo ’ , order= ’ id ’ )def new_todo(text): db.insert( ’ todo ’ , title=text)def del_todo(id): db.delete( ’ todo ’ , where= " id=$id " , vars=locals())
  12. 12. base.html$def with (page)<html><head> <title>Todo list</title></head><body>$:page</body></html>
  13. 13. index.html$def with (todos, form)<table> <tr> <th>What to do ?</th> <th></th> </tr>$for todo in todos: <tr> <td>$todo.title</td> <td> <form action= "/del/$todo.id" method= "post" > <input type= "submit" value= "Delete" /> </form> </td> </tr></table><form action= "" method= "post" >$:form.render()</form>
  14. 14. todo.py """ Basic todo list using webpy 0.3 """import webimport modelurls = ( ’ / ’ , ’ Index ’ , ’ /del/( d+) ’ , ’ Delete ’)render = web.template.render( ’ templates ’ , base= ’ base ’ )
  15. 15. todo.pyclass Index: form = web.form.Form( web.form.Textbox( ’ title ’ , web.form.notnull, description= " I need to: " , size=75), web.form.Button( ’ Add todo ’ ), )
  16. 16. todo.pydef GET(self): """ Show page """ todos = model.get_todos() form = self.form() return render.index(todos, form)
  17. 17. todo.pydef POST(self): """ Add new entry """ form = self.form() if not form.validates(): todos = model.get_todos() return render.index(todos, form) model.new_todo(form.d.title) raise web.seeother( ’ / ’ )
  18. 18. todo.pyclass Delete: def POST(self, id): """ Delete based on ID """ id = int(id) model.del_todo(id) raise web.seeother( ’ / ’ )
  19. 19. todo.pyapp = web.application(urls, globals())if __name__ == ’ __main__ ’ : app.run()
  20. 20. install scriptInstall Script
  21. 21. install scriptapt-get updateapt-get upgrade -y --force-yesapt-get install -y python-webpyapt-get install -y mercurialapt-get install -y sqlite3
  22. 22. install scripthg clone https://bitbucket.org/ananelson/dexy-examplescd dexy-examplescd webpysqlite3 todo.sqlite3 < schema.sqlpython todo.py
  23. 23. install scriptexport UBUNTU_AMI= "ami-06ad526f" # nattycd ~/.ec2ec2run $UBUNTU_AMI -k $EC2_KEYPAIR -t t1.micro -f ~/dev/dexy-examples/webpy/ubuntu-install.sh(Make sure to allow access to port 8080 in security group.)
  24. 24. Now What• We have an app and we have it running.• We have an install script which we can use to create an install guide.• Now we need a script to show how the app works.
  25. 25. Watir• Watir lets us automate the web browser• Can be integrated with functional tests• For extra awesomeness, let’s use Watir to take screenshots
  26. 26. watirrequire ’rubygems’require ’safariwatir’IP_ADDRESS = ENV[ ’EC2_INSTANCE_IP’ ]PORT = ’8080’BASE = " http:// #{ IP_ADDRESS } : #{ PORT } / "
  27. 27. watirWe create a reference to the browser:browser = Watir::Safari.newAnd define a helper method to take screenshots:def take_screenshot(filename) sleep(1) # Make sure page is finished loading. ‘ screencapture #{ filename } ‘ ‘ convert -crop 800x500+0+0 #{ filename } #{ filename } ‘end
  28. 28. watirNow we’re ready to go!browser.goto(BASE)take_screenshot( " dexy--index.png " )
  29. 29. watirLet’s enter a TODO:browser.text_field( :name , " title " ).set( " Prepare Refresh Austin Talk Demotake_screenshot( " dexy--enter.png " )
  30. 30. watirClick the ”Add todo” button to add it. We’ll verify that it was actually added.browser.button( :name , " Add todo " ).clickraise unless browser.html.include?( " <td>Prepare Refresh Austin Talk Demo</td>take_screenshot( " dexy--add.png " )
  31. 31. watirAnd delete it again:browser.form( :index , 1).submittake_screenshot( " dexy--delete.png " )
  32. 32. • Now we have screenshots we can use in our documentation, and which we can update any time.• We also know that the steps described in our screenshots WORK.• Note that we are also validating our install script.• You will want to return your DB to its original state within your script, or have a reset method in your app.

×