Skip to content

Commit

Permalink
Merge pull request #5 from facebook/docs-a
Browse files Browse the repository at this point in the history
[website] Extract platform metadata from components
  • Loading branch information
mkonicek committed Jul 24, 2015
2 parents d15b077 + f88ec5f commit 62a5584
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions website/server/extractDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ var path = require('path');
var slugify = require('../core/slugify');
var jsDocs = require('../jsdocs/jsdocs.js');

var ANDROID_SUFFIX = 'android';
var CROSS_SUFFIX = 'cross';
var IOS_SUFFIX = 'ios';

function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}

function getNameFromPath(filepath) {
var ext = null;
while (ext = path.extname(filepath)) {
Expand All @@ -30,10 +38,24 @@ function getNameFromPath(filepath) {
return filepath;
}

function getExample(componentName) {
function getPlatformFromPath(filepath) {
var ext = null;
while (ext = path.extname(filepath)) {
filepath = path.basename(filepath, ext);
}

if (endsWith(filepath, 'Android')) {
return ANDROID_SUFFIX;
} else if (endsWith(filepath, 'IOS')) {
return IOS_SUFFIX;
}
return CROSS_SUFFIX;
}

function getExample(componentName, componentPlatform) {
var path = '../Examples/UIExplorer/' + componentName + 'Example.js';
if (!fs.existsSync(path)) {
path = '../Examples/UIExplorer/' + componentName + 'Example.ios.js';
path = '../Examples/UIExplorer/' + componentName + 'Example.'+ componentPlatform +'.js';
if (!fs.existsSync(path)) {
return;
}
Expand Down Expand Up @@ -83,18 +105,20 @@ function getNextComponent(i) {

function componentsToMarkdown(type, json, filepath, i, styles) {
var componentName = getNameFromPath(filepath);

var componentPlatform = getPlatformFromPath(filepath);
var docFilePath = '../docs/' + componentName + '.md';

if (fs.existsSync(docFilePath)) {
json.fullDescription = fs.readFileSync(docFilePath).toString();
}
json.type = type;
json.filepath = filepath.replace(/^\.\.\//, '');
json.componentName = componentName;
json.componentPlatform = componentPlatform;
if (styles) {
json.styles = styles;
}
json.example = getExample(componentName);
json.example = getExample(componentName, componentPlatform);

// Put Flexbox into the Polyfills category
var category = (type === 'style' ? 'Polyfills' : type + 's');
Expand All @@ -107,6 +131,7 @@ function componentsToMarkdown(type, json, filepath, i, styles) {
'layout: autodocs',
'category: ' + category,
'permalink: docs/' + slugify(componentName) + '.html',
'platform: ' + componentPlatform,
'next: ' + next,
'sidebar: ' + shouldDisplayInSidebar(componentName),
'runnable:' + isRunnable(componentName),
Expand Down

0 comments on commit 62a5584

Please sign in to comment.