Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial cssProps feature #389

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f5b68d6
Initial cssProps feature
B-Teague Nov 10, 2021
3a924ed
Merge branch 'master' into cssProps
cristianbote Nov 22, 2021
ab3d317
Merge branch 'master' into cssProps
cristianbote Nov 22, 2021
bc7095a
Add mustache templates and regen
B-Teague Nov 28, 2021
c0a797c
Finish creating mustache templates
B-Teague Nov 28, 2021
02a3f69
Merge branch 'cristianbote:master' into cssProps
B-Teague Nov 28, 2021
2e9d0d6
Merge branch 'cssProps' of github.com:B-Teague/goober into cssProps
B-Teague Nov 28, 2021
ec5c294
Create dedicated syntax files
B-Teague Dec 9, 2021
58e67fe
Merge branch 'master' into cssProps
cristianbote Dec 10, 2021
14158a6
creating peggy css syntax parser
B-Teague Dec 11, 2021
987bba5
Merge branch 'cssProps' of github.com:B-Teague/goober into cssProps
B-Teague Dec 11, 2021
2347192
Merge branch 'master' into cssProps
cristianbote Jan 14, 2022
8888225
Updated template generators
B-Teague Feb 2, 2023
b656ee4
Merge branch 'cristianbote:master' into cssProps
B-Teague Feb 2, 2023
9127d2f
Reformat mdn data
B-Teague Feb 4, 2023
e435719
Updating template generators with using cssMdnData
B-Teague Feb 9, 2023
cd26ce4
Update template generators with simpler syntax using cssMsnData
B-Teague Feb 9, 2023
8c1eb88
delete tests
B-Teague Feb 10, 2023
7ca4a9d
generators and templates
B-Teague Feb 10, 2023
8acd2a2
updated indices
B-Teague Feb 10, 2023
fdd8454
updated indices
B-Teague Feb 10, 2023
f6fb511
updated indices
B-Teague Feb 10, 2023
413ac09
Merge branch 'cristianbote:master' into cssProps
B-Teague Feb 10, 2023
c2f95fd
Generate README
B-Teague Feb 10, 2023
6092ff2
Finish units
B-Teague Feb 10, 2023
b395825
Remove jsdocs
B-Teague Feb 11, 2023
d8b2735
Remove jsdocs
B-Teague Feb 11, 2023
f23d677
Remove jsdocs
B-Teague Feb 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Prev Previous commit
Next Next commit
Add mustache templates and regen
  • Loading branch information
B-Teague committed Nov 28, 2021
commit bc7095a1043353300ebaba5f750ee2e0df68c4e0
16 changes: 16 additions & 0 deletions cssProps/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cssProps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"mdn-browser-compat-data": "^1.1.2",
"mdn-data": "^2.0.22",
"microbundle": "^0.12.4",
"mustache": "^4.2.0",
"preact": "^10.5.6"
}
}
91 changes: 17 additions & 74 deletions cssProps/scripts/generateAtRules.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const jetpack = require('fs-jetpack')
const mdnData = require('mdn-data')
const jetpack = require('fs-jetpack');
const mdnData = require('mdn-data');
//[ 'api', 'css', 'l10n' ]

const cssData = mdnData.css;
//[ 'atRules', 'selectors', 'types', 'properties', 'syntaxes', 'units' ]

const cssAtRules = cssData.atRules
const cssAtRules = cssData.atRules;
// '@counter-style': {
// syntax: '@counter-style <counter-style-name> {\n' +
// ' [ system: <counter-system>; ] ||\n' +
Expand Down Expand Up @@ -37,85 +37,28 @@ const cssAtRules = cssData.atRules
// mdn_url: 'https://developer.mozilla.org/docs/Web/CSS/@counter-style'
// },


const cssStandardAtRules = Object.keys(cssAtRules).reduce((result, nextKey) => {
if(cssAtRules[nextKey].status === 'standard'){
result[nextKey] = cssAtRules[nextKey]
const cssStandardAtRules = Object.keys(cssAtRules).reduce((result, nextKey) => {
if (cssAtRules[nextKey].status === 'standard') {
result[nextKey] = cssAtRules[nextKey];
}
return result
}, {})

// jetpack.write('./cssStandardAtRules.json', cssStandardAtRules)


let indexTemplate = "//Do not modify this file. This file is generated from ./scripts/generateAtRules.js\n"
let testTemplate = `//Do not modify this file. This file is generated from ./scripts/generateAtRules.js
import * as cssAtRules from '../index';
import { color, maxWidth } from '../../props/index';
import { css, setup } from 'goober';

jest.mock('goober', () => ({
css: jest.fn().mockReturnValue('css()')
}));

describe('cssAtRules', () => {
beforeEach(() => {
css.mockClear();
});
`
return result;
}, {});

//Loop through all the css properties generating the source code, the root index file, and the jest tests
Object.keys(cssStandardAtRules).forEach(atRule => {
const isNested = ['@charset', '@import', '@namespace'].includes(atRule) ? false : true
const atRuleCamelCase = toCamelCase(atRule.slice(1)) //Also removes '@' character

jetpack.dir(`./src/atRules/${atRuleCamelCase}`);
jetpack.write(`./src/atRules/${atRuleCamelCase}/index.js`, functionIndexTemplate(atRule, atRuleCamelCase));

indexTemplate += `export { default as ${atRuleCamelCase} } from './${atRuleCamelCase}/index'\n`

testTemplate += `
it('${atRule} type', () => {
expect(typeof cssAtRules.${atRuleCamelCase}).toEqual('function');
});

it('${atRule}', () => {
expect(cssAtRules.${atRuleCamelCase}("(param)", [
color("blue"),
maxWidth("100px")
])).toEqual({"${atRule} (param)": {"color": "blue", "maxWidth": "100px"}});
});
Object.keys(cssStandardAtRules).forEach((atRule) => {
const isNested = ['@charset', '@import', '@namespace'].includes(atRule) ? false : true;
const atRuleCamelCase = toCamelCase(atRule.slice(1)); //Also removes '@' character

`
jetpack.dir(`./src/atRules/${atRuleCamelCase}`);
jetpack.write(
`./src/atRules/${atRuleCamelCase}/index.js`,
functionIndexTemplate(atRule, atRuleCamelCase)
);
});

testTemplate += "});"
jetpack.write('./src/atRules/index.js', indexTemplate);
jetpack.write('./src/atRules/__tests__/atRules.test.js', testTemplate);

function toCamelCase(str) {
return str.replace(/-[a-z]/g, g => g[1].toUpperCase())
return str.replace(/-[a-z]/g, (g) => g[1].toUpperCase());
}

function functionIndexTemplate(atRule, atRuleCamelCase) {
return `//Do not modify this file. This file is generated from ./scripts/generateAtRules.js
/**
* @name ${atRuleCamelCase}
* @category CssProps Helper
* @summary Returns a numerical value appended with the css atRule ${atRule}
*
* @description
* Returns a numerical value appended with the css atRule ${atRule}
*
* @param {number} atRule- The numerical value that the css atRule will be appended
* @returns {string} numerical value with appended atRule ${atRule}
*/

export default function charset(atRuleParams, arrayOfCssProps) {
return {
["${atRule}" + (atRuleParams ? " " + atRuleParams : "")]: arrayOfCssProps.reduce((result, cssPropObj) => {
return Object.assign(result, cssPropObj)
}, {})
}
}`
}
100 changes: 30 additions & 70 deletions cssProps/scripts/generateProps.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
const jetpack = require('fs-jetpack')
const mdnData = require('mdn-data')
const jetpack = require('fs-jetpack');
const Mustache = require('mustache');
const mdnData = require('mdn-data');
//[ 'api', 'css', 'l10n' ]

const cssData = mdnData.css;
//[ 'atRules', 'selectors', 'types', 'properties', 'syntaxes', 'units' ]

const cssProperties = cssData.properties
const cssStandardProperties = Object.keys(cssProperties).reduce((result, nextKey) => {
if(cssProperties[nextKey].status === 'standard'){
result[nextKey] = cssProperties[nextKey]
const cssProperties = cssData.properties;
const cssStandardProperties = Object.keys(cssProperties).reduce((result, nextKey) => {
if (cssProperties[nextKey].status === 'standard') {
result[nextKey] = cssProperties[nextKey];
}
return result
}, {})

// jetpack.write('./cssProperties.json', cssStandardProperties)
return result;
}, {});

const cssSyntax = Object.keys(cssStandardProperties).map((prop) => {
return cssStandardProperties[prop].syntax
})

// jetpack.write('./cssPropertiesSyntax.json', cssSyntax)

return cssStandardProperties[prop].syntax;
});
// {
// syntax: 'false | true',
// media: 'visual',
Expand All @@ -36,69 +32,33 @@ const cssSyntax = Object.keys(cssStandardProperties).map((prop) => {
// mdn_url: 'https://developer.mozilla.org/docs/Web/CSS/-ms-accelerator'
// }

let indexTemplate = "//Do not modify this file. This file is generated from ./scripts/generateProps.js\n"
let testTemplate = `//Do not modify this file. This file is generated from ./scripts/generateProps.js
import * as cssProps from '../index';
import { css, setup } from 'goober';
const propsIndexTemplate = jetpack.read('./templates/props.index.mustache');
const propsPropIndexTemplate = jetpack.read('./templates/props.prop.index.mustache');
const propsTestTemplate = jetpack.read('./templates/props.test.mustache');

jest.mock('goober', () => ({
css: jest.fn().mockReturnValue('css()')
}));

describe('cssProps', () => {
beforeEach(() => {
css.mockClear();
});
`
const propsListView = {
Props: []
};

//Loop through all the css properties generating the source code, the root index file, and the jest tests
Object.keys(cssStandardProperties).forEach(property => {
Object.keys(cssStandardProperties).forEach((property) => {
const prop = toCamelCase(property);

jetpack.dir(`./src/props/${prop}`);
jetpack.write(`./src/props/${prop}/index.js`, functionIndexTemplate(prop));

indexTemplate += `export { default as ${prop} } from './${prop}/index'\n`

testTemplate += `
it('${prop} type', () => {
expect(typeof cssProps.${prop}).toEqual('function');
});

it('${prop}', () => {
expect(cssProps.${prop}("value")).toEqual({${prop}:'value'});
});
propView = { prop: prop };
propsListView.Props.push(propView);

const propsPropIndexFile = Mustache.render(propsPropIndexTemplate, propView);

`
jetpack.dir(`./src/props/${prop}`);
jetpack.write(`./src/props/${prop}/index.js`, propsPropIndexFile);
});

testTemplate += "});"
jetpack.write('./src/props/index.js', indexTemplate);
jetpack.write('./src/props/__tests__/props.test.js', testTemplate);
const propsIndexFile = Mustache.render(propsIndexTemplate, propsListView);
jetpack.write('./src/props/index.js', propsIndexFile);

const propsTestFile = Mustache.render(propsTestTemplate, propsListView);
jetpack.write('./src/props/__tests__/props.test.js', propsTestFile);

function toCamelCase(str) {
return str.replace(/-[a-z]/g, g => g[1].toUpperCase())
return str.replace(/-[a-z]/g, (g) => g[1].toUpperCase());
}

function functionIndexTemplate(prop) {
return `//Do not modify this file. This file is generated from ./scripts/generateProps.js
import { default as appendArgs } from '../../util/index'

/**
* @name ${prop}
* @category CssProps Helper
* @summary Returns css property ${prop} and value as an object
*
* @description
* Returns an object with the css property ${prop} with its passed in values
*
* @param - One or more parameters that will be appended together based on a delimiter
* @returns ${prop} property as object
*/

export default function ${prop}() {
return {
${prop}: appendArgs(arguments)
}
}`
}
Loading