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