-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParsingNodes.cs
74 lines (58 loc) · 1.75 KB
/
ParsingNodes.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System.Linq;
using CsQuery;
using VVVV.PluginInterfaces.V2;
namespace VVVV.Nodes.csQuery
{
[PluginInfo(Name = "Select", Category = "csQuery", Author = "alg", Help = "Perform jQuery select on HTML")]
public class SelectNode : IPluginEvaluate
{
[Input("HTML")]
protected IDiffSpread<string> HTMLIn;
[Input("jQuery Selector")]
private ISpread<string> FSelectorIn;
[Output("Selection Result")]
private ISpread<string> FSelectionOut;
[Output("DOM Object")]
private ISpread<ISpread<IDomObject>> FDOMObjectOut;
[Output("Status")]
private ISpread<string> FStatusOut;
private readonly Spread<CQ> FDom = new Spread<CQ>();
public void Evaluate(int spreadMax)
{
FSelectionOut.SliceCount = FDOMObjectOut.SliceCount = FStatusOut.SliceCount = FDom.SliceCount = spreadMax;
for (var i = 0; i < spreadMax; i++)
{
if (HTMLIn.IsChanged)
{
FDom[i] = CQ.Create(HTMLIn[i]);
FStatusOut[i] = "DOM Created";
}
var result = FDom[i].Select(FSelectorIn[i]);
var count = FDOMObjectOut[i].SliceCount = result.Count();
for (var j = 0; j < count; j++)
{
FDOMObjectOut[i][j] = result[j];
}
FSelectionOut[i] = result.RenderSelection();
}
}
}
[PluginInfo(Name = "GetAttribute", Category = "csQuery", Author = "alg", Help = "Get element attribute value")]
public class GetAttributeNode : IPluginEvaluate
{
[Input("DOM Object")]
private ISpread<IDomObject> FDomObjectIn;
[Input("Attribute")]
private ISpread<string> FAttributeIn;
[Output("Value")]
private ISpread<string> FValueOut;
public void Evaluate(int spreadMax)
{
FValueOut.SliceCount = spreadMax;
for (var i = 0; i < spreadMax; i++)
{
FValueOut[i] = FDomObjectIn[i].GetAttribute(FAttributeIn[i]);
}
}
}
}