• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

allura


Commit MetaInfo

修訂19787336c579de23075c794be1ed4fa409d7407e (tree)
時間2012-04-27 23:51:35
作者Jenny Steele <jsteele@geek...>
CommiterCory Johns

Log Message

[#2151] More file types are now "viewable" in repos

Change Summary

差異

--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -36,6 +36,9 @@ config = utils.ConfigProxy(
3636 common_prefix='forgemail.url')
3737
3838 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']
3942
4043 class RepositoryImplementation(object):
4144
@@ -1005,6 +1008,8 @@ class Blob(RepoObject):
10051008 self.commit = tree.commit
10061009 self.tree = tree
10071010 self.name = name
1011+ fn, ext = os.path.splitext(self.name)
1012+ self.extension = ext or fn
10081013
10091014 @LazyProperty
10101015 def _content_type_encoding(self):
@@ -1050,8 +1055,17 @@ class Blob(RepoObject):
10501055 return self.tree.path() + h.really_unicode(self.name)
10511056
10521057 @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
10531064 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
10551069
10561070 @property
10571071 def has_image_view(self):
--- a/Allura/allura/templates/repo/file.html
+++ b/Allura/allura/templates/repo/file.html
@@ -42,11 +42,15 @@
4242 Try to <a href="?force=True">display it</a> anyway or
4343 <a href="?format=raw">download it</a> instead.</p>
4444 {% 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 %}
4646 <p><a href="?format=raw">Download this file</a></p>
4747 <div class="clip grid-19">
4848 <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 %}
5054 </div>
5155 {% endif %}
5256 {% endblock %}