-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
YRB(.pres) support for language bundles #96
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -403,11 +403,105 @@ var buildCoverage = function (mod, name, callback) { | |
} | ||
callback(); | ||
}); | ||
|
||
}; | ||
|
||
exports.coverage = buildCoverage; | ||
|
||
/** | ||
* Extract heredoc block | ||
* | ||
* @param {Sting} value start line of heredoc with token | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* @param {Int} ix index of the buffer where heredoc starts | ||
* @param {Array} buffer raw array from YRB(.pres) | ||
* @return {Object} heredoc value from heredoc block plus new index to continue into parsePrestoJson method | ||
*/ | ||
var getHeredocString = function(value, ix, buffer) { | ||
var | ||
token = value.replace('<<<', '').trim(), | ||
heredoc = {}; | ||
value = []; | ||
|
||
while ( buffer[ix].indexOf(token) === -1) { | ||
el = buffer[ix]; | ||
if (el.indexOf('#') !== 0) { | ||
value.push(el); | ||
} | ||
ix += 1; | ||
} | ||
heredoc.value = value.join('\\n'); | ||
heredoc.ix = ix + 1; | ||
return heredoc; | ||
}; | ||
|
||
/** | ||
* Parsing YRB(.pres) file content string to a la Json format | ||
* http://yuilibrary.com/yui/docs/intl/#yrb | ||
* | ||
* @param {String} presStr YRB formatted string | ||
* @return {String} buffer Json parsed string from YRB | ||
*/ | ||
var parsePresToJson = function (presStr) { | ||
var | ||
buffer, | ||
key, | ||
value, | ||
ixof, | ||
el, ix = 0, len, | ||
heredoc, | ||
line = [], | ||
buff = []; | ||
|
||
buffer = presStr.split(/\r\n|\n|\r/); | ||
len = buffer.length; | ||
|
||
for (;ix < len;) { | ||
el = buffer[ix++]; | ||
line = []; | ||
|
||
el = el.trim(); | ||
if (el && el.indexOf('#') !== 0) { | ||
key = el.split('=', 1).pop().trim(); | ||
line.push(key); | ||
|
||
ixof = el.indexOf('='); | ||
value = el.slice(++ixof).trim(); | ||
|
||
if ( value.indexOf('<<<') === 0 ) { | ||
heredoc = getHeredocString(value, ix, buffer); | ||
value = heredoc.value; | ||
ix = heredoc.ix; | ||
} | ||
|
||
line.push('"' + value + '"'); | ||
|
||
buff.push(line.join(':')); | ||
} | ||
} | ||
|
||
buffer = '{' + buff.join(',') + '}'; | ||
return buffer; | ||
}; | ||
|
||
/** | ||
* Reads the file in either a la Json(.js) or YRB(.pres) | ||
* formats, and return content in Json | ||
* | ||
* @param {String} modName | ||
* @return {String} output | ||
*/ | ||
var getLangJsonSting = function (modName) { | ||
var | ||
output, | ||
fileExtention = ((fs.existsSync(path.join(shifter.cwd(), 'lang', modName + '.js'))? '.js': '.pres')); | ||
fileNameReadFrom = modName + fileExtention; | ||
output = fs.readFileSync(path.join(shifter.cwd(), 'lang', fileNameReadFrom), 'utf8'); | ||
if (fileExtention === '.pres') { | ||
log.info('parsing lang Json from YRB source ' + fileNameReadFrom ); | ||
output = parsePresToJson(output); | ||
} | ||
return output; | ||
}; | ||
|
||
var buildLang = function (mod, name, callback) { | ||
var langs = [''].concat(mod.config.lang), | ||
stack = new Stack(); | ||
|
@@ -421,7 +515,7 @@ var buildLang = function (mod, name, callback) { | |
}), | ||
modName = name + (lang ? '_' + lang : ''), | ||
fileName = modName + '.js', | ||
strings = fs.readFileSync(path.join(shifter.cwd(), 'lang', fileName), 'utf8'); | ||
strings = getLangJsonSting(modName); | ||
|
||
queue.read([path.join(__dirname, '../files/langtemplate.txt')]) | ||
.replace(replaceOptions) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do this, please. We can't take this pull request because of this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry I did not realize it will be included in request, that's my first pull request on github
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, no need to change this anyway, since all pushes to a given pull request branch will cause builds under yui3's Travis space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am struggling with running tests on local env, so as intern solution trying to use travis (better than nothing). Thanks for comments, I will be back :)