lucky_hxml
Version, currently 0.1.01 version
- 0.1.0latestOct 16, 2023
github.com/luckyframework/lucky_hxml
Similar to LuckyHTML, but for Hyperview (https://hyperview.org/).
2 stars
1 dependent
License: MIT
Installation
# Add this to your shard.yml
dependencies:
lucky_hxml:
github: luckyframework/lucky_hxml
version: ~> 0.1.0Then run:
shards installshard.yml
- Crystal
~> 1.6- License
- MIT
- Author
- Michael Wagner
Dependencies
Runtime Dependencies
README
LuckyHXML
Similar to LuckyHTML, but for Hyperview.
Installation
- Add the dependency to your
shard.yml:
dependencies:
lucky_hxml:
github: luckyframework/lucky_hxml
version: ~> 0.1
- Run
shards install
Add to Lucky
- Add the dependency to
src/shards.cr:
require "lucky"
require "avram/lucky"
# ...
require "lucky_hxml"
- Add a
src/components/base_hxml_component.crfile:
abstract class BaseHXMLComponent < LuckyHXML::Component
end
Synonymous with Lucky Components
- Add a
src/screens/main_screen.crfile:
abstract class MainScreen < LuckyHXML::Screen
end
Synonymous with Lucky HTML
- Include in
BrowserAction(or anyLucky::Action) and modifyaccepted_formats:
abstract class BrowserAction < Lucky::Action
# ...
include LuckyHXML::Renderable
accepted_formats [:html, :json, :xml], default: :html
# ^^^^
end
Usage
Create a Screen
class HomeScreen < MainScreen
def render
doc do
screen do
styles do
style id: "body", flex: "1", backgroundColor: "white"
end
body style: "body" do
view do
text "Welcome!"
end
end
end
end
end
end
Create a Component
class PhoneBehaviorComponent < BaseHXMLComponent
needs trigger : String = "press"
needs phone_number : String
def render
behavior(
"xmlns:comms": "https://hypermedia.systems/hyperview/communications",
trigger: trigger,
action: "open-phone",
"comms:phone-number": phone_number
)
end
end
Create Custom Elements
You can create custom elements and attributes with element & attribute methods respectively.
class SwipeRowComponent < BaseHXMLComponent
def render(&)
element "swipe:row" do
swipe_namespace
yield
end
end
private def swipe_namespace : Nil
attribute "xmlns:swipe", "https://hypermedia.systems/hyperview/swipeable"
end
end
Mount a Component
mount PhoneBehaviorComponent, phone_number: "123-456-7890"
With a block:
mount SwipeRowComponent do
# ...
end
Render a Screen
class Home::Index < BrowserAction
get "/" do
# Same as `html` macro
hxml HomeScreen
end
end
Render a Component
class Home::Index < BrowserAction
get "/" do
# Same as `component` method
hxml_component PhoneBehaviorComponent, phone_number: "111-222-3333"
end
end
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.1.0- Tagged
- Oct 16, 2023
- Commit
60e9e917d625- Crystal
~> 1.6- Indexed
- yes
Dependents
Repository
github.com/luckyframework/lucky_hxml
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 14, 2026
- Synced
- Aug 14, 2026
- Versions
- 1