//[XmlAttribute] //public string Url; //[XmlAttribute] //public string Style; public override IEnumerable<tag> Generate(body pg, LoggerMemory wr) { //if (string.IsNullOrEmpty(urlText) && string.IsNullOrEmpty(urlDialog)) wr.ErrorLine(pg.url, "Missing url-text or url-dialog attribute"); //if (!string.IsNullOrEmpty(urlText) && !string.IsNullOrEmpty(urlDialog)) wr.ErrorLine(pg.url, "Use only one from url-text or url-dialog attributes"); //var isDialog = !string.IsNullOrEmpty(urlDialog); var cid = "macrovideo_" + cnt++.ToString(); //var file = isDialog ? (include)new includeDialog { cutUrl = urlDialog} : new includeText { cutUrl = urlText}; switch (displayStyle) { case "WithDialog": yield return htmlTag.create(htmlTag.div, htmlTag.create(htmlTag.div, "class", "col-md-5 video-hidden-xs video-hidden-sm", new mediaVideo { classSetter = "video-hidden-xs video-hidden-sm", shareMediaId = cid }, new mediaPlayer { classSetter = "hidden-xs hidden-sm", shareMediaId = cid } ), htmlTag.create(htmlTag.div, "class", "col-md-7", new mediaText { id = cid, /*audioUrl = audioUrl,*/ mediaUrl = mediaUrl, cutUrl = cutUrl } ) ); break; default: yield return htmlTag.create(htmlTag.div, new mediaVideo() { id = cid, /*audioUrl = audioUrl,*/ mediaUrl = mediaUrl, cutUrl = cutUrl }, new mediaPlayer() { shareMediaId = cid }); break; } }
//[XmlAttribute] //public CheckItemTexts TextId; public override IEnumerable<tag> Generate(body pg, LoggerMemory wr) { var lines = smartElement.splitLines(cdata); if (lines.Length == 0) { wr.ErrorLine(pg.url, "Missing lines with data"); yield break; } lines = lines.Select(l => smartElement.removeNums(l).Trim()).ToArray(); yield return new listGroup() { //width = width, Items = lines.Select(l => new checkItem() { correctValue = l.StartsWith("#"), textType = textId, Items = smartElement.replaceMacroHardReturn(l.Replace("#", null), wr).ToArray() }).ToArray() }; }
public static void applyCSS(ref body pg, CourseMeta.ex ex) { //all styles (LM and CSS) from tags foreach (var tg in pg.scan()) { var hasSheet = !string.IsNullOrEmpty(tg.styleSheet); if (hasSheet) pg.bodyStyle += "" + CSS.prefixTagId(tg.id, tg.styleSheet); tg.styleSheet = null; } //all styles (LM and CSS) from parents CourseMeta.data p = ex; StringBuilder sb = new StringBuilder(pg.bodyStyle); while (p != null) { if (!string.IsNullOrEmpty(p.styleSheet)) sb.Insert(0, p.styleSheet.Trim() + " "); p = p.parent; } sb.Insert(0, CourseMeta.ex.stdStyle); pg.bodyStyle = sb.ToString(); //separate LM a CSS styles rules lmCss = separateLM_CSS_styles(pg); if (lmCss == null) return; //apply LM styles to XML XElement root = pg.ToElement(); var bodyTags = root.Element("body").DescendantsAndSelf(); foreach (var ctrl in bodyTags.Where(c => Lib.courseModelJsonMLMeta.allCSControls.Contains(c.Name.LocalName))) { var html = new DomElement(ctrl); var typeMeta = Lib.courseModelJsonMLMeta.types[ctrl.Name.LocalName]; var attrsSpecs = new Dictionary<string, specificity>(); //nejlepsi hodnoty pro kazdou property for (var i = lmCss.lmRules.Count - 1; i >= 0; i--) { //jednotilve rule var spec = lmCss.lmRules[i].data.matchesSelectors(html, null); if (spec == null) continue; foreach (var prop in lmCss.lmRules[i].props.Where(pr => typeMeta.allProps.ContainsKey(pr.name))) { //jednotlive rule properties specificity sp; if (!attrsSpecs.TryGetValue(prop.name, out sp) || sp.I_am_worse(spec, prop.important)) attrsSpecs[prop.name] = new specificity(spec, prop.important, prop.value); //nova nebo lepsi value } } //dosad values do XML foreach (var kv in attrsSpecs) { var at = ctrl.Attribute(kv.Key); if (at != null) continue; ctrl.Add(new XAttribute(kv.Key, kv.Value.value)); } } //zpracuj cssTagIds properties //foreach (var attr in bodyTags.SelectMany(el => el.Attributes()).Where(a => Lib.courseModelJsonMLMeta.allCssTagIds.Contains(a.Parent.Name.LocalName + "." + a.Name.LocalName))) { // attr.Value = cssTagRx.Replace(attr.Value, m => { // var ruleTxt = m.Groups["selector"].Value + " {}"; // var rule = CssDataFactory.parseStylesheet(ruleTxt).getRulesets(CssDataFactory.defaultMedium).First(); // return bodyTags.Where(el => rule.matchesSelectors(new DomElement(el), null) != null).Select(el => "#" + el.AttributeValue("id")).Where(id => id != "#").Aggregate((r, i) => r + "|" + i); // }); //} //body from XML pg = tag.FromElement<body>(root); }
public override IEnumerable<tag> Generate(body pg, LoggerMemory wr) { var txt = doubleCrLf.Replace(cdata, "#####"); var linesSingleChs = txt.Split(new string[] { "#####" }, StringSplitOptions.RemoveEmptyEntries); if (linesSingleChs.Length == 0) { wr.ErrorLine(pg.url, "Missing lines with data"); yield break; } var singleChs = linesSingleChs.Select(l => smartElement.splitLines(l).Select(ll => smartElement.removeNums(ll)).ToArray()); //var cnt = 0; var res = new twoColumn() { Items = singleChs.Where(l => l.Count() > 0).Select(singleCh => new panel() { header = new headerProp { Items = new tag[] { htmlTag.create(htmlTag.h4, smartElement.replaceMacroHardReturn(singleCh[0], wr)) } }, //id = cnt++<0 ? "": null, //noop majici sideefekt - zvetseni cnt Items = new tag[] { new singleChoice { Items = singleCh.Skip(1).Select(t => new radioButton{correctValue = t.StartsWith("#"), Items = new tag[] { new text{title = t.TrimStart('#')}}}).ToArray()}, } }).ToArray() }; yield return res; }
public override IEnumerable<tag> Generate(body pg, LoggerMemory wr) { yield return htmlTag.create(htmlTag.h3, new text() { title = cdata }); }
public override IEnumerable<tag> Generate(body pg, LoggerMemory wr) { var lines = smartElement.splitLines(cdata); if (lines.Length == 0) return Enumerable.Empty<tag>(); list res = new list() { //width = width, delim = delim, isStriped = isStriped, icon = icon, color = color, Items = lines.Select(l => smartElement.removeNums(l).Trim()).Select(l => htmlTag.create(htmlTag.li, smartTag.formatedText(l))).ToArray() }; return (res as IMacroTemplate).Generate(pg, wr); }
public override IEnumerable<tag> Generate(body pg, LoggerMemory wr) { if (cdata == null) yield break; var lines = smartElement.splitLines(cdata); if (lines.Length == 0) yield break; string tableStyleSheet; tag pref = macroTable.prefix(this, inlineType, ref lines, out tableStyleSheet); if (pref != null) yield return pref; var res = new listGroup() { //width = width, Items = lines.Select(l => smartElement.removeNums(l).Trim()).Select(l => new node() { Items = smartTag.replaceMacroHardReturn(l, wr, inlineType).ToArray() }).ToArray() }; //smartElement.adjustWidths(res2, inlineType, wr); yield return res; }
public override IEnumerable<tag> Generate(body pg, LoggerMemory wr) { var lines = smartElement.splitLines(cdata); if (lines.Length == 0) { wr.ErrorLine(pg.url, "Missing lines with data"); yield break; } string tableStyleSheet; tag pref = prefix(this, inlineType, ref lines, out tableStyleSheet); if (pref != null) yield return pref; var cells = lines.Select(l => l.Split('\\').Select(w => w.Trim()).ToArray()).ToArray(); if (cells.GroupBy(c => c.Length).Count() > 1) { wr.ErrorLine(pg.url, "The equal number of cells in every row required"); yield break; } var res = htmlTag.create(htmlTag.table, "class", "table table-bordered oli-table", //width = width, cells.Select((cls, rowIdx) => htmlTag.create(htmlTag.tr, cls.Select((c, colIdx) => createCell(c, wr, inlineType, rowIdx, colIdx)) )) ); res.styleSheet = tableStyleSheet; //smartElement.adjustWidths(res2, inlineType, wr); yield return res; }
public override IEnumerable<tag> Generate(body pg, LoggerMemory wr) { var lines = smartElement.splitLines(cdata); if (lines.Length == 0) { wr.ErrorLine(pg.url, "Missing lines with data"); yield break; } List<pairingItem> items = new List<pairingItem>(); foreach (var l in lines) { var parts = l.Split('\\').Select(w => w.Trim()).ToArray(); if (parts.Length != 2) { wr.ErrorLine(pg.url, "Two part of pairing data required"); continue; }; items.Add(new pairingItem() { right = smartElement.removeNums(parts[1]), Items = smartElement.replaceMacroHardReturn(smartElement.removeNums(parts[0]), wr).ToArray() }); } yield return new pairing() { Items = items.ToArray()/*, width = width*/ }; }
public override IEnumerable<tag> Generate(body pg, LoggerMemory wr) { var lines = smartElement.splitLines(cdata); if (lines.Length < 2) { wr.ErrorLine(pg.url, "At least 2 lines with data required"); yield break; } yield return new listGroup() { isStriped = true, //width = width, Items = doubles(lines).Select(db => new node() { Items = new tag[] { new text() { title = smartElement.splitEx(db.Item1).Select(p => p.Trim()).Aggregate((r, it) => r + " / " + it) }, htmlTag.create(htmlTag.br), new gapFill() { correctValue = db.Item2.Trim() } } }).ToArray() }; }
//z sheet style roztridi LM styles (a zpracuje je do rules) a zbytek (normalni CSS styly) static rules separateLM_CSS_styles(body pg) { if (string.IsNullOrEmpty(pg.bodyStyle)) return null; rules res = null; StringBuilder htmlCss = new StringBuilder("\r\n"); StringBuilder htmlCssComment = new StringBuilder(); StringBuilder lmCss = new StringBuilder(); //pouze selektor a prazdna {} //*** simple CSS parser: var obj = parseCSS(pg.bodyStyle); foreach (var rule in obj) { bool isAnyHtml = false; List<ruleProp> lmProps = null; foreach (var prop in rule.props) { var whichProp = Lib.courseModelJsonMLMeta.isLMProp(prop.name); var isLm = whichProp != false; var isHtml = whichProp != true; if (isLm) { if (res == null) res = new rules { lmRules = new List<rule>() }; if (lmProps == null) { res.lmRules.Add(new rule { selector = rule.selector, props = lmProps = new List<ruleProp>() }); lmCss.AppendLine(rule.selector + " {}"); htmlCssComment.AppendLine(rule.selector + " {"); } lmProps.Add(prop); htmlCssComment.Append(" "); prop.ToBuilder(htmlCssComment); } if (isHtml) { if (!isAnyHtml) { htmlCss.AppendLine(rule.htmlSelector + " {"); isAnyHtml = true; } htmlCss.Append(" "); prop.ToBuilder(htmlCss); } } if (isAnyHtml) htmlCss.AppendLine("}"); if (lmProps != null) htmlCssComment.AppendLine("}"); } pg.bodyStyle = htmlCss.ToString() + "/*\r\n" + htmlCssComment.ToString() + "*/\r\n"; //*** ModelText parsing if (res != null) res.finish(lmCss.ToString()); //merge simple CSS rules o ICssRulesetData return res; }