2
2
3
3
namespace Blocks ;
4
4
5
- use Blocks \Script ;
6
- use Blocks \Attribute ;
5
+ use \Blocks \Script ;
6
+ use \Blocks \Attribute ;
7
+
8
+ use \Blocks \Traits \Register ;
9
+ use \Blocks \Traits \Compose ;
7
10
8
11
use function Roots \view ;
9
12
use function Roots \asset ;
13
16
*/
14
17
class Builder
15
18
{
19
+ public $ namespace ;
20
+
21
+ public $ name ;
22
+
23
+ public $ designation ;
24
+
25
+ public $ attributes ;
26
+
27
+ public $ type ;
28
+
29
+ public $ editor_script ;
30
+
31
+ public $ style ;
32
+
33
+ public $ handling ;
34
+
16
35
/**
17
36
* Construct
18
37
*/
19
- public function __construct ($ namespace )
38
+ public function __construct ()
20
39
{
21
- /**
22
- * Block namespace
23
- */
24
- $ this ->namespace = 'sage ' ;
25
-
26
- /**
27
- * Block name
28
- */
29
- $ this ->name = 'card ' ;
30
-
31
- /**
32
- * Block attributes
33
- **/
34
- $ this ->attributes = [];
35
-
36
- /**
37
- * Editor script
38
- */
39
- $ this ->editor_script = object;
40
-
41
- /**
42
- * Style
43
- */
44
- $ this ->style = object;
45
-
46
- /**
47
- * Handling
48
- *
49
- * Use in usingScript, etc. to determine
50
- * what parameter we are manipulating call-to-call
51
- */
52
- $ this ->handling = '' ;
53
-
54
- /**
55
- * Set namespace if passed as param
56
- */
57
- if (isset ($ namespace )) {
58
- $ this ->setNamespace ($ namespace );
59
- }
60
-
40
+ $ this ->compose ();
61
41
return $ this ;
62
42
}
63
43
44
+ use Compose;
45
+
64
46
/**
65
47
* Set block namespace
66
48
*
@@ -74,19 +56,6 @@ public function setNamespace($name)
74
56
return $ this ;
75
57
}
76
58
77
- /**
78
- * setNamespace() sugar
79
- *
80
- * @param string namespace
81
- * @return self
82
- */
83
- public function namespace ($ name )
84
- {
85
- $ this ->setNamespace ($ name );
86
-
87
- return $ this ;
88
- }
89
-
90
59
/**
91
60
* Set block name
92
61
*
@@ -100,19 +69,6 @@ public function setName($name)
100
69
return $ this ;
101
70
}
102
71
103
- /**
104
- * setName() sugar
105
- *
106
- * @param string name
107
- * @return self
108
- */
109
- public function name ($ name )
110
- {
111
- $ this ->setName ($ name );
112
-
113
- return $ this ;
114
- }
115
-
116
72
/**
117
73
* Get qualified name
118
74
*/
@@ -160,87 +116,4 @@ public function addString($name)
160
116
161
117
return $ this ;
162
118
}
163
-
164
- /**
165
- * Set Style
166
- *
167
- * @param string style reference
168
- * @return self
169
- * @todo #todo incomplete
170
- */
171
- public function style ($ style_name )
172
- {
173
- $ this ->assets ->style = "{$ this ->namespace }- {$ style_name }" ;
174
-
175
- return $ this ;
176
- }
177
-
178
- /**
179
- * Add Script
180
- */
181
- public function addEditorScript ($ definition = null )
182
- {
183
- $ this ->editor_script = $ definition
184
- ? new Script ($ definition )
185
- : new Script ([
186
- 'namespace ' => $ this ->namespace ,
187
- 'name ' => $ this ->name ,
188
- 'type ' => 'block ' ,
189
- ]);
190
-
191
- $ this ->handling = 'editor_script ' ;
192
-
193
- return $ this ->editor_script ;
194
- }
195
-
196
- /**
197
- * Uses existing editor_script
198
- *
199
- * @param mixed script
200
- * @return self
201
- */
202
- public function usesEditorScript ($ namespace , $ name )
203
- {
204
- if (is_string ($ script )) {
205
- $ this ->editor_script = new Script ([
206
- 'name ' => $ name ,
207
- 'namespace ' => $ namespace ,
208
- ]);
209
- }
210
-
211
- return $ this ;
212
- }
213
-
214
- /**
215
- * Register blocktype
216
- *
217
- * @param object data
218
- * @return void
219
- */
220
- public function register ()
221
- {
222
- add_action ('init ' , function () {
223
- register_block_type ($ this ->getDesignation (), [
224
- 'attributes ' => $ this ->attributes ,
225
- 'editor_script ' => $ this ->editor_script ->getDesignation (),
226
- 'render_callback ' => function ($ attributes ) {
227
- return view (
228
- "blocks. {$ this ->name }. {$ this ->name }" ,
229
- $ this ->data ($ attributes )
230
- );
231
- }
232
- ]);
233
- });
234
- }
235
-
236
- /**
237
- * Data
238
- *
239
- * @param array block attributes
240
- * @return array view data
241
- */
242
- public function data ($ attributes )
243
- {
244
- return $ attributes ;
245
- }
246
119
}
0 commit comments