vocabs.metadata: add "vocab-resources" word to read list of deployable resource files from a "resources.txt" file in the vocab directory. add "vocabs.metadata.resources" subvocab that expands globs and directory names in resources.txt entries
parent
1632fa6448
commit
c0aee19082
|
@ -18,6 +18,11 @@ ARTICLE: "vocabs.metadata" "Vocabulary metadata"
|
|||
set-vocab-tags
|
||||
add-vocab-tags
|
||||
}
|
||||
"Vocabulary resources:"
|
||||
{ $subsections
|
||||
vocab-resources
|
||||
set-vocab-resources
|
||||
}
|
||||
"Getting and setting arbitrary vocabulary metadata:"
|
||||
{ $subsections
|
||||
vocab-file-contents
|
||||
|
@ -50,3 +55,11 @@ HELP: set-vocab-tags
|
|||
{ $values { "tags" "a sequence of strings" } { "vocab" "a vocabulary specifier" } }
|
||||
{ $description "Stores a list of short tags classifying the vocabulary to the " { $snippet "tags.txt" } " file in the vocabulary's directory." } ;
|
||||
|
||||
HELP: vocab-resources
|
||||
{ $values { "vocab" "a vocabulary specifier" } { "patterns" "a sequence of glob patterns" } }
|
||||
{ $description "Outputs a list of glob patterns matching files that will be deployed with an application that includes " { $snippet "vocab" } ", as specified by the " { $snippet "resources.txt" } " file in the vocabulary's directory. Outputs an empty array if the file doesn't exist." }
|
||||
{ $notes "The " { $vocab-link "vocabs.metadata.resources" } " vocabulary contains words that will expand the glob patterns and directory names in " { $snippet "patterns" } " and return all the matching files." } ;
|
||||
|
||||
HELP: set-vocab-resources
|
||||
{ $values { "patterns" "a sequence of glob patterns" } { "vocab" "a vocabulary specifier" } }
|
||||
{ $description "Stores a list of glob patterns matching files that will be deployed with an application that includes " { $snippet "vocab" } " to the " { $snippet "resources.txt" } " file in the vocabulary's directory." } ;
|
||||
|
|
|
@ -19,6 +19,15 @@ MEMO: vocab-file-contents ( vocab name -- seq )
|
|||
3append throw
|
||||
] ?if ;
|
||||
|
||||
: vocab-resources-path ( vocab -- string )
|
||||
vocab-dir "resources.txt" append-path ;
|
||||
|
||||
: vocab-resources ( vocab -- patterns )
|
||||
dup vocab-resources-path vocab-file-contents harvest ;
|
||||
|
||||
: set-vocab-resources ( patterns vocab -- )
|
||||
dup vocab-resources-path set-vocab-file-contents ;
|
||||
|
||||
: vocab-summary-path ( vocab -- string )
|
||||
vocab-dir "summary.txt" append-path ;
|
||||
|
||||
|
@ -67,4 +76,4 @@ M: vocab-link summary vocab-summary ;
|
|||
dup vocab-authors-path set-vocab-file-contents ;
|
||||
|
||||
: unportable? ( vocab -- ? )
|
||||
vocab-tags "unportable" swap member? ;
|
||||
vocab-tags "unportable" swap member? ;
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
! (c)2010 Joe Groff bsd license
|
||||
USING: help.markup help.syntax kernel ;
|
||||
IN: vocabs.metadata.resources
|
||||
|
||||
HELP: expand-vocab-resource-files
|
||||
{ $values
|
||||
{ "vocab" "a vocabulary specifier" } { "resource-glob-strings" "a sequence of glob patterns" }
|
||||
{ "filenames" "a sequence of filenames" }
|
||||
}
|
||||
{ $description "Matches all the glob patterns in " { $snippet "resource-glob-strings" } " to the set of files inside " { $snippet "vocab" } "'s directory and outputs a sequence containing the individual files and directories that match. Any matching directories will also have their contents recursively included in the output. The paths in the output will be relative to " { $snippet "vocab" } "'s directory." } ;
|
||||
|
||||
HELP: vocab-resource-files
|
||||
{ $values
|
||||
{ "vocab" "a vocabulary specifier" }
|
||||
{ "filenames" "a sequence of filenames" }
|
||||
}
|
||||
{ $description "Outputs a sequence containing the individual resource files and directories that match the patterns specified in " { $snippet "vocab" } "'s " { $snippet "resources.txt" } " file. Any matching directories will also have their contents recursively included in the output. The paths in the output will be relative to " { $snippet "vocab" } "'s directory." } ;
|
||||
|
||||
ARTICLE: "vocabs.metadata.resources" "vocabs.metadata.resources"
|
||||
"The " { $vocab-link "vocabs.metadata.resources" } " vocabulary contains words to retrieve the full list of files that match the patterns specified in a vocabulary's " { $snippet "resources.txt" } " file."
|
||||
{ $subsections
|
||||
vocab-resource-files
|
||||
expand-vocab-resource-files
|
||||
} ;
|
||||
|
||||
ABOUT: "vocabs.metadata.resources"
|
|
@ -0,0 +1,19 @@
|
|||
! (c)2010 Joe Groff bsd license
|
||||
USING: sorting tools.test vocabs.metadata.resources ;
|
||||
IN: vocabs.metadata.resources.tests
|
||||
|
||||
[ { "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/buh"
|
||||
"resource-dir/foo"
|
||||
} ] [ "vocabs.metadata.resources.test.3" vocab-resource-files natural-sort ] unit-test
|
|
@ -0,0 +1,24 @@
|
|||
! (c)2010 Joe Groff bsd license
|
||||
USING: arrays fry globs io.directories 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 ;
|
||||
PRIVATE>
|
||||
|
||||
: expand-vocab-resource-files ( vocab resource-glob-strings -- filenames )
|
||||
[ [ find-vocab-root ] [ vocab-dir ] bi append-path ] dip [ <glob> ] map '[
|
||||
_ filter-resources
|
||||
[ (expand-vocab-resource) ] map concat
|
||||
] with-directory-tree-files ;
|
||||
|
||||
: vocab-resource-files ( vocab -- filenames )
|
||||
dup vocab-resources expand-vocab-resource-files ;
|
|
@ -0,0 +1,6 @@
|
|||
USING: io kernel ;
|
||||
IN: vocabs.metadata.resources.test.1
|
||||
|
||||
: main ( -- ) "Resources test 1" print ;
|
||||
|
||||
MAIN: main
|
|
@ -0,0 +1,3 @@
|
|||
foo
|
||||
bar
|
||||
bas
|
|
@ -0,0 +1,6 @@
|
|||
USING: io kernel ;
|
||||
IN: vocabs.metadata.resources.test.2
|
||||
|
||||
: main ( -- ) "Resources test 2" print ;
|
||||
|
||||
MAIN: main
|
|
@ -0,0 +1 @@
|
|||
*.wtf
|
|
@ -0,0 +1,6 @@
|
|||
USING: io kernel ;
|
||||
IN: vocabs.metadata.resources.test.3
|
||||
|
||||
: main ( -- ) "Resources test 3" print ;
|
||||
|
||||
MAIN: main
|
|
@ -0,0 +1 @@
|
|||
resource-dir
|
Loading…
Reference in New Issue