Skip to content

Commit

Permalink
Merge pull request #2 from openmls/keks/highlighting-bookmarklet
Browse files Browse the repository at this point in the history
Add bookmarklet page
  • Loading branch information
keks authored Mar 6, 2024
2 parents afe9834 + 0d52df1 commit 98311ad
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/build-html.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
run: |
mkdir _site
dhall text --file views/dashboard.dhall >_site/index.html
dhall text --file views/bookmarkletPage.dhall >_site/bookmarklet.html
chmod 644 _site/index.html
chmod 755 _site
Expand Down
82 changes: 82 additions & 0 deletions utils/css.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
let Prelude =
https://prelude.dhall-lang.org/v22.0.0/package.dhall
sha256:1c7622fdc868fe3a23462df3e6f533e50fdc12ecf3b42c0bb45c328ec8c4293e
let XML = Prelude.XML

let Property
: Type
= { key : Text, value : Text }

let Property/highlight
: Property
= { key = "background-color", value = "#fde995" }

let Property/cssText
: Property -> Text
= \(prop : Property) -> prop.key ++ ":" ++ prop.value ++ ";"

let PropertyList = List Property

let PropertyList/cssText =
\(list : PropertyList) ->
Prelude.Text.concatMapSep "\n" Property Property/cssText list

let IdSelector
: Type
= { id : Text }

let IdSelector/cssText
: IdSelector -> Text
= \(sel : IdSelector) -> "#" ++ Prelude.Text.replace "." "\\." sel.id

let IdSelectorList = List IdSelector

let IdSelectorList/cssText =
\(list : IdSelectorList) ->
Prelude.Text.concatMapSep ",%0a" IdSelector IdSelector/cssText list

let IdSelectorsRule
: Type
= { selectors : IdSelectorList, properties : PropertyList }

let IdSelectorsRule/cssText =
\(rule : IdSelectorsRule) ->
let selectors = IdSelectorList/cssText rule.selectors

let properties = PropertyList/cssText rule.properties

in "${selectors} { ${properties} }"

let IdSelectorsRule/styleBlock =
\(rule : IdSelectorsRule) ->
XML.element
{ name = "style"
, attributes = [ XML.attribute "type" "text/css" ]
, content = [ XML.rawText (IdSelectorsRule/cssText rule) ]
}

let IdSelectorsRule/bookmarklet =
\(rule : IdSelectorsRule) ->
let cssText = IdSelectorsRule/cssText rule

let jsBody =
''
let cssBody = document.createTextNode(String.raw`${cssText}`);
let styleElem = document.createElement('style');
document.head.appendChild(styleElem);
styleElem.setAttribute('type', 'text/css');
styleElem.appendChild(cssBody);
''

let jsWrapped = "void function(){${jsBody}}()"

in "javascript:${jsWrapped}"

in { Property
, Property/highlight
, IdSelector
, IdSelectorsRule
, IdSelectorsRule/cssText
, IdSelectorsRule/styleBlock
, IdSelectorsRule/bookmarklet
}
51 changes: 51 additions & 0 deletions views/bookmarkletPage.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
let Prelude =
https://prelude.dhall-lang.org/v22.0.0/package.dhall
sha256:1c7622fdc868fe3a23462df3e6f533e50fdc12ecf3b42c0bb45c328ec8c4293e
let XML = Prelude.XML

let Types = ../types.dhall

let Css = ../utils/css.dhall
let Html = ../utils/html.dhall

let checksets = ../checksets.dhall

let Check/fragments = \(check : Types.Check) -> check.desc.rfcFragments

let CheckSet/fragments =
\(checkSet : Types.CheckSet) ->
Prelude.List.foldLeft
Types.Check
checkSet.checks
(List Text)
(\(acc : List Text) -> \(cur : Types.Check) -> acc # Check/fragments cur)
([]: List Text)

let fragments = Prelude.List.concatMap Types.CheckSet Text CheckSet/fragments checksets

let cssSelectors =
Prelude.List.map
Text
Css.IdSelector
(\(fragment : Text) -> { id = fragment })
fragments

let cssProperties = [ Css.Property/highlight ]

let cssRule
: Css.IdSelectorsRule
= { selectors = cssSelectors, properties = cssProperties }

let bookmarklet = Css.IdSelectorsRule/bookmarklet cssRule

let linkElem =
XML.element
{ name = "a"
, attributes = [ XML.attribute "href" bookmarklet ]
, content = [ XML.rawText "✨ Highlight MLS RFC" ]
}

let label = XML.rawText "Drag this to your bookmarks bar:"

let page= Html.outerTemplate "Bookmarklet page" [ label, linkElem ]
in "<!DOCTYPE html>" ++ XML.render page
14 changes: 13 additions & 1 deletion views/dashboard.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ let XML = Prelude.XML
let checkSetHtmls =
Prelude.List.map Types.CheckSet XML.Type Html.CheckSet/table CheckSets

let page = Html.outerTemplate "OpenMLS validation status" checkSetHtmls
let footer = XML.element {
name = "footer",
attributes = XML.emptyAttributes,
content = [
XML.element {
name = "a",
attributes = [ XML.attribute "href" "bookmarklet.html" ],
content = "highlighting bookmarklet page"
}
]
}

let page = Html.outerTemplate "OpenMLS validation status" checkSetHtmls # [footer]

in "<!DOCTYPE html>" ++ XML.render page

0 comments on commit 98311ad

Please sign in to comment.