Skip to content

Commit

Permalink
First step to issue #359, no change to the HTML output (#361)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
finanalyst committed Apr 3, 2024
1 parent 3f27363 commit c782dd4
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Website/configs/02-plugins.raku
Expand Up @@ -8,12 +8,12 @@
filtered-toc
camelia simple-extras listfiles images deprecate-span filterlines
tablemanager secondaries typegraph generated
options-search link-error-test
options-search link-error-test sqlite-db
gather-js-jq gather-css sitemap
>,
:report<link-plugin-assets-report sitemap>,
:transfer<secondaries gather-js-jq gather-css images raku-doc-setup options-search>,
:compilation<secondaries listfiles link-error-test options-search>,
:transfer<secondaries gather-js-jq gather-css images raku-doc-setup options-search sqlite-db>,
:compilation<secondaries listfiles link-error-test options-search sqlite-db>,
:completion<cro-app>,
),
)
7 changes: 6 additions & 1 deletion Website/configs/03-plugin-options.raku
Expand Up @@ -8,10 +8,15 @@
link-error-test => %(
:no-remote,
:run-tests,
:structure-files<introduction about index miscellaneous reference routines types>,
),
sitemap => %(
:root-domain<https://docs.raku.org>,
:sitemap-destination<../../rendered_html>,
)
),
sqlite-db => %(
:database-dir<../../sqlite_dir>,
:db-filename<sqlite-db-definition.sql>,
),
),
)
19 changes: 19 additions & 0 deletions Website/plugins/sqlite-db/README.rakudoc
@@ -0,0 +1,19 @@
=begin rakudoc
=TITLE sqlite-db is a plugin for Collection

The plugin is for the render, compilation, & transfer milestones

Relies on 'secondaries' plugin creating routines data for the 'tablemanager' plugin. So the plugin must
follow the 'secondaries' plugin.

Outputs a file for the sqlite executable. Transfers it to the directory named in the `database-dir` field.

Transfer cleans up the plugin directory.

=head1 Custom blocks
None

=head1 Templates
None

=end rakudoc
6 changes: 6 additions & 0 deletions Website/plugins/sqlite-db/cleanup.raku
@@ -0,0 +1,6 @@
#!/usr/bin/env raku
use v6.d;
sub ($pr, %processed, %options --> Array) {
$pr.get-data('sqlite-db')<db-filename>.IO.unlink;
[]
}
27 changes: 27 additions & 0 deletions Website/plugins/sqlite-db/compilation-callable.raku
@@ -0,0 +1,27 @@
use v6.d;
sub ( $pr, %processed, %options) {
my $sql;
my %config = $pr.get-data('sqlite-db');
if $pr.plugin-datakeys (cont) 'tablemanager' {
my @rows = $pr.get-data('tablemanager').<dataset><routines>.list;
$sql = q:to/SQL/;
INSERT INTO routines ( Category, Name, Type, URL )
VALUES
SQL
$sql ~= [~] @rows[0 ^..* ].map({
'("' ~ .[0] ~ '" , "' ~ .[1] ~ '" , "'~ .[2] ~ '" , "'
~ .[3] ~ '#' ~ .[4]
~ '")'
})
.join(",\n") ~ ";\n";
}
else {
# change the line below to create a string that will cause a better sqlite result
$sql = 'There is no tablemanager data'
}
%config<db-filename>.IO.spurt: $sql;
[
[ %config<database-dir> ~ '/schema.sql' , 'myself', 'schema.sql' ],
[ %config<database-dir> ~ '/' ~ %config<db-filename> , 'myself', %config<db-filename> ]
]
}
16 changes: 16 additions & 0 deletions Website/plugins/sqlite-db/config.raku
@@ -0,0 +1,16 @@
%(
:auth<collection>,
:authors(
"finanalyst",
),
:compilation<compilation-callable.raku>,
:custom-raku(),
:license<Artistic-2.0>,
:name<sqlite-db>,
:render,
:transfer<cleanup.raku>,
:template-raku(),
:version<0.1.0>,
:database-dir<../sqlite-db>,
:db-filename<sqlite-db.sql>,
)
6 changes: 6 additions & 0 deletions Website/plugins/sqlite-db/schema.sql
@@ -0,0 +1,6 @@
CREATE TABLE IF NOT EXISTS routines (
Category TEXT,
Name TEXT,
Type TEXT,
URL TEXT
);
5 changes: 5 additions & 0 deletions Website/plugins/sqlite-db/t/05-basic.rakutest
@@ -0,0 +1,5 @@
use v6.d;
use Test;
use Test::CollectionPlugin;
test-plugin();
done-testing

0 comments on commit c782dd4

Please sign in to comment.