opal-bootbox 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +113 -17
- data/lib/opal/bootbox/version.rb +1 -1
- data/lib/opal/bootbox.rb +17 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e03c9979426124d97ba07e3a8b82903a5ad69663
|
4
|
+
data.tar.gz: 61ee41675725fa420a64c941ec858089353fbede
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a730c039e1d02632a913d5bca56df884c6d77f9683b763fc4907a199271bb1972a78e3b68b5af37f594c77b41afb2c45e82b33c28d6a17433a28a187b38e1afe
|
7
|
+
data.tar.gz: 0a8c01ffc9b5e71e2271a0cf515572332b1020c2ba2412d1f53690f4a69f70bc819aba298273d0db6a0a9827384713bd6c132e443efee784640345958ed89a03
|
data/README.md
CHANGED
@@ -42,10 +42,22 @@ require 'opal'
|
|
42
42
|
require 'opal-bootbox'
|
43
43
|
```
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
You need to bring your own `bootbox.js` or `bootbox.min.js` and bootstrap files
|
46
|
+
|
47
|
+
* http://bootboxjs.com/download/
|
48
|
+
* http://getbootstrap.com/getting-started/#download
|
49
|
+
|
50
|
+
and put the files in `app/` or whichever directory you are compiling assets from.
|
51
|
+
|
52
|
+
The Opal/Ruby interface is largely consistent with the Javascript interface.
|
53
|
+
|
54
|
+
See http://bootboxjs.com/documentation.html for Javascript library documentation.
|
55
|
+
|
56
|
+
Where a method expects a single callback substitute a block for the JS function.
|
57
|
+
|
58
|
+
The value for a `callback:` keyword argument should be a Ruby proc.
|
59
|
+
|
60
|
+
Keyword arguments should preserve the JS camelcase (e.g. className:).
|
49
61
|
|
50
62
|
### Examples
|
51
63
|
|
@@ -53,19 +65,35 @@ require 'opal-bootbox'
|
|
53
65
|
$bootbox.alert('Hello world!') do
|
54
66
|
puts 'hello world acknowledged'
|
55
67
|
end
|
68
|
+
```
|
56
69
|
|
57
|
-
|
58
|
-
|
59
|
-
|
70
|
+
```
|
71
|
+
$bootbox.alert(
|
72
|
+
size: 'small',
|
73
|
+
title: 'Alert',
|
74
|
+
message: 'Hello world!',
|
75
|
+
callback: -> {puts 'hello world acknowledged'}
|
76
|
+
)
|
77
|
+
```
|
60
78
|
|
79
|
+
```
|
61
80
|
$bootbox.confirm('Are you sure?') do |result|
|
62
81
|
puts "user is #{result ? 'sure' : 'unsure'}"
|
63
82
|
end
|
83
|
+
```
|
64
84
|
|
65
|
-
|
66
|
-
|
85
|
+
```
|
86
|
+
$bootbox.confirm(
|
87
|
+
size: 'small',
|
88
|
+
title: 'Confirmation',
|
89
|
+
message: 'Are you sure?'
|
90
|
+
callback: ->(result) {
|
91
|
+
puts "user is #{result ? 'sure' : 'unsure'}"
|
92
|
+
}
|
67
93
|
end
|
94
|
+
```
|
68
95
|
|
96
|
+
```
|
69
97
|
$bootbox.prompt('What is your name?') do |result|
|
70
98
|
if result
|
71
99
|
puts "user's name is '#{result}'"
|
@@ -73,26 +101,94 @@ $bootbox.prompt('What is your name?') do |result|
|
|
73
101
|
puts "prompt dismissed"
|
74
102
|
end
|
75
103
|
end
|
104
|
+
```
|
76
105
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
106
|
+
```
|
107
|
+
$bootbox.prompt(
|
108
|
+
size: 'small',
|
109
|
+
title: 'Prompt',
|
110
|
+
message: 'What is your name?',
|
111
|
+
value: 'default name'),
|
112
|
+
callback: ->(result) {
|
113
|
+
if result
|
114
|
+
puts "user's name is '#{result}'"
|
115
|
+
else
|
116
|
+
puts "prompt dismissed"
|
117
|
+
}
|
118
|
+
)
|
119
|
+
```
|
84
120
|
|
85
121
|
```
|
122
|
+
$bootbox.dialog(
|
123
|
+
# required
|
124
|
+
message: "I am a custom dialog",
|
125
|
+
|
126
|
+
# optional - adds a header to the dialog and places this text in an h4
|
127
|
+
title: "Custom title",
|
128
|
+
|
129
|
+
# optional - allows the user to dismiss the dialog by hitting ESC
|
130
|
+
# which will call this proc
|
131
|
+
onEscape: -> { puts 'user press escape' },
|
132
|
+
|
133
|
+
# optional - whether the dialog should be shown immediately
|
134
|
+
show: true,
|
135
|
+
|
136
|
+
# optional - whether the dialog should be have a backdrop or not
|
137
|
+
backdrop: true,
|
138
|
+
|
139
|
+
# optional - whether to show a close button (default true)
|
140
|
+
closeButton: true,
|
141
|
+
|
142
|
+
# optional - whether to animate (default true)
|
143
|
+
animate: true,
|
144
|
+
|
145
|
+
# optional - an additional CSS class to apply to the Bootstrap dialog wrapper
|
146
|
+
className: "my-modal",
|
147
|
+
|
148
|
+
# optional - a hash of buttons to be shown in the dialog's footer
|
149
|
+
buttons: {
|
150
|
+
|
151
|
+
success: {
|
152
|
+
# optional - the button label
|
153
|
+
label: "Success!",
|
154
|
+
|
155
|
+
# optional - an additional CSS class to apply to the button
|
156
|
+
className: "btn-success",
|
157
|
+
|
158
|
+
# optional - call proc when button is clicked
|
159
|
+
callback: -> { puts 'success!' }
|
160
|
+
},
|
161
|
+
|
162
|
+
"Danger!": {
|
163
|
+
# no label is provided so the key is used as the button label
|
164
|
+
|
165
|
+
# optional - an additional CSS class to apply to the button
|
166
|
+
className: "btn-danger",
|
167
|
+
|
168
|
+
callback: -> { puts 'danger!' }
|
169
|
+
},
|
170
|
+
|
171
|
+
# if the only value supplied is a callback proc,
|
172
|
+
# the key is used as the button label and all
|
173
|
+
# other options are defaulted
|
174
|
+
|
175
|
+
"Warning!": -> { puts 'warning!}
|
176
|
+
}
|
177
|
+
)
|
178
|
+
```
|
179
|
+
|
86
180
|
|
87
181
|
`$bootbox` is a global variable. `Opal::Bootbox` may be substituted.
|
88
182
|
|
89
183
|
Strings (text) provided as arguments to bootbox methods may be HTML format.
|
90
184
|
|
185
|
+
All methods are executed asynchronously, hence the use of callback blocks and procs.
|
186
|
+
|
91
187
|
## To do
|
92
188
|
|
93
|
-
* Implement Bootbox custom dialog options.
|
94
189
|
* Documentation
|
95
190
|
* Testing
|
191
|
+
* snake case keywords ?
|
96
192
|
|
97
193
|
## Getting involved
|
98
194
|
|
data/lib/opal/bootbox/version.rb
CHANGED
data/lib/opal/bootbox.rb
CHANGED
@@ -7,12 +7,20 @@ if RUBY_ENGINE == 'opal'
|
|
7
7
|
|
8
8
|
require 'native'
|
9
9
|
|
10
|
+
# see http://bootboxjs.com/documentation.html
|
11
|
+
|
10
12
|
module Opal
|
11
13
|
module Bootbox
|
12
14
|
module_function
|
13
15
|
|
14
16
|
def bootbox_call(method, *args, &block)
|
15
|
-
|
17
|
+
arg = args.first
|
18
|
+
if arg.is_a?(Hash) && arg[:callback].nil?
|
19
|
+
arg[:callback] = block
|
20
|
+
Native.call(`bootbox`, method, arg.to_n)
|
21
|
+
else
|
22
|
+
Native.call(`bootbox`, method, arg.to_n, &block)
|
23
|
+
end
|
16
24
|
end
|
17
25
|
|
18
26
|
# Creates an alert window.
|
@@ -37,6 +45,14 @@ module Opal
|
|
37
45
|
bootbox_call(__method__, *args, &block)
|
38
46
|
end
|
39
47
|
|
48
|
+
# Creates a custom dialog window.
|
49
|
+
# Method executes asynchronously.
|
50
|
+
# The result passed to given block is a String or nil.
|
51
|
+
# see http://bootboxjs.com/examples.html
|
52
|
+
def dialog(*args, &block)
|
53
|
+
bootbox_call(__method__, *args, &block)
|
54
|
+
end
|
55
|
+
|
40
56
|
end
|
41
57
|
end
|
42
58
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-bootbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin Gunn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|