Type=Class
Version=6.5
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@
Sub Class_Globals
Public ID As String
Public ElementType As String
Private properties As Map
Private Contents As List
Public Styles As List
Private classes As List
Private jsCode As List
Private style As Map
Private SingleQuote As List
Type ElementEnum(div As String, li As String, p As String,ul As String, input As String, b As String, i As String, hr As String, small As String, s As String, head As String, title As String, HTML As String, _
body As String, style As String, Meta As String, script As String, nav As String, article As String, footer As String, a As String, link As String, section As String, _
Form As String, label As String, TABle As String, tr As String, th As String, video As String, track As String, audio As String, source As String, _
keygen As String, Menu As String, command As String, img As String)
Public EnumElementType As ElementEnum
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(sid As String, sElementType As String)
ElementType = sElementType
style.Initialize
EnumElementType.input = "input"
EnumElementType.Initialize
EnumElementType.div = "div"
EnumElementType.li = "li"
EnumElementType.p = "p"
EnumElementType.ul = "ul"
EnumElementType.input = "input"
EnumElementType.b = "b"
EnumElementType.i = "i"
EnumElementType.hr = "hr"
EnumElementType.small = "small"
EnumElementType.s = "s"
EnumElementType.head = "head"
EnumElementType.title = "title"
EnumElementType.HTML = "html"
EnumElementType.body = "body"
EnumElementType.style = "style"
EnumElementType.Meta = "meta"
EnumElementType.script = "script"
EnumElementType.nav = "nav"
EnumElementType.article = "article"
EnumElementType.footer = "footer"
EnumElementType.a = "a"
EnumElementType.link = "link"
EnumElementType.section = "section"
EnumElementType.Form = "form"
EnumElementType.label = "label"
EnumElementType.TABle = "table"
EnumElementType.th = "th"
EnumElementType.tr = "tr"
EnumElementType.video = "video"
EnumElementType.audio = "audio"
EnumElementType.track = "track"
EnumElementType.track = "source"
EnumElementType.keygen = "keygen"
EnumElementType.Menu = "menu"
EnumElementType.command = "command"
EnumElementType.img = "img"
ID = sid
classes.Initialize
properties.Initialize
Contents.Initialize
Styles.Initialize
jsCode.Initialize
SingleQuote.Initialize
End Sub
'render a string in quotes
Sub InQuotes(value As String) As String
Return QUOTE & value & QUOTE
End Sub
' what is the lengths of the contents list of this element
Sub Size() As Int
Return Contents.Size
End Sub
'clear the contents of this element
Sub ClearContent
Contents.clear
End Sub
'clear the styles of this element
Sub ClearStyles
Styles.Initialize
End Sub
'clear the classes of this element
Sub ClearClasses
classes.Initialize
End Sub
'add a style to the element
Sub AddStyle1(attribute As String, value As String)
attribute = attribute.tolowercase
style.Put(attribute, value)
End Sub
'add single quote
Sub AddSingleQuote(value As String)
If SingleQuote.IndexOf(value) = -1 Then SingleQuote.Add(value)
End Sub
'add a class to the element
Sub AddClass(value As String)
If classes.IndexOf(value) = -1 Then classes.Add(value)
End Sub
'add a style to the element
Sub AddStyle(value As String)
If Styles.IndexOf(value) = -1 Then Styles.Add(value)
End Sub
'add content to the element
public Sub AddContent(value As String)
Contents.Add(value)
End Sub
'add content to the element
public Sub AddJSCode(value As String)
jsCode.Add(value)
End Sub
'add an attribute to the element
public Sub AddAttribute(propName As String, propValue As String)
propName = propName.ToLowerCase
properties.Put(propName, propValue)
End Sub
'define the opening of the element
private Sub Open() As String
Dim thisClass As String = BuildClass
If thisClass.Length > 0 Then AddAttribute("class", thisClass)
Dim thisStyle As String = BuildStyle
If thisStyle.Length > 0 Then AddAttribute("style", thisStyle)
Dim strValue As String
Dim sb As StringBuilder
sb.Initialize
sb.Append("<").Append(ElementType).Append(" ")
If ID.Length > 0 Then
sb.Append(ToProperty("id",ID))
sb.Append(" ")
End If
For Each strKey As String In properties.Keys
strValue = properties.Get(strKey)
If SingleQuote.IndexOf(strKey) = -1 Then
sb.Append(ToProperty(strKey,strValue))
Else
sb.Append(ToSingleQuoteProperty(strKey,strValue))
End If
sb.Append(" ")
Next
sb.Remove(sb.Length-1,sb.Length)
sb.Append(">").Append(CRLF)
Return sb.tostring
End Sub
'define the closure of the element
private Sub Close() As String
Dim sb As StringBuilder
sb.Initialize
sb.Append("").Append(ElementType).Append(">").Append(CRLF)
Return sb.tostring
End Sub
'turn the element into html
public Sub HTML() As String
Dim sb As StringBuilder
sb.Initialize
sb.Append(Open)
For Each strContent As String In Contents
sb.Append(strContent).append(CRLF)
Next
sb.Append(Close)
Return sb.tostring
End Sub
'render the styles
public Sub GetStyles() As String
Dim sb As StringBuilder
sb.Initialize
'add the available styles
sb.Append("").Append(CRLF)
Return sb.tostring
End Sub
'render the javascript
public Sub GetJavaScript() As String
Dim sb As StringBuilder
sb.Initialize
sb.Append("").Append(CRLF)
Return sb.tostring
End Sub
'return a key value string for an attribute
public Sub ToProperty(name As String, value As String) As String
Dim sb As StringBuilder
sb.Initialize
sb.Append(name).Append("=").Append(QUOTE).Append(value).Append(QUOTE)
Return sb.tostring
End Sub
'return a key value string for an attribute
public Sub ToSingleQuoteProperty(name As String, value As String) As String
Dim sb As StringBuilder
sb.Initialize
sb.Append(name).Append("=").Append("'").Append(value).Append("'")
Return sb.tostring
End Sub
'convert key value to style
public Sub ToStyle(name As String, value As String) As String
Dim sb As StringBuilder
sb.Initialize
sb.Append(name).Append(":").Append(value).Append(";")
Return sb.tostring
End Sub
'convert a map to properties
private Sub BuildClass() As String
Dim sb As StringBuilder
sb.Initialize
For Each strClass As String In classes
sb.Append(strClass).Append(" ")
Next
Return RemDelim(sb.ToString," ")
End Sub
'convert a map to properties
private Sub BuildStyle() As String
Dim sb As StringBuilder
Dim strValue As String
sb.Initialize
For Each strKey As String In style.Keys
strValue = style.Get(strKey)
sb.Append(ToStyle(strKey,strValue))
sb.Append(" ")
Next
Return RemDelim(sb.ToString, " ")
End Sub
private Sub RemDelim(value As String, delim As String) As String
If value.endswith(delim) = True Then
Dim sb As StringBuilder
Dim dLength As Int = delim.length
sb.Initialize
sb.Append(value)
sb.Remove(sb.Length-dLength,sb.Length)
Return sb.tostring
Else
Return value
End If
End Sub
'convert a map to properties
Public Sub Map2Attributes(m As Map, bSingleQuote As Boolean) As String
Dim xq As String
If bSingleQuote = True Then
xq = "'"
Else
xq = QUOTE
End If
Dim sb As StringBuilder
Dim i As Int
sb.Initialize
For i = 0 To m.Size - 1
sb.Append(m.GetKeyAt(i)).Append("=").Append(xq).Append(m.GetValueAt(i)).Append(xq)
If i <> m.Size - 1 Then
sb.Append(" ")
End If
Next
Return sb.ToString.trim
End Sub