jekyll-sqlite 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +2 -0
- data/README.md +17 -26
- data/lib/jekyll-sqlite/generator.rb +35 -21
- data/lib/jekyll-sqlite/version.rb +1 -1
- metadata +5 -7
- data/Gemfile.lock +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f14ced1e5bddd23e8aca1460f7acc53449b2d19fbf3bb67eb97f55f194facc95
|
4
|
+
data.tar.gz: f2a21e3b7d89d2d8d476c71ee2876025037009eb311df7d64fb1b9e2dca5cac3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50c29d5008eb35fd2ed1fd6d9b6acf7cca7c1fcc0b5e3b4933506f0a29875118c02934ccbd2cec94f3676d7276f71527803bb4324467b36a29dcddfe8b8d2064
|
7
|
+
data.tar.gz: '09b4bd31b5fe04534892df1e5a229e3aca26cc447a147f2cf43d5e306a4c14c30156505b08481c78b89c1216b7e0aec6ba54ee3979ab002363d46dec3fc8f11a'
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -25,41 +25,32 @@ plugins:
|
|
25
25
|
|
26
26
|
## Usage
|
27
27
|
|
28
|
-
Update your `_config.yml` to define your data sources with your SQLite database.
|
28
|
+
Update your `_config.yml` to define your data sources with your SQLite database. Please see
|
29
|
+
the `test` directory for a functional example with the [Northwind database](https://github.com/jpwhite3/northwind-SQLite3).
|
29
30
|
|
30
31
|
```yml
|
31
32
|
...
|
32
|
-
# These are run in sequence, so any nested data can work well.
|
33
33
|
sqlite:
|
34
|
-
- data:
|
35
|
-
file: _db/
|
36
|
-
query: SELECT *
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
34
|
+
- data: orders
|
35
|
+
file: &db "_db/northwind.db"
|
36
|
+
query: SELECT * from Orders
|
37
|
+
- data: customers
|
38
|
+
file: *db
|
39
|
+
query: SELECT * from Customers
|
40
|
+
- data: categories
|
41
|
+
file: *db
|
42
|
+
query: SELECT CategoryID, CategoryName, Description FROM Categories
|
43
|
+
# Note that the CategoryID parameter in the query is coming from site.data.categories[].CategoryID
|
44
|
+
# which was picked up in the previous query
|
45
|
+
- data: categories.products
|
46
|
+
file: *db
|
47
|
+
query: SELECT ProductID, ProductName FROM Products WHERE Products.CategoryID=:CategoryID
|
45
48
|
```
|
46
49
|
|
47
50
|
Then, you can use the `site.data` attributes accordingly:
|
48
51
|
|
49
52
|
```liquid
|
50
|
-
{
|
51
|
-
- {{member.username}}
|
52
|
-
|
53
|
-
# Your Posts
|
54
|
-
{% for post in member.posts %}
|
55
|
-
{{post}}
|
56
|
-
{% endfor %}
|
57
|
-
{% endfor %}
|
58
|
-
|
59
|
-
# Result here is an array instead of a hash.
|
60
|
-
{% for user in site.data.verified %}
|
61
|
-
- :check: {{user[0]}} (Email: {{user[1]}})
|
62
|
-
{% endfor %}
|
53
|
+
{{ site.data.categories | jsonify }}
|
63
54
|
```
|
64
55
|
|
65
56
|
## Generating Pages
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require
|
2
|
+
require "sqlite3"
|
3
|
+
|
3
4
|
module JekyllSQlite
|
4
5
|
# Main generator class
|
5
6
|
class Generator < Jekyll::Generator
|
@@ -14,22 +15,22 @@ module JekyllSQlite
|
|
14
15
|
end
|
15
16
|
|
16
17
|
# Get the root of where we are generating the data
|
17
|
-
def get_root(root,
|
18
|
-
|
18
|
+
def get_root(root, db_name)
|
19
|
+
db_name.split(".")[0..-2].each do |p|
|
19
20
|
root = root[p]
|
20
21
|
end
|
21
22
|
root
|
22
23
|
end
|
23
24
|
|
24
|
-
def gen_hash_data(root, db,
|
25
|
+
def gen_hash_data(root, db, db_name, query)
|
25
26
|
root ||= {}
|
26
27
|
|
27
|
-
root[
|
28
|
-
root[
|
28
|
+
root[db_name] = db.execute(query)
|
29
|
+
root[db_name].size
|
29
30
|
end
|
30
31
|
|
31
|
-
def gen_nested_data(item, db, query,
|
32
|
-
item[
|
32
|
+
def gen_nested_data(item, db, query, db_name)
|
33
|
+
item[db_name] = []
|
33
34
|
db.prepare(query) do |stmt|
|
34
35
|
# We bind params, ignoring any errors
|
35
36
|
# Since there's no way to get required params
|
@@ -38,30 +39,30 @@ module JekyllSQlite
|
|
38
39
|
stmt.bind_param key, value
|
39
40
|
rescue StandardError # rubocop:disable Lint/SuppressedException
|
40
41
|
end
|
41
|
-
stmt.execute.each { |d| item[
|
42
|
+
stmt.execute.each { |d| item[db_name] << d }
|
42
43
|
end
|
43
|
-
item[
|
44
|
+
item[db_name].size
|
44
45
|
end
|
45
46
|
|
46
|
-
def array_gen(root, config,
|
47
|
+
def array_gen(root, config, db_name, db)
|
47
48
|
count = 0
|
48
49
|
root.each do |item|
|
49
50
|
# TODO: Add support for binding Arrays as well.
|
50
51
|
if item.is_a? Hash
|
51
|
-
count += gen_nested_data(item, db, config["query"],
|
52
|
+
count += gen_nested_data(item, db, config["query"], db_name)
|
52
53
|
else
|
53
|
-
Jekyll.logger.info "Jekyll SQLite:", "Item is not a hash for #{
|
54
|
+
Jekyll.logger.info "Jekyll SQLite:", "Item is not a hash for #{db_name}. Unsupported configuration"
|
54
55
|
end
|
55
56
|
end
|
56
57
|
count
|
57
58
|
end
|
58
59
|
|
59
|
-
def gen_data(root, config,
|
60
|
+
def gen_data(root, config, db_name, db)
|
60
61
|
count = 0
|
61
62
|
if root.nil? || (root.is_a? Hash)
|
62
|
-
count = gen_hash_data(root, db, config["query"])
|
63
|
+
count = gen_hash_data(root, db, db_name, config["query"])
|
63
64
|
elsif root.is_a? Array
|
64
|
-
count = array_gen(root, config,
|
65
|
+
count = array_gen(root, config, db_name, db)
|
65
66
|
end
|
66
67
|
count
|
67
68
|
end
|
@@ -70,15 +71,28 @@ module JekyllSQlite
|
|
70
71
|
name.split(".")[-1]
|
71
72
|
end
|
72
73
|
|
74
|
+
def validate_config(config)
|
75
|
+
return false unless config.is_a? Hash
|
76
|
+
return false unless config.key?("query")
|
77
|
+
return false unless File.exist?(config["file"])
|
78
|
+
return false unless config.key?("data")
|
79
|
+
true
|
80
|
+
end
|
81
|
+
|
73
82
|
def generate(site)
|
74
|
-
site.config[
|
75
|
-
|
83
|
+
gem_config = site.config['sqlite'] || []
|
84
|
+
gem_config.each do |config|
|
85
|
+
unless validate_config(config)
|
86
|
+
Jekyll.logger.error "Jekyll SQLite:", "Invalid Configuration. Skipping"
|
87
|
+
next
|
88
|
+
end
|
89
|
+
d_name = config["data"]
|
76
90
|
SQLite3::Database.new config["file"], readonly: true do |db|
|
77
91
|
fast_setup db
|
78
92
|
db.results_as_hash = config.fetch("results_as_hash", true)
|
79
|
-
root = get_root(site.data,
|
80
|
-
count = gen_data(root, config, get_tip(
|
81
|
-
Jekyll.logger.info "Jekyll SQLite:", "Loaded #{
|
93
|
+
root = get_root(site.data, d_name)
|
94
|
+
count = gen_data(root, config, get_tip(d_name), db)
|
95
|
+
Jekyll.logger.info "Jekyll SQLite:", "Loaded #{d_name}. Count=#{count}"
|
82
96
|
end
|
83
97
|
end
|
84
98
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-sqlite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nemo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
version: '1.6'
|
27
27
|
description:
|
28
28
|
email:
|
29
|
-
- jekyll@captnemo.in
|
29
|
+
- jekyll-sqlite@captnemo.in
|
30
30
|
executables: []
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
@@ -35,7 +35,6 @@ files:
|
|
35
35
|
- CHANGELOG.md
|
36
36
|
- CODE_OF_CONDUCT.md
|
37
37
|
- Gemfile
|
38
|
-
- Gemfile.lock
|
39
38
|
- README.md
|
40
39
|
- Rakefile
|
41
40
|
- lib/jekyll-sqlite/generator.rb
|
@@ -64,9 +63,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
63
|
- !ruby/object:Gem::Version
|
65
64
|
version: '0'
|
66
65
|
requirements: []
|
67
|
-
rubygems_version: 3.
|
66
|
+
rubygems_version: 3.5.9
|
68
67
|
signing_key:
|
69
68
|
specification_version: 4
|
70
|
-
summary: A Jekyll plugin
|
71
|
-
a data source.
|
69
|
+
summary: A Jekyll plugin to use SQLite databases as a data source.
|
72
70
|
test_files: []
|
data/Gemfile.lock
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
jekyll-sqlite (0.1.1)
|
5
|
-
sqlite3 (~> 1.6)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
ast (2.4.2)
|
11
|
-
json (2.6.3)
|
12
|
-
parallel (1.23.0)
|
13
|
-
parser (3.2.2.1)
|
14
|
-
ast (~> 2.4.1)
|
15
|
-
rainbow (3.1.1)
|
16
|
-
rake (13.0.6)
|
17
|
-
regexp_parser (2.8.0)
|
18
|
-
rexml (3.2.5)
|
19
|
-
rubocop (1.50.2)
|
20
|
-
json (~> 2.3)
|
21
|
-
parallel (~> 1.10)
|
22
|
-
parser (>= 3.2.0.0)
|
23
|
-
rainbow (>= 2.2.2, < 4.0)
|
24
|
-
regexp_parser (>= 1.8, < 3.0)
|
25
|
-
rexml (>= 3.2.5, < 4.0)
|
26
|
-
rubocop-ast (>= 1.28.0, < 2.0)
|
27
|
-
ruby-progressbar (~> 1.7)
|
28
|
-
unicode-display_width (>= 2.4.0, < 3.0)
|
29
|
-
rubocop-ast (1.28.1)
|
30
|
-
parser (>= 3.2.1.0)
|
31
|
-
rubocop-rake (0.6.0)
|
32
|
-
rubocop (~> 1.0)
|
33
|
-
ruby-progressbar (1.13.0)
|
34
|
-
sqlite3 (1.6.2-aarch64-linux)
|
35
|
-
sqlite3 (1.6.2-x86_64-linux)
|
36
|
-
unicode-display_width (2.4.2)
|
37
|
-
|
38
|
-
PLATFORMS
|
39
|
-
aarch64-linux
|
40
|
-
x86_64-linux
|
41
|
-
|
42
|
-
DEPENDENCIES
|
43
|
-
jekyll-sqlite!
|
44
|
-
rake (~> 13.0)
|
45
|
-
rubocop (~> 1.21)
|
46
|
-
rubocop-rake (~> 0.6.0)
|
47
|
-
|
48
|
-
BUNDLED WITH
|
49
|
-
2.4.1
|