diff options
author | Valerio Virgillito | 2012-05-11 14:46:51 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-05-11 14:46:51 -0700 |
commit | 1fb663b5f348fe2ff5ce86a80e8a61be289eba70 (patch) | |
tree | 7ccb54a07eb4adf793bae3f1a4ddd622bd4f9a0c /js/mediators | |
parent | 647a7cf0697debe7b3d6fa0d68cd6b37996d6b59 (diff) | |
parent | d2e1d4eeba4439ed26f2adf1c34991caf44a591f (diff) | |
download | ninja-1fb663b5f348fe2ff5ce86a80e8a61be289eba70.tar.gz |
Merge pull request #222 from joseeight/Document
Adding partial support for templates
Diffstat (limited to 'js/mediators')
-rw-r--r-- | js/mediators/io-mediator.js | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index dae0f359..0bff1f3b 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -53,14 +53,14 @@ exports.IoMediator = Montage.create(Component, { | |||
53 | // | 53 | // |
54 | fileNew: { | 54 | fileNew: { |
55 | enumerable: false, | 55 | enumerable: false, |
56 | value: function (file, template, callback) { | 56 | value: function (file, url, callback, template) { |
57 | //Loading template from template URL | 57 | //Loading template from template URL |
58 | var xhr = new XMLHttpRequest(), result; | 58 | var xhr = new XMLHttpRequest(), result; |
59 | xhr.open("GET", template, false); | 59 | xhr.open("GET", url, false); |
60 | xhr.send(); | 60 | xhr.send(); |
61 | if (xhr.readyState === 4) { | 61 | if (xhr.readyState === 4) { |
62 | //Making call to create file, checking for return code | 62 | //Making call to create file, checking for return code |
63 | switch (this.fio.newFile({ uri: file, contents: xhr.response })) { | 63 | switch (this.fio.newFile({ uri: file, contents: parseTemplate(xhr.response, template) })) { |
64 | case 201: | 64 | case 201: |
65 | result = { status: 201, success: true, uri: file }; | 65 | result = { status: 201, success: true, uri: file }; |
66 | break; | 66 | break; |
@@ -74,6 +74,20 @@ exports.IoMediator = Montage.create(Component, { | |||
74 | result = { status: 500, success: false, uri: file }; | 74 | result = { status: 500, success: false, uri: file }; |
75 | break; | 75 | break; |
76 | } | 76 | } |
77 | //TODO: Improve template data injection | ||
78 | function parseTemplate (content, template) { | ||
79 | // | ||
80 | if (template.name.toLowerCase() === 'banner') { | ||
81 | //Getting dimensions of banner | ||
82 | var dimensions = template.id.split('x'); | ||
83 | dimensions = {width: String(dimensions[0])+'px', height: String(dimensions[1])+'px'}; | ||
84 | // | ||
85 | content = content.replace(/Dimensions@@@/gi, "Dimensions@@@"+template.id); | ||
86 | content = content.replace(/ninja-banner {}/gi, "ninja-banner {width: "+dimensions.width+"; height: "+dimensions.height+"}"); | ||
87 | } | ||
88 | // | ||
89 | return content; | ||
90 | } | ||
77 | } else { | 91 | } else { |
78 | result = { status: 500, success: false, uri: file }; | 92 | result = { status: 500, success: false, uri: file }; |
79 | } | 93 | } |