hx_selectors


https://github.com/josuigoa/hx_selectors/

To install, run:

haxelib install hx_selectors 1.0.2 

See using Haxelib in Haxelib documentation for more information.

README.md

hx_selectors

This library parses html and css files defined in the hxml file and extracts the id and class elements to create a type-safe access.

build.hxml

--library hx_selectors
-D indexPath=bin/index.html,bin/style.css

index.html

<input id="my-input">

<div class="hidden">
    <div id="first_hidden_child"></div>
    <div id="second_hidden_child"></div>
</div>

<div id="my_template">
    <div class="template_child"></div>
    <div class="template_child"></div>
</div>

Main.hx

// converts in compile time to js.Browser.document.getElementById("my-input").value
trace(Id.my_input.as(InputElement).value);
// converts in compile time to js.Browser.document.getElementsByClassName("hidden")
var hiddenElements = Cls.hidden.get();
for (h in hiddenElements)
  h.classList.remove(Cls.hidden);

// Gets the first element from the array of the elements containing "template_child" class inside the element with "my_template" id
// converts in compile time to js.Browser.getElementById("my_template").getElementsByClassName("template_child")[0]
switch Cls.template_child.firstFrom(Id.my_template.get()) {
    case Some(elementFound):
        // do something with the element
    case None:
        trace('No ${Cls.template_child.selector()} found in ${Id.my_template.selector()}');
}
Contributors
josuigoa
Version
1.0.2
Published
4 years ago
License
GPL

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub

⌂