Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
118 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
local array_includes | ||
array_includes = function(array, val) | ||
for _index_0 = 1, #array do | ||
local array_val = array[_index_0] | ||
if array_val == val then | ||
return true | ||
end | ||
end | ||
return false | ||
end | ||
local query_page_match | ||
query_page_match = function(page, query) | ||
if not query or not next(query) then | ||
return true | ||
end | ||
for k, query_val in pairs(query) do | ||
local _continue_0 = false | ||
repeat | ||
local page_val = page.meta[k] | ||
if type(page_val) == "table" then | ||
if array_includes(page_val, query_val) then | ||
_continue_0 = true | ||
break | ||
end | ||
end | ||
if page_val ~= query_val then | ||
return false | ||
end | ||
_continue_0 = true | ||
until true | ||
if not _continue_0 then | ||
break | ||
end | ||
end | ||
return true | ||
end | ||
local query_pages | ||
query_pages = function(pages, query, opts) | ||
if query == nil then | ||
query = { } | ||
end | ||
if opts == nil then | ||
opts = { } | ||
end | ||
local out | ||
do | ||
local _accum_0 = { } | ||
local _len_0 = 1 | ||
for _index_0 = 1, #pages do | ||
local _continue_0 = false | ||
repeat | ||
local page = pages[_index_0] | ||
if not (query_page_match(page, query)) then | ||
_continue_0 = true | ||
break | ||
end | ||
local _value_0 = page | ||
_accum_0[_len_0] = _value_0 | ||
_len_0 = _len_0 + 1 | ||
_continue_0 = true | ||
until true | ||
if not _continue_0 then | ||
break | ||
end | ||
end | ||
out = _accum_0 | ||
end | ||
if opts.sort then | ||
local _ = nil | ||
end | ||
return out | ||
end | ||
return { | ||
query_pages = query_pages | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
array_includes = (array, val) -> | ||
for array_val in *array | ||
return true if array_val == val | ||
false | ||
|
||
query_page_match = (page, query) -> | ||
-- empty query matches all | ||
return true if not query or not next query | ||
|
||
for k,query_val in pairs query | ||
page_val = page.meta[k] | ||
|
||
if type(page_val) == "table" | ||
if array_includes page_val, query_val | ||
continue | ||
|
||
if page_val != query_val | ||
return false | ||
|
||
true | ||
|
||
query_pages = (pages, query={}, opts={}) -> | ||
out = for page in *pages | ||
continue unless query_page_match page, query | ||
page | ||
|
||
-- sort.. | ||
if opts.sort | ||
nil | ||
|
||
out | ||
|
||
{ :query_pages } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters