zen-coding: default DIV tag support in HTML/XHTML files; tests

This commit is contained in:
Eugene Kudelevsky
2010-04-22 21:50:34 +04:00
parent 80bd90c971
commit 6fca237f5c
2 changed files with 20 additions and 3 deletions
@@ -46,6 +46,7 @@ public class XmlZenCodingTemplate extends ZenCodingTemplate {
private static final String SELECTORS = ".#[";
private static final String ID = "id";
private static final String CLASS = "class";
private static final String DEFAULT_TAG = "div";
private static String getPrefix(@NotNull String templateKey) {
for (int i = 0, n = templateKey.length(); i < n; i++) {
@@ -160,10 +161,26 @@ public class XmlZenCodingTemplate extends ZenCodingTemplate {
return type == StdFileTypes.XHTML || type == StdFileTypes.JSPX || type == StdFileTypes.XML;
}
private static boolean isHtml(CustomTemplateCallback callback) {
FileType type = callback.getFileType();
return type == StdFileTypes.HTML || type == StdFileTypes.XHTML;
}
@Override
@Nullable
protected TemplateToken parseTemplateKey(String key, CustomTemplateCallback callback) {
String prefix = getPrefix(key);
boolean useDefaultTag = false;
if (prefix.length() == 0) {
if (!isHtml(callback)) {
return null;
}
else {
useDefaultTag = true;
prefix = DEFAULT_TAG;
key = prefix + key;
}
}
TemplateImpl template = callback.findApplicableTemplate(prefix);
if (template == null && !isXML11ValidQName(prefix)) {
return null;
@@ -172,6 +189,9 @@ public class XmlZenCodingTemplate extends ZenCodingTemplate {
if (token == null) {
return null;
}
if (useDefaultTag && token.myAttribute2Value.size() == 0) {
return null;
}
if (template != null && (token.myAttribute2Value.size() > 0 || isTrueXml(callback))) {
assert prefix.equals(token.myKey);
token.myTemplate = template;
@@ -68,9 +68,6 @@ public abstract class ZenCodingTemplate implements CustomLiveTemplate {
result.add(new NumberToken(num));
}
else {
if (key.length() == 0) {
return null;
}
TemplateToken token = parseTemplateKey(key, callback);
if (token == null) return null;
result.add(token);