@40q/40q-cli 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@40q/40q-cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "40q CLI tool",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -1,5 +1,7 @@
1
- export const typeChoices = ['block'] as const;
1
+ import { config } from '../../config';
2
+
3
+ export const typeChoices = config.typeChoices;
2
4
  export type Types = (typeof typeChoices)[number];
3
5
 
4
- export const templateChoices = ['section-header'] as const;
6
+ export const templateChoices = config.templateChoices.block;
5
7
  export type Templates = (typeof templateChoices)[number] | 'default';
@@ -42,7 +42,7 @@ export class GenerateBlock {
42
42
  process.cwd(),
43
43
  `resources/views/blocks/${this.name}.blade.php`
44
44
  ),
45
- ''
45
+ this.getTemplate('blade')
46
46
  );
47
47
 
48
48
  fs.writeFileSync(
@@ -71,11 +71,15 @@ export class GenerateBlock {
71
71
  }
72
72
 
73
73
  private getTemplate(name: string) {
74
- const cliRoot = findCliRoot(__dirname);
75
- const templateFolder = `templates/blocks/${this.template}`;
76
- return fs.readFileSync(
77
- path.join(cliRoot, `${templateFolder}/${name}.txt`),
78
- 'utf8'
79
- );
74
+ try {
75
+ const cliRoot = findCliRoot(__dirname);
76
+ const templateFolder = `templates/blocks/${this.template}`;
77
+ return fs.readFileSync(
78
+ path.join(cliRoot, `${templateFolder}/${name}.txt`),
79
+ 'utf8'
80
+ );
81
+ } catch (e) {
82
+ return '';
83
+ }
80
84
  }
81
85
  }
package/src/config.ts ADDED
@@ -0,0 +1,6 @@
1
+ export const config = {
2
+ typeChoices: ['block'] as const,
3
+ templateChoices: {
4
+ block: ['section-header'] as const
5
+ },
6
+ }
@@ -0,0 +1,15 @@
1
+ <?php
2
+
3
+ namespace App\Blocks;
4
+
5
+ class {{camelCaseName}} extends BlockHandler
6
+ {
7
+ public function __invoke($block_content, $block)
8
+ {
9
+ return view('blocks.{{name}}', [
10
+ 'eyebrow' => $block['attrs']['eyebrow'] ?? null,
11
+ 'title' => $block['attrs']['title'] ?? null,
12
+ 'description' => $block['attrs']['description'] ?? null,
13
+ ]);
14
+ }
15
+ }
@@ -0,0 +1,120 @@
1
+ import { __ } from "@wordpress/i18n";
2
+ import { PanelBody, ToggleControl } from "@wordpress/components";
3
+ import {
4
+ InspectorControls,
5
+ RichText,
6
+ useBlockProps,
7
+ useInnerBlocksProps,
8
+ } from "@wordpress/block-editor";
9
+
10
+ /* Block name */
11
+ export const name = "by40q/{{name}}";
12
+
13
+ /* Block title */
14
+ export const title = __("{{title}}", "40q");
15
+
16
+ /* Block category */
17
+ export const category = "text";
18
+
19
+ /* Block attributes */
20
+ export const attributes = {
21
+ showEyebrow: {
22
+ type: "boolean",
23
+ default: true,
24
+ },
25
+ eyebrow: {
26
+ type: "string",
27
+ default: "Introducing",
28
+ },
29
+ title: {
30
+ type: "string",
31
+ default: "40Q",
32
+ },
33
+ showDescription: {
34
+ type: "boolean",
35
+ default: true,
36
+ },
37
+ description: {
38
+ type: "string",
39
+ default:
40
+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, diam id tincidunt ultrices, nunc nisl ultrices nunc, vitae aliquam nisl nunc eu nisl. Sed euismod, diam id tincidunt ultrices, nunc nisl ultrices nunc, vitae aliquam nisl nunc eu nisl.",
41
+ },
42
+ showCta: {
43
+ type: "boolean",
44
+ default: false,
45
+ },
46
+ };
47
+
48
+ /* Block edit */
49
+ export const edit = ({ attributes, setAttributes }) => {
50
+ const { showEyeBrow, eyebrow, title, showDescription, description, showCta } =
51
+ attributes;
52
+
53
+ const blockProps = useBlockProps();
54
+
55
+ const innerBlocksProps = useInnerBlocksProps(blockProps, {
56
+ template: [["core/button"]],
57
+ allowedBlocks: [],
58
+ templateLock: "all",
59
+ });
60
+
61
+ return (
62
+ <>
63
+ <InspectorControls>
64
+ <PanelBody title={__("Section Header Settings")} initialOpen>
65
+ <ToggleControl
66
+ label="Eyebrow"
67
+ checked={!!showEyeBrow}
68
+ onChange={(showEyeBrow) => setAttributes({ showEyeBrow })}
69
+ />
70
+ <ToggleControl
71
+ label="Description"
72
+ checked={!!showDescription}
73
+ onChange={(showDescription) => setAttributes({ showDescription })}
74
+ />
75
+
76
+ <ToggleControl
77
+ label="Cta"
78
+ checked={!!showCta}
79
+ onChange={(showCta) => setAttributes({ showCta })}
80
+ />
81
+ </PanelBody>
82
+ </InspectorControls>
83
+
84
+ <div {...blockProps}>
85
+ {!!showEyeBrow && (
86
+ <RichText
87
+ className=""
88
+ tagName="p"
89
+ placeholder={__("Eyebrow")}
90
+ value={eyebrow}
91
+ onChange={(eyebrow) => setAttributes({ eyebrow })}
92
+ />
93
+ )}
94
+ <RichText
95
+ className=""
96
+ tagName="h2"
97
+ placeholder={__("40Q")}
98
+ value={title}
99
+ onChange={(title) => setAttributes({ title })}
100
+ />
101
+ {!!showDescription && (
102
+ <RichText
103
+ className=""
104
+ tagName="p"
105
+ placeholder={__("Lorem ipsum dolor sit amet.")}
106
+ value={description}
107
+ onChange={(description) => setAttributes({ description })}
108
+ />
109
+ )}
110
+ {!!showCta && <div {...innerBlocksProps} />}
111
+ </div>
112
+ </>
113
+ );
114
+ };
115
+
116
+ /* Block save */
117
+ export const save = <></>;
118
+
119
+ /* Block styles */
120
+ export const styles = [];