Skip to content

Commit e596155

Browse files
committed
feat(config): config_builder saves output to $rime_user_dir/build/
1 parent 9e9493b commit e596155

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

src/rime/config/plugins.h

+15
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ class BuildInfoPlugin : public ConfigCompilerPlugin {
5151
Review ReviewLinkOutput;
5252
};
5353

54+
class ResourceResolver;
55+
struct ResourceType;
56+
57+
class SaveOutputPlugin : public ConfigCompilerPlugin {
58+
public:
59+
SaveOutputPlugin(const ResourceType& output_resource);
60+
~SaveOutputPlugin();
61+
62+
Review ReviewCompileOutput;
63+
Review ReviewLinkOutput;
64+
65+
private:
66+
the<ResourceResolver> resource_resolver_;
67+
};
68+
5469
} // namespace rime
5570

5671
#endif // RIME_CONFIG_PLUGINS_H_

src/rime/config/save_output_plugin.cc

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// Copyright RIME Developers
3+
// Distributed under the BSD License
4+
//
5+
#include <boost/filesystem.hpp>
6+
#include <rime/resource.h>
7+
#include <rime/service.h>
8+
#include <rime/config/config_compiler.h>
9+
#include <rime/config/config_types.h>
10+
#include <rime/config/plugins.h>
11+
12+
namespace rime {
13+
14+
SaveOutputPlugin::SaveOutputPlugin(const ResourceType& output_resource)
15+
: resource_resolver_(new ResourceResolver(output_resource)) {
16+
resource_resolver_->set_root_path(
17+
Service::instance().deployer().user_data_dir);
18+
}
19+
20+
SaveOutputPlugin::~SaveOutputPlugin() {}
21+
22+
bool SaveOutputPlugin::ReviewCompileOutput(
23+
ConfigCompiler* compiler, an<ConfigResource> resource) {
24+
return true;
25+
}
26+
27+
bool SaveOutputPlugin::ReviewLinkOutput(
28+
ConfigCompiler* compiler, an<ConfigResource> resource) {
29+
auto file_path = resource_resolver_->ResolvePath(resource->resource_id);
30+
return resource->data->SaveToFile(file_path.string());
31+
}
32+
33+
} // namespace rime

src/rime/core_module.cc

+6-5
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,21 @@ static void rime_core_initialize() {
2020
LOG(INFO) << "registering core components.";
2121
Registry& r = Registry::instance();
2222

23+
const ResourceType build_output{"config", "build/", ".yaml"};
2324
auto config_builder = new ConfigComponent<ConfigBuilder>(
24-
[](ConfigBuilder* builder) {
25+
[&](ConfigBuilder* builder) {
2526
builder->InstallPlugin(new AutoPatchConfigPlugin);
2627
builder->InstallPlugin(new DefaultConfigPlugin);
2728
builder->InstallPlugin(new LegacyPresetConfigPlugin);
2829
builder->InstallPlugin(new LegacyDictionaryConfigPlugin);
2930
builder->InstallPlugin(new BuildInfoPlugin);
31+
builder->InstallPlugin(new SaveOutputPlugin(build_output));
3032
});
3133
r.Register("config_builder", config_builder);
3234

33-
//auto config_loader =
34-
// new ConfigComponent<ConfigLoader>({"config", "build/", ".yaml"});
35-
r.Register("config", config_builder);
36-
r.Register("schema", new SchemaComponent(config_builder));
35+
auto config_loader = new ConfigComponent<ConfigLoader>(build_output);
36+
r.Register("config", config_loader);
37+
r.Register("schema", new SchemaComponent(config_loader));
3738

3839
auto user_config = new ConfigComponent<ConfigLoader>(
3940
[](ConfigLoader* loader) {

0 commit comments

Comments
 (0)