-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
178 lines (143 loc) · 5.11 KB
/
index.html
File metadata and controls
178 lines (143 loc) · 5.11 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html>
<!--[if IE]><![endif]-->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Hyperstack-JS Demo</title>
<!-- React and JQuery -->
<script crossorigin src="https://unpkg.com/[email protected]/umd/react-dom.production.min.js"></script>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<!-- Opal (or bring your own) -->
<script src="../dist/opal.js"></script>
<!--Hyperstack -->
<script src="../dist/hyperstack.js"></script>
<script src="../dist/hyper-router.js"></script>
<script src="../dist/hyperstack-compiler.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
include Hyperstack::Component
render(DIV) do
DIV(class: 'container') do
H1 { "Components, Stores and Operations" }
P { "A few examples using Hyperstack 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()
TheRouter()
end
end
end
class Buttons
include Hyperstack::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
include Hyperstack::Component
render(DIV) do
H2 { "MyStore value is '#{MyStore.value}'" }
INPUT(type: :text, value: MyStore.value )
.on(:change) { |e| MyStore.value = e.target.value }
end
end
class Clock
include Hyperstack::Component
include Hyperstack::State::Observable
param format: '%a, %e %b %Y %H:%M:%S'
before_mount do
@time = Time.now.strftime(@Format)
every(1) do
mutate { @time = Time.now.strftime(@Format) }
end
end
render(DIV) do
H2 { "And a clock" }
SPAN { "The time is #{@time}" }
end
end
class MyStore
include Hyperstack::State::Observable
class << self
state_accessor :value
mutator :clear do
@value = ''
end
end
end
class ClearOp < Hyperstack::Operation
step { puts "about to clear everything" }
step { MyStore.clear }
end
class StylishTable
include Hyperstack::Component
render(DIV) do
H2 { "A stylish table" }
TABLE(class: '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(class: 'text-success') { MyStore.value }
end
end
end
end
end
class TheRouter
include Hyperstack::Component
include Hyperstack::Router
include Hyperstack::Router::Helpers
LINKS = %w[foo bar baz].freeze
history :hash
def active?(link)
location.pathname == "/#{link}" ? 'active' : ''
end
render(DIV) do
UL(class: "nav nav-tabs") do
LINKS.each do |link|
LI(role: "presentation", class: active?(link)) do
Link("/#{link}") { link.capitalize }
end
end
end
DIV(class: 'tab-content') do
Switch do
LINKS.each do |link|
Route("/#{link}") do
DIV(class: "tab-pane active") do
H4 { "#{link.capitalize} here!" }
end
end
end
end
end
end
end
</script>
</head>
<body>
<div data-hyperstack-mount="TopLevelComponent"></div>
</body>
</html>