allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [2/6] git commit: [#7168] ticket:561 Extend include macro to load content from a repo
Date Fri, 04 Apr 2014 19:57:31 GMT
[#7168] ticket:561 Extend include macro to load content from a repo


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/cd345b09
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/cd345b09
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/cd345b09

Branch: refs/heads/master
Commit: cd345b096dbbc49404fc251d50545f5665a9e714
Parents: 323c00d
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Mar 25 14:46:47 2014 +0200
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Apr 4 19:51:23 2014 +0000

----------------------------------------------------------------------
 Allura/allura/lib/macro.py                   | 39 ++++++++++++++++++++++-
 Allura/allura/templates/widgets/include.html |  6 +++-
 2 files changed, 43 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/cd345b09/Allura/allura/lib/macro.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/macro.py b/Allura/allura/lib/macro.py
index 80123de..ba9a04d 100644
--- a/Allura/allura/lib/macro.py
+++ b/Allura/allura/lib/macro.py
@@ -321,10 +321,47 @@ def gittip_button(username):
     return response
 
 
+def parse_repo(repo):
+    from allura import model as M
+    parts = repo.split(':')
+    project, app = c.project, c.app
+    if len(parts) == 2:
+        project = M.Project.query.get(shortname=parts[0])
+        app = project.app_instance(parts[1])
+    elif len(parts) == 1:
+        app = project.app_instance(parts[0]) if project else None
+    return app
+
+
+def include_file(repo, path=None, rev=None, **kw):
+    app = parse_repo(repo)
+    if not app:
+        return '[[include repo %s (not found)]]' % repo
+    rev = app.repo.head if rev is None else rev
+    if not path or not app.repo.is_file(path, rev):
+        return "[[include can't find file %s in revision %s]]" % (path, rev)
+
+    file = app.repo.commit(rev).get_path(path)
+    text = ''
+    if file.has_pypeline_view:
+        text = h.render_any_markup(file.name, file.text, code_mode=True)
+    elif file.has_html_view:
+        text = g.highlight(file.text, filename=file.name)
+    else:
+        return "[[include can't display file %s in revision %s]]" % (path, rev)
+
+    from allura.lib.widgets.macros import Include
+    sb = Include()
+    g.resource_manager.register(sb)
+    return sb.display(text=text, attrs=kw)
+
+
 @macro()
-def include(ref=None, **kw):
+def include(ref=None, repo=None, **kw):
     from allura import model as M
     from allura.lib.widgets.macros import Include
+    if repo is not None:
+        return include_file(repo, **kw)
     if ref is None:
         return '[-include-]'
     link = M.Shortlink.lookup(ref)

http://git-wip-us.apache.org/repos/asf/allura/blob/cd345b09/Allura/allura/templates/widgets/include.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/include.html b/Allura/allura/templates/widgets/include.html
index a4078f0..9639e93 100644
--- a/Allura/allura/templates/widgets/include.html
+++ b/Allura/allura/templates/widgets/include.html
@@ -17,6 +17,10 @@
        under the License.
 -#}
 <div{{attrs|default({}, true)|xmlattr}}>
-  {{artifact.html_text|safe}}
+  {% if artifact %}
+    {{artifact.html_text|safe}}
+  {% else %}
+    {{text|safe}}
+  {% endif %}
 </div>
 


Mime
View raw message