Skip to content

Commit

Permalink
Added support for binding on the parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmackrodt committed Feb 9, 2016
1 parent 488cf29 commit 762775e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
1 change: 0 additions & 1 deletion Hcas.njsproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<PropertyGroup Condition="'$(Configuration)' == 'Debug'" />
<PropertyGroup Condition="'$(Configuration)' == 'Release'" />
<ItemGroup>
<Content Include="HcasTestApp\index.vash" />
<Content Include="package.json" />
<Content Include="README.md" />
<Content Include="example.hcas" />
Expand Down
4 changes: 2 additions & 2 deletions HcasTestApp/index.hcas
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<StackPanel orientation="vertical"
horizontalAlign="stretch"
background="#000000">
<Header text="This is the Header" />
<Header text="{binding title}" />

<Grid>
<!--Grid.Columns>
Expand All @@ -16,7 +16,7 @@

<StackPanel>
<Button content="Button Top" />
<TextBlock text="TextBlock with normal text property" />
<TextBlock text="{binding message}" />
</StackPanel>

<TextBlock text="Before Text: This is a full, hardcoded paragraph where you can write full texts in the way you want." />
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports.__express = function (filePath, options, callback) {
process.exit(1);
}

hcas.parse(data.substring(0, data.length), function(result) {
hcas.parse(data.substring(0, data.length), options, function(result) {
rendered = result.render();
return callback(null, rendered);
});
Expand Down
2 changes: 1 addition & 1 deletion nodeTestApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var router = express.Router();

router.get('/', function (req, res) {
console.log('Rendering view...')
res.render('index.hcas', { title: 'Hey', message: 'Hello there!'});
res.render('index.hcas', { title: 'Bound title', message: 'Hello there!'});
});

// router.get('/', function (req, res) {
Expand Down
2 changes: 1 addition & 1 deletion src/hcas.htmlBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var HtmlBuilder = function () {
return buildTag(item);
else if (item.$endTag)
return buildEndTag(item);
else if (item.$raw)
else if (item.$raw || typeof item.$raw === 'string')
return item.$raw;
else if (item.$childrenPlacement)
return item.$childrenPlacement();
Expand Down
26 changes: 19 additions & 7 deletions src/hcas.parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var utils = require('./hcas.utils.js');
var Control = require('./hcas.control.js');
var sax = require('sax');

var repository;
var controlRepository;
var documentBindings = {};

var tree = {
name: "HcasDocument",
Expand Down Expand Up @@ -36,17 +37,27 @@ function getPreviousNode() {
return nodeObj;
}

function parseBinding(value) {
var regex = /^{\s*binding\s+(\w+)\s*}$/g;
var match = regex.exec(value);
if (match !== null) {
var key = match[1];
return documentBindings[key] || '';
}

return value;
}

parser.onattribute = function (attr) {
currentAttributes[attr.name] = attr.value;
currentAttributes[attr.name] = parseBinding(attr.value);

logTree(attr.name);
};

parser.onopentag = function (tag) {
var node = getPreviousNode();

var ct = repository.retrieveControl(tag.name);
var ct = controlRepository.retrieveControl(tag.name);
var control = new Control(ct);
levels.push(control);

Expand Down Expand Up @@ -93,11 +104,12 @@ parser.onend = function () {
finishedCallback(tree);
};

module.exports = function(repo) {
repository = repo;
module.exports = function(repository) {
controlRepository = repository;
return {
parse: function (document, callback) {
finishedCallback = callback;
parse: function (document, bindings, callback) {
finishedCallback = callback;
documentBindings = bindings;
parser.write(document).close();
}
};
Expand Down

0 comments on commit 762775e

Please sign in to comment.