mirror of
https://github.com/bobwen-dev/react-templates
synced 2025-04-12 00:56:39 +02:00
fixed #63
This commit is contained in:
parent
b3fd044344
commit
205546eb3c
@ -1,6 +1,3 @@
|
||||
/**
|
||||
* Created by avim on 11/9/2014.
|
||||
*/
|
||||
'use strict';
|
||||
var cheerio = require('cheerio');
|
||||
var _ = require('lodash');
|
||||
@ -451,7 +448,7 @@ function convertHtmlToReact(node, context) {
|
||||
stringUtils.addIfMissing(context.boundParams, alias);
|
||||
|
||||
data.innerScope.scopeName += stringUtils.capitalize(alias);
|
||||
data.innerScope.innerMapping[alias] = value;
|
||||
data.innerScope.innerMapping[alias] = 'var ' + alias + ' = ' + value + ';';
|
||||
validateJS(data.innerScope.innerMapping[alias], node, context);
|
||||
});
|
||||
}
|
||||
@ -485,7 +482,7 @@ function convertHtmlToReact(node, context) {
|
||||
}
|
||||
|
||||
if (node.attribs[scopeAttr]) {
|
||||
var scopeVarDeclarations = _.map(data.innerScope.innerMapping, function (v, k) { return 'var ' + k + ' = ' + v + ';'; }).join('\n');
|
||||
var scopeVarDeclarations = _.map(data.innerScope.innerMapping, function (v) { return v; }).join('\n');
|
||||
var functionBody = scopeVarDeclarations + 'return ' + data.body;
|
||||
var generatedFuncName = generateInjectedFunc(context, 'scope' + data.innerScope.scopeName, functionBody, _.keys(data.innerScope.outerMapping));
|
||||
data.body = generatedFuncName + '.apply(this, [' + _.values(data.innerScope.outerMapping).join(',') + '])';
|
||||
|
@ -1,5 +1,5 @@
|
||||
<div>
|
||||
<div rt-repeat="pirate in [{first: 'Jack', last: 'Sparrow', photo: {url: 'jack.jpg'}}, {first: 'Unknown', last: 'Pirate'}]">
|
||||
<div rt-repeat="pirate in [{first: 'Jack', last: 'Sparrow', photo: {url: 'jack.jpg'}}, {first: 'Unknown', last: 'Pirate'}]" key="a{pirateIndex}">
|
||||
<h1>{pirate.first} {pirate.last}</h1>
|
||||
<div rt-if="pirate.photo" rt-scope="pirate.photo.url as url">
|
||||
<img src="{url}"/>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<div>
|
||||
<div rt-scope="15 as fifteen; 10 as ten">
|
||||
<div rt-repeat="number in [111]">
|
||||
<div rt-repeat="pirate in [{name: 'Jack Sparrow', profile: {age: 99}}, {name: 'Someone Else', profile: {age: 98}}]" rt-scope="pirate.profile as profile; 20 as twenty">
|
||||
<div rt-repeat="number in [111]" key="a{numberIndex}">
|
||||
<div rt-repeat="pirate in [{name: 'Jack Sparrow', profile: {age: 99}}, {name: 'Someone Else', profile: {age: 98}}]" rt-scope="pirate.profile as profile; 20 as twenty" key="a{pirateIndex}">
|
||||
{number}-{numberIndex}-{fifteen}-{ten}-{pirateIndex}-{pirate.name}-{profile.age}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,10 +1,10 @@
|
||||
<div>
|
||||
<div rt-repeat="foo in [1]">
|
||||
<div rt-repeat="foo in [1]" key="a{fooIndex}">
|
||||
<!-- can't seem to have an object literal here; will deal with this separately -->
|
||||
<div rt-scope="[{first: 'Jack', last: 'Sparrow', skills: ['talking', 'fighting', 'commandeering']}][0] as pirate; pirate.first as first">
|
||||
<h1>{first} {pirate.last}</h1>
|
||||
<div rt-scope="pirate.skills as skills">
|
||||
<span rt-repeat="skill in skills">{skill}</span>
|
||||
<span rt-repeat="skill in skills" key="a{skillIndex}">{skill}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,8 +1,7 @@
|
||||
<div>
|
||||
<div rt-scope="['a','b','c'] as items">
|
||||
<span rt-repeat="item in items">Item:#{itemIndex} = {item}</span>
|
||||
<span rt-repeat="item in items" key="i-{itemIndex}">Item:#{itemIndex} = {item}</span>
|
||||
</div>
|
||||
<span>{typeof (items) == 'undefined'?'items not in scope':'items in scope'}</span>
|
||||
<span>{typeof (item) == 'undefined'?'item not in scope':'item in scope'}</span>
|
||||
|
||||
</div>
|
||||
|
@ -9,7 +9,6 @@ var fs = require('fs');
|
||||
var _ = require('lodash');
|
||||
var path = require('path');
|
||||
var React = require('react/addons');
|
||||
var cheerio = require('cheerio');
|
||||
var RTCodeError = reactTemplates.RTCodeError;
|
||||
var dataPath = path.resolve(__dirname, '..', 'data');
|
||||
|
||||
@ -194,7 +193,7 @@ test('convert jsrt and test source results', function (t) {
|
||||
test('html tests', function (t) {
|
||||
var files = ['scope.rt', 'scope-trailing-semicolon.rt', 'scope-variable-references.rt', 'lambda.rt', 'eval.rt', 'props.rt', 'custom-element.rt', 'style.rt', 'concat.rt',
|
||||
'js-in-attr.rt', 'props-class.rt', 'rt-class.rt', 'className.rt',
|
||||
'scope-evaluated-after-repeat.rt', 'scope-evaluated-after-repeat2.rt', 'scope-evaluated-after-if.rt'
|
||||
'scope-evaluated-after-repeat.rt', 'scope-evaluated-after-repeat2.rt', 'scope-evaluated-after-if.rt', 'scope-obj.rt'
|
||||
];
|
||||
t.plan(files.length);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user