Rename helpers folder, move some vue filters

This commit is contained in:
Pavel Djundik 2019-11-05 12:36:44 +02:00
parent b164e95290
commit fc1c9568e2
44 changed files with 66 additions and 85 deletions

View File

@ -9,8 +9,8 @@
# Ignore client folder as it's being built into public/ folder # Ignore client folder as it's being built into public/ folder
# except for the specified files which are used by the server # except for the specified files which are used by the server
client/** client/**
!client/js/libs/handlebars/ircmessageparser/findLinks.js !client/js/helpers/ircmessageparser/findLinks.js
!client/js/libs/handlebars/ircmessageparser/cleanIrcMessage.js !client/js/helpers/ircmessageparser/cleanIrcMessage.js
!client/index.html.tpl !client/index.html.tpl
public/js/bundle.vendor.js.map public/js/bundle.vendor.js.map

View File

@ -2,7 +2,7 @@
<ChannelWrapper ref="wrapper" :network="network" :channel="channel"> <ChannelWrapper ref="wrapper" :network="network" :channel="channel">
<span class="name">{{ channel.name }}</span> <span class="name">{{ channel.name }}</span>
<span v-if="channel.unread" :class="{highlight: channel.highlight}" class="badge">{{ <span v-if="channel.unread" :class="{highlight: channel.highlight}" class="badge">{{
channel.unread | roundBadgeNumber unreadCount
}}</span> }}</span>
<template v-if="channel.type === 'channel'"> <template v-if="channel.type === 'channel'">
<span <span
@ -25,6 +25,7 @@
</template> </template>
<script> <script>
const roundBadgeNumber = require("../js/helpers/roundBadgeNumber");
import ChannelWrapper from "./ChannelWrapper.vue"; import ChannelWrapper from "./ChannelWrapper.vue";
export default { export default {
@ -36,6 +37,11 @@ export default {
network: Object, network: Object,
channel: Object, channel: Object,
}, },
computed: {
unreadCount() {
return roundBadgeNumber(this.channel.unread);
},
},
methods: { methods: {
close() { close() {
this.$refs.wrapper.close(); this.$refs.wrapper.close();

View File

@ -77,8 +77,7 @@
</template> </template>
<template v-else-if="link.type === 'error'"> <template v-else-if="link.type === 'error'">
<em v-if="link.error === 'image-too-big'"> <em v-if="link.error === 'image-too-big'">
This image is larger than {{ link.maxSize | friendlysize }} and cannot be This image is larger than {{ imageMaxSize }} and cannot be previewed.
previewed.
<a :href="link.link" target="_blank" rel="noopener">Click here</a> <a :href="link.link" target="_blank" rel="noopener">Click here</a>
to open it in a new window. to open it in a new window.
</em> </em>
@ -108,6 +107,8 @@
</template> </template>
<script> <script>
const friendlysize = require("../js/helpers/friendlysize");
export default { export default {
name: "LinkPreview", name: "LinkPreview",
props: { props: {
@ -124,6 +125,9 @@ export default {
moreButtonLabel() { moreButtonLabel() {
return this.isContentShown ? "Less" : "More"; return this.isContentShown ? "Less" : "More";
}, },
imageMaxSize() {
return friendlysize(this.link.maxSize);
},
}, },
watch: { watch: {
"link.type"() { "link.type"() {

View File

@ -28,7 +28,7 @@
<span class="not-connected-icon" /> <span class="not-connected-icon" />
</span> </span>
<span v-if="channel.unread" :class="{highlight: channel.highlight}" class="badge">{{ <span v-if="channel.unread" :class="{highlight: channel.highlight}" class="badge">{{
channel.unread | roundBadgeNumber unreadCount
}}</span> }}</span>
</div> </div>
<span <span
@ -47,6 +47,7 @@
</template> </template>
<script> <script>
const roundBadgeNumber = require("../js/helpers/roundBadgeNumber");
import ChannelWrapper from "./ChannelWrapper.vue"; import ChannelWrapper from "./ChannelWrapper.vue";
import socket from "../js/socket"; import socket from "../js/socket";
const storage = require("../js/localStorage"); const storage = require("../js/localStorage");
@ -67,6 +68,9 @@ export default {
joinChannelLabel() { joinChannelLabel() {
return this.isJoinChannelShown ? "Cancel" : "Join a channel…"; return this.isJoinChannelShown ? "Cancel" : "Join a channel…";
}, },
unreadCount() {
return roundBadgeNumber(this.channel.unread);
},
}, },
methods: { methods: {
close() { close() {

View File

@ -1,5 +1,5 @@
<script> <script>
const parse = require("../js/libs/handlebars/parse"); const parse = require("../js/helpers/parse");
export default { export default {
name: "ParsedMessage", name: "ParsedMessage",

View File

@ -1,6 +1,6 @@
<template> <template>
<span <span
:class="['user', $options.filters.colorClass(user.nick), {active: active}]" :class="['user', nickColor, {active: active}]"
:data-name="user.nick" :data-name="user.nick"
role="button" role="button"
v-on="onHover ? {mouseover: hover} : {}" v-on="onHover ? {mouseover: hover} : {}"
@ -9,6 +9,8 @@
</template> </template>
<script> <script>
const colorClass = require("../js/helpers/colorClass");
export default { export default {
name: "Username", name: "Username",
props: { props: {
@ -16,6 +18,11 @@ export default {
active: Boolean, active: Boolean,
onHover: Function, onHover: Function,
}, },
computed: {
nickColor() {
return colorClass(this.user.nick);
},
},
methods: { methods: {
hover() { hover() {
return this.onHover(this.user); return this.onHover(this.user);

View File

@ -1,6 +1,6 @@
<template> <template>
<span <span
:class="['user', $options.filters.colorClass(user.original.nick), {active: active}]" :class="['user', nickColor, {active: active}]"
:data-name="user.original.nick" :data-name="user.original.nick"
role="button" role="button"
@mouseover="hover" @mouseover="hover"
@ -9,6 +9,8 @@
</template> </template>
<script> <script>
const colorClass = require("../js/helpers/colorClass");
export default { export default {
name: "UsernameFiltered", name: "UsernameFiltered",
props: { props: {
@ -16,6 +18,11 @@ export default {
active: Boolean, active: Boolean,
onHover: Function, onHover: Function,
}, },
computed: {
nickColor() {
return colorClass(this.user.original.nick);
},
},
methods: { methods: {
hover() { hover() {
this.onHover ? this.onHover(this.user.original) : null; this.onHover ? this.onHover(this.user.original) : null;

View File

@ -4,7 +4,7 @@ const $ = require("jquery");
const fuzzy = require("fuzzy"); const fuzzy = require("fuzzy");
const Mousetrap = require("mousetrap"); const Mousetrap = require("mousetrap");
const {Textcomplete, Textarea} = require("textcomplete"); const {Textcomplete, Textarea} = require("textcomplete");
const emojiMap = require("./libs/simplemap.json"); const emojiMap = require("./helpers/simplemap.json");
const constants = require("./constants"); const constants = require("./constants");
const store = require("./store").default; const store = require("./store").default;

View File

@ -7,10 +7,10 @@ const findEmoji = require("./ircmessageparser/findEmoji");
const findNames = require("./ircmessageparser/findNames"); const findNames = require("./ircmessageparser/findNames");
const merge = require("./ircmessageparser/merge"); const merge = require("./ircmessageparser/merge");
const colorClass = require("./colorClass"); const colorClass = require("./colorClass");
const emojiMap = require("../fullnamemap.json"); const emojiMap = require("./fullnamemap.json");
const LinkPreviewToggle = require("../../../components/LinkPreviewToggle.vue").default; const LinkPreviewToggle = require("../../components/LinkPreviewToggle.vue").default;
const LinkPreviewFileSize = require("../../../components/LinkPreviewFileSize.vue").default; const LinkPreviewFileSize = require("../../components/LinkPreviewFileSize.vue").default;
const InlineChannel = require("../../../components/InlineChannel.vue").default; const InlineChannel = require("../../components/InlineChannel.vue").default;
const emojiModifiersRegex = /[\u{1f3fb}-\u{1f3ff}]/gu; const emojiModifiersRegex = /[\u{1f3fb}-\u{1f3ff}]/gu;
// Create an HTML `span` with styling information for a given fragment // Create an HTML `span` with styling information for a given fragment

View File

@ -1,16 +0,0 @@
"use strict";
module.exports = function(a, b, opt) {
if (arguments.length !== 3) {
throw new Error("Handlebars helper `equal` expects 3 arguments");
}
a = a.toString();
b = b.toString();
if (a === b) {
return opt.fn(this);
}
return opt.inverse(this);
};

View File

@ -1,7 +1,7 @@
"use strict"; "use strict";
const socket = require("../socket"); const socket = require("../socket");
const cleanIrcMessage = require("../libs/handlebars/ircmessageparser/cleanIrcMessage"); const cleanIrcMessage = require("../helpers/ircmessageparser/cleanIrcMessage");
const webpush = require("../webpush"); const webpush = require("../webpush");
const {vueApp} = require("../vue"); const {vueApp} = require("../vue");
const store = require("../store").default; const store = require("../store").default;

View File

@ -4,18 +4,12 @@ const Vue = require("vue").default;
const store = require("./store").default; const store = require("./store").default;
const App = require("../components/App.vue").default; const App = require("../components/App.vue").default;
const roundBadgeNumber = require("./libs/handlebars/roundBadgeNumber"); const localetime = require("./helpers/localetime");
const localetime = require("./libs/handlebars/localetime");
const friendlysize = require("./libs/handlebars/friendlysize");
const colorClass = require("./libs/handlebars/colorClass");
const storage = require("./localStorage"); const storage = require("./localStorage");
const {router} = require("./router"); const {router} = require("./router");
const constants = require("./constants"); const constants = require("./constants");
Vue.filter("localetime", localetime); Vue.filter("localetime", localetime);
Vue.filter("friendlysize", friendlysize);
Vue.filter("colorClass", colorClass);
Vue.filter("roundBadgeNumber", roundBadgeNumber);
const appName = document.title; const appName = document.title;

View File

@ -24,12 +24,12 @@ const fs = require("fs");
const fullNameEmojiMapOutput = JSON.stringify(fullNameEmojiMap, null, 2) + "\n"; const fullNameEmojiMapOutput = JSON.stringify(fullNameEmojiMap, null, 2) + "\n";
fs.writeFileSync( fs.writeFileSync(
path.resolve(path.join(__dirname, "..", "client", "js", "libs", "simplemap.json")), path.resolve(path.join(__dirname, "..", "client", "js", "helpers", "simplemap.json")),
emojiMapOutput emojiMapOutput
); );
fs.writeFileSync( fs.writeFileSync(
path.resolve(path.join(__dirname, "..", "client", "js", "libs", "fullnamemap.json")), path.resolve(path.join(__dirname, "..", "client", "js", "helpers", "fullnamemap.json")),
fullNameEmojiMapOutput fullNameEmojiMapOutput
); );
})(); })();

View File

@ -5,8 +5,8 @@ const got = require("got");
const URL = require("url").URL; const URL = require("url").URL;
const mime = require("mime-types"); const mime = require("mime-types");
const Helper = require("../../helper"); const Helper = require("../../helper");
const cleanIrcMessage = require("../../../client/js/libs/handlebars/ircmessageparser/cleanIrcMessage"); const cleanIrcMessage = require("../../../client/js/helpers/ircmessageparser/cleanIrcMessage");
const findLinks = require("../../../client/js/libs/handlebars/ircmessageparser/findLinks"); const findLinks = require("../../../client/js/helpers/ircmessageparser/findLinks");
const storage = require("../storage"); const storage = require("../storage");
const currentFetchPromises = new Map(); const currentFetchPromises = new Map();
const imageTypeRegex = /^image\/.+/; const imageTypeRegex = /^image\/.+/;

View File

@ -3,7 +3,7 @@
const Chan = require("../../models/chan"); const Chan = require("../../models/chan");
const Msg = require("../../models/msg"); const Msg = require("../../models/msg");
const LinkPrefetch = require("./link"); const LinkPrefetch = require("./link");
const cleanIrcMessage = require("../../../client/js/libs/handlebars/ircmessageparser/cleanIrcMessage"); const cleanIrcMessage = require("../../../client/js/helpers/ircmessageparser/cleanIrcMessage");
const Helper = require("../../helper"); const Helper = require("../../helper");
const nickRegExp = /(?:\x03[0-9]{1,2}(?:,[0-9]{1,2})?)?([\w[\]\\`^{|}-]+)/g; const nickRegExp = /(?:\x03[0-9]{1,2}(?:,[0-9]{1,2})?)?([\w[\]\\`^{|}-]+)/g;

View File

@ -1,9 +1,9 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const friendlysize = require("../../../../../client/js/libs/handlebars/friendlysize"); const friendlysize = require("../../../../client/js/helpers/friendlysize");
describe("friendlysize Handlebars helper", function() { describe("friendlysize helper", function() {
it("should render big values in human-readable version", function() { it("should render big values in human-readable version", function() {
expect(friendlysize(51200)).to.equal("50 KB"); expect(friendlysize(51200)).to.equal("50 KB");
}); });

View File

@ -1,7 +1,7 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const anyIntersection = require("../../../../../../client/js/libs/handlebars/ircmessageparser/anyIntersection"); const anyIntersection = require("../../../../../client/js/helpers/ircmessageparser/anyIntersection");
describe("anyIntersection", () => { describe("anyIntersection", () => {
it("should not intersect on edges", () => { it("should not intersect on edges", () => {

View File

@ -1,7 +1,7 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const cleanIrcMessage = require("../../../../../../client/js/libs/handlebars/ircmessageparser/cleanIrcMessage"); const cleanIrcMessage = require("../../../../../client/js/helpers/ircmessageparser/cleanIrcMessage");
describe("cleanIrcMessage", function() { describe("cleanIrcMessage", function() {
it("should remove all formatting", function() { it("should remove all formatting", function() {

View File

@ -1,7 +1,7 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const fill = require("../../../../../../client/js/libs/handlebars/ircmessageparser/fill"); const fill = require("../../../../../client/js/helpers/ircmessageparser/fill");
describe("fill", () => { describe("fill", () => {
const text = "01234567890123456789"; const text = "01234567890123456789";

View File

@ -1,7 +1,7 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const findChannels = require("../../../../../../client/js/libs/handlebars/ircmessageparser/findChannels"); const findChannels = require("../../../../../client/js/helpers/ircmessageparser/findChannels");
describe("findChannels", () => { describe("findChannels", () => {
it("should find single letter channel", () => { it("should find single letter channel", () => {

View File

@ -1,7 +1,7 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const findEmoji = require("../../../../../../client/js/libs/handlebars/ircmessageparser/findEmoji"); const findEmoji = require("../../../../../client/js/helpers/ircmessageparser/findEmoji");
describe("findEmoji", () => { describe("findEmoji", () => {
it("should find default emoji presentation character", () => { it("should find default emoji presentation character", () => {

View File

@ -1,7 +1,7 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const findLinks = require("../../../../../../client/js/libs/handlebars/ircmessageparser/findLinks"); const findLinks = require("../../../../../client/js/helpers/ircmessageparser/findLinks");
describe("findLinks", () => { describe("findLinks", () => {
it("should find url", () => { it("should find url", () => {

View File

@ -1,7 +1,7 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const findNames = require("../../../../../../client/js/libs/handlebars/ircmessageparser/findNames"); const findNames = require("../../../../../client/js/helpers/ircmessageparser/findNames");
describe("findNames", () => { describe("findNames", () => {
it("should find nicks in text", () => { it("should find nicks in text", () => {

View File

@ -1,7 +1,7 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const merge = require("../../../../../../client/js/libs/handlebars/ircmessageparser/merge"); const merge = require("../../../../../client/js/helpers/ircmessageparser/merge");
describe("merge", () => { describe("merge", () => {
it("should split style information", () => { it("should split style information", () => {

View File

@ -1,7 +1,7 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const parseStyle = require("../../../../../../client/js/libs/handlebars/ircmessageparser/parseStyle"); const parseStyle = require("../../../../../client/js/helpers/ircmessageparser/parseStyle");
describe("parseStyle", () => { describe("parseStyle", () => {
it("should skip control codes", () => { it("should skip control codes", () => {

View File

@ -1,9 +1,9 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const localetime = require("../../../../../client/js/libs/handlebars/localetime"); const localetime = require("../../../../client/js/helpers/localetime");
describe("localetime Handlebars helper", () => { describe("localetime helper", () => {
it("should render a human-readable date", () => { it("should render a human-readable date", () => {
// 12PM in UTC time // 12PM in UTC time
const date = new Date("2014-05-22T12:00:00Z"); const date = new Date("2014-05-22T12:00:00Z");

View File

@ -3,7 +3,7 @@
const expect = require("chai").expect; const expect = require("chai").expect;
import {renderToString} from "@vue/server-test-utils"; import {renderToString} from "@vue/server-test-utils";
import ParsedMessageTestWrapper from "../../../components/ParsedMessageTestWrapper.vue"; import ParsedMessageTestWrapper from "../../components/ParsedMessageTestWrapper.vue";
function getParsedMessageContents(text, message) { function getParsedMessageContents(text, message) {
let contents = renderToString(ParsedMessageTestWrapper, { let contents = renderToString(ParsedMessageTestWrapper, {
@ -19,7 +19,7 @@ function getParsedMessageContents(text, message) {
return contents; return contents;
} }
describe("parse Handlebars helper", () => { describe("IRC formatted message parser", () => {
it("should not introduce xss", () => { it("should not introduce xss", () => {
const testCases = [ const testCases = [
{ {

View File

@ -1,9 +1,9 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const roundBadgeNumber = require("../../../../../client/js/libs/handlebars/roundBadgeNumber"); const roundBadgeNumber = require("../../../../client/js/helpers/roundBadgeNumber");
describe("roundBadgeNumber Handlebars helper", function() { describe("roundBadgeNumber helper", function() {
it("should return any number under 1000 as a string", function() { it("should return any number under 1000 as a string", function() {
expect(roundBadgeNumber(123)).to.equal("123"); expect(roundBadgeNumber(123)).to.equal("123");
}); });

View File

@ -1,25 +0,0 @@
"use strict";
const expect = require("chai").expect;
const equal = require("../../../../../client/js/libs/handlebars/equal");
describe("equal Handlebars helper", function() {
const block = {
fn: () => "fn",
inverse: () => "inverse",
};
it("should render the first block if both values are equal", function() {
expect(equal("foo", "foo", block)).to.equal("fn");
});
it("should render the inverse block if values are not equal", function() {
expect(equal("foo", "bar", block)).to.equal("inverse");
});
it("should throw if too few or too many arguments are given", function() {
expect(() => equal("foo", block)).to.throw(Error, /expects 3 arguments/);
expect(() => equal("foo", "bar", "baz", block)).to.throw(Error, /expects 3 arguments/);
});
});