Ability to capture trees as JSON files (#1565)
Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1565 This adds a `captureTree` method intended to be injected in somewhere where you would like a JSON representation of a yoga tree. Right now it is very simple and just calls on `nodeToString` to serialize a node into JSON, and then saves that into a file in the given path. Some buck file changes needed to be done as well to use this in other files. Reviewed By: NickGerleman Differential Revision: D52972995 fbshipit-source-id: f4e09a815edef92ab959cfc76bacccbce225d940
This commit is contained in:
committed by
Facebook GitHub Bot
parent
bb83f45872
commit
efd27efd70
22
capture/CaptureTree.cpp
Normal file
22
capture/CaptureTree.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include <capture/CaptureTree.h>
|
||||
#include <capture/NodeToString.h>
|
||||
|
||||
namespace facebook::yoga {
|
||||
|
||||
void captureTree(YGNodeRef node, const std::filesystem::path& path) {
|
||||
std::string str;
|
||||
nodeToString(str, node, YGPrintOptionsStyle | YGPrintOptionsChildren);
|
||||
std::ofstream file(path);
|
||||
file << str;
|
||||
}
|
||||
|
||||
} // namespace facebook::yoga
|
18
capture/CaptureTree.h
Normal file
18
capture/CaptureTree.h
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
namespace facebook::yoga {
|
||||
|
||||
void captureTree(YGNodeRef node, const std::filesystem::path& path);
|
||||
|
||||
} // namespace facebook::yoga
|
Reference in New Issue
Block a user