Add auxiliary viewer for README

This commit is contained in:
Douwe Maan 2017-05-14 14:01:12 -05:00
parent d4d9b731c4
commit 82c2296a12
6 changed files with 31 additions and 4 deletions

View File

@ -40,6 +40,7 @@ class Blob < SimpleDelegator
BlobViewer::GitlabCiYml,
BlobViewer::RouteMap,
BlobViewer::Readme,
BlobViewer::License,
BlobViewer::Contributing,
BlobViewer::Changelog

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -6,10 +6,7 @@
- blob_commit = @repository.last_commit_for_path(@commit.id, blob.path)
= render blob_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

View File

@ -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)