From 41e2ba8299e9d8d609e8a26fdbd3e04a1cbf4b83 Mon Sep 17 00:00:00 2001 From: Lachlan Kermode Date: Fri, 7 Dec 2018 13:02:50 +0000 Subject: [PATCH] defaultRoute -> defaultResource --- src/blueprinters/{byColumn.js => columns.js} | 10 ++++----- src/blueprinters/{byGroup.js => groups.js} | 8 +++---- src/blueprinters/{byId.js => ids.js} | 8 +++---- src/blueprinters/{byRow.js => rows.js} | 8 +++---- src/blueprinters/{byTree.js => tree.js} | 8 +++---- src/lib/Fetcher.js | 9 +++++++- src/lib/blueprinters.js | 9 ++++++-- test/internals.js | 22 ++++++++++---------- 8 files changed, 46 insertions(+), 36 deletions(-) rename src/blueprinters/{byColumn.js => columns.js} (75%) rename src/blueprinters/{byGroup.js => groups.js} (84%) rename src/blueprinters/{byId.js => ids.js} (80%) rename src/blueprinters/{byRow.js => rows.js} (79%) rename src/blueprinters/{byTree.js => tree.js} (85%) diff --git a/src/blueprinters/byColumn.js b/src/blueprinters/columns.js similarity index 75% rename from src/blueprinters/byColumn.js rename to src/blueprinters/columns.js index d2144e2..eee7bc8 100644 --- a/src/blueprinters/byColumn.js +++ b/src/blueprinters/columns.js @@ -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 diff --git a/src/blueprinters/byGroup.js b/src/blueprinters/groups.js similarity index 84% rename from src/blueprinters/byGroup.js rename to src/blueprinters/groups.js index 3d1ce65..30ef755 100644 --- a/src/blueprinters/byGroup.js +++ b/src/blueprinters/groups.js @@ -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 = {} diff --git a/src/blueprinters/byId.js b/src/blueprinters/ids.js similarity index 80% rename from src/blueprinters/byId.js rename to src/blueprinters/ids.js index 936957c..d027be1 100644 --- a/src/blueprinters/byId.js +++ b/src/blueprinters/ids.js @@ -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) => { diff --git a/src/blueprinters/byRow.js b/src/blueprinters/rows.js similarity index 79% rename from src/blueprinters/byRow.js rename to src/blueprinters/rows.js index 544d4f0..6966480 100644 --- a/src/blueprinters/byRow.js +++ b/src/blueprinters/rows.js @@ -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) => { diff --git a/src/blueprinters/byTree.js b/src/blueprinters/tree.js similarity index 85% rename from src/blueprinters/byTree.js rename to src/blueprinters/tree.js index c43d266..143d419 100644 --- a/src/blueprinters/byTree.js +++ b/src/blueprinters/tree.js @@ -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 = { diff --git a/src/lib/Fetcher.js b/src/lib/Fetcher.js index 2f3497c..d7c3c6d 100644 --- a/src/lib/Fetcher.js +++ b/src/lib/Fetcher.js @@ -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 {} }) diff --git a/src/lib/blueprinters.js b/src/lib/blueprinters.js index 53f3980..1d9d03a 100644 --- a/src/lib/blueprinters.js +++ b/src/lib/blueprinters.js @@ -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) diff --git a/test/internals.js b/test/internals.js index a2a00fa..64ef814 100644 --- a/test/internals.js +++ b/test/internals.js @@ -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,