refactor: renderers + auth providers + fixes

This commit is contained in:
NGPixel
2018-01-14 22:05:08 -05:00
parent 24fc806b0e
commit 74bd722168
41 changed files with 475 additions and 770 deletions

View File

@@ -1,15 +0,0 @@
'use strict'
import filesize from 'filesize.js'
import toUpper from 'lodash/toUpper'
module.exports = {
/**
* Convert bytes to humanized form
* @param {number} rawSize Size in bytes
* @returns {string} Humanized file size
*/
filesize(rawSize) {
return toUpper(filesize(rawSize))
}
}

View File

@@ -1,25 +0,0 @@
'use strict'
module.exports = {
/**
* Set Input Selection
* @param {DOMElement} input The input element
* @param {number} startPos The starting position
* @param {nunber} endPos The ending position
*/
setInputSelection: (input, startPos, endPos) => {
input.focus()
if (typeof input.selectionStart !== 'undefined') {
input.selectionStart = startPos
input.selectionEnd = endPos
} else if (document.selection && document.selection.createRange) {
// IE branch
input.select()
var range = document.selection.createRange()
range.collapse(true)
range.moveEnd('character', endPos)
range.moveStart('character', startPos)
range.select()
}
}
}

View File

@@ -1,10 +1,59 @@
'use strict'
import filesize from 'filesize.js'
/* global siteConfig */
const _ = require('./lodash')
const helpers = {
_: require('./lodash'),
common: require('./common'),
form: require('./form'),
pages: require('./pages')
/**
* Minimal set of lodash functions
*/
_,
/**
* Convert bytes to humanized form
* @param {number} rawSize Size in bytes
* @returns {string} Humanized file size
*/
filesize (rawSize) {
return _.toUpper(filesize(rawSize))
},
/**
* Convert raw path to safe path
* @param {string} rawPath Raw path
* @returns {string} Safe path
*/
makeSafePath (rawPath) {
let rawParts = _.split(_.trim(rawPath), '/')
rawParts = _.map(rawParts, (r) => {
return _.kebabCase(_.deburr(_.trim(r)))
})
return _.join(_.filter(rawParts, (r) => { return !_.isEmpty(r) }), '/')
},
resolvePath (path) {
if (_.startsWith(path, '/')) { path = path.substring(1) }
return `${siteConfig.path}${path}`
},
/**
* Set Input Selection
* @param {DOMElement} input The input element
* @param {number} startPos The starting position
* @param {nunber} endPos The ending position
*/
setInputSelection (input, startPos, endPos) {
input.focus()
if (typeof input.selectionStart !== 'undefined') {
input.selectionStart = startPos
input.selectionEnd = endPos
} else if (document.selection && document.selection.createRange) {
// IE branch
input.select()
var range = document.selection.createRange()
range.collapse(true)
range.moveEnd('character', endPos)
range.moveStart('character', startPos)
range.select()
}
}
}
export default {

View File

@@ -1,5 +1,3 @@
'use strict'
// ====================================
// Load minimal lodash
// ====================================

View File

@@ -1,26 +0,0 @@
'use strict'
import deburr from 'lodash/deburr'
import filter from 'lodash/filter'
import isEmpty from 'lodash/isEmpty'
import join from 'lodash/join'
import kebabCase from 'lodash/kebabCase'
import map from 'lodash/map'
import split from 'lodash/split'
import trim from 'lodash/trim'
module.exports = {
/**
* Convert raw path to safe path
* @param {string} rawPath Raw path
* @returns {string} Safe path
*/
makeSafePath: (rawPath) => {
let rawParts = split(trim(rawPath), '/')
rawParts = map(rawParts, (r) => {
return kebabCase(deburr(trim(r)))
})
return join(filter(rawParts, (r) => { return !isEmpty(r) }), '/')
}
}