-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sections for bool and non-null variables
- Loading branch information
1 parent
4eaefe5
commit 23d0a17
Showing
3 changed files
with
155 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
create extension if not exists plmustache; | ||
NOTICE: extension "plmustache" already exists, skipping | ||
\echo | ||
|
||
create or replace function bool_section(x1 text, x2 bool) returns text as $$ | ||
Section: {{#x2}}Show {{x1}}{{/x2}} | ||
$$ language plmustache; | ||
\echo | ||
|
||
select bool_section('Something', true); | ||
bool_section | ||
------------------------- | ||
Section: Show Something | ||
(1 row) | ||
|
||
select bool_section('Something', false); | ||
bool_section | ||
-------------- | ||
Section: | ||
(1 row) | ||
|
||
create or replace function bool_section_inverted(x1 text, x2 bool) returns text as $$ | ||
Section: Show {{#x2}}{{x1}}{{/x2}}{{^x2}}Nothing{{/x2}} | ||
$$ language plmustache; | ||
\echo | ||
|
||
select bool_section_inverted('Something', true); | ||
bool_section_inverted | ||
------------------------- | ||
Section: Show Something | ||
(1 row) | ||
|
||
select bool_section_inverted('Something', false); | ||
bool_section_inverted | ||
----------------------- | ||
Section: Show Nothing | ||
(1 row) | ||
|
||
create or replace function foo_test(foo text) returns text as $$ | ||
{{#foo}}foo is {{foo}}{{/foo}} | ||
$$ language plmustache; | ||
\echo | ||
|
||
select foo_test('bar'); | ||
foo_test | ||
------------ | ||
foo is bar | ||
(1 row) | ||
|
||
create or replace function foo_test(foo bool) returns text as $$ | ||
foo is {{#foo}}{{foo}}{{/foo}}{{^foo}}{{foo}}{{/foo}} | ||
$$ language plmustache; | ||
\echo | ||
|
||
select foo_test(true); | ||
foo_test | ||
---------- | ||
foo is t | ||
(1 row) | ||
|
||
select foo_test(false); | ||
foo_test | ||
---------- | ||
foo is f | ||
(1 row) | ||
|
||
create or replace function foo_null_test(foo bool) returns text as $$ | ||
foo is {{#foo}}full{{/foo}}{{^foo}}null{{/foo}} | ||
$$ language plmustache; | ||
select foo_null_test(null); | ||
foo_null_test | ||
--------------- | ||
foo is null | ||
(1 row) | ||
|
||
select foo_null_test(true); | ||
foo_null_test | ||
--------------- | ||
foo is full | ||
(1 row) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
create extension if not exists plmustache; | ||
\echo | ||
|
||
create or replace function bool_section(x1 text, x2 bool) returns text as $$ | ||
Section: {{#x2}}Show {{x1}}{{/x2}} | ||
$$ language plmustache; | ||
\echo | ||
|
||
select bool_section('Something', true); | ||
|
||
select bool_section('Something', false); | ||
|
||
create or replace function bool_section_inverted(x1 text, x2 bool) returns text as $$ | ||
Section: Show {{#x2}}{{x1}}{{/x2}}{{^x2}}Nothing{{/x2}} | ||
$$ language plmustache; | ||
\echo | ||
|
||
select bool_section_inverted('Something', true); | ||
|
||
select bool_section_inverted('Something', false); | ||
|
||
create or replace function foo_test(foo text) returns text as $$ | ||
{{#foo}}foo is {{foo}}{{/foo}} | ||
$$ language plmustache; | ||
\echo | ||
|
||
select foo_test('bar'); | ||
|
||
create or replace function foo_test(foo bool) returns text as $$ | ||
foo is {{#foo}}{{foo}}{{/foo}}{{^foo}}{{foo}}{{/foo}} | ||
$$ language plmustache; | ||
\echo | ||
|
||
select foo_test(true); | ||
|
||
select foo_test(false); | ||
|
||
create or replace function foo_null_test(foo bool) returns text as $$ | ||
foo is {{#foo}}full{{/foo}}{{^foo}}null{{/foo}} | ||
$$ language plmustache; | ||
|
||
select foo_null_test(null); | ||
|
||
select foo_null_test(true); |