This commit is contained in:
Adam D. Ruppe 2018-11-10 21:33:51 -05:00
parent b1f0a46ca8
commit 3109d426ef
6 changed files with 75 additions and 4 deletions

3
cgi.d
View File

@ -26,6 +26,9 @@
* have data presentation magic
* do the skeleton stuff like 1.0
* auto-cache generated stuff in files (at least if pure?)
https://linux.die.net/man/3/posix_spawn
*/
/++

35
dom.d
View File

@ -2028,7 +2028,36 @@ class Element {
@property Element lastChild() {
return children.length ? children[$ - 1] : null;
}
/// UNTESTED
/// the next element you would encounter if you were reading it in the source
Element nextInSource() {
auto n = firstChild;
if(n is null)
n = nextSibling();
if(n is null) {
auto p = this.parentNode;
while(p !is null && n is null) {
n = p.nextSibling;
}
}
return n;
}
/// UNTESTED
/// ditto
Element previousInSource() {
auto p = previousSibling;
if(p is null) {
auto par = parentNode;
if(par)
p = par.lastChild;
if(p is null)
p = par;
}
return p;
}
///.
@property Element previousSibling(string tagName = null) {
@ -4895,6 +4924,12 @@ class Table : Element {
foreach(ele; e)
a.appendChild(ele);
row.appendChild(a);
} else static if(is(typeof(e) == string[])) {
foreach(ele; e) {
Element a = Element.make(innerType);
a.innerText = to!string(ele);
row.appendChild(a);
}
} else {
Element a = Element.make(innerType);
a.innerText = to!string(e);

19
jsvar.d
View File

@ -1162,8 +1162,13 @@ struct var {
}
public ref var opIndexAssign(T)(T t, string name, string file = __FILE__, size_t line = __LINE__) {
if(name.length && name[0] >= '0' && name[0] <= '9')
return opIndexAssign(t, to!size_t(name), file, line);
if(name.appearsNumeric()) {
try {
auto i = to!size_t(name);
return opIndexAssign(t, i, file, line);
} catch(Exception)
{} // ignore bad index, use it as a string instead lol
}
_requireType(Type.Object); // FIXME?
if(_payload._object is null)
throw new DynamicTypeException(var(null), Type.Object, file, line);
@ -1793,6 +1798,16 @@ bool isScriptableOpaque(T)() {
return false;
}
bool appearsNumeric(string n) {
if(n.length == 0)
return false;
foreach(c; n) {
if(c < '0' || c > '9')
return false;
}
return true;
}
/// Wraps a struct by reference. The pointer is stored - be sure the struct doesn't get freed or go out of scope!
///

View File

@ -1,5 +1,7 @@
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb775498%28v=vs.85%29.aspx
// need a viewer widget that works like a web page - arrows scroll down consistently
// FIXME: the menus should be a bit more discoverable, at least a single click to open the others instead of two.
// and help info about menu items.
// and search in menus?

2
ttf.d
View File

@ -31,7 +31,7 @@ struct TtfFont {
throw new Exception("load font problem");
}
///
/// Note that you must stbtt_FreeBitmap(returnValue.ptr, null); this thing or it will leak!!!!
ubyte[] renderCharacter(dchar c, int size, out int width, out int height, float shift_x = 0.0, float shift_y = 0.0) {
auto ptr = stbtt_GetCodepointBitmapSubpixel(&font, 0.0,stbtt_ScaleForPixelHeight(&font, size),
shift_x, shift_y, c, &width, &height, null,null);

18
web.d
View File

@ -211,6 +211,13 @@ struct Text {
alias content this;
}
///
struct URL {
string url; ///
string title; ///
alias url this;
}
/// This is the JSON envelope format
struct Envelope {
bool success; /// did the call succeed? false if it threw an exception
@ -3977,7 +3984,16 @@ Table structToTable(T)(Document document, T arr, string[] fieldsToSkip = null) i
foreach(s; arr) {
auto tr = tbody.addChild("tr");
foreach(member; s.tupleof) {
tr.addChild("td", to!string(member));
static if(is(typeof(member) == URL[])) {
auto td = tr.addChild("td");
foreach(i, link; member) {
td.addChild("a", link.title.length ? link.title : to!string(i), link.url);
td.appendText(" ");
}
} else {
tr.addChild("td", to!string(member));
}
}
if(odd)