Changeset - ed7abf925696
[Not reviewed]
default
0 4 0
Marcin Kuzminski - 15 years ago 2010-06-13 16:27:19
marcin@python-works.com
#4: changes proposed by feedback to annotation
4 files changed with 16 insertions and 10 deletions:
0 comments (0 inline, 0 general)
pylons_app/lib/helpers.py
Show inline comments
 
@@ -39,87 +39,86 @@ class _Link(object):
 
        return link_fn
 

	
 

	
 
class _GetError(object):
 

	
 
    def __call__(self, field_name, form_errors):
 
        tmpl = """<span class="error_msg">%s</span>"""
 
        if form_errors and form_errors.has_key(field_name):
 
            return literal(tmpl % form_errors.get(field_name))
 

	
 
class _FilesBreadCrumbs(object):
 
    
 
    def __call__(self, repo_name, rev, paths):
 
        url_l = [link_to(repo_name, url('files_home', repo_name=repo_name, revision=rev, f_path=''))]
 
        paths_l = paths.split('/')
 
        
 
        for cnt, p in enumerate(paths_l, 1):
 
            if p != '':
 
                url_l.append(link_to(p, url('files_home', repo_name=repo_name, revision=rev, f_path='/'.join(paths_l[:cnt]))))
 

	
 
        return literal(' / '.join(url_l))
 

	
 
def pygmentize(filenode, **kwargs):
 
    """
 
    pygmentize function using pygments
 
    @param filenode:
 
    """
 
    return literal(code_highlight(filenode.content, filenode.lexer, HtmlFormatter(**kwargs)))
 

	
 
def pygmentize_annotation(filenode, **kwargs):
 
    """
 
    pygmentize function for annotation
 
    @param filenode:
 
    """
 
    
 
    color_dict = g.changeset_annotation_colors
 
    def gen_color():
 
        import random
 
        return [str(random.randrange(10, 235)) for _ in xrange(3)]
 
    def get_color_string(cs):
 
        if color_dict.has_key(cs):
 
            col = color_dict[cs]
 
        else:
 
            color_dict[cs] = gen_color()
 
            col = color_dict[cs]
 
        return "color: rgb(%s) ! important;" % (','.join(col))
 
        
 
    def url_func(changeset):
 
        return '%s\n' % (link_to(changeset.raw_id,
 
        return '%s\n' % (link_to('r%s:%s' % (changeset.revision, changeset.raw_id),
 
        url('changeset_home', repo_name='test', revision=changeset.raw_id),
 
        title=_('author') + ':%s rev:%s %s' % (changeset.author, changeset.revision,
 
                                                changeset.message,),
 
        title=_('author') + ':%s - %s' % (changeset.author, changeset.message,),
 
        style=get_color_string(changeset.raw_id)))
 
           
 
    return literal(annotate_highlight(filenode, url_func, **kwargs))
 

	
 
def recursive_replace(str, replace=' '):
 
    """
 
    Recursive replace of given sign to just one instance
 
    @param str: given string
 
    @param replace:char to find and replace multiple instances
 
        
 
    Examples::
 
    >>> recursive_replace("Mighty---Mighty-Bo--sstones",'-')
 
    'Mighty-Mighty-Bo-sstones'
 
    """
 

	
 
    if str.find(replace * 2) == -1:
 
        return str
 
    else:
 
        str = str.replace(replace * 2, replace)
 
        return recursive_replace(str, replace)  
 
      
 
def repo_name_slug(value):
 
    """
 
    Return slug of name of repository
 
    """
 
    slug = urlify(value)
 
    for c in """=[]\;'"<>,/~!@#$%^&*()+{}|:""":
 
        slug = slug.replace(c, '-')
 
    slug = recursive_replace(slug, '-')
 
    return slug
 
    
 
files_breadcrumbs = _FilesBreadCrumbs()
 
link = _Link()
 
flash = _Flash()
 
get_error = _GetError()
pylons_app/templates/files/files.html
Show inline comments
 
<%inherit file="/base/base.html"/>
 

	
 
<%def name="title()">
 
    ${_('Repository managment')}
 
</%def>
 
<%def name="breadcrumbs()">
 
    ${h.link_to(u'Home',h.url('/'))}
 
    / 
 
    ${h.link_to(c.repo_name,h.url('files_home',repo_name=c.repo_name))}
 
    /
 
    ${_('files')}
 
</%def>
 
<%def name="page_nav()">
 
    ${self.menu('files')}     
 
</%def>
 
<%def name="css()">
 
<link rel="stylesheet" href="/css/monoblue_custom.css" type="text/css" />
 
<link rel="stylesheet" href="/css/pygments.css" type="text/css" />
 
</%def>
 
<%def name="main()">
 
    <h2 class="no-link no-border">${_('Files')}</h2>
 
	<div id="files_data">
 
	%if c.files_list:
 
		<h2>${_('Location')}: ${h.files_breadcrumbs(c.repo_name,c.cur_rev,c.files_list.path)}</h2>
 
			%if c.files_list.is_dir():
 
				<%include file='files_browser.html'/>
 
			%else:
 
				<%include file='files_source.html'/>			
 
			%endif	
 
	%else:
 
		<h2><a href="#" onClick="javascript:parent.history.back();" target="main">${_('Go back')}</a> ${_('No files at given path')}: "${c.f_path or "/"}" </h2>
 
		<h2>
 
			<a href="#" onClick="javascript:parent.history.back();" target="main">${_('Go back')}</a> 
 
			${_('No files at given path')}: "${c.f_path or "/"}" 
 
		</h2>
 
	%endif
 

	
 
	</div>
 
</%def>    
 
\ No newline at end of file
pylons_app/templates/files/files_annotate.html
Show inline comments
 
<%inherit file="/base/base.html"/>
 

	
 
<%def name="title()">
 
    ${_('File annotate')}
 
</%def>
 
<%def name="breadcrumbs()">
 
    ${h.link_to(u'Home',h.url('/'))}
 
    / 
 
    ${h.link_to(c.repo_name,h.url('files_home',repo_name=c.repo_name))}
 
    /
 
    ${_('files')}
 
</%def>
 
<%def name="page_nav()">
 
		${self.menu('files')}     
 
</%def>
 
<%def name="css()">
 
	<link rel="stylesheet" href="/css/monoblue_custom.css" type="text/css" />
 
	<link rel="stylesheet" href="/css/pygments.css" type="text/css" />
 
</%def>
 
<%def name="main()">
 
    <h2 class="no-link no-border">${_('Annotate')}</h2>
 
	<div id="files_data">
 
		<h2>${_('Location')}: ${h.files_breadcrumbs(c.repo_name,c.cur_rev,c.file.path)}</h2>
 
		<dl class="overview">
 
			<dt>${_('Revision')}</dt>
 
			<dd>r${c.file.last_changeset.revision}:${c.file.last_changeset._short}</dd>
 
			<dt>${_('Size')}</dt>
 
			<dd>${h.format_byte_size(c.file.size,binary=True)}</dd>
 
			<dt>${_('Options')}</dt>
 
			<dd>${h.link_to(_('source'),
 
			h.url('files_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}  / ${h.link_to(_('raw'),
 
			h.url('files_raw_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}</dd>				
 
			<dd>${h.link_to(_('show source'),
 
					h.url('files_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}  
 
				/ ${h.link_to(_('download as raw'),
 
					h.url('files_raw_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}
 
			</dd>				
 
		</dl>
 
		<div id="body" class="codeblock">
 
			<div class="code-header">
 
				<div class="revision">${c.file.name}@r${c.file.last_changeset.revision}:${c.file.last_changeset._short}</div>
 
				<div class="commit" style="font-size:70%">"${c.file_msg}"</div>
 
			</div>
 
			<div class="code-body">
 
				${h.pygmentize_annotation(c.file,linenos=True,anchorlinenos=True,lineanchors='S',cssclass="code-highlight")}
 
			</div>
 
		</div>
 
	</div>
 
</%def> 
 
\ No newline at end of file
pylons_app/templates/files/files_source.html
Show inline comments
 
<dl class="overview">
 
	<dt>${_('Revision')}</dt>
 
	<dd>r${c.files_list.last_changeset.revision}:${c.files_list.last_changeset._short}</dd>
 
	<dt>${_('Size')}</dt>
 
	<dd>${h.format_byte_size(c.files_list.size,binary=True)}</dd>
 
	<dt>${_('Options')}</dt>
 
	<dd>${h.link_to(_('annotate'),
 
	h.url('files_annotate_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}  / ${h.link_to(_('raw'),
 
	h.url('files_raw_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}</dd>
 
	<dd>${h.link_to(_('show annotation'),
 
			h.url('files_annotate_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}  
 
		 / ${h.link_to(_('download as raw'),
 
			h.url('files_raw_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}
 
	</dd>
 
	<dt>${_('History')}</dt>
 
	<dd>
 
		${h.form(h.url('files_diff_home',repo_name=c.repo_name,f_path=c.f_path),method='GET')}
 
		${h.hidden('diff2',c.files_list.last_changeset._short)}
 
		${h.select('diff1','',c.file_history)}
 
		${h.submit('diff','diff')}
 
		${h.end_form()}
 
	</dd>
 
					
 
</dl>		
 
<div id="body" class="codeblock">
 
	<div class="code-header">
 
		<div class="revision">${c.files_list.name}@r${c.files_list.last_changeset.revision}:${c.files_list.last_changeset._short}</div>
 
		<div class="commit" style="font-size:70%">"${c.files_list.last_changeset.message}"</div>
 
	</div>
 
	<div class="code-body">
 
		${h.pygmentize(c.files_list,linenos=True,anchorlinenos=True,lineanchors='S',cssclass="code-highlight")}
 
	</div>
 
</div>
 
\ No newline at end of file
0 comments (0 inline, 0 general)