Преглед изворни кода

Add data constructors for button elements

jherve пре 1 година
родитељ
комит
a3c22567a0
3 измењених фајлова са 15 додато и 0 уклоњено
  1. 11 0
      src/LinkedIn.purs
  2. 2 0
      src/LinkedIn/Profile/Utils.purs
  3. 2 0
      src/LinkedIn/UIElements/Types.purs

+ 11 - 0
src/LinkedIn.purs

@@ -78,6 +78,7 @@ queryAll' constructor selector doc = do
 data DetachedNode =
   DetachedElement {tag :: String, content :: String, id :: Maybe String, classes :: List String}
   | DetachedA {content :: String, href :: String}
+  | DetachedButton {content :: String, role :: Maybe String, classes :: List String}
   | DetachedComment String
   | DetachedText String
 
@@ -128,6 +129,16 @@ toDetached node = unsafePartial $ toDetached' (nodeType node) node where
       href: unsafePartial $ fromJust href
     }
 
+  elementToDetached el "BUTTON" text = do
+    role <- getAttribute "role" el
+    classes <- getClassList el
+
+    pure $ DetachedButton {
+      content: normalize text,
+      role,
+      classes
+    }
+
   elementToDetached el tag text = do
     id <- E.id el
     -- On SVG elements "className" returns a weird "SVGString" type that cannot be trimmed

+ 2 - 0
src/LinkedIn/Profile/Utils.purs

@@ -38,5 +38,7 @@ toUIElement ∷ DetachedNode → Either ParseError UIElement
 toUIElement (DetachedElement {content}) = runParser content uiElementP
 toUIElement (DetachedComment str) = runParser str uiElementP
 toUIElement (DetachedText str) = runParser str uiElementP
+toUIElement (DetachedButton {content, role}) =  map toButton $ runParser content uiElementP
+  where toButton ui = UIButton role ui
 toUIElement (DetachedA {content, href}) = map toLink $ runParser content uiElementP
   where toLink ui = UILink href ui

+ 2 - 0
src/LinkedIn/UIElements/Types.purs

@@ -4,6 +4,7 @@ import Prelude
 
 import Data.Date (Month, Year)
 import Data.Generic.Rep (class Generic)
+import Data.Maybe (Maybe)
 import Data.Show.Generic (genericShow)
 
 data MonthYear = MonthYear Month Year
@@ -40,6 +41,7 @@ data UIElement =
   | UIPlainText String
   | UIDotSeparated UIElement UIElement
   | UILink String UIElement
+  | UIButton (Maybe String) UIElement
 
 derive instance Generic UIElement _
 instance Show UIElement where