How to use the @accordproject/cicero-core.Template.fromUrl function in @accordproject/cicero-core

To help you get started, we’ve selected a few @accordproject/cicero-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github accordproject / template-studio / src / TemplateStudio / index.js View on Github external
async loadTemplateFromUrl(templateURL) {
        const thisTemplateURL = templateURL;
        this.setState({ loading: true });
        console.log(`Loading template:  ${thisTemplateURL}`);
        let template;
        try {
            template = await Template.fromUrl(thisTemplateURL);
        } catch (error) {
            console.log(`LOAD FAILED! ${error.message}`); // Error!
            this.handleLoadingFailed(error.message);
            return false;
        }
        try {
            const newState = {...this.state};
            newState.templateURL = thisTemplateURL;
            newState.clause = new Clause(template);
            newState.templateName = newState.clause.getTemplate().getMetadata().getName();
            newState.templateVersion = newState.clause.getTemplate().getMetadata().getVersion();
            newState.templateType = newState.clause.getTemplate().getMetadata().getTemplateType();
            newState.package = JSON.stringify(template.getMetadata().getPackageJson(), null, 2);
            newState.grammar = template.getParserManager().getTemplatizedGrammar();
            newState.model = template.getModelManager().getModels();
            newState.logic = template.getScriptManager().getLogic();
github accordproject / template-studio-v2 / src / sagas / templatesSaga.js View on Github external
export function* addTemplateObjectToStore(action) {
  const templateObjects = yield select(selectors.templateObjects);

  if (!templateObjects || !templateObjects[action.uri]) {
    try {
      const templateObj = yield Template.fromUrl(action.uri);
      yield put(actions.loadTemplateObjectSuccess(action.uri, templateObj));
      return templateObj;
    } catch (err) {
      yield put(appActions.addAppError('Failed to load template object', err));
      return err;
    }
  }

  return templateObjects[action.uri];
}
github accordproject / template-studio-v2 / src / sagas / templatesSaga.js View on Github external
export function* addTemplateObjectToStore(action) {
  const templateObjects = yield select(selectors.templateObjects);

  if (!templateObjects || !templateObjects[action.uri]) {
    try {
      const templateObj = yield Template.fromUrl(action.uri);
      yield put(actions.loadTemplateObjectSuccess(action.uri, templateObj));
      return templateObj;
    } catch (err) {
      yield put(appActions.addAppError('Failed to load template object', err));
      return err;
    }
  }

  return templateObjects[action.uri];
}