defaultRoute -> defaultResource

This commit is contained in:
Lachlan Kermode
2018-12-07 13:02:50 +00:00
parent 8a5bce0842
commit 41e2ba8299
8 changed files with 46 additions and 36 deletions

View File

@@ -1,5 +1,5 @@
import R from 'ramda'
import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
import { defaultBlueprint, defaultResource } from '../lib/blueprinters'
/**
* byColumn - generate a Blueprint from a data sheet by column. Each column
@@ -9,7 +9,7 @@ import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
* @return {type} Blueprint
* generated.
*/
function byColumn (tabName, sheetName, sheetId, data) {
function columns (tabName, sheetName, sheetId, data) {
// Define Blueprint props
const bp = R.clone(defaultBlueprint)
bp.sheet = {
@@ -21,7 +21,7 @@ function byColumn (tabName, sheetName, sheetId, data) {
// column names define resources
const labels = data[0]
labels.forEach(label => {
bp.resources[label] = R.clone(defaultRoute)
bp.resources[label] = R.clone(defaultResource)
})
// remaining rows as data
@@ -34,6 +34,4 @@ function byColumn (tabName, sheetName, sheetId, data) {
return bp
}
byColumn.resourceName = 'columns'
export default byColumn
export default columns

View File

@@ -1,9 +1,9 @@
import R from 'ramda'
import { fmtObj } from '../lib/util'
import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
import { defaultBlueprint, defaultResource } from '../lib/blueprinters'
/**
* byGroup - generate a Blueprint from a data sheet grouped by a column called 'group'
* groups - generate a Blueprint from a data sheet grouped by a column called 'group'
* The resource name defaults to 'groups', or a custom resource name can be passed.
* Each resource item is an object with values labelled according to column
* names. Items are inserted in the data list at idx = id.
@@ -13,7 +13,7 @@ import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
* @param {type} name="" name of blueprint.
* @return {type} Blueprint
*/
export default function byGroup (
export default function groups (
tabName,
sheetName,
sheetId,
@@ -31,7 +31,7 @@ export default function byGroup (
// Column names define resources
const itemLabels = data[0]
const fmt = fmtObj(itemLabels)
bp.resources[label] = R.clone(defaultRoute)
bp.resources[label] = R.clone(defaultResource)
bp.resources[label].data = []
const dataGroups = {}

View File

@@ -1,9 +1,9 @@
import R from 'ramda'
import { fmtObj } from '../lib/util'
import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
import { defaultBlueprint, defaultResource } from '../lib/blueprinters'
/**
* byId - generate a Blueprint from a data sheet by id, which is an integer.
* ids - generate a Blueprint from a data sheet by id, which is an integer.
* The resource name defaults to 'ids', or a custom resource name can be passed.
* Each resource item is an object with values labelled according to column
* names. Items are inserted in the data list at idx = id.
@@ -13,7 +13,7 @@ import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
* @param {type} name="" name of blueprint.
* @return {type} Blueprint
*/
export default function byId (
export default function ids (
tabName,
sheetName,
sheetId,
@@ -31,7 +31,7 @@ export default function byId (
// Column names define resources
const itemLabels = data[0]
const fmt = fmtObj(itemLabels)
bp.resources[label] = R.clone(defaultRoute)
bp.resources[label] = R.clone(defaultResource)
bp.resources[label].data = []
data.forEach((row, idx) => {

View File

@@ -1,9 +1,9 @@
import R from 'ramda'
import { fmtObj } from '../lib/util'
import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
import { defaultBlueprint, defaultResource } from '../lib/blueprinters'
/**
* byRow - generate a Blueprint from a data sheet by row. The resource name
* rows - generate a Blueprint from a data sheet by row. The resource name
* defaults to 'rows', or a custom resource name can be passed. Each resource
* item is an object with values labelled according to column names.
*
@@ -12,7 +12,7 @@ import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
* @param {type} name="" name of blueprint.
* @return {type} Blueprint
*/
export default function byRow (
export default function rows (
tabName,
sheetName,
sheetId,
@@ -30,7 +30,7 @@ export default function byRow (
// Column names define resources
const itemLabels = data[0]
const fmt = fmtObj(itemLabels)
bp.resources[label] = R.clone(defaultRoute)
bp.resources[label] = R.clone(defaultResource)
bp.resources[label].data = []
data.forEach((row, idx) => {

View File

@@ -1,8 +1,8 @@
import R from 'ramda'
import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
import { defaultBlueprint, defaultResource } from '../lib/blueprinters'
/**
* byTree - generate a Blueprint from a data sheet grouped by a column called 'group'
* tree - generate a Blueprint from a data sheet grouped by a column called 'group'
* The resource name defaults to 'groups', or a custom resource name can be passed.
* Each resource item is an object with values labelled according to column
* names. Items are inserted in the data list at idx = id.
@@ -12,7 +12,7 @@ import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
* @param {type} name="" name of blueprint.
* @return {type} Blueprint
*/
export default function byTree (
export default function tree (
tabName,
sheetName,
sheetId,
@@ -28,7 +28,7 @@ export default function byTree (
bp.name = tabName
// Column names define resources
bp.resources[label] = R.clone(defaultRoute)
bp.resources[label] = R.clone(defaultResource)
bp.resources[label].data = {}
const tree = {

View File

@@ -48,7 +48,14 @@ class Fetcher {
*/
this.blueprints = this._indexDbForBlueprints()
.then(allUrls => {
const supportedUrls = allUrls.filter(url => url.startsWith(this.id))
const allParts = allUrls.reduce((acc, url) => {
if (url.startsWith(this.id)) {
const parts = url.split('/')
acc.push([ parts[1], parts[2] ])
return acc
}
}, [])
console.log(allParts)
return {}
})

View File

@@ -1,5 +1,6 @@
import path from 'path'
import fs from 'fs'
import R from 'ramda'
export const defaultBlueprint = {
name: null,
@@ -8,13 +9,17 @@ export const defaultBlueprint = {
resources: {}
}
export const defaultRoute = {
export const defaultResource = {
options: {
fragment: true
},
data: []
}
export function buildDesaturated (tab, resource) {
const bp = R.clone(defaultBlueprint)
}
// import all default exports from 'blueprinters' folder
const allBps = {}
const REL_PATH_TO_BPS = '../blueprinters'
@@ -28,5 +33,5 @@ fs.readdirSync(normalizedPath).forEach(file => {
// each file in blueprinters folder available for granular import from here.
module.exports = Object.assign({
defaultBlueprint,
defaultRoute
defaultResource
}, allBps)

View File

@@ -2,9 +2,9 @@ import test from 'ava'
import R from 'ramda'
import {
defaultBlueprint,
defaultRoute,
byColumn,
byRow
defaultResource,
columns,
rows
} from '../src/lib/blueprinters'
const egInput1 = [
@@ -23,32 +23,32 @@ test('defaultBlueprint exports', t => {
t.deepEqual(expected, defaultBlueprint)
})
test('byColumn blueprinter generates expected output', t => {
const actual = byColumn('eg ColumnBlueprint', 'egSheetName', 'egSheetId', egInput1)
test('columns blueprinter generates expected output', t => {
const actual = columns('eg ColumnBlueprint', 'egSheetName', 'egSheetId', egInput1)
const expected = R.clone(defaultBlueprint)
expected.name = 'eg ColumnBlueprint'
expected.sheet = {
id: 'egSheetId',
name: 'egSheetName'
}
expected.resources['h1'] = R.clone(defaultRoute)
expected.resources['h1'] = R.clone(defaultResource)
expected.resources['h1'].data = [1, 4]
expected.resources['h2'] = R.clone(defaultRoute)
expected.resources['h2'] = R.clone(defaultResource)
expected.resources['h2'].data = [2, 5]
expected.resources['h3'] = R.clone(defaultRoute)
expected.resources['h3'] = R.clone(defaultResource)
expected.resources['h3'].data = [3, 6]
t.deepEqual(expected, actual)
})
test('byRow blueprinter generates expected output', t => {
const actual = byRow('egRowBlueprint', 'egSheetName', 'egSheetId', egInput1, 'items')
test('rows blueprinter generates expected output', t => {
const actual = rows('egRowBlueprint', 'egSheetName', 'egSheetId', egInput1, 'items')
const expected = R.clone(defaultBlueprint)
expected.name = 'egRowBlueprint'
expected.sheet = {
id: 'egSheetId',
name: 'egSheetName'
}
expected.resources['items'] = R.clone(defaultRoute)
expected.resources['items'] = R.clone(defaultResource)
expected.resources['items'].data = [{
h1: 1,
h2: 2,