allura
修訂 | 19787336c579de23075c794be1ed4fa409d7407e (tree) |
---|---|
時間 | 2012-04-27 23:51:35 |
作者 | Jenny Steele <jsteele@geek...> |
Commiter | Cory Johns |
[#2151] More file types are now "viewable" in repos
@@ -36,6 +36,9 @@ config = utils.ConfigProxy( | ||
36 | 36 | common_prefix='forgemail.url') |
37 | 37 | |
38 | 38 | README_RE = re.compile('^README(\.[^.]*)?$', re.IGNORECASE) |
39 | +VIEWABLE_EXTENSIONS = ['.php','.py','.js','.java','.html','.htm','.yaml','.sh', | |
40 | + '.rb','.phtml','.txt','.bat','.ps1','.xhtml','.css','.cfm','.jsp','.jspx', | |
41 | + '.pl','.php4','.php3','.rhtml','.svg','.markdown','.json','.ini','.tcl','.vbs','.xsl'] | |
39 | 42 | |
40 | 43 | class RepositoryImplementation(object): |
41 | 44 |
@@ -1005,6 +1008,8 @@ class Blob(RepoObject): | ||
1005 | 1008 | self.commit = tree.commit |
1006 | 1009 | self.tree = tree |
1007 | 1010 | self.name = name |
1011 | + fn, ext = os.path.splitext(self.name) | |
1012 | + self.extension = ext or fn | |
1008 | 1013 | |
1009 | 1014 | @LazyProperty |
1010 | 1015 | def _content_type_encoding(self): |
@@ -1050,8 +1055,17 @@ class Blob(RepoObject): | ||
1050 | 1055 | return self.tree.path() + h.really_unicode(self.name) |
1051 | 1056 | |
1052 | 1057 | @property |
1058 | + def has_pypeline_view(self): | |
1059 | + if README_RE.match(self.name) or self.extension in ['.md', '.rst']: | |
1060 | + return True | |
1061 | + return False | |
1062 | + | |
1063 | + @property | |
1053 | 1064 | def has_html_view(self): |
1054 | - return self.content_type.startswith('text/') | |
1065 | + if self.content_type.startswith('text/') or self.extension in VIEWABLE_EXTENSIONS or \ | |
1066 | + self.extension in self._additional_viewable_extensions: | |
1067 | + return True | |
1068 | + return False | |
1055 | 1069 | |
1056 | 1070 | @property |
1057 | 1071 | def has_image_view(self): |
@@ -42,11 +42,15 @@ | ||
42 | 42 | Try to <a href="?force=True">display it</a> anyway or |
43 | 43 | <a href="?format=raw">download it</a> instead.</p> |
44 | 44 | {% endif %} |
45 | - {% if blob.has_html_view and not blob.has_image_view or force_display %} | |
45 | + {% if (blob.has_html_view or blob.has_pypeline_view) and not blob.has_image_view or force_display %} | |
46 | 46 | <p><a href="?format=raw">Download this file</a></p> |
47 | 47 | <div class="clip grid-19"> |
48 | 48 | <h3><span class="ico-l"><b data-icon="{{g.icons['table'].char}}" class="ico {{g.icons['table'].css}}"></b> {{h.really_unicode(blob.name)}}</span></h3> |
49 | - {{g.highlight(blob.text, filename=blob.name)}} | |
49 | + {% if blob.has_pypeline_view %} | |
50 | + {{h.render_any_markup(blob.name, blob.text)}} | |
51 | + {% else %} | |
52 | + {{g.highlight(blob.text, filename=blob.name)}} | |
53 | + {% endif %} | |
50 | 54 | </div> |
51 | 55 | {% endif %} |
52 | 56 | {% endblock %} |