Skip to content

Commit c782dd4

Browse files
authored
First step to issue #359, no change to the HTML output (#361)
* First step to issue #359, no change to the HTML output - add sqlite-db plugin - plugin accesses the dataset created for the Routines page in the website - the data is formatted into the rows of an sqlite table - the completed sqlite database is output into a filename specified in the `configs/03-plugin-options.raku` config file, so changing the value of the `db-filename` field of the `sqlite-db` sub-hash changes the output file name. - the sqlite file is moved by Collection to a directory defined by 'database-dir' relative to the directory in which Collection runs. As set up here, the directory sqlite_dir will be at the same level as the existing renedered_html * Separate out schema from data - data is now in filename specified in plugin config
1 parent 3f27363 commit c782dd4

File tree

8 files changed

+88
-4
lines changed

8 files changed

+88
-4
lines changed

Website/configs/02-plugins.raku

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
filtered-toc
99
camelia simple-extras listfiles images deprecate-span filterlines
1010
tablemanager secondaries typegraph generated
11-
options-search link-error-test
11+
options-search link-error-test sqlite-db
1212
gather-js-jq gather-css sitemap
1313
>,
1414
:report<link-plugin-assets-report sitemap>,
15-
:transfer<secondaries gather-js-jq gather-css images raku-doc-setup options-search>,
16-
:compilation<secondaries listfiles link-error-test options-search>,
15+
:transfer<secondaries gather-js-jq gather-css images raku-doc-setup options-search sqlite-db>,
16+
:compilation<secondaries listfiles link-error-test options-search sqlite-db>,
1717
:completion<cro-app>,
1818
),
1919
)

Website/configs/03-plugin-options.raku

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
link-error-test => %(
99
:no-remote,
1010
:run-tests,
11+
:structure-files<introduction about index miscellaneous reference routines types>,
1112
),
1213
sitemap => %(
1314
:root-domain<https://docs.raku.org>,
1415
:sitemap-destination<../../rendered_html>,
15-
)
16+
),
17+
sqlite-db => %(
18+
:database-dir<../../sqlite_dir>,
19+
:db-filename<sqlite-db-definition.sql>,
20+
),
1621
),
1722
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=begin rakudoc
2+
=TITLE sqlite-db is a plugin for Collection
3+
4+
The plugin is for the render, compilation, & transfer milestones
5+
6+
Relies on 'secondaries' plugin creating routines data for the 'tablemanager' plugin. So the plugin must
7+
follow the 'secondaries' plugin.
8+
9+
Outputs a file for the sqlite executable. Transfers it to the directory named in the `database-dir` field.
10+
11+
Transfer cleans up the plugin directory.
12+
13+
=head1 Custom blocks
14+
None
15+
16+
=head1 Templates
17+
None
18+
19+
=end rakudoc
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env raku
2+
use v6.d;
3+
sub ($pr, %processed, %options --> Array) {
4+
$pr.get-data('sqlite-db')<db-filename>.IO.unlink;
5+
[]
6+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use v6.d;
2+
sub ( $pr, %processed, %options) {
3+
my $sql;
4+
my %config = $pr.get-data('sqlite-db');
5+
if $pr.plugin-datakeys (cont) 'tablemanager' {
6+
my @rows = $pr.get-data('tablemanager').<dataset><routines>.list;
7+
$sql = q:to/SQL/;
8+
INSERT INTO routines ( Category, Name, Type, URL )
9+
VALUES
10+
SQL
11+
$sql ~= [~] @rows[0 ^..* ].map({
12+
'("' ~ .[0] ~ '" , "' ~ .[1] ~ '" , "'~ .[2] ~ '" , "'
13+
~ .[3] ~ '#' ~ .[4]
14+
~ '")'
15+
})
16+
.join(",\n") ~ ";\n";
17+
}
18+
else {
19+
# change the line below to create a string that will cause a better sqlite result
20+
$sql = 'There is no tablemanager data'
21+
}
22+
%config<db-filename>.IO.spurt: $sql;
23+
[
24+
[ %config<database-dir> ~ '/schema.sql' , 'myself', 'schema.sql' ],
25+
[ %config<database-dir> ~ '/' ~ %config<db-filename> , 'myself', %config<db-filename> ]
26+
]
27+
}

Website/plugins/sqlite-db/config.raku

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
%(
2+
:auth<collection>,
3+
:authors(
4+
"finanalyst",
5+
),
6+
:compilation<compilation-callable.raku>,
7+
:custom-raku(),
8+
:license<Artistic-2.0>,
9+
:name<sqlite-db>,
10+
:render,
11+
:transfer<cleanup.raku>,
12+
:template-raku(),
13+
:version<0.1.0>,
14+
:database-dir<../sqlite-db>,
15+
:db-filename<sqlite-db.sql>,
16+
)

Website/plugins/sqlite-db/schema.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE TABLE IF NOT EXISTS routines (
2+
Category TEXT,
3+
Name TEXT,
4+
Type TEXT,
5+
URL TEXT
6+
);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use v6.d;
2+
use Test;
3+
use Test::CollectionPlugin;
4+
test-plugin();
5+
done-testing

0 commit comments

Comments
 (0)