Skip to content

Commit

Permalink
Improved signal type
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Jan 27, 2023
1 parent 2ac5778 commit e148c37
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub fn register_helpers<'a>(h: Handlebars<'a>) -> Handlebars<'a> {
let h = register_contains_helper(h);
let h = register_includes_helper(h);
let h = register_case_helpers(h);
let h = register_replace_helper(h);
let h = register_pluralize_helpers(h);
let h = register_merge_scope(h);
let h = register_uniq_lines(h);
Expand Down Expand Up @@ -228,6 +229,13 @@ pub fn register_includes_helper<'a>(mut h: Handlebars<'a>) -> Handlebars<'a> {
h
}

pub fn register_replace_helper<'a>(mut h: Handlebars<'a>) -> Handlebars<'a> {
handlebars_helper!(replace: |s: String, pattern: String, replaced_by: String| s.replace(&pattern, replaced_by.as_str()));
h.register_helper("replace", Box::new(replace));

h
}

pub fn register_pluralize_helpers<'a>(mut h: Handlebars<'a>) -> Handlebars<'a> {
handlebars_helper!(singular: |s: String| pluralizer::pluralize(s.as_str(), 1, false));
h.register_helper("singular", Box::new(singular));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,4 @@ export type {{pascal_case zome_manifest.name}}Signal = {
link_type: string;
};

export type EntryTypes = {
type: string;
} & any;
export type EntryTypes = {};
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{{previous_file_content}}
{{#if (includes previous_file_content "export type EntryTypes = {};")}}
{{replace previous_file_content "export type EntryTypes = {};" (concat "export type EntryTypes =\n | ({ type: '" (pascal_case entry_type.name) "'; } & " (pascal_case entry_type.name) ");")}}
{{else}}
{{replace previous_file_content "export type EntryTypes =" (concat "export type EntryTypes =\n | ({ type: '" (pascal_case entry_type.name) "'; } & " (pascal_case entry_type.name) ")")}}
{{/if}}

export interface {{pascal_case entry_type.name}} { {{#each entry_type.fields}}
{{#if (not (eq cardinality "vector" ) )}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,4 @@ export type {{pascal_case zome_manifest.name}}Signal = {
link_type: string;
};

export type EntryTypes = {
type: string;
} & any;
export type EntryTypes = {};
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{{previous_file_content}}
{{#if (includes previous_file_content "export type EntryTypes = {};")}}
{{replace previous_file_content "export type EntryTypes = {};" (concat "export type EntryTypes =\n | ({ type: '" (pascal_case entry_type.name) "'; } & " (pascal_case entry_type.name) ");")}}
{{else}}
{{replace previous_file_content "export type EntryTypes =" (concat "export type EntryTypes =\n | ({ type: '" (pascal_case entry_type.name) "'; } & " (pascal_case entry_type.name) ")")}}
{{/if}}

export interface {{pascal_case entry_type.name}} { {{#each entry_type.fields}}
{{#if (not (eq cardinality "vector" ) )}}
Expand All @@ -9,3 +13,4 @@ export interface {{pascal_case entry_type.name}} { {{#each entry_type.fields}}
{{/each}}
}


Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,4 @@ export type {{pascal_case zome_manifest.name}}Signal = {
link_type: string;
};

export type EntryTypes = {
type: string;
} & any;
export type EntryTypes = {};
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{{previous_file_content}}
{{#if (includes previous_file_content "export type EntryTypes = {};")}}
{{replace previous_file_content "export type EntryTypes = {};" (concat "export type EntryTypes =\n | ({ type: '" (pascal_case entry_type.name) "'; } & " (pascal_case entry_type.name) ");")}}
{{else}}
{{replace previous_file_content "export type EntryTypes =" (concat "export type EntryTypes =\n | ({ type: '" (pascal_case entry_type.name) "'; } & " (pascal_case entry_type.name) ")")}}
{{/if}}

export interface {{pascal_case entry_type.name}} { {{#each entry_type.fields}}
{{#if (not (eq cardinality "vector" ) )}}
Expand All @@ -9,3 +13,4 @@ export interface {{pascal_case entry_type.name}} { {{#each entry_type.fields}}
{{/each}}
}


0 comments on commit e148c37

Please sign in to comment.