dlangui icon indicating copy to clipboard operation
dlangui copied to clipboard

Dml From File

Open MggMuggins opened this issue 6 years ago • 3 comments

Sorry, I've been opening a lot of issues lately...

Is there any way to put my dml into a separate file and load that at runtime instead of writing it out in my D code? The reason I ask is that the documentation has this prototype for parseML:

Widget parseML(T)( 
  string code, 
  string filename = "", 
  Widget context = null 
);

MggMuggins avatar Sep 18 '17 22:09 MggMuggins

Currently, there is no such functionality. It makes sense to implement it. It could be possible to choose one of markup files from resources depending on DPI, screen size, etc. like it's done in Android UI API. As well, it may be easier to edit such file comparing to embedded string constant in .d code.

buggins avatar Sep 19 '17 06:09 buggins

I agree. I also really like the idea of choosing different DML based on screen size.

How does that string constant even work? The syntax is this:

q{String Contents}

But that doesn't make a whole lot of sense to me.

MggMuggins avatar Sep 19 '17 17:09 MggMuggins

I'll open a PR sometime in the next few days with dml file support added in a rudimentary sort of way. I'd like to do it in such a way that the tokenizer uses the file as a stream instead of simply copying the whole thing into RAM like my hacky solution (file.readln('\x00'))...

It's probably best not to allow parseML to take both a filename and a string at the same time. Seems like that introduces more complexity than is necessary, as well as leading to some ambiguous cases where it's not clear what the user wants. I may in that case somehow overload parseML and make some changes to the tokenizer to allow for a "mode".

Any thoughts on API? I would recommend deprecating the current declaration of parseML (with the signature I provided above) and doing two like this (rather than passing a string as the filename, since that's ambiguous and doesn't have a clear solution in my mind):

T parseML(T = Widget)(string code, Widget context = null);
T parseML(T = Widget)(File file, Widget context = null);

Any ideas?

EDIT: The problem with this is that the user then defines the read/write mode on the file, which is something that we absolutely do not want... I don't know of any standard path object that we could pass in there, and a string is most convenient. Is there any way to leverage the type system and specify that one takes as a parameter an explicit token string, and the other a regular string?

EDIT2: I'm feeling at this point like it would be best to do something like this:

T parseML(T = Widget)(string code, Widget context = null);
T parseMLFile(T = Widget)(string filename, Widget context = null);

MggMuggins avatar Nov 10 '17 00:11 MggMuggins