From 7734b68d0bf212aae5c3d34fbf96a67f22c2f049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maren=20S=C3=BCwer?= Date: Mon, 29 Oct 2018 13:19:16 +0100 Subject: [PATCH] add source code viewer for different languages --- .../components/content/SourcecodeViewer.js | 21 ++++++++++++++++++- .../content/SourcecodeViewer.test.js | 11 +++++++++- .../src/repos/sources/containers/Content.js | 1 + 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/scm-ui/src/repos/sources/components/content/SourcecodeViewer.js b/scm-ui/src/repos/sources/components/content/SourcecodeViewer.js index d1b6dadb61..8c0d27661b 100644 --- a/scm-ui/src/repos/sources/components/content/SourcecodeViewer.js +++ b/scm-ui/src/repos/sources/components/content/SourcecodeViewer.js @@ -86,10 +86,29 @@ class SourcecodeViewer extends React.Component { } export function getLanguage(contentType: string) { - return contentType.substring( + const language = contentType.substring( contentType.indexOf("/") + 1, contentType.length ); + + let languageType; + + switch (language) { + case "x-go": + languageType = "go"; + break; + case "x-java-source": + languageType = "java"; + break; + case "x-web-markdown": + languageType = "markdown"; + break; + default: + languageType = language; + } + + console.log(languageType); + return languageType; } export function getContent(url: string) { diff --git a/scm-ui/src/repos/sources/components/content/SourcecodeViewer.test.js b/scm-ui/src/repos/sources/components/content/SourcecodeViewer.test.js index a318b8854a..a33dba454b 100644 --- a/scm-ui/src/repos/sources/components/content/SourcecodeViewer.test.js +++ b/scm-ui/src/repos/sources/components/content/SourcecodeViewer.test.js @@ -20,11 +20,20 @@ describe("get content", () => { }); }); -describe("get correct language Type", () => { +describe("get correct language type", () => { it("should return javascript", () => { expect(getLanguage("application/javascript")).toBe("javascript"); }); it("should return text", () => { expect(getLanguage("text/plain")).toBe("plain"); }); + it("should return go", () => { + expect(getLanguage("text/x-go")).toBe("go"); + }); + it("should return java", () => { + expect(getLanguage("text/x-java-source")).toBe("java"); + }); + it("should return markdown", () => { + expect(getLanguage("text/x-web-markdown")).toBe("markdown"); + }); }); diff --git a/scm-ui/src/repos/sources/containers/Content.js b/scm-ui/src/repos/sources/containers/Content.js index a9f2e46df9..23e33c407d 100644 --- a/scm-ui/src/repos/sources/containers/Content.js +++ b/scm-ui/src/repos/sources/containers/Content.js @@ -152,6 +152,7 @@ export function getContentType(url: string, state: any) { return apiClient .head(url) .then(response => { + console.log(response.headers.get("Content-Type")); return { type: response.headers.get("Content-Type") }; }) .catch(err => {