@@ -8,27 +8,44 @@ class PatternkitPattern {
88 /**
99 * PatternkitPattern constructor.
1010 *
11+ * @param \PatternkitLibInterface $library
12+ * The library the pattern belongs to.
13+ *
1114 * @param object|array $schema
1215 * An optional JSON Schema object to use.
1316 */
14- public function __construct ($ schema = array ()) {
17+ public function __construct (PatternkitLibInterface $ library , $ schema = array ()) {
1518 $ this ->subtype = NULL ;
1619 $ this ->title = NULL ;
1720 $ this ->html = NULL ;
18- $ this ->library = NULL ;
1921 $ this ->version = NULL ;
2022 $ this ->attachments = NULL ;
2123 $ this ->schema = $ schema ;
2224 if (empty ($ schema )) {
2325 return ;
2426 }
2527 foreach ($ schema as $ key => $ value ) {
26- if ($ key !== 'schema ' && property_exists ($ this , $ key )) {
28+ if ($ key !== 'schema ' && property_exists ($ this , ( string ) $ key )) {
2729 $ this ->{$ key } = $ value ;
2830 }
2931 }
32+ $ this ->library = $ library ;
3033 }
3134
35+ /**
36+ * The required minimum data for a pattern.
37+ *
38+ * @ingroup required
39+ * @{
40+ */
41+
42+ /**
43+ * The Patternkit Library that loaded the pattern.
44+ *
45+ * @var \PatternkitLibInterface
46+ */
47+ public $ library ;
48+
3249 /**
3350 * The subtype for the pattern. Typically "pk_$pattern".
3451 *
@@ -46,11 +63,8 @@ public function __construct($schema = array()) {
4663 public $ title ;
4764
4865 /**
49- * An override TTL in ms for the pattern.
50- *
51- * @var int
66+ * @}
5267 */
53- public $ ttl ;
5468
5569 /**
5670 * Optional array of attached assets.
@@ -83,18 +97,18 @@ public function __construct($schema = array()) {
8397 public $ body ;
8498
8599 /**
86- * Pre-rendered HTML using the configuration object, if available .
100+ * The pattern template file .
87101 *
88102 * @var string
89103 */
90- public $ html ;
104+ public $ filename ;
91105
92106 /**
93- * The Patternkit Library that loaded the pattern .
107+ * Pre-rendered HTML using the configuration object, if available .
94108 *
95- * @var \PatternkitLibInterface
109+ * @var string
96110 */
97- public $ library ;
111+ public $ html ;
98112
99113 /**
100114 * The JSON Schema for the pattern.
@@ -105,6 +119,22 @@ public function __construct($schema = array()) {
105119 */
106120 public $ schema ;
107121
122+ /**
123+ * Optional pattern template contents.
124+ *
125+ * Typically Twig or Nunjucks, others include Handlebars and Jinja.
126+ *
127+ * @var string
128+ */
129+ public $ template ;
130+
131+ /**
132+ * An override TTL in ms for the pattern.
133+ *
134+ * @var int
135+ */
136+ public $ ttl ;
137+
108138 /**
109139 * The API URL for the pattern.
110140 *
@@ -132,4 +162,17 @@ public function fetchAssets(PatternkitEditorConfig $config) {
132162 return $ this ;
133163 }
134164
165+ /**
166+ * Renders the pattern and returns the generated markup.
167+ *
168+ * @param \PatternkitEditorConfig $config
169+ * The editor configuration for the pattern.
170+ *
171+ * @return string
172+ * The rendered HTML pattern markup.
173+ */
174+ public function getRenderedMarkup (PatternkitEditorConfig $ config ) {
175+ return $ this ->library ->getRenderedPatternMarkup ($ this , $ config );
176+ }
177+
135178}
0 commit comments