ember-tribe 2.6.4 → 2.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ # ember-tribe
2
+
3
+ For information about ember-tribe, visit [https://tribe-framework.org/frontend](https://tribe-framework.org/frontend).
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ /**
5
+ * php-dist — single-file edition
6
+ *
7
+ * Usage: node php-dist
8
+ *
9
+ * Reads dist/index.html, injects PHP includes, strips <title> and
10
+ * <meta name="description">, prepends _init.php, and writes dist/index.php.
11
+ * Replicates the behaviour of `php sync-dist.php`.
12
+ */
13
+
14
+ const fs = require('fs');
15
+ const path = require('path');
16
+
17
+ // ---------------------------------------------------------------------------
18
+ // Helpers
19
+ // ---------------------------------------------------------------------------
20
+
21
+ /** Minimal colour helpers — same feel as the PHP tput calls */
22
+ const green = (s) => `\x1b[32m${s}\x1b[0m`;
23
+ const red = (s) => `\x1b[31m${s}\x1b[0m`;
24
+ const hr = '~~~~~~~~~~';
25
+
26
+ /**
27
+ * Remove every occurrence of a tag (and its contents) that matches a
28
+ * predicate. We do this with a regex-free string walk so we never need
29
+ * a full DOM parser dependency.
30
+ *
31
+ * @param {string} html
32
+ * @param {string} tagName — lower-case tag name, e.g. 'title' or 'meta'
33
+ * @param {(attrs: string) => boolean} predicate
34
+ * @returns {string}
35
+ */
36
+ function removeTags(html, tagName, predicate) {
37
+ const result = [];
38
+ let i = 0;
39
+
40
+ while (i < html.length) {
41
+ // Look for the opening '<'
42
+ const openAngle = html.indexOf('<', i);
43
+ if (openAngle === -1) { result.push(html.slice(i)); break; }
44
+
45
+ // Collect everything up to this '<'
46
+ result.push(html.slice(i, openAngle));
47
+
48
+ // Find the end of this tag
49
+ const closeAngle = html.indexOf('>', openAngle);
50
+ if (closeAngle === -1) { result.push(html.slice(openAngle)); break; }
51
+
52
+ const rawTag = html.slice(openAngle + 1, closeAngle); // e.g. 'meta name="description" ...'
53
+ const isSelfClosing = rawTag.endsWith('/');
54
+ const tagBody = isSelfClosing ? rawTag.slice(0, -1).trim() : rawTag.trim();
55
+ const spaceIdx = tagBody.search(/[\s/]/);
56
+ const tag = (spaceIdx === -1 ? tagBody : tagBody.slice(0, spaceIdx)).toLowerCase();
57
+ const attrs = spaceIdx === -1 ? '' : tagBody.slice(spaceIdx);
58
+
59
+ if (tag === tagName && predicate(attrs)) {
60
+ // For void / self-closing elements (like <meta>) there is no closing tag.
61
+ const voidElements = new Set(['area','base','br','col','embed','hr','img','input',
62
+ 'link','meta','param','source','track','wbr']);
63
+ if (voidElements.has(tagName) || isSelfClosing) {
64
+ // Just skip the tag entirely — move past '>'
65
+ i = closeAngle + 1;
66
+ } else {
67
+ // Skip tag + inner content + closing tag
68
+ const closing = `</${tagName}>`;
69
+ const closeIdx = html.toLowerCase().indexOf(closing, closeAngle + 1);
70
+ if (closeIdx === -1) {
71
+ // No closing tag found — skip just the opening tag
72
+ i = closeAngle + 1;
73
+ } else {
74
+ i = closeIdx + closing.length;
75
+ }
76
+ }
77
+ } else {
78
+ // Not a match — keep it
79
+ result.push(`<${rawTag}>`);
80
+ i = closeAngle + 1;
81
+ }
82
+ }
83
+
84
+ return result.join('');
85
+ }
86
+
87
+ // ---------------------------------------------------------------------------
88
+ // Main
89
+ // ---------------------------------------------------------------------------
90
+
91
+ (function main() {
92
+ const cwd = process.cwd();
93
+ const inputFile = path.join(cwd, 'dist', 'index.html');
94
+ const outputFile = path.join(cwd, 'dist', 'index.php');
95
+
96
+ if (!fs.existsSync(inputFile)) {
97
+ console.log(hr);
98
+ console.log(red('Run "ember build -prod" before syncing with PHP.'));
99
+ console.log(hr);
100
+ process.exit(1);
101
+ }
102
+
103
+ let html = fs.readFileSync(inputFile, 'utf8');
104
+
105
+ // Inject PHP includes ---------------------------------------------------
106
+
107
+ // Before <title>: _head.php
108
+ html = html.replace('<title>', '<?php include_once("_head.php");?><title>');
109
+
110
+ // Before </head>: _head_footer.php
111
+ html = html.replace('</head>', '<?php include_once("_head_footer.php");?></head>');
112
+
113
+ // Before </body>: _body_footer.php
114
+ html = html.replace('</body>', '<?php include_once("_body_footer.php");?></body>');
115
+
116
+ // Remove <meta name="description"> ------------------------------------
117
+ html = removeTags(html, 'meta', (attrs) => {
118
+ // Match name="description" or name='description'
119
+ return /name\s*=\s*["']description["']/i.test(attrs);
120
+ });
121
+
122
+ // Remove <title>…</title> --------------------------------------------
123
+ html = removeTags(html, 'title', () => true);
124
+
125
+ // Prepend _init.php ---------------------------------------------------
126
+ html = '<?php include_once("_init.php");?>' + html;
127
+
128
+ // Write output --------------------------------------------------------
129
+ fs.writeFileSync(outputFile, html, 'utf8');
130
+
131
+ console.log(hr);
132
+ console.log(green('Middleware successfully installed. Synced "/dist" folder with PHP.'));
133
+ console.log(hr);
134
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-tribe",
3
- "version": "2.6.4",
3
+ "version": "2.6.5",
4
4
  "description": "The default blueprint for using Tribe API and Junction within EmberJS.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -1,58 +0,0 @@
1
- <?php
2
- if (file_exists('dist/index.html') !== false) {
3
- //get html
4
- $html = file_get_contents('dist/index.html');
5
-
6
- //replace head, before title
7
- $html = str_replace('<title>', '<?php include_once("_head.php");?><title>', $html);
8
-
9
- //replace head-footer, before </head> ends
10
- $html = str_replace('</head>', '<?php include_once("_head_footer.php");?></head>', $html);
11
-
12
- //replace body-footer, before </body> ends
13
- $html = str_replace('</body>', '<?php include_once("_body_footer.php");?></body>', $html);
14
-
15
- //load dom
16
- $dom = new DOMDocument();
17
- $dom->loadHTML($html);
18
-
19
- //for tags to be removed
20
- $remove = [];
21
-
22
- //remove meta description tag
23
- $metas = $dom->getElementsByTagName('meta');
24
- for($i=0; $i <$metas-> length; $i++) {
25
- $name = $metas->item($i)->getAttribute("name");
26
- if ($name == 'description')
27
- $remove[] = $metas->item($i);
28
- }
29
-
30
- //remove title tag
31
- $titles = $dom->getElementsByTagName('title');
32
- foreach($titles as $item)
33
- $remove[] = $item;
34
-
35
- //remove identified tags
36
- foreach ($remove as $item)
37
- $item->parentNode->removeChild($item);
38
-
39
- //save edit dom html
40
- $html = $dom->saveHTML();
41
-
42
- //prepend _init.php for $type and $slug and Tribe composer
43
- $html = '<?php include_once("_init.php");?>'.$html;
44
-
45
- //save to file
46
- file_put_contents('dist/index.php', $html);
47
-
48
- //echo success message on commandline
49
- echo '~~~~~~~~~~'."\r\n";
50
- echo `tput setaf 2`.'Middleware successfully installed. Synced "/dist" folder with PHP.'.`tput sgr0`."\r\n";
51
- echo '~~~~~~~~~~'."\r\n";
52
- }
53
- else {
54
- echo '~~~~~~~~~~'."\r\n";
55
- echo `tput setaf 1`.'Run "ember build -prod" before syncing with PHP.'.`tput sgr0`."\r\n";
56
- echo '~~~~~~~~~~'."\r\n";
57
- }
58
- ?>