]> gitweb.factorcode.org Git - factor.git/commitdiff
vocabs.metadata.resources: refactoring of code for gathering resources
authorBjörn Lindqvist <bjourne@gmail.com>
Tue, 13 Sep 2016 03:29:15 +0000 (05:29 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Tue, 13 Sep 2016 03:36:50 +0000 (05:36 +0200)
basis/vocabs/metadata/resources/resources-docs.factor
basis/vocabs/metadata/resources/resources-tests.factor
basis/vocabs/metadata/resources/resources.factor

index a20775e9370cf037d798feb34977dd70d28a7a29..cb3e53c670dfa2fd26066a1733c8b3687efeb393 100644 (file)
@@ -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" }
index 96ff25a69621ccf6de5d51e50a1ea2ca08fe91cf..afb0d2ad733c15de69f878d85072fccca7bf39ac 100644 (file)
@@ -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
+{
+    {
+        "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
index 4872068e58f82bedad85773c9938bc4307e89a33..635bd4cc3f4c90c2db28eefbf2e67b2c738b3a46 100644 (file)
@@ -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-resource ( resource-path -- filenames )
+    dup dup file-info directory? [
+        dup directory-tree-files [ append-path ] with map
+    ] [ drop { } ] if swap prefix ;
 
-: 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 ;
+: 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