([^<>]+)<\/title>/g,
36 | replace: `DocHead.setTitle("$1");`
37 | }
38 | ];
39 |
--------------------------------------------------------------------------------
/package.js:
--------------------------------------------------------------------------------
1 | Package.describe({
2 | name: 'timbrandin:blaze-react',
3 | version: '0.4.0',
4 | summary: 'React templates for Meteor',
5 | git: 'https://github.com/timbrandin/blaze-react',
6 | documentation: 'README.md'
7 | });
8 |
9 | Package.registerBuildPlugin({
10 | name: 'blaze-react',
11 | use: [
12 | 'ecmascript@0.1.6',
13 | 'babel-compiler@5.8.24_1',
14 | 'underscore@1.0.4',
15 | 'tracker@1.0.9',
16 | ],
17 | sources: [
18 | // 'lib/xregexp.js',
19 | 'lib/template-regex.js',
20 | 'lib/react-regex.js',
21 | 'lib/react-template-compiler.js',
22 | 'plugin/plugin.js'
23 | ],
24 | npmDependencies: {
25 | 'xregexp': '3.0.0'
26 | }
27 | });
28 |
29 | Package.onUse(function (api) {
30 | api.versionsFrom('1.2.1');
31 |
32 | api.use([
33 | 'ecmascript@0.1.6',
34 | 'underscore@1.0.4',
35 | 'isobuild:compiler-plugin@1.0.0',
36 | 'react-runtime@0.14.1_1',
37 | 'jsx@0.1.6',
38 | 'check',
39 | 'minimongo'
40 | ]);
41 | api.imply([
42 | 'ecmascript@0.1.6',
43 | 'babel-runtime@0.1.4',
44 | 'react-runtime@0.14.1_1',
45 | 'kadira:dochead@1.3.2',
46 | 'timbrandin:safestring@0.0.1',
47 | 'timbrandin:classnames@0.0.1'
48 | ]);
49 |
50 | api.use('kadira:flow-router-ssr@3.5.0', ['client', 'server'], {weak: true});
51 |
52 | api.addFiles([
53 | 'lib/blaze-react.jsx',
54 | 'lib/create-from-blaze.js',
55 | 'lib/fragment.jsx',
56 | 'lib/inject.jsx',
57 | 'lib/context-proxy.js'
58 | ]);
59 |
60 | api.export(['ReactTemplate', 'Template', 'Fragment', 'Inject']);
61 | });
62 |
63 | Npm.depends({'xregexp': '3.0.0'});
64 |
65 | Package.onTest(function (api) {
66 | api.use([
67 | 'ecmascript@0.1.6',
68 | 'babel-compiler@5.8.24_1',
69 | 'underscore@1.0.4',
70 | 'tracker@1.0.9',
71 | ]);
72 |
73 | api.addFiles([
74 | 'lib/template-regex.js',
75 | 'lib/react-regex.js',
76 | 'lib/react-template-compiler.js'
77 | ]);
78 |
79 | api.use("tinytest");
80 | api.use("timbrandin:blaze-react");
81 | api.addFiles("test/test.js", "server");
82 | });
83 |
--------------------------------------------------------------------------------
/plugin/plugin.js:
--------------------------------------------------------------------------------
1 | Plugin.registerCompiler({
2 | extensions: ['html'],
3 | isTemplate: true
4 | }, () => new ReactTemplateCompiler()
5 | );
6 |
--------------------------------------------------------------------------------
/test/test.js:
--------------------------------------------------------------------------------
1 | Tinytest.add(
2 | "blaze-react - transpiling - {{#each docs}}", function (test, expect) {
3 | let str = `
4 |
5 | {{#each docs}}
6 | Hello world
7 | {{/each}}
8 |
9 | `;
10 | test.equal(ReactCompiler.parseMarkup(str), `
11 |
12 | {context('docs', 'array').length > 0 ? context('docs', 'array').map((context, index) => {return (
13 | Hello world
14 | )}):''}
15 |
16 | `);
17 | });
18 |
19 | Tinytest.add(
20 | "blaze-react - transpiling - {{#each docs}} {{else}}", function (test, expect) {
21 | let str = `
22 |
23 | {{#each docs}}
24 | Hello world
25 | {{else}}
26 | No documents found.
27 | {{/each}}
28 |
29 | `;
30 | test.equal(ReactCompiler.parseMarkup(str), `
31 |
32 | {context('docs', 'array').length > 0 ? context('docs', 'array').map((context, index) => {return (
33 | Hello world
34 | )}):(
35 | No documents found.
36 | )}
37 |
38 | `);
39 | });
40 |
41 | Tinytest.add(
42 | "blaze-react - transpiling - {{#each docs}} (nested)", function (test, expect) {
43 | let str = `
44 |
45 | {{#each docs}}
46 | {{#each docs}}
47 | Hello world
48 | {{/each}}
49 | {{/each}}
50 |
51 | `;
52 | test.equal(ReactCompiler.parseMarkup(str), `
53 |
54 | {context('docs', 'array').length > 0 ? context('docs', 'array').map((context, index) => {return (
55 | {context('docs', 'array').length > 0 ? context('docs', 'array').map((context, index) => {return (
56 | Hello world
57 | )}):''}
58 | )}):''}
59 |
60 | `);
61 | });
62 |
63 | Tinytest.add(
64 | "blaze-react - transpiling - {{#each doc in docs}}", function (test, expect) {
65 | let str = `
66 |
67 | {{#each doc in docs}}
68 | Hello world
69 | {{/each}}
70 |
71 | `;
72 | test.equal(ReactCompiler.parseMarkup(str), `
73 |
74 | {context('docs', 'array').length > 0 ? context('docs', 'array', 'doc').map((context, index) => {return (
75 | Hello world
76 | )}):''}
77 |
78 | `);
79 | });
80 |
81 | Tinytest.add(
82 | "blaze-react - transpiling - {{#each doc in docs}} (nested)", function (test, expect) {
83 | let str = `
84 |
85 | {{#each doc in docs}}
86 | {{#each doc in docs}}
87 | Hello world
88 | {{/each}}
89 | {{/each}}
90 |
91 | `;
92 | test.equal(ReactCompiler.parseMarkup(str), `
93 |
94 | {context('docs', 'array').length > 0 ? context('docs', 'array', 'doc').map((context, index) => {return (
95 | {context('docs', 'array').length > 0 ? context('docs', 'array', 'doc').map((context, index) => {return (
96 | Hello world
97 | )}):''}
98 | )}):''}
99 |
100 | `);
101 | });
102 |
103 | Tinytest.add(
104 | "blaze-react - transpiling - {{#with doc}}", function (test, expect) {
105 | let str = `
106 |
107 | {{#with doc}}
108 | Hello world {{name}}
109 | {{/with}}
110 |
111 | `;
112 | test.equal(ReactCompiler.parseMarkup(str), `
113 |
114 | {context('doc') ? (
115 | Hello world {context('name')}
116 | ):''}
117 |
118 | `);
119 | });
120 |
121 | Tinytest.add(
122 | "blaze-react - transpiling - {{#with doc}} (nested)", function (test, expect) {
123 | let str = `
124 |
125 | {{#with doc}}
126 | {{#with doc}}
127 | Hello world {{name}}
128 | {{/with}}
129 | {{/with}}
130 |
131 | `;
132 | test.equal(ReactCompiler.parseMarkup(str), `
133 |
134 | {context('doc') ? (
135 | {context('doc') ? (
136 | Hello world {context('name')}
137 | ):''}
138 | ):''}
139 |
140 | `);
141 | });
142 |
143 | Tinytest.add(
144 | "blaze-react - transpiling - {{#if boolean}}", function (test, expect) {
145 | let str = `
146 |
147 | {{#if true}}
148 | Hello world
149 | {{/if}}
150 |
151 | `;
152 | test.equal(ReactCompiler.parseMarkup(str), `
153 |
154 | {true ? (
155 | Hello world
156 | ):''}
157 |
158 | `);
159 | });
160 |
161 | Tinytest.add(
162 | "blaze-react - transpiling - {{#if helper}}", function (test, expect) {
163 | str = `
164 |
165 | {{#if docs}}
166 | Hello world
167 | {{/if}}
168 |
169 | `;
170 | test.equal(ReactCompiler.parseMarkup(str), `
171 |
172 | {context('docs') ? (
173 | Hello world
174 | ):''}
175 |
176 | `);
177 | });
178 |
179 | Tinytest.add(
180 | "blaze-react - transpiling - {{#if helper arg=value}}", function (test, expect) {
181 | str = `
182 |
183 | {{#if docs arg=value}}
184 | Hello world
185 | {{/unless}}
186 |
187 | `;
188 | test.equal(ReactCompiler.parseMarkup(str), `
189 |
190 | {context('docs', {arg: context('value')}) ? (
191 | Hello world
192 | ):''}
193 |
194 | `);
195 | });
196 |
197 | Tinytest.add(
198 | "blaze-react - transpiling - {{#if helper arg1=value arg2=value}}", function (test, expect) {
199 | str = `
200 |
201 | {{#if docs arg1=value arg2=value}}
202 | Hello world
203 | {{/unless}}
204 |
205 | `;
206 | test.equal(ReactCompiler.parseMarkup(str), `
207 |
208 | {context('docs', {arg1: context('value'), arg2: context('value')}) ? (
209 | Hello world
210 | ):''}
211 |
212 | `);
213 | });
214 |
215 | Tinytest.add(
216 | "blaze-react - transpiling - {{#if helper}} (nested)", function (test, expect) {
217 | str = `
218 |
219 | {{#if docs}}
220 | {{#if docs}}
221 | Hello world
222 | {{/if}}
223 | {{/if}}
224 |
225 | `;
226 | test.equal(ReactCompiler.parseMarkup(str), `
227 |
228 | {context('docs') ? (
229 | {context('docs') ? (
230 | Hello world
231 | ):''}
232 | ):''}
233 |
234 | `);
235 | });
236 |
237 | Tinytest.add(
238 | "blaze-react - transpiling - {{#unless boolean}}", function (test, expect) {
239 | let str = `
240 |
241 | {{#unless true}}
242 | Hello world
243 | {{/unless}}
244 |
245 | `;
246 | test.equal(ReactCompiler.parseMarkup(str), `
247 |
248 | {!true ? (
249 | Hello world
250 | ):''}
251 |
252 | `);
253 | });
254 |
255 | Tinytest.add(
256 | "blaze-react - transpiling - {{#unless helper}}", function (test, expect) {
257 | str = `
258 |
259 | {{#unless docs}}
260 | Hello world
261 | {{/unless}}
262 |
263 | `;
264 | test.equal(ReactCompiler.parseMarkup(str), `
265 |
266 | {!context('docs') ? (
267 | Hello world
268 | ):''}
269 |
270 | `);
271 | });
272 |
273 | Tinytest.add(
274 | "blaze-react - transpiling - {{#unless helper arg=value}}", function (test, expect) {
275 | str = `
276 |
277 | {{#unless docs arg=value}}
278 | Hello world
279 | {{/unless}}
280 |
281 | `;
282 | test.equal(ReactCompiler.parseMarkup(str), `
283 |
284 | {!context('docs', {arg: context('value')}) ? (
285 | Hello world
286 | ):''}
287 |
288 | `);
289 | });
290 |
291 | Tinytest.add(
292 | "blaze-react - transpiling - {{#unless helper arg1=value arg2=value}}", function (test, expect) {
293 | str = `
294 |
295 | {{#unless docs arg1=value arg2=value}}
296 | Hello world
297 | {{/unless}}
298 |
299 | `;
300 | test.equal(ReactCompiler.parseMarkup(str), `
301 |
302 | {!context('docs', {arg1: context('value'), arg2: context('value')}) ? (
303 | Hello world
304 | ):''}
305 |
306 | `);
307 | });
308 |
309 | Tinytest.add(
310 | "blaze-react - transpiling - {{#unless helper}} (nested)", function (test, expect) {
311 | str = `
312 |
313 | {{#unless docs}}
314 | {{#unless docs}}
315 | Hello world
316 | {{/unless}}
317 | {{/unless}}
318 |
319 | `;
320 | test.equal(ReactCompiler.parseMarkup(str), `
321 |
322 | {!context('docs') ? (
323 | {!context('docs') ? (
324 | Hello world
325 | ):''}
326 | ):''}
327 |
328 | `);
329 | });
330 |
331 | Tinytest.add(
332 | "blaze-react - transpiling - {{> template}}", function (test, expect) {
333 | let str = `
334 |
335 | {{> template}}
336 |
337 | `;
338 | test.equal(ReactCompiler.parseMarkup(str), `
339 |
340 |
341 |
342 | `);
343 | });
344 |
345 | Tinytest.add(
346 | "blaze-react - transpiling - {{helper}}", function (test, expect) {
347 | let str = `
348 |
349 | {{helper}}
350 |
351 | `;
352 | test.equal(ReactCompiler.parseMarkup(str), `
353 |
354 | {context('helper')}
355 |
356 | `);
357 | });
358 |
359 | Tinytest.add(
360 | "blaze-react - transpiling - {{helper arg=value}}", function (test, expect) {
361 | let str = `
362 |
363 | {{helper arg=value}}
364 |
365 | `;
366 | test.equal(ReactCompiler.parseMarkup(str), `
367 |
368 | {context('helper', {arg: context('value')})}
369 |
370 | `);
371 | });
372 |
373 | Tinytest.add(
374 | "blaze-react - transpiling - {{helper arg1=value arg2=value}}", function (test, expect) {
375 | let str = `
376 |
377 | {{helper arg1=value arg2=value}}
378 |
379 | `;
380 | test.equal(ReactCompiler.parseMarkup(str), `
381 |
382 | {context('helper', {arg1: context('value'), arg2: context('value')})}
383 |
384 | `);
385 | });
386 |
387 | Tinytest.add(
388 | "blaze-react - transpiling - {{helper \"arg1\" arg2=value arg3=\"arg3\"}}", function (test, expect) {
389 | let str = `
390 |
391 | {{helper "arg1" arg2=value arg3="arg3"}}
392 |
393 | `;
394 | test.equal(ReactCompiler.parseMarkup(str), `
395 |
396 | {context('helper', {0: "arg1", arg2: context('value'), arg3: "arg3"})}
397 |
398 | `);
399 | });
400 |
401 | Tinytest.add(
402 | "blaze-react - transpiling - {{{helper}}} (raw HTML)", function (test, expect) {
403 | let str = `
404 |
405 | {{{helper}}}
406 |
407 | `;
408 | test.equal(ReactCompiler.parseMarkup(str), `
409 |
410 |
411 |
412 | `);
413 | });
414 |
415 | Tinytest.add(
416 | "blaze-react - transpiling - {{{helper arg=value}}}} (raw HTML)", function (test, expect) {
417 | let str = `
418 |
419 | {{{helper arg=value}}}
420 |
421 | `;
422 | test.equal(ReactCompiler.parseMarkup(str), `
423 |
424 |
425 |
426 | `);
427 | });
428 |
429 | Tinytest.add(
430 | "blaze-react - transpiling - {{{helper arg1=value arg2=value}}}} (raw HTML)", function (test, expect) {
431 | let str = `
432 |
433 | {{{helper arg1=value arg2=value}}}
434 |
435 | `;
436 | test.equal(ReactCompiler.parseMarkup(str), `
437 |
438 |
439 |
440 | `);
441 | });
442 |
443 | Tinytest.add(
444 | "blaze-react - transpiling - {{{helper \"arg1\" arg2=value arg3=\"arg3\"}}} (raw HTML)", function (test, expect) {
445 | let str = `
446 |
447 | {{{helper "arg1" arg2=value arg3="arg3"}}}
448 |
449 | `;
450 | test.equal(ReactCompiler.parseMarkup(str), `
451 |
452 |
453 |
454 | `);
455 | });
456 |
457 | Tinytest.add(
458 | "blaze-react - transpiling - class={{helper}} – Dynamic Attribute (class)", function (test, expect) {
459 | let str = `
460 |
461 |
462 | `;
463 | test.equal(ReactCompiler.parseMarkup(str), `
464 |
465 |
466 | `);
467 | });
468 |
469 | Tinytest.add(
470 | "blaze-react - transpiling - class={{helper arg=value}} – Dynamic Attribute (class)", function (test, expect) {
471 | let str = `
472 |
473 |
474 | `;
475 | test.equal(ReactCompiler.parseMarkup(str), `
476 |
477 |
478 | `);
479 | });
480 |
481 | Tinytest.add(
482 | "blaze-react - transpiling - class={{helper arg1=value arg2=value}} – Dynamic Attribute (class)", function (test, expect) {
483 | let str = `
484 |
485 |
486 | `;
487 | test.equal(ReactCompiler.parseMarkup(str), `
488 |
489 |
490 | `);
491 | });
492 |
493 | Tinytest.add(
494 | "blaze-react - transpiling - class={{helper \"arg1\" arg2=value arg3=\"arg3\"}} – Dynamic Attribute (class)", function (test, expect) {
495 | let str = `
496 |
497 |
498 | `;
499 | test.equal(ReactCompiler.parseMarkup(str), `
500 |
501 |
502 | `);
503 | });
504 |
505 | Tinytest.add(
506 | "blaze-react - transpiling - title={{helper}} – Dynamic Attribute (other)", function (test, expect) {
507 | let str = `
508 |
509 |
510 | `;
511 | test.equal(ReactCompiler.parseMarkup(str), `
512 |
513 |
514 | `);
515 | });
516 |
517 | Tinytest.add(
518 | "blaze-react - transpiling - class=\"{{helper}}\" – In Attribute Values (class)", function (test, expect) {
519 | let str = `
520 |
521 |
522 | `;
523 | test.equal(ReactCompiler.parseMarkup(str), `
524 |
525 |
526 | `);
527 | });
528 |
529 | Tinytest.add(
530 | "blaze-react - transpiling - class=\"{{helper arg=value}}\" – In Attribute Values (class)", function (test, expect) {
531 | let str = `
532 |
533 |
534 | `;
535 | test.equal(ReactCompiler.parseMarkup(str), `
536 |
537 |
538 | `);
539 | });
540 |
541 | Tinytest.add(
542 | "blaze-react - transpiling - class=\"{{helper arg1=value arg2=value}}\" – In Attribute Values (class)", function (test, expect) {
543 | let str = `
544 |
545 |
546 | `;
547 | test.equal(ReactCompiler.parseMarkup(str), `
548 |
549 |
550 | `);
551 | });
552 |
553 | Tinytest.add(
554 | "blaze-react - transpiling - class=\"{{helper \"arg1\" arg2=value arg3=\"arg3\"}}\" – In Attribute Values (class)", function (test, expect) {
555 | let str = `
556 |
557 |
558 | `;
559 | test.equal(ReactCompiler.parseMarkup(str), `
560 |
561 |
562 | `);
563 | });
564 |
565 | Tinytest.add(
566 | "blaze-react - transpiling - title=\"{{helper}}\" – In Attribute Values (other)", function (test, expect) {
567 | let str = `
568 |
569 |
570 | `;
571 | test.equal(ReactCompiler.parseMarkup(str), `
572 |
573 |
574 | `);
575 | });
576 |
577 | Tinytest.add(
578 | "blaze-react - transpiling - template", function (test, expect) {
579 | let str = `
580 |
581 | Hello world
582 |
583 | `;
584 | test.equal(ReactCompiler.parse(str), `
585 | React.Component.createFromBlaze("template", "template", function(context) {return (
586 | Hello world
587 | )});
588 | `);
589 | });
590 |
591 | Tinytest.add(
592 | "blaze-react - transpiling - body", function (test, expect) {
593 | let str = `
594 |
595 |