diff options
author | Rémy Coutable <remy@rymai.me> | 2017-05-18 07:30:11 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-05-18 07:30:11 +0000 |
commit | c9e61fa3cd8eeb63aced9a55039dc4d17616cd42 (patch) | |
tree | 5cacc30a4e206f678263d9f2be4c759879de0aab | |
parent | 0b946a7bc69058a952a558a9530cd3e8302361e7 (diff) | |
parent | 82c2296a1274b6e7c3bb3031a7e903c01bc8a3c4 (diff) | |
download | gitlab-ce-c9e61fa3cd8eeb63aced9a55039dc4d17616cd42.tar.gz |
Merge branch 'dm-readme-viewer' into 'master'
Add auxiliary blob viewer for README
See merge request !11366
-rw-r--r-- | app/models/blob.rb | 1 | ||||
-rw-r--r-- | app/models/blob_viewer/auxiliary.rb | 6 | ||||
-rw-r--r-- | app/models/blob_viewer/readme.rb | 14 | ||||
-rw-r--r-- | app/views/projects/blob/_auxiliary_viewer.html.haml | 5 | ||||
-rw-r--r-- | app/views/projects/blob/_blob.html.haml | 5 | ||||
-rw-r--r-- | app/views/projects/blob/viewers/_readme.html.haml | 4 |
6 files changed, 31 insertions, 4 deletions
diff --git a/app/models/blob.rb b/app/models/blob.rb index 5ae35d3ab08..8e25ba590c7 100644 --- a/app/models/blob.rb +++ b/app/models/blob.rb @@ -40,6 +40,7 @@ class Blob < SimpleDelegator BlobViewer::GitlabCiYml, BlobViewer::RouteMap, + BlobViewer::Readme, BlobViewer::License, BlobViewer::Contributing, BlobViewer::Changelog diff --git a/app/models/blob_viewer/auxiliary.rb b/app/models/blob_viewer/auxiliary.rb index cd6e596ed60..07a207730cf 100644 --- a/app/models/blob_viewer/auxiliary.rb +++ b/app/models/blob_viewer/auxiliary.rb @@ -2,11 +2,17 @@ module BlobViewer module Auxiliary extend ActiveSupport::Concern + include Gitlab::Allowable + included do self.loading_partial_name = 'loading_auxiliary' self.type = :auxiliary self.overridable_max_size = 100.kilobytes self.max_size = 100.kilobytes end + + def visible_to?(current_user) + true + end end end diff --git a/app/models/blob_viewer/readme.rb b/app/models/blob_viewer/readme.rb new file mode 100644 index 00000000000..75c373a03bb --- /dev/null +++ b/app/models/blob_viewer/readme.rb @@ -0,0 +1,14 @@ +module BlobViewer + class Readme < Base + include Auxiliary + include Static + + self.partial_name = 'readme' + self.file_types = %i(readme) + self.binary = false + + def visible_to?(current_user) + can?(current_user, :read_wiki, project) + end + end +end diff --git a/app/views/projects/blob/_auxiliary_viewer.html.haml b/app/views/projects/blob/_auxiliary_viewer.html.haml new file mode 100644 index 00000000000..9749afdc580 --- /dev/null +++ b/app/views/projects/blob/_auxiliary_viewer.html.haml @@ -0,0 +1,5 @@ +- blob = local_assigns.fetch(:blob) +- auxiliary_viewer = blob.auxiliary_viewer +- if auxiliary_viewer && auxiliary_viewer.render_error.nil? && auxiliary_viewer.visible_to?(current_user) + .well-segment.blob-auxiliary-viewer + = render 'projects/blob/viewer', viewer: auxiliary_viewer diff --git a/app/views/projects/blob/_blob.html.haml b/app/views/projects/blob/_blob.html.haml index c90a7440480..8bd336269ff 100644 --- a/app/views/projects/blob/_blob.html.haml +++ b/app/views/projects/blob/_blob.html.haml @@ -5,10 +5,7 @@ %ul.blob-commit-info = render 'projects/commits/commit', commit: @last_commit, project: @project, ref: @ref - - auxiliary_viewer = blob.auxiliary_viewer - - if auxiliary_viewer && !auxiliary_viewer.render_error - .well-segment.blob-auxiliary-viewer - = render 'projects/blob/viewer', viewer: auxiliary_viewer + = render "projects/blob/auxiliary_viewer", blob: blob #blob-content-holder.blob-content-holder %article.file-holder diff --git a/app/views/projects/blob/viewers/_readme.html.haml b/app/views/projects/blob/viewers/_readme.html.haml new file mode 100644 index 00000000000..334b33faf48 --- /dev/null +++ b/app/views/projects/blob/viewers/_readme.html.haml @@ -0,0 +1,4 @@ += icon('info-circle fw') += succeed '.' do + To learn more about this project, read + = link_to "the wiki", namespace_project_wikis_path(viewer.project.namespace, viewer.project) |