Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create core PSHTML object (PSHTML.Document) #218

Open
Stephanevg opened this issue Mar 16, 2019 · 3 comments
Open

Create core PSHTML object (PSHTML.Document) #218

Stephanevg opened this issue Mar 16, 2019 · 3 comments
Labels
design enhancement New feature or request
Milestone

Comments

@Stephanevg
Copy link
Owner

Stephanevg commented Mar 16, 2019

(Isolating theme from #156)

Objective

  • Have an overall PSHTML Object that contains the HTML stucture tree
  • Have the classes, ID's and attributes

I would imagine a structure along these lines:

PSHTML.Document

Postion Type Id Class Attributes
[int] [String]Div,Body, etc.. [String]html id [String[]] html class [HashTable] Attributes

Perhaps also think of adding a content on the object, which would contain the content of each HTML tab part. It could potentially, also contain another PSHTML.Document, for nested elements.

Postion Type Id Class Attributes Content
[int] [String]Div,Body, etc.. [String]html id [String[]] html class [HashTable] Attributes [PSHTML.Document] or [String]

This would be done implementing the Composite Pattern

Some sources for inspiration for the exports:

@Stephanevg
Copy link
Owner Author

Proposed implementation by @LxLeChat

Class Element {
    [string]$Name
    [string]$id
    [string]$type = ($this.GetType()).Name
    [System.Collections.ArrayList]$Child = @()
    Element () {}
    Element ($name,$id) {
        $this.Name = $name
        $this.id = $id
    }
    AddChild ([Element]$Element) {
        $this.Child.Add($Element)
    }
    [string]ToString () {
        $childreturn = ''
        foreach ($child in $this.child) {
            if ( $childreturn -eq '' ) {
                $childreturn = $child.ToString()
            } else {
                $childreturn = $childreturn +$child.ToString()
            }
        }
        return '<{0} id={1}>{2}</{0}>' -f $this.Type, $this.id,$childreturn
    }
}
class html:Element{
    html($id,$name):base($id,$name) {}
}
class body:Element{
    body($id,$name):base($id,$name) {}
}
class div:Element{
    div($id,$name):base($id,$name) {}
}
class p:Element{
    p($id,$name):base($id,$name) {}
}
class script:Element{
    script($id,$name):base($id,$name) {}
}
$h = [html]::new('html','htmltag')
$b =  [body]::new('body','bodytag')
$s = [script]::new('script','scripttag')
$d = [div]::new('div','divtag')
$h.AddChild($b)
$h.AddChild($s)
$b.AddChild($d)
$d.AddChild([p]::new('p','ptag0'))
$d.AddChild([p]::new('p','ptag1'))
$d.AddChild([p]::new('p','ptag2'))
$b.ToString()
$h.ToString()
$d.tostring()

@Stephanevg
Copy link
Owner Author

I have create a new branch to experiment on this called Feature_tagv3

I have a first working implementation in the following file:
https://github.com/Stephanevg/PSHTML/blob/feature_tagv3/tagv3Prototype.ps1

It actually works pretty well. The nested elements is a part I would like to change, because for the moment it only works with script blocks (as in v2 of the solution). we should change that to an object of type htmltag.

The idea, is that we can have something like this:

$e = div -id 'TopheaderDiv' -Class "class1 class2" -Content {

        div "plop scriptblock content in my superdiv" 
} 

$e
$e.GetChildren()
$e.generatehtml()

(This actually works, except for the children element in -Content.)

We want to be able to see the content of the HTML Tree and also to be able to generate the html structure (parts of it or the whole) using GenerateHTML() (or to be changed) method.

@Stephanevg
Copy link
Owner Author

The children part has been fixed in this commit -> ea5513d from @LxLeChat

With that, I actually think we have a working prototype. 🎉

What is still to do is:
Update Out-PSHMLTDocument

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design enhancement New feature or request
Development

No branches or pull requests

1 participant