Skip to content
Browse files

Working footer_option/slice_option

  • Loading branch information...
1 parent 9c1d080 commit 96c6086a22b5a70fa70df49c33eb829446ce5c7a @robertkrimen robertkrimen committed Aug 25, 2011
Showing with 19 additions and 13 deletions.
  1. +10 −4 gist_it/__init__.py
  2. +6 −6 gist_it/appengine.py
  3. +2 −2 jinja2-assets/gist.jinja.html
  4. +1 −1 test/test_gist_it.py
View
14 gist_it/__init__.py
@@ -25,6 +25,9 @@ def parse_footer( footer_option ):
return '1'
def parse_slice( slice_option ):
+ if slice_option is None:
+ return ( 0, 0 )
+
match = re.match( r'^(-?\d+)$', slice_option )
if match:
return ( int( match.group(1) ), None )
@@ -63,7 +66,7 @@ def match( self, location ):
return match
@classmethod
- def parse( self, location, slice_ = '' ):
+ def parse( self, location, slice_option = None, footer_option = None ):
match = self.match( location )
if not match:
return None
@@ -95,9 +98,11 @@ def parse( self, location, slice_ = '' ):
user_repository_branch_path = parse[ 'user_repository_branch_path' ] = '/'.join([ user_repository, branch, path ]);
user_repository_url = parse[ 'user_repository_url' ] = urlparse.urljoin( 'https://github.com', user_repository )
- slice_ = parse_slice( slice_ )
- parse[ 'start_line' ] = slice_[0]
- parse[ 'end_line' ] = slice_[1]
+ slice_option = parse_slice( slice_option )
+ parse[ 'start_line' ] = slice_option[0]
+ parse[ 'end_line' ] = slice_option[1]
+
+ parse[ 'footer' ] = parse_footer( footer_option )
return Gist( **parse )
@@ -107,6 +112,7 @@ def __init__( self, **arguments ):
'raw_path', 'raw_url',
'user_repository', 'user_repository_branch_path', 'user_repository_url',
'start_line', 'end_line',
+ 'footer'
]:
setattr( self, key, arguments[ key ] )
View
12 gist_it/appengine.py
@@ -48,7 +48,7 @@ def dispatch_gist_it( dispatch, location ):
slice_option = dispatch.request.get( 'slice' )
footer_option = dispatch.request.get( 'footer' )
- gist = gist_it.Gist.parse( location, slice_option = slice_option )
+ gist = gist_it.Gist.parse( location, slice_option = slice_option, footer_option = footer_option )
if not gist:
dispatch.response.set_status( 500 )
dispatch.response.out.write( "Unable to parse \"%s\": Not a valid repository path?" % ( location ) )
@@ -76,18 +76,18 @@ def dispatch_gist_it( dispatch, location ):
return
else:
gist_content = take_slice( response.content, gist.start_line, gist.end_line )
- if dispatch.request.get( 'test' ):
- dispatch.response.headers['Content-Type'] = 'text/plain';
- dispatch.response.out.write( gist_content )
- return
- gist_html = str( render_gist_html( base, gist, gist_content ) ).strip()
+ gist_html = str( render_gist_html( base, gist, gist_content, footer = gist.footer ) ).strip()
callback = dispatch.request.get( 'callback' );
if callback != '':
result = render_gist_js_callback( callback, gist, gist_html )
else:
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 )
+ return
if _CACHE_:
memcache.add( memcache_key, data, 60 * 60 * 24 )
View
4 jinja2-assets/gist.jinja.html
@@ -7,12 +7,12 @@
<div class="gist-meta">
{% if footer != 'noby' %}
<span><a href="{{ gist.blob_url }}">This Gist</a> by <a href="{{ base }}">gist-it</a></span>
- {% end %}
+ {% endif %}
<span style="float: right; color: #369;"><a href="{{ gist.raw_url }}">view raw</a></span>
<span style="float: right; margin-right: 8px;">
<a style="color: rgb(102, 102, 102);" href="{{ gist.blob_url }}">{{ gist.path }}</a></span>
<!-- Generated by: {{ base }} -->
</div>
- {% end %}
+ {% endif %}
</div>
</div>
View
2 test/test_gist_it.py
@@ -33,7 +33,7 @@ def runTest( self ):
self.assertEqual( gist.start_line, 0 )
self.assertEqual( gist.end_line, 0 )
- gist = gist_it.parse( 'github/robertkrimen/yzzy-projection/raw/master/src/yzzy/projection/View.as', slice_ = '1:' )
+ gist = gist_it.parse( 'github/robertkrimen/yzzy-projection/raw/master/src/yzzy/projection/View.as', slice_option = '1:' )
self.assertEqual( gist.start_line, 1 )
self.assertEqual( gist.end_line, 0 )

0 comments on commit 96c6086

Please sign in to comment.
Something went wrong with that request. Please try again.