feat: introduce new composable data providers and increment version
- Added `AnchorDataProvider`, `AnchorCollectionDataProvider`, `ContentsDataProvider`, `ContentsArrayDataProvider`, `DropDownDataProvider`, `ListContentDataProvider`, and `ParagraphedContentDataProvider` for enhanced data extraction flexibility. - Updated project version to 2.5.0.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using HtmlAgilityPack;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Beam.Abstractions;
|
||||
|
||||
namespace Beam.Dynamic {
|
||||
public class AnchorDataProvider : IComposableDataProvider<string> {
|
||||
public IBinding? Content { get; set; }
|
||||
public Uri? RelativeTo { get; set; }
|
||||
|
||||
public string Get(HtmlDocument document) {
|
||||
var node = Select(document);
|
||||
return node is null ? "" : Get(node);
|
||||
}
|
||||
|
||||
public virtual string Get(HtmlNode node) {
|
||||
if (Uri.TryCreate(RelativeTo, node.GetAttributeValue("href", ""), out var uri))
|
||||
return uri.AbsoluteUri;
|
||||
return "";
|
||||
}
|
||||
public HtmlNode? Select(HtmlDocument doc) {
|
||||
return Content?.Select(doc);
|
||||
}
|
||||
|
||||
public HtmlNode? Select(HtmlNode node) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user