Skip to content

Commit

Permalink
feat(config): config_builder saves output to $rime_user_dir/build/
Browse files Browse the repository at this point in the history
  • Loading branch information
lotem committed Feb 11, 2018
1 parent 9e9493b commit e596155
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
15 changes: 15 additions & 0 deletions src/rime/config/plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ class BuildInfoPlugin : public ConfigCompilerPlugin {
Review ReviewLinkOutput;
};

class ResourceResolver;
struct ResourceType;

class SaveOutputPlugin : public ConfigCompilerPlugin {
public:
SaveOutputPlugin(const ResourceType& output_resource);
~SaveOutputPlugin();

Review ReviewCompileOutput;
Review ReviewLinkOutput;

private:
the<ResourceResolver> resource_resolver_;
};

} // namespace rime

#endif // RIME_CONFIG_PLUGINS_H_
33 changes: 33 additions & 0 deletions src/rime/config/save_output_plugin.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Copyright RIME Developers
// Distributed under the BSD License
//
#include <boost/filesystem.hpp>
#include <rime/resource.h>
#include <rime/service.h>
#include <rime/config/config_compiler.h>
#include <rime/config/config_types.h>
#include <rime/config/plugins.h>

namespace rime {

SaveOutputPlugin::SaveOutputPlugin(const ResourceType& output_resource)
: resource_resolver_(new ResourceResolver(output_resource)) {
resource_resolver_->set_root_path(
Service::instance().deployer().user_data_dir);
}

SaveOutputPlugin::~SaveOutputPlugin() {}

bool SaveOutputPlugin::ReviewCompileOutput(
ConfigCompiler* compiler, an<ConfigResource> resource) {
return true;
}

bool SaveOutputPlugin::ReviewLinkOutput(
ConfigCompiler* compiler, an<ConfigResource> resource) {
auto file_path = resource_resolver_->ResolvePath(resource->resource_id);
return resource->data->SaveToFile(file_path.string());
}

} // namespace rime
11 changes: 6 additions & 5 deletions src/rime/core_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@ static void rime_core_initialize() {
LOG(INFO) << "registering core components.";
Registry& r = Registry::instance();

const ResourceType build_output{"config", "build/", ".yaml"};
auto config_builder = new ConfigComponent<ConfigBuilder>(
[](ConfigBuilder* builder) {
[&](ConfigBuilder* builder) {
builder->InstallPlugin(new AutoPatchConfigPlugin);
builder->InstallPlugin(new DefaultConfigPlugin);
builder->InstallPlugin(new LegacyPresetConfigPlugin);
builder->InstallPlugin(new LegacyDictionaryConfigPlugin);
builder->InstallPlugin(new BuildInfoPlugin);
builder->InstallPlugin(new SaveOutputPlugin(build_output));
});
r.Register("config_builder", config_builder);

//auto config_loader =
// new ConfigComponent<ConfigLoader>({"config", "build/", ".yaml"});
r.Register("config", config_builder);
r.Register("schema", new SchemaComponent(config_builder));
auto config_loader = new ConfigComponent<ConfigLoader>(build_output);
r.Register("config", config_loader);
r.Register("schema", new SchemaComponent(config_loader));

auto user_config = new ConfigComponent<ConfigLoader>(
[](ConfigLoader* loader) {
Expand Down

0 comments on commit e596155

Please sign in to comment.