Skip to content

Commit

Permalink
Merge pull request #190 from SpeciesFileGroup/development
Browse files Browse the repository at this point in the history
Add uncapitalize
  • Loading branch information
José Luis Pereira authored and GitHub committed Nov 6, 2023
2 parents 26e397e + b118e99 commit cd88724
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
10 changes: 8 additions & 2 deletions src/modules/otus/composables/useChildrenRoutes.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { useRouter } from 'vue-router'
import { humanize } from '@/utils/strings'
import { humanize, uncapitalize } from '@/utils/strings'

export default function useChildrenRoutes() {
const router = useRouter()
const { children } = router
.getRoutes()
.find((route) => route.name === 'otus-id')

const makeLabel = (path, isUncapitalize) => {
const label = humanize(path)

return isUncapitalize ? uncapitalize(label) : label
}

return children.map(({ path, name, meta }) => ({
label: path && humanize(path),
label: path && makeLabel(path, meta.uncapitalize),
path,
name,
meta
Expand Down
7 changes: 5 additions & 2 deletions src/modules/otus/constants/layouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ function parsePanelConfiguraion(panelLayout) {
const layouts = {}

for (const key in tabsLayout) {
const tabLayout = tabsLayout[key]

layouts[key] = {
panels: parsePanelConfiguraion(tabsLayout[key]?.panels || {}),
rankGroup: tabsLayout[key].rank_group || []
panels: parsePanelConfiguraion(tabLayout?.panels || {}),
rankGroup: tabLayout.rank_group || [],
uncapitalize: tabLayout.uncapitalize
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/modules/otus/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ function makeChildrenRoutes() {
component: PageLayout,
meta: {
tab,
rankGroup: layouts[tab].rankGroup
rankGroup: layouts[tab].rankGroup,
uncapitalize: layouts[tab].uncapitalize
}
}))
}
Expand Down
12 changes: 7 additions & 5 deletions src/utils/strings.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
function humanize (text) {
function humanize(text) {
return text
.replace(/^[\s_]+|[\s_]+$/g, '')
.replace(/[_\s]+/g, ' ')
.replace(/^[a-z]/, m => m.toUpperCase())
.replace(/^[a-z]/, (m) => m.toUpperCase())
}

export {
humanize
}
function uncapitalize(text) {
return text.replace(/^[A-Z]/, (m) => m.toLowerCase())
}

export { humanize, uncapitalize }

0 comments on commit cd88724

Please sign in to comment.