Skip to content

Commit

Permalink
[#129] Adding styles and variations
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-schmidt-viget committed Jul 24, 2024
1 parent d2f1ff6 commit 2444cc5
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 8 deletions.
26 changes: 25 additions & 1 deletion wp-content/themes/wp-starter/plop-templates/block.json.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,35 @@
"category": "components",
"textdomain": "wp-starter",
"keywords": ["{{dashCase name}}"],
"attributes": {
"align": {
"type": "string",
"default": "full"
},
"style": {
"type": "object",
"default": {
"spacing": {
"padding": {
"top": "var:preset|spacing|20",
"bottom": "var:preset|spacing|20",
"left": "var:preset|spacing|20",
"right": "var:preset|spacing|20"
}
}
}
}
},
"supports": {
"jsx": true,
"mode": false,
"alignWide": true
"alignWide": true,
"color": {
"background": true
}
},
-- PREPEND STYLES HERE --
-- PREPEND VARIATIONS HERE --
"acf": {
"mode": "preview"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"styles": [
{
"name": "default",
"label": "Default",
"isDefault": true
}
],
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"variations": [
{
"name": "{{dashCase name}}-variation",
"icon": "schedule",
"title": "{{titleCase name}} Variation",
"scope": ["transform"],
"isDefault": true
}
],
68 changes: 61 additions & 7 deletions wp-content/themes/wp-starter/plopfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,68 @@ module.exports = function (plop) {
{
type: 'input',
name: 'name',
message: 'What is the block name?'
message: 'What is the block name?',
validate: function (value) {
if (/.+/.test(value)) {
return true;
}
return "Name is required";
},
},
{
type: 'confirm',
name: 'styles',
message: 'Do you want block styles?'
},
{
type: 'confirm',
name: 'variations',
message: 'Do you want block variations?'
}
],
actions: [{
type: 'addMany',
destination: 'blocks/{{name}}/',
base: 'plop-templates',
templateFiles: 'plop-templates/*.hbs'
}]
actions: function(data) {
var actions = [{
type: 'addMany',
destination: 'blocks/{{dashCase name}}/',
base: 'plop-templates',
templateFiles: 'plop-templates/*.hbs',
abortOnFail: true,
}];

// add styles
if (data.styles) {
actions.push({
type: 'modify',
path: 'blocks/{{dashCase name}}/block.json',
pattern: /-- PREPEND STYLES HERE --/gi,
templateFile: 'plop-templates/parts/styles.json.hbs'
});
} else {
actions.push({
type: 'modify',
path: 'blocks/{{dashCase name}}/block.json',
pattern: /-- PREPEND STYLES HERE --/gi
});
}

// add styles
if (data.styles) {
actions.push({
type: 'modify',
path: 'blocks/{{dashCase name}}/block.json',
pattern: /-- PREPEND VARIATIONS HERE --/gi,
templateFile: 'plop-templates/parts/variations.json.hbs'
});
} else {
actions.push({
type: 'modify',
path: 'blocks/{{dashCase name}}/block.json',
pattern: /-- PREPEND VARIATIONS HERE --/gi
});
}


return actions;
}
});
};

0 comments on commit 2444cc5

Please sign in to comment.