Skip to content

Commit 77009ac

Browse files
committed
Update query param name and add docs
1 parent 9c7097f commit 77009ac

File tree

5 files changed

+43
-9
lines changed

5 files changed

+43
-9
lines changed

examples/cards-with-remote-content/index.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ This is useful if you want to display a lot of text in the card, with many optio
1212
- etc.' as description_md;
1313
select
1414
'A card with lazy-loaded chart' as title,
15-
'/chart-example.sql?embed' as embed;
15+
'/chart-example.sql?_sqlpage_embed' as embed;
1616
select
1717
'A card with lazy-loaded map' as title,
18-
'/map-example.sql?embed' as embed;
18+
'/map-example.sql?_sqlpage_embed' as embed;
1919
select
2020
'A card with lazy-loaded table' as title,
21-
'/table-example.sql?embed' as embed;
21+
'/table-example.sql?_sqlpage_embed' as embed;

examples/official-site/custom_components.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Each page in SQLPage is composed of a `shell` component,
1616
which contains the page title and the navigation bar,
1717
and a series of normal components that display the data.
1818
19-
The `shell` component is always present. If you don''t call it explicitly,
20-
it will be invoked with the default parameters automatically before your first component
19+
The `shell` component is always present unless explicitly skipped via the `?_sqlpage_embed` query parameter.
20+
If you don''t call it explicitly, it will be invoked with the default parameters automatically before your first component
2121
invocation that tries to render data on the page.
2222
2323
There can be only one `shell` component per site, but you can customize its appearance as you see fit.
@@ -135,4 +135,4 @@ Some interesting examples are:
135135
- the `../` syntax to access the parent context,
136136
- and the `@key` to work with objects whose keys are not known in advance.
137137
138-
' as contents_md;
138+
' as contents_md;

examples/official-site/safety.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ website, and have it perform an action on your website in the user''s name,
115115
because the browser will not send the cookies to your website.
116116
117117
SQLPage differentiates between POST variables (accessed with the `:variable` syntax), and
118-
variables that can come from URL parameters (accessible with `$variable`).
118+
variables that can come from URL parameters (accessible with `$variable`). Note that URL parameters
119+
prefixed with `_sqlpage_` are reserved for internal use.
119120
120121
When a user submits a form, you should use POST variables to access the form data.
121122
This ensures that you only use data that indeed comes from the form, and not from a
@@ -138,4 +139,4 @@ create a specific user for SQLPage that only has access to the specific tables y
138139
139140
If your entire application is read-only, you can even create a user that only has the `SELECT` privilege on your database,
140141
141-
' as contents_md;
142+
' as contents_md;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
DELETE FROM component WHERE name = 'card';
2+
3+
INSERT INTO component(name, icon, description) VALUES
4+
('card', 'credit-card', 'A grid where each element is a small card that displays a piece of data.');
5+
INSERT INTO parameter(component, name, description, type, top_level, optional) SELECT 'card', * FROM (VALUES
6+
-- top level
7+
('title', 'Text header at the top of the list of cards.', 'TEXT', TRUE, TRUE),
8+
('description', 'A short paragraph displayed below the title.', 'TEXT', TRUE, TRUE),
9+
('description_md', 'A short paragraph displayed below the title - formatted using markdown.', 'TEXT', TRUE, TRUE),
10+
('columns', 'The number of columns in the grid of cards. This is just a hint, the grid will adjust dynamically to the user''s screen size, rendering fewer columns if needed to fit the contents.', 'INTEGER', TRUE, TRUE),
11+
-- item level
12+
('title', 'Name of the card, displayed at the top.', 'TEXT', FALSE, FALSE),
13+
('description', 'The body of the card, where you put the main text contents of the card.
14+
This does not support rich text formatting, only plain text.
15+
If you want to use rich text formatting, use the `description_md` property instead.', 'TEXT', FALSE, TRUE),
16+
('description_md', '
17+
The body of the card, in Markdown format.
18+
This is useful if you want to display a lot of text in the card, with many options for formatting, such as
19+
line breaks, **bold**, *italics*, lists, #titles, [links](target.sql), ![images](photo.jpg), etc.', 'TEXT', FALSE, TRUE),
20+
('top_image', 'The URL (absolute or relative) of an image to display at the top of the card.', 'URL', FALSE, TRUE),
21+
('footer', 'Muted text to display at the bottom of the card.', 'TEXT', FALSE, TRUE),
22+
('footer_md', 'Muted text to display at the bottom of the card, with rich text formatting in Markdown format.', 'TEXT', FALSE, TRUE),
23+
('link', 'An URL to which the user should be taken when they click on the card.', 'URL', FALSE, TRUE),
24+
('footer_link', 'An URL to which the user should be taken when they click on the footer.', 'URL', FALSE, TRUE),
25+
('icon', 'Name of an icon to display on the left side of the card.', 'ICON', FALSE, TRUE),
26+
('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),
28+
('embed', 'A url whose contents will be fetched and injected into the body of this card.
29+
This can be used to inject arbitrary html content, but is especially useful for injecting
30+
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)
32+
) x;
33+

src/webserver/http.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ async fn render_sql(
225225
let (resp_send, resp_recv) = tokio::sync::oneshot::channel::<HttpResponse>();
226226
actix_web::rt::spawn(async move {
227227
let layout_context = &LayoutContext {
228-
is_embedded: req_param.get_variables.get("embed").is_none(),
228+
is_embedded: req_param.get_variables.get("_sqlpage_embed").is_some(),
229229
};
230230
let database_entries_stream =
231231
stream_query_results(&app_state.db, &sql_file, &mut req_param);

0 commit comments

Comments
 (0)