This repository has been archived by the owner on Oct 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
111 lines (97 loc) · 3.42 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<!--[if IE]><![endif]-->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Hyperloop-JS Demo</title>
<!-- React and JQuery -->
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<!-- Opal (or bring your own) -->
<script src="dist/opal.min.js"></script>
<!--Hyperloop -->
<script src="dist/hyperloop.min.js"></script>
<script src="dist/hyperloop-compiler.min.js"></script>
<!-- Bootstrap for this example -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script type="text/ruby">
class TopLevelComponent < Hyperloop::Component
render(DIV) do
div.container do
H1 { "Components, Stores and Operations" }
P { "A few examples using Hyperloop Components which wrap React, Stores to hold state which is shared between Components and an Operation for mutating the Store's state. Finally, a Clock which demonstrates local state and a callback which triggers every second." }
TypeAlong()
Buttons()
Clock()
StylishTable()
end
end
end
class Buttons < Hyperloop::Component
render(DIV) do
H2 { "Some buttons" }
BUTTON(class: 'btn btn-primary') { 'See the value' }.on(:click) { alert "MyStore value is '#{ MyStore.value }'" }
BUTTON(class: 'btn btn-link') { 'Clear' }.on(:click) { ClearOp.run }
end
end
class TypeAlong < Hyperloop::Component
render(DIV) do
H2 { "MyStore value is '#{ MyStore.value }'" }
INPUT(type: :text, value: MyStore.value ).on(:change) do |e|
MyStore.set_value e.target.value
end
end
end
class Clock < Hyperloop::Component
param format: '%a, %e %b %Y %H:%M:%S'
before_mount do
mutate.time Time.now.strftime(params.format)
every(1) { mutate.time Time.now.strftime(params.format) }
end
render(DIV) do
H2 { "And a clock" }
"The time is #{state.time}"
end
end
class MyStore < Hyperloop::Store
state :value, reader: true, scope: :class
def self.set_value value
mutate.value value
end
def self.clear
mutate.value ""
end
end
class ClearOp < Hyperloop::Operation
step { puts "about to clear everything" }
step { MyStore.clear }
end
class StylishTable < Hyperloop::Component
render(DIV) do
H2 { "A stylish table" }
table.table.table_bordered do
thead do
tr do
th { "First Name" }
th { "Last Name" }
th { "Username" }
end
end
tbody do
tr do
td { "Mark" }
td { "Otto" }
td.text_success { MyStore.value }
end
end
end
end
end
</script>
</head>
<body>
<div data-hyperloop-mount="TopLevelComponent"></div>
</body>
</html>