[nap] refactoring and adding templates
This commit is contained in:
@@ -1,15 +1,28 @@
|
||||
(defnew [&prop :String archiveDir
|
||||
&prop :Array<System> systems]
|
||||
(defnew [&prop :String archiveDir]
|
||||
|
||||
[:Map<String,Entry> entries
|
||||
[:Array<System> systems
|
||||
[]
|
||||
:Map<String,Template> templates
|
||||
(new Map)
|
||||
:Map<String,Entry> entries
|
||||
(let [entryFiles (FileSystem.readDirectory (Path.join [archiveDir "entries"]))]
|
||||
(for file entryFiles =>(file.withoutExtension) ~(the Entry (Json.parse (File.getContent (Path.join [archiveDir "entries" file]))))))]
|
||||
(for file entryFiles =>(file.withoutExtension) ~(the Entry (Json.parse (File.getContent (Path.join [archiveDir "entries" file]))))))])
|
||||
|
||||
(defmethod addSystem [:System system]
|
||||
// Assign entries to the Systems that care about them
|
||||
(doFor system systems
|
||||
(doFor =>id entry entries
|
||||
(when (system.canProcessEntry entry)
|
||||
(system.entries.push entry)))))
|
||||
(doFor =>id entry entries
|
||||
(system.checkEntryInOrOut this entry))
|
||||
(systems.push system))
|
||||
|
||||
(defmethod addTemplate [name template]
|
||||
(dictSet templates name template))
|
||||
|
||||
(defmethod :Entry createEntry [template]
|
||||
(let [e (_newEntry)]
|
||||
(.prepareEntry (dictGet templates template) e)
|
||||
(doFor system systems
|
||||
(system.checkEntryInOrOut this e))
|
||||
e))
|
||||
|
||||
(defun :Entry _newEntry []
|
||||
(object
|
||||
|
||||
@@ -2,5 +2,8 @@ package nap;
|
||||
|
||||
import kiss.Prelude;
|
||||
|
||||
typedef EntryChecker = (Archive, Entry) -> Bool;
|
||||
typedef EntryProcessor = (Archive, Entry) -> Void;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class System {}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
(defprop :List<Entry> entries (new List))
|
||||
(defprop :Map<String,Entry> entries (new Map))
|
||||
|
||||
(defmethod :Void process []
|
||||
(entries.map processEntry))
|
||||
(defmethod :Void process [:Archive archive]
|
||||
(doFor e (entries.iterator) (processEntry archive e)))
|
||||
|
||||
(defmethod :Void processEntry [:Entry e]
|
||||
(throw "can't process $e"))
|
||||
(defnew [&prop :EntryChecker canProcessEntry
|
||||
&prop :EntryProcessor processEntry]
|
||||
[])
|
||||
|
||||
(defmethod :Bool canProcessEntry [:Entry e]
|
||||
(throw "can't decide whether to process $e"))
|
||||
(defmethod :Void checkEntryInOrOut [:Archive archive :Entry e]
|
||||
(if (canProcessEntry archive e)
|
||||
(dictSet entries e.id e)
|
||||
(entries.remove e.id)))
|
||||
|
||||
5
projects/nap/src/nap/Template.hx
Normal file
5
projects/nap/src/nap/Template.hx
Normal file
@@ -0,0 +1,5 @@
|
||||
package nap;
|
||||
|
||||
interface Template {
|
||||
function prepareEntry(e:Entry):Void;
|
||||
}
|
||||
@@ -1,4 +1,9 @@
|
||||
(defnew [&prop :String tagFilterString] [])
|
||||
(load "../Lib.kiss")
|
||||
|
||||
(defmethod &override :Bool canProcessEntry [:Entry e] (print false))
|
||||
// (Lib.evalBoolExp tagFilterString (getTags e)))
|
||||
// TODO make a &super annotation that passes an argument to the super constructor
|
||||
(defnew [&prop :String tagFilterString
|
||||
&prop :EntryProcessor processor]
|
||||
[]
|
||||
(super
|
||||
(lambda [:Archive archive :Entry e] (tagsMatch archive e tagFilterString))
|
||||
processor))
|
||||
@@ -1,4 +1,6 @@
|
||||
// TODO external programs need to be able to find and (load) this path to get the macros:
|
||||
// ^ That should be solved by allowing an optional first argument to load that is a symbol
|
||||
// of a library name that can be used to resolve the source dir in the user's Haxelib maybe?
|
||||
(load "../nap/Lib.kiss")
|
||||
|
||||
|
||||
@@ -10,10 +12,8 @@
|
||||
(assert !(BoolExpInterp.eval "(and flag false)" ["flag"]))
|
||||
(assert (BoolExpInterp.eval "(or flag otherFlag)" ["otherFlag"]))
|
||||
//trace(error);
|
||||
(let [systems
|
||||
[]
|
||||
archive
|
||||
(new Archive "src/test/example-archive" systems)
|
||||
(let [archive
|
||||
(new Archive "src/test/example-archive")
|
||||
song1
|
||||
(dictGet archive.entries "song1")
|
||||
song2
|
||||
|
||||
Reference in New Issue
Block a user