vocabs.metadata.resources: refactoring of code for gathering resources
parent
ab7e077b1d
commit
c23dbf0f8f
|
@ -1,7 +1,11 @@
|
|||
! (c)2010 Joe Groff bsd license
|
||||
USING: help.markup help.syntax kernel ;
|
||||
USING: help.markup help.syntax strings ;
|
||||
IN: vocabs.metadata.resources
|
||||
|
||||
HELP: copy-vocab-resources
|
||||
{ $values { "dir" string } { "vocab" string } }
|
||||
{ $description "Copies all the vocabs resource files to the given directory." } ;
|
||||
|
||||
HELP: expand-vocab-resource-files
|
||||
{ $values
|
||||
{ "vocab" "a vocabulary specifier" } { "resource-glob-strings" "a sequence of glob patterns" }
|
||||
|
|
|
@ -1,18 +1,28 @@
|
|||
! (c)2010 Joe Groff bsd license
|
||||
USING: sorting tools.test vocabs.metadata.resources ;
|
||||
USING: arrays globs sorting tools.test vocabs.metadata.resources ;
|
||||
IN: vocabs.metadata.resources.tests
|
||||
|
||||
! filter-resources
|
||||
{ { "hello.txt" } } [
|
||||
"*.txt" <glob> 1array { "hello.txt" } filter-resources
|
||||
] unit-test
|
||||
|
||||
! vocab-resource-files
|
||||
{ { "bar" "bas" "foo" } }
|
||||
[ "vocabs.metadata.resources.test.1" vocab-resource-files natural-sort ] unit-test
|
||||
|
||||
{ { "bar.wtf" "foo.wtf" } }
|
||||
[ "vocabs.metadata.resources.test.2" vocab-resource-files natural-sort ] unit-test
|
||||
|
||||
{ {
|
||||
{
|
||||
{
|
||||
"resource-dir"
|
||||
"resource-dir/bar"
|
||||
"resource-dir/bas"
|
||||
"resource-dir/bas/zang"
|
||||
"resource-dir/bas/zim"
|
||||
"resource-dir/foo"
|
||||
} } [ "vocabs.metadata.resources.test.3" vocab-resource-files natural-sort ] unit-test
|
||||
}
|
||||
} [
|
||||
"vocabs.metadata.resources.test.3" vocab-resource-files natural-sort
|
||||
] unit-test
|
||||
|
|
|
@ -1,19 +1,10 @@
|
|||
! (c)2010 Joe Groff bsd license
|
||||
USING: arrays fry globs io.directories io.directories.hierarchy
|
||||
io.files.info io.pathnames kernel regexp sequences vocabs.loader
|
||||
vocabs.metadata ;
|
||||
USING: globs io.directories io.directories.hierarchy io.files.info
|
||||
io.pathnames kernel regexp sequences vocabs.loader vocabs.metadata ;
|
||||
IN: vocabs.metadata.resources
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: (expand-vocab-resource) ( resource-path -- filenames )
|
||||
dup file-info directory?
|
||||
[ dup '[ _ directory-tree-files [ append-path ] with map ] [ prefix ] bi ]
|
||||
[ 1array ] if ;
|
||||
|
||||
: filter-resources ( vocab-files resource-globs -- resource-files )
|
||||
'[ _ [ matches? ] with any? ] filter ;
|
||||
|
||||
: copy-vocab-resource ( to from file -- )
|
||||
[ append-path ] curry bi@
|
||||
dup file-info directory?
|
||||
|
@ -23,17 +14,21 @@ IN: vocabs.metadata.resources
|
|||
PRIVATE>
|
||||
|
||||
: vocab-dir-in-root ( vocab -- dir )
|
||||
[ find-vocab-root ] [ vocab-dir ] bi append-path ;
|
||||
vocab-source-path parent-directory ;
|
||||
|
||||
: expand-vocab-resource-files ( vocab resource-glob-strings -- filenames )
|
||||
[ vocab-dir-in-root ] dip [ <glob> ] map '[
|
||||
_ filter-resources
|
||||
[ (expand-vocab-resource) ] map concat
|
||||
] with-directory-tree-files ;
|
||||
: expand-resource ( resource-path -- filenames )
|
||||
dup dup file-info directory? [
|
||||
dup directory-tree-files [ append-path ] with map
|
||||
] [ drop { } ] if swap prefix ;
|
||||
|
||||
: filter-resources ( resource-globs vocab-files -- vocab-files' )
|
||||
[ swap [ matches? ] with any? ] with filter ;
|
||||
|
||||
: vocab-resource-files ( vocab -- filenames )
|
||||
dup vocab-resources
|
||||
[ drop f ] [ expand-vocab-resource-files ] if-empty ;
|
||||
[ vocab-resources [ <glob> ] map ] [ vocab-dir-in-root ] bi
|
||||
[
|
||||
filter-resources [ expand-resource ] map concat
|
||||
] with-directory-files ;
|
||||
|
||||
: copy-vocab-resources ( dir vocab -- )
|
||||
dup vocab-resource-files
|
||||
|
|
Loading…
Reference in New Issue