Skip to content

Commit

Permalink
Fixes #9294
Browse files Browse the repository at this point in the history
Differential Revision: D3752878

fbshipit-source-id: f248082effde9133dd6a9edf8a2f2cfc05279eab
  • Loading branch information
grabbou authored and Facebook Github Bot 7 committed Aug 22, 2016
1 parent b59fde8 commit 107fc72
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
20 changes: 20 additions & 0 deletions local-cli/link/__tests__/android/makeStringsPatch.spec.js
@@ -0,0 +1,20 @@
'use strict';

jest.autoMockOff();

const makeStringsPatch = require('../../android/patches/makeStringsPatch');

describe('makeStringsPatch', () => {
it('should export a patch with <string> element', () => {
const params = {
keyA: 'valueA',
};

expect(makeStringsPatch(params, 'module').patch)
.toContain('<string moduleConfig="true" name="module_keyA">valueA</string>');
});

it('should export an empty patch if no params given', () => {
expect(makeStringsPatch({}, 'module').patch).toBe('');
});
});
17 changes: 11 additions & 6 deletions local-cli/link/android/patches/makeStringsPatch.js
@@ -1,14 +1,19 @@
const toCamelCase = require('lodash').camelCase;

module.exports = function makeStringsPatch(params, prefix) {
const patch = Object.keys(params).map(param => {
const name = toCamelCase(prefix) + '_' + param;
return ' ' +
`<string moduleConfig="true" name="${name}">${params[param]}</string>`;
}).join('\n') + '\n';
const values = Object.keys(params)
.map(param => {
const name = toCamelCase(prefix) + '_' + param;
return ' ' +
`<string moduleConfig="true" name="${name}">${params[param]}</string>`;
});

const patch = values.length > 0
? values.join('\n') + '\n'
: '';

return {
pattern: '<resources>\n',
patch: patch,
patch,
};
};

0 comments on commit 107fc72

Please sign in to comment.