Permalink
Browse files

More ?test options

  • Loading branch information...
1 parent 96c6086 commit 887431744b851de86b2ed176470abd7083e35e09 @robertkrimen robertkrimen committed Aug 26, 2011
Showing with 33 additions and 11 deletions.
  1. +17 −7 gist_it/__init__.py
  2. +16 −4 gist_it/appengine.py
View
@@ -59,6 +59,17 @@ def take_slice( content, start_line = None, end_line = None ):
class Gist:
@classmethod
+ def keylist( self ):
+ return [
+ 'user', 'repository', 'branch', 'path',
+ 'blob_path', 'blob_url',
+ 'raw_path', 'raw_url',
+ 'user_repository', 'user_repository_branch_path', 'user_repository_url',
+ 'start_line', 'end_line',
+ 'footer'
+ ]
+
+ @classmethod
def match( self, location ):
match = re.match( r'^(?:/https?:/)?/?github(?:\.com)?/(.*)$', location )
if not match:
@@ -107,12 +118,11 @@ def parse( self, location, slice_option = None, footer_option = None ):
return Gist( **parse )
def __init__( self, **arguments ):
- for key in [ 'user', 'repository', 'branch', 'path',
- 'blob_path', 'blob_url',
- 'raw_path', 'raw_url',
- 'user_repository', 'user_repository_branch_path', 'user_repository_url',
- 'start_line', 'end_line',
- 'footer'
- ]:
+ for key in self.keylist():
setattr( self, key, arguments[ key ] )
+ def value( self ):
+ value = {}
+ for key in self.keylist():
+ value[ key ] = getattr( self, key )
+ return value
View
@@ -4,6 +4,7 @@
import cgi
import sys
import urllib
+import simplejson
jinja2 = None
@@ -84,13 +85,24 @@ def dispatch_gist_it( dispatch, location ):
result = render_gist_js( base, gist, gist_html )
result = str( result ).strip()
data = result
- if dispatch.request.get( 'test' ):
- dispatch.response.headers['Content-Type'] = 'text/plain';
- dispatch.response.out.write( gist_html )
+ test = dispatch.request.get( 'test' )
+ if test:
+ if test == 'json':
+ dispatch.response.headers['Content-Type'] = 'text/plain';
+ dispatch.response.out.write(simplejson.dumps({
+ 'gist': gist.value(),
+ 'content': gist_content,
+ 'html': gist_html,
+ }))
+ elif False and test == 'example':
+ pass
+ else:
+ dispatch.response.headers['Content-Type'] = 'text/plain'
+ dispatch.response.out.write( gist_html )
return
if _CACHE_:
memcache.add( memcache_key, data, 60 * 60 * 24 )
- dispatch.response.headers['Content-Type'] = 'text/javascript';
+ dispatch.response.headers['Content-Type'] = 'text/javascript'
dispatch.response.out.write( data )

0 comments on commit 8874317

Please sign in to comment.