diff options
Diffstat (limited to 'platform/darwin/scripts')
-rw-r--r-- | platform/darwin/scripts/generate-style-code.js | 43 | ||||
-rw-r--r-- | platform/darwin/scripts/update-examples.js | 32 |
2 files changed, 53 insertions, 22 deletions
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index 3998246580..cacca57700 100644 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -11,7 +11,7 @@ const cocoaConventions = require('./style-spec-cocoa-conventions-v8.json'); const prefix = 'MGL'; const suffix = 'StyleLayer'; -let spec = _.merge(require('mapbox-gl-style-spec').latest, require('./style-spec-overrides-v8.json')); +let spec = _.merge(require('../../../mapbox-gl-js/src/style-spec/reference/v8'), require('./style-spec-overrides-v8.json')); /// // Temporarily IGNORE layers that are in the spec yet still not supported in mbgl core @@ -31,7 +31,7 @@ _.forOwn(cocoaConventions, function (properties, kind) { } delete spec[kind][oldName]; spec[kind][newName] = property; - + // Update requirements in other properties. let updateRequirements = function (property, name) { let requires = property.requires || []; @@ -225,7 +225,7 @@ global.testHelperMessage = function (property, layerType, isFunction) { }; global.propertyDoc = function (propertyName, property, layerType, kind) { - // Match references to other property names & values. + // Match references to other property names & values. // Requires the format 'When `foo` is set to `bar`,'. let doc = property.doc.replace(/`([^`]+?)` is set to `([^`]+?)`/g, function (m, peerPropertyName, propertyValue, offset, str) { let otherProperty = camelizeWithLeadingLowercase(peerPropertyName); @@ -280,6 +280,30 @@ global.propertyDoc = function (propertyName, property, layerType, kind) { } doc += `\n\nThis attribute corresponds to the <a href="https://www.mapbox.com/mapbox-gl-style-spec/#${anchor}"><code>${property.original}</code></a> layout property in the Mapbox Style Specification.`; } + doc += '\n\nYou can set this property to an instance of:\n\n' + + '* `MGLStyleConstantValue`\n'; + if (property["property-function"]) { + doc += '* `MGLCameraStyleFunction` with an interpolation mode of:\n' + + ' * `MGLInterpolationModeExponential`\n' + + ' * `MGLInterpolationModeInterval`\n' + + '* `MGLSourceStyleFunction` with an interpolation mode of:\n' + + ' * `MGLInterpolationModeExponential`\n' + + ' * `MGLInterpolationModeInterval`\n' + + ' * `MGLInterpolationModeCategorical`\n' + + ' * `MGLInterpolationModeIdentity`\n' + + '* `MGLCompositeStyleFunction` with an interpolation mode of:\n' + + ' * `MGLInterpolationModeExponential`\n' + + ' * `MGLInterpolationModeInterval`\n' + + ' * `MGLInterpolationModeCategorical`\n'; + } else { + if (property.function === "interpolated") { + doc += '* `MGLCameraStyleFunction` with an interpolation mode of:\n' + + ' * `MGLInterpolationModeExponential`\n' + + ' * `MGLInterpolationModeInterval`\n'; + } else { + doc += '* `MGLCameraStyleFunction` with an interpolation mode of `MGLInterpolationModeInterval`\n'; + } + } } return doc; }; @@ -410,6 +434,13 @@ global.propertyType = function (property) { } }; +global.isInterpolatable = function (property) { + const type = property.type === 'array' ? property.value : property.type; + return type !== 'boolean' && + type !== 'enum' && + type !== 'string'; +}; + global.valueTransformerArguments = function (property) { let objCType = propertyType(property); switch (property.type) { @@ -420,7 +451,7 @@ global.valueTransformerArguments = function (property) { case 'string': return ['std::string', objCType]; case 'enum': - return [`mbgl::style::${mbglType(property)}`, objCType]; + return [mbglType(property), 'NSValue *', mbglType(property), `MGL${camelize(property.name)}`]; case 'color': return ['mbgl::Color', objCType]; case 'array': @@ -561,13 +592,13 @@ for (var layer of layers) { if (enumProperties.length) { layer.enumProperties = enumProperties; } - + let renamedProperties = {}; _.assign(renamedProperties, _.filter(layer.properties, prop => 'original' in prop || 'getter' in prop)); if (!_.isEmpty(renamedProperties)) { renamedPropertiesByLayerType[layer.type] = renamedProperties; } - + fs.writeFileSync(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.h`, duplicatePlatformDecls(layerH(layer))); fs.writeFileSync(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.mm`, layerM(layer)); fs.writeFileSync(`platform/darwin/test/${prefix}${camelize(layer.type)}${suffix}Tests.mm`, testLayers(layer)); diff --git a/platform/darwin/scripts/update-examples.js b/platform/darwin/scripts/update-examples.js index 6291326068..404cda102a 100644 --- a/platform/darwin/scripts/update-examples.js +++ b/platform/darwin/scripts/update-examples.js @@ -10,9 +10,9 @@ const examplesSrc = fs.readFileSync('platform/darwin/test/MGLDocumentationExampl // /** Front matter to describe the example. **/ // func testMGLClass$member() { // ... -// //#-example-code +// // #-example-code // let sampleCode: String? -// //#-end-example-code +// // #-end-example-code // ... // } // @@ -35,16 +35,16 @@ function completeSymbolInSource(src, line, exampleCode) { // Split the file contents right before the symbol declaration (but after its documentation comment). let srcUpToSymbol = src.split('\n', line - 1).join('\n'); let srcFromSymbol = src.substr(srcUpToSymbol.length); - + // Match the documentation comment block that is not followed by the beginning or end of a declaration. let commentMatch = srcUpToSymbol.match(/\/\*\*\s*(?:[^*]|\*(?!\/))+?\s*\*\/[^;{}]*?$/); - + // Replace the Swift code block with the test method’s contents. let completedComment = commentMatch[0].replace(/^([ \t]*)```swift\n[^]*?```/m, function (m, indentation) { // Apply the original indentation to each line. return ('```swift\n' + exampleCode + '\n```').replace(/^/gm, indentation); }); - + // Splice the modified comment into the overall file contents. srcUpToSymbol = (srcUpToSymbol.substr(0, commentMatch.index) + completedComment + srcUpToSymbol.substr(commentMatch.index + commentMatch[0].length)); @@ -60,13 +60,13 @@ while ((match = exampleRegex.exec(examplesSrc)) !== null) { // Trim leading whitespace from the example code. exampleCode = exampleCode.replace(new RegExp('^' + indentation, 'gm'), ''); - + examples[testMethodName] = exampleCode; } function completeExamples(os) { console.log(`Installing ${os} SDK examples…`); - + let sdk = os === 'iOS' ? 'iphonesimulator' : 'macosx'; let sysroot = execFileSync('xcrun', ['--show-sdk-path', '--sdk', sdk]).toString().trim(); let umbrellaPath = `platform/${os.toLowerCase()}/src/Mapbox.h`; @@ -88,17 +88,17 @@ function completeExamples(os) { _.forEachRight(substructure['key.substructure'], function (substructure, idx, substructures) { completeSubstructure(substructure, idx, substructures, _.concat(symbolPath, substructure['key.name'])); }); - + let comment = substructure['key.doc.comment']; if (!comment || !comment.match(/^(?:\s*)```swift\n/m)) { return; } - + // Lazily read in the existing file. if (!src) { newSrc = src = fs.readFileSync(path, 'utf8'); } - + // Get the contents of the test method whose name matches the symbol path. let testMethodName = symbolPath.join('$').replace(/\$[+-]/, '$').replace(/:/g, '_'); let example = examples[testMethodName]; @@ -106,23 +106,23 @@ function completeExamples(os) { console.error(`MGLDocumentationExampleTests.${testMethodName}() not found.`); process.exit(1); } - + // Resolve conditional compilation blocks. - example = example.replace(/^(\s*)#if\s+os\((iOS|macOS)\)\n([^]*?)(?:^\1#else\n([^]*?))?^\1#endif\n/gm, + example = example.replace(/^(\s*)#if\s+os\((iOS|macOS)\)\n([^]*?)(?:^\1#else\n([^]*?))?^\1#endif\b\n?/gm, function (m, indentation, ifOs, ifCase, elseCase) { return (os === ifOs ? ifCase : elseCase).replace(new RegExp('^ ', 'gm'), ''); - }); - + }).replace(/\n$/, ''); + // Insert the test method contents into the documentation comment just // above the substructure. let startLine = substructure['key.parsed_scope.start']; newSrc = completeSymbolInSource(newSrc, startLine, example); }); - + if (!src) { return; } - + // Write out the modified file contents. if (src === newSrc) { console.log('Skipping', path); |