summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/components/repo_preview.vue
blob: e47270a9855fd3bb91bf14f22960dbe5b4a83fd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<script>
  import { mapGetters } from 'vuex';
  import LineHighlighter from '../../line_highlighter';
  import syntaxHighlight from '../../syntax_highlight';

  export default {
    computed: {
      ...mapGetters([
        'activeFile',
      ]),
      renderErrorTooLarge() {
        return this.activeFile.renderError === 'too_large';
      },
    },
    mounted() {
      this.highlightFile();
      this.lineHighlighter = new LineHighlighter({
        fileHolderSelector: '.blob-viewer-container',
        scrollFileHolder: true,
      });
    },
    updated() {
      this.$nextTick(() => {
        this.highlightFile();
      });
    },
    methods: {
      highlightFile() {
        syntaxHighlight($(this.$el).find('.file-content'));
      },
    },
  };
</script>

<template>
  <div>
    <div
      v-if="!activeFile.renderError"
      v-html="activeFile.html"
      class="multi-file-preview-holder"
    >
    </div>
    <div
      v-else-if="activeFile.tempFile"
      class="vertical-center render-error">
      <p class="text-center">
        The source could not be displayed for this temporary file.
      </p>
    </div>
    <div
      v-else-if="renderErrorTooLarge"
      class="vertical-center render-error">
      <p class="text-center">
        The source could not be displayed because it is too large.
        You can <a
          :href="activeFile.rawPath"
          download>download</a> it instead.
      </p>
    </div>
    <div
      v-else
      class="vertical-center render-error">
      <p class="text-center">
        The source could not be displayed because a rendering error occurred.
        You can <a
          :href="activeFile.rawPath"
          download>download</a> it instead.
      </p>
    </div>
  </div>
</template>