Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios, macos] Add MGLLight generation script
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-guerra committed Jun 13, 2017
1 parent 6cde1a4 commit d2153a6
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 9 deletions.
9 changes: 6 additions & 3 deletions platform/darwin/scripts/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ global.testHelperMessage = function (property, layerType, isFunction) {
};

global.propertyDoc = function (propertyName, property, layerType, kind) {
console.log(propertyName + " : " + property + " : " + layerType + " : " + kind)
// 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) {
Expand Down Expand Up @@ -527,6 +528,8 @@ const lightProperties = Object.keys(spec[`light`]).reduce((memo, name) => {
return memo;
}, []);

console.log(lightProperties);

const layerH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.h.ejs', 'utf8'), { strict: true });
const layerM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.mm.ejs', 'utf8'), { strict: true});
const testLayers = ejs.compile(fs.readFileSync('platform/darwin/test/MGLStyleLayerTests.mm.ejs', 'utf8'), { strict: true});
Expand All @@ -536,8 +539,8 @@ const templatesMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guides/Til

const lightH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLLight.h.ejs', 'utf8'), {strict: true});;
const lightM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLLight.mm.ejs', 'utf8'), {strict: true});;
fs.writeFileSync(`platform/darwin/src/MGLLight.h`, lightH(lightProperties));
fs.writeFileSync(`platform/darwin/src/MGLLight.mm`, lightM(lightProperties));
fs.writeFileSync(`platform/darwin/src/MGLLight.h`, lightH({ properties: lightProperties, }));
fs.writeFileSync(`platform/darwin/src/MGLLight.mm`, lightM({ properties: lightProperties, }));



Expand All @@ -555,7 +558,7 @@ const layers = _(spec.layer.type.values).map((value, layerType) => {
memo.push(spec[`paint_${layerType}`][name]);
return memo;
}, []);

console.log(spec.layer.type.values[layerType].doc)
return {
doc: spec.layer.type.values[layerType].doc,
type: layerType,
Expand Down
5 changes: 4 additions & 1 deletion platform/darwin/src/MGLLight.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This file is generated.
// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.

#import <CoreLocation/CoreLocation.h>

#import "MGLFoundation.h"
Expand All @@ -20,7 +23,7 @@ typedef NS_ENUM(NSUInteger, MGLLightAnchor) {
*/
typedef struct MGLSphericalPosition {
/** Distance from the center of the base of an object to its light. */
CLLocationDistance radial;
CGFloat radial;
/** Position of the light relative to 0° (0° when `MGLLight.anchor` is set to viewport corresponds
to the top of the viewport, or 0° when `MGLLight.anchor` is set to map corresponds to due north,
and degrees proceed clockwise). */
Expand Down
10 changes: 9 additions & 1 deletion platform/darwin/src/MGLLight.h.ejs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<%
const properties = locals.properties;
const type = locals.type;
const doc = locals.doc;
-%>
// This file is generated.
// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.

#import <CoreLocation/CoreLocation.h>

#import "MGLFoundation.h"
Expand All @@ -20,7 +28,7 @@ typedef NS_ENUM(NSUInteger, MGLLightAnchor) {
*/
typedef struct MGLSphericalPosition {
/** Distance from the center of the base of an object to its light. */
CLLocationDistance radial;
CGFloat radial;
/** Position of the light relative to 0° (0° when `MGLLight.anchor` is set to viewport corresponds
to the top of the viewport, or 0° when `MGLLight.anchor` is set to map corresponds to due north,
and degrees proceed clockwise). */
Expand Down
6 changes: 5 additions & 1 deletion platform/darwin/src/MGLLight.mm
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// This file is generated.
// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
// test

#import "MGLLight.h"

#import "MGLTypes.h"
Expand All @@ -9,7 +13,7 @@
#import <mbgl/style/types.hpp>

namespace mbgl {

MBGL_DEFINE_ENUM(MGLLightAnchor, {
{ MGLLightAnchorMap, "map" },
{ MGLLightAnchorViewport, "viewport" },
Expand Down
18 changes: 15 additions & 3 deletions platform/darwin/src/MGLLight.mm.ejs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<%
const properties = locals.properties;
-%>
// This file is generated.
// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
// test

#import "MGLLight.h"

#import "MGLTypes.h"
Expand All @@ -9,10 +16,15 @@
#import <mbgl/style/types.hpp>

namespace mbgl {

MBGL_DEFINE_ENUM(MGLLightAnchor, {
{ MGLLightAnchorMap, "map" },
{ MGLLightAnchorViewport, "viewport" },
<% for (const property of properties) { -%>
<% if (property.type == "enum") { -%>
<% for (const value in property.values) { -%>
{ MGLLightAnchor<%- camelize(value) %>, "<%- value %>" },
<% } -%>
<% } -%>
<% } -%>
});

}
Expand Down

0 comments on commit d2153a6

Please sign in to comment.