File tree Expand file tree Collapse file tree 6 files changed +104
-0
lines changed Expand file tree Collapse file tree 6 files changed +104
-0
lines changed Original file line number Diff line number Diff line change @@ -171,6 +171,7 @@ public function convert(): string
171
171
if ($ scriptElement ) {
172
172
$ this ->registerProperties ($ scriptElement );
173
173
$ this ->insertDefaultValues ();
174
+ $ this ->registerData ($ scriptElement );
174
175
}
175
176
176
177
if ($ twigBlocks ->length ) {
@@ -467,6 +468,15 @@ public function registerProperties(DOMElement $scriptElement): void
467
468
}
468
469
}
469
470
471
+ public function registerData (DOMElement $ scriptElement ): void
472
+ {
473
+ if ($ scriptElement ->hasAttribute ('lang ' ) && $ scriptElement ->getAttribute ('lang ' ) === 'ts ' ) {
474
+ // TypeScript
475
+ } else {
476
+ // JavaScript
477
+ }
478
+ }
479
+
470
480
/**
471
481
* @throws Exception
472
482
*/
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Paneon \VueToTwig \Tests ;
4
+
5
+ use Exception ;
6
+
7
+ class DataTest extends AbstractTestCase
8
+ {
9
+ /**
10
+ * @dataProvider dataProvider
11
+ *
12
+ * @param mixed $html
13
+ * @param mixed $expected
14
+ *
15
+ * @throws Exception
16
+ */
17
+ public function testData ($ html , $ expected )
18
+ {
19
+ $ compiler = $ this ->createCompiler ($ html );
20
+
21
+ $ actual = $ compiler ->convert ();
22
+
23
+ $ this ->assertEqualHtml ($ expected , $ actual );
24
+ }
25
+
26
+ /**
27
+ * @return array
28
+ */
29
+ public function dataProvider ()
30
+ {
31
+ return $ this ->loadFixturesFromDir ('data ' );
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ {% set bar = bar | default (' baz' ) %}
2
+ <div class =" {{ class | default (' ' ) }}" style =" {{ style | default (' ' ) }}" > Hello World! </div >
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <div >
3
+ Hello World!
4
+ </div >
5
+ </template >
6
+
7
+ <script lang="ts">
8
+ import { Vue , Component , Prop } from ' vue-property-decorator' ;
9
+
10
+ @Component ()
11
+ export default class Foo extends Vue {
12
+
13
+ @Prop ({ type: String , default: ' baz' }) readonly bar! : string ;
14
+
15
+ private myNumber = 1 ;
16
+
17
+ private myString = ' foo' ;
18
+
19
+ private myArray: [' a' , ' b' , ' c' ];
20
+
21
+ private myObject: { a: ' x' , b: ' y' , c: ' z' };
22
+ };
23
+ </script >
Original file line number Diff line number Diff line change
1
+ {% set bar = bar | default (' baz' ) %}
2
+ <div class =" {{ class | default (' ' ) }}" style =" {{ style | default (' ' ) }}" > Hello World! </div >
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <div >
3
+ Hello World!
4
+ </div >
5
+ </template >
6
+
7
+ <script >
8
+ export default {
9
+ name: ' Foo' ,
10
+ props: {
11
+ bar: {
12
+ type: String ,
13
+ default: ' baz' ,
14
+ },
15
+ },
16
+ data () {
17
+ return {
18
+ myNumber: 1 ,
19
+ myString: ' foo' ,
20
+ myArray: [
21
+ ' a' ,
22
+ ' b' ,
23
+ ' c' ,
24
+ ],
25
+ myObject: {
26
+ a: ' x' ,
27
+ b: ' y' ,
28
+ c: ' z' ,
29
+ },
30
+ calculatedNumber: this .myString .length + 1 ,
31
+ };
32
+ },
33
+ };
34
+ </script >
You can’t perform that action at this time.
0 commit comments