Skip to content

Commit 49fd4f0

Browse files
authored
Support iframe embed mode (#188)
1 parent 21407bc commit 49fd4f0

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

examples/official-site/documentation.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ select 'card' as component, 3 AS columns where $component IS NOT NULL;
7474
select
7575
name as title,
7676
(CASE WHEN optional THEN '' ELSE 'REQUIRED. ' END) || description as description,
77+
(CASE WHEN optional THEN '' ELSE 'REQUIRED. ' END) || description_md as description_md,
7778
type as footer,
7879
CASE type
7980
WHEN 'COLOR' THEN 'https://tabler.io/docs/base/colors'
@@ -90,6 +91,7 @@ select 'card' as component, 3 AS columns where $component IS NOT NULL;
9091
select
9192
name as title,
9293
(CASE WHEN optional THEN '' ELSE 'REQUIRED. ' END) || description as description,
94+
(CASE WHEN optional THEN '' ELSE 'REQUIRED. ' END) || description_md as description_md,
9395
type as footer,
9496
CASE type
9597
WHEN 'COLOR' THEN 'https://tabler.io/docs/base/colors'
@@ -163,4 +165,4 @@ from example where component = $component AND properties IS NOT NULL;
163165
SELECT 'title' AS component, 3 AS level, 'Examples' AS contents
164166
WHERE EXISTS (SELECT 1 FROM example WHERE component = $component AND properties IS NULL);
165167
SELECT 'text' AS component, description AS contents_md
166-
FROM example WHERE component = $component AND properties IS NULL;
168+
FROM example WHERE component = $component AND properties IS NULL;

examples/official-site/sqlpage/migrations/01_documentation.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ CREATE TABLE parameter(
99
top_level BOOLEAN DEFAULT FALSE,
1010
name TEXT,
1111
component TEXT REFERENCES component(name) ON DELETE CASCADE,
12-
description TEXT NOT NULL,
12+
description TEXT,
13+
description_md TEXT,
1314
type TEXT,
1415
optional BOOLEAN DEFAULT FALSE,
1516
PRIMARY KEY (component, top_level, name)

examples/official-site/sqlpage/migrations/31_card_docs_update.sql

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,18 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
2424
('footer_link', 'An URL to which the user should be taken when they click on the footer.', 'URL', FALSE, TRUE),
2525
('icon', 'Name of an icon to display on the left side of the card.', 'ICON', FALSE, TRUE),
2626
('color', 'The name of a color, to be displayed on the left of the card to highlight it.', 'COLOR', FALSE, TRUE),
27-
('active', 'Whether this item in the grid is considered "active". Active items are displayed more prominently.', 'BOOLEAN', FALSE, TRUE),
27+
('active', 'Whether this item in the grid is considered "active". Active items are displayed more prominently.', 'BOOLEAN', FALSE, TRUE)
28+
) x;
29+
INSERT INTO parameter(component, name, description_md, type, top_level, optional) SELECT 'card', * FROM (VALUES
2830
('embed', 'A url whose contents will be fetched and injected into the body of this card.
2931
This can be used to inject arbitrary html content, but is especially useful for injecting
3032
the output of other sql files rendered by SQLPage. For the latter case you can pass the
31-
`?_sqlpage_embed` query parameter, which will skip the shell layout', 'TEXT', FALSE, TRUE)
33+
`?_sqlpage_embed` query parameter, which will skip the shell layout', 'TEXT', FALSE, TRUE),
34+
('embed_mode', 'Set to ''iframe'' to embed the target (specified through embed property) in an iframe.
35+
Unless this is explicitly set, the embed target is fetched and injected within the parent page. If embed_mode is set to iframe,
36+
You can also set height and width parameters to configure the appearance and the sandbox and allow parameters to configure
37+
security aspects of the iframe. Refer to the [MDN page](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe)
38+
for an explanation of these parameters.', 'TEXT', FALSE, TRUE)
3239
) x;
3340

3441
INSERT INTO example(component, description, properties) VALUES
@@ -52,6 +59,6 @@ INSERT INTO example(component, description, properties) VALUES
5259
('card', 'Cards with remote content',
5360
json('[
5461
{"component":"card", "title":"Card with embedded remote content", "columns": 2},
55-
{"title": "Embedded Chart", "embed": "/examples/chart.sql?_sqlpage_embed" },
56-
{"title": "Description", "description_md": "You can find the sql file that generates the chart [here](https://github.com/lovasoa/SQLpage/tree/main/examples/official-site/examples/chart.sql)" }
57-
]'));
62+
{"title": "Embedded Chart", "embed": "/examples/chart.sql?_sqlpage_embed", "footer_md": "You can find the sql file that generates the chart [here](https://github.com/lovasoa/SQLpage/tree/main/examples/official-site/examples/chart.sql)" },
63+
{"title": "Embedded Video", "embed": "https://www.youtube.com/embed/mXdgmSdaXkg", "allow": "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share", "embed_mode": "iframe", "height": "350" }
64+
]'));

sqlpage/templates/card.handlebars

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
mt-1 mb-3 {{class}}">
2424
{{#each_row}}
2525
<div class="col {{class}}" {{#if id}}id="{{id}}"{{/if}}>
26-
<div class="card h-100 {{#if active}}card-active{{/if}}" {{#if embed }}data-pre-init="card" data-embed="{{embed}}"{{/if}}>
26+
<div class="card h-100 {{#if active}}card-active{{/if}}" {{#if (and embed (ne embed_mode "iframe"))}}data-pre-init="card" data-embed="{{embed}}"{{/if}}>
2727
{{#if link}}
2828
<a href="{{link}}" style="text-decoration: inherit; color: inherit">
2929
{{/if}}
@@ -41,10 +41,20 @@
4141
{{{markdown description_md}}}
4242
{{~/if~}}
4343
</div>
44-
{{~#if embed~}}
45-
<div class="spinner-border card-loading-placeholder" role="status" style="width: 3rem; height: 3rem;">
46-
<span class="visually-hidden">Loading...</span>
47-
</div>
44+
{{~#if embed ~}}
45+
{{~#if (eq embed_mode "iframe")}}
46+
<iframe src="{{embed}}"
47+
width="{{#if width}}{{width}}{{else}}100%{{/if}}"
48+
{{~#if height}} height="{{height}}"{{/if~}}
49+
{{~#if allow}} allow="{{allow}}"{{/if~}}
50+
{{~#if sandbox}} sandbox="{{sandbox}}"{{/if~}}
51+
>
52+
</iframe>
53+
{{~else~}}
54+
<div class="spinner-border card-loading-placeholder" role="status" style="width: 3rem; height: 3rem;">
55+
<span class="visually-hidden">Loading...</span>
56+
</div>
57+
{{~/if~}}
4858
{{~/if~}}
4959
</div>
5060
{{#if link}}

0 commit comments

Comments
 (0)