Skip to content
This repository has been archived by the owner on Nov 21, 2018. It is now read-only.

Commit

Permalink
build process #264: deep merge for i18n template.json, switches to `s…
Browse files Browse the repository at this point in the history
…ource/project.js` (vs json)
  • Loading branch information
snostorm committed Mar 4, 2015
1 parent 6193fe0 commit fcb2fb8
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 18 deletions.
31 changes: 19 additions & 12 deletions content/en/template.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
{
"browser-title":"io.js - JavaScript I/O",
"contribute-message":"See something you like? Want to help? Visit https://github.com/iojs/website to contribute",
"heading-languages":"Languages",
"logo-text":"io.js",
"faq-link":"FAQ",
"es6-link":"ES6",
"api-link":"API Docs",
"issues-link":"GitHub Issues",
"org-link":"GitHub Org",
"irc-link":"IRC Chat",
"irc-logs-link":"Logs",
"gov-link":"Governance"
"browser-title": "io.js - JavaScript I/O",
"contribute-message": "See something you like? Want to help? Visit https://github.com/iojs/website to contribute",
"heading-languages": "Languages",
"logo-text": "io.js",
"faq-link": "FAQ",
"es6-link": "ES6",
"api-link": "API Docs",
"issues-link": "GitHub Issues",
"org-link": "GitHub Org",
"irc-link": "IRC Chat",
"irc-logs-link": "Logs",
"gov-link": "Governance",
"downloads": {
"linux": "Linux",
"win32": "Win32",
"win64": "Win64",
"mac": "Mac",
"all": "Others"
}
}
2 changes: 1 addition & 1 deletion gulp/tasks/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function generateContentAndTemplates() {
*/
base = path.resolve(__dirname, '..', '..'); /* 1 */
contentBase = path.resolve(base, 'content'); /* 2 */
projectJSON = require('../../source/project.json'); /* 3 */
projectJSON = require('../../source/project.js'); /* 3 */
i18nJSON = {}; /* 4 */
hbsTemplates = {}; /* 5 */

Expand Down
17 changes: 12 additions & 5 deletions gulp/util/template-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ var CONTENT_DIRECTORY = 'content';
// load template.json for given language, but use default language as fallback
// for properties which are not present in the given language
module.exports.loadTemplateJSON = function(lang) {
var defaultJSON = require('../../' + CONTENT_DIRECTORY + '/' + DEFAULT_LANG + '/template.json');
var defaultJSON = require('../../' + CONTENT_DIRECTORY + '/' + DEFAULT_LANG + '/template.json');
var templateJSON = require('../../' + CONTENT_DIRECTORY + '/' + lang + '/template.json');
var finalJSON = _.cloneDeep(defaultJSON);
_.forEach(templateJSON, function(value, key) {
finalJSON[key] = value;
});
var merge = function(targetJSON, customJSON) {
_.forEach(customJSON, function(value, key) {
if (typeof value === "object") {
merge(targetJSON[key], value)
} else {
targetJSON[key] = value;
}
});
}
merge(finalJSON, templateJSON)
return finalJSON;
};

Expand Down Expand Up @@ -39,4 +46,4 @@ module.exports.loadMdFiles = function(contentFiles, lang) {
return obj;
});
return templateFilesInThisLang;
};
};
46 changes: 46 additions & 0 deletions source/project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// temporary merge to help avoid some merge confusion when landed:
var project = require('./project.json');

/*
// This will replace `./project.json`

This comment has been minimized.

Copy link
@therebelrobot

therebelrobot Mar 6, 2015

Contributor

@snostorm Is there a reason this should be merged with project.json? I'd prefer the data for this be separated from the logic, and having a separate json file makes it easy to update that without touching actual code. Keeps things a little more atomic.

This comment has been minimized.

Copy link
@snostorm

snostorm Mar 6, 2015

Author Contributor

We could keep both, I have mixed feelings.

If anything as this evolves, we might just include smaller partials vs one big one. So, a languages.json would include from here, for example. (Replacing the inline languages array.)

I think a lot of the data managed here will be generated or use tricks to keep things DRY. So, for example, a "Version History" page might need download, changelog, API doc, etc. URLs generated for each version.

The current_version_downloads, further down, is basically one step away from being in a function that would feed in a version number (for example.)

This comment has been minimized.

Copy link
@snostorm

snostorm Mar 7, 2015

Author Contributor

@therebelrobot I've been thinking about this more.

In my local branch I've already split off a languages.json and content.json (to track special info about how to render specific content) and while I like keeping them .json in theory we lose out on the ability to add comments, and on occasion, organize the document in a more readable/object-driven ways.

A big JSON file of like 30, 40, 50 languages or pages will get hard to follow as one big object/tree.

That all said, I would like to keep the files very singular in purpose. So, a languages.js (vs .json) would still only contain a very specific set of data.

This comment has been minimized.

Copy link
@therebelrobot

therebelrobot Mar 8, 2015

Contributor

Agreed on the commenting and the fact that one big json file would be unwieldy. Let's try out using the .js files for that data, see how it works for us.

project = {
"current_version": "1.4.3",
"current_v8": "4.1.0.21"
}
project.languages = [
{"code": "cn", "name": "简体中文", "name-en": "Chinese (Simple)"},
{"code": "de", "name": "Deutsch", "name-en": "German"},
{"code": "el", "name": "Ελληνικά", "name-en": "Greek"},
{"code": "en", "name": "English", "name-en": "English"},
{"code": "es", "name": "Español", "name-en": "Spanish"},
{"code": "fi", "name": "Suomi", "name-en": "Finnish"},
{"code": "fr", "name": "Français", "name-en": "French"},
{"code": "he", "name": "עברית", "name-en": "Hebrew", "rtl": true},
{"code": "id", "name": "Bahasa Indonesia", "name-en": "Indonesian"},
{"code": "it", "name": "Italiano", "name-en": "Italian"},
{"code": "ja", "name": "日本語", "name-en": "Japanese"},
{"code": "ko", "name": "한국어", "name-en": "Korean"},
{"code": "no", "name": "Norsk", "name-en": "Norwegian"},
{"code": "pt_BR", "name": "Português (BR)", "name-en": "Portuguese (Brazil)"},
{"code": "pt_PT", "name": "Português (PT)", "name-en": "Portuguese (Portugal)"},
{"code": "ru", "name": "Русский", "name-en": "Russian"},
{"code": "tr", "name": "Türkçe", "name-en": "Turkish"},
{"code": "uk", "name": "Українська", "name-en": "Ukrainian"},
{"code": "zh_TW", "name": "正體中文(台灣)", "name-en": "Chinese Traditional (Taiwan)"}
]
*/

var baseURL = `https://iojs.org/dist`;
project.current_version_downloads = [
{key: 'linux', url: `${baseURL}/${project.current_version}/iojs-${project.current_version}-linux-x64.tar.xz`},
{key: 'win32', url: `${baseURL}/${project.current_version}/iojs-${project.current_version}-x86.msi`},
{key: 'win64', url: `${baseURL}/${project.current_version}/iojs-${project.current_version}-x64.msi`},
{key: 'mac', url: `${baseURL}/${project.current_version}/iojs-${project.current_version}.pkg`},
{key: 'all', url: `${baseURL}/${project.current_version}/`}
];
Object.defineProperty(project.current_version_downloads, 'all', {value: `${baseURL}/${project.current_version}/`});

module.exports = project;

0 comments on commit fcb2fb8

Please sign in to comment.