From: Andy Mikhaylenko <neit...@gmail.com>
To: shp...@googlegroups.com
Sent: Sunday, July 15, 2012 5:46 AM
Subject: Re: SHPAML still alive?
From: zak <zakd...@gmail.com>
To: shp...@googlegroups.com
Cc: jia...@gmail.com
Sent: Monday, September 3, 2012 12:07 PM
Subject: Re: SHPAML still alive?
From: Niklas Hambüchen <n...@deditus.de>
To: shp...@googlegroups.com
Cc: zak <zakd...@gmail.com>; jia...@gmail.com
Sent: Tuesday, September 4, 2012 8:47 PM
Subject: Re: SHPAML still alive?
I'm the original author of shpaml, and I'm excited that you're working on this.
First, I like your decision to output "well formed" shpaml, certainly for version one. For me the most compelling feature of the language is the removal of end tags, and then almost everything else is gravy. I also like the sugar for div tags, id parameters, and class parameters, all of which are shamelessly stolen from haml. I actually pushed back on some features--including the removal of quotes from attributes--because I felt they went a little too far. After trying them out, I was glad that folks pushed for them. But, in creating a tool to help migrate people, I think a few extra quotes are pretty harmless, as long as they get the big win from nice indentation and less clutter related to div tags.
One of my goals with the translator was to keep it fairly dumb about html itself and fairly liberal about what it would translate. My goal was to reduce visual clutter in the source document, but then I leave it to the programmer to make sure that the output produced by the translator worked within their goals. And, of course, there are plenty of tools to help in that. One workflow, for example, is to write in shpaml, then wire up your editor to automatically translate it, then integrate with a more full featured templating language, and then automatically validate the final HTML with a validator. When you list all the steps, it sounds somewhat cumbersome, but it's all fairly easy to script.
Subject: Re: SHPAML still alive?
From: Niklas Hambüchen <n...@deditus.de>
To: shp...@googlegroups.com
Cc: Steve Howell <show...@yahoo.com>
Sent: Wednesday, September 5, 2012 8:21 AM
#! /usr/bin/pythonimport sysimport codecsfrom WebElements import Basefrom WebElements.Parser import WebElementTreefrom WebElements.StringUtils import interpretAsStringBase.INDENTATION = " "class ShpamlTree(WebElementTree):def endTag(self):return ""def startTag(self):if not self.tagName:return u''self.attributes['name'] = self.fullName()self.attributes['style'] = self.stylestartTag = self.tagNameID = self.fullId()if ID:startTag += "#" + IDfor cssClass in self.classes:startTag += "." + cssClassstartTag += " "for key, value in self.attributes.iteritems():value = interpretAsString(value)if value:if value == '<BLANK>':value = ""if value == '<EMPTY>':startTag += key + " "else:if not " " in value and not '"' in value:startTag += key + '=' + value + ' 'else:startTag += key + '="' + value.replace('"', '"') + '" 'if self.tagSelfCloses:startTag = '> ' + startTagelif not self.childElements:startTag = startTag[:-1] + "\n%(indent)s::comment\n%(indent)s%(indent)sempty " % {"indent":Base.INDENTATION}elif len(self.childElements) == 1 and type(self.childElements[0]) == Base.TextNode:textNode = self.childElements[0]if not "\n" in textNode.text():startTag += "| " + textNode.text() + " "self.removeChild(textNode)return startTag[:-1]def parseFile(fileName, saveChanges=True):with open(fileName, 'r') as fileObj:text = fileObj.read().decode('utf8')tree = ShpamlTree(text)print tree.toHtml(formatted=True)return treedef printDoc():print "Html2Shpaml 0.1 is a forgiving html to shpaml converter"print "usage: Html2Shpaml (filename)"print ""print "Directly prints Shpaml syntaxt - with can then be redirected into a file"def main(argv):if len(argv) < 2:printDoc()elif len(argv) == 2:parseFile(argv[1])else:printDoc()if __name__ == '__main__':main(sys.argv)Let me know what you think, Thanks!Timothy