fron-ui 1.0.0rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +38 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +7 -0
  7. data/.yardopts +8 -0
  8. data/Gemfile +8 -0
  9. data/Gemfile.lock +105 -0
  10. data/Rakefile +37 -0
  11. data/Readme.md +4 -0
  12. data/db.json +192 -0
  13. data/fron-ui.gemspec +21 -0
  14. data/lib/fron-ui.rb +1 -0
  15. data/lib/fron_ui.rb +5 -0
  16. data/lib/fron_ui/version.rb +7 -0
  17. data/opal/fron-ui/base.rb +49 -0
  18. data/opal/fron-ui/behaviors/action.rb +40 -0
  19. data/opal/fron-ui/behaviors/actions.rb +40 -0
  20. data/opal/fron-ui/behaviors/confirmation.rb +23 -0
  21. data/opal/fron-ui/behaviors/dropdown.rb +27 -0
  22. data/opal/fron-ui/behaviors/file.rb +48 -0
  23. data/opal/fron-ui/behaviors/intendable_children.rb +76 -0
  24. data/opal/fron-ui/behaviors/keydown.rb +31 -0
  25. data/opal/fron-ui/behaviors/loop.rb +41 -0
  26. data/opal/fron-ui/behaviors/render.rb +30 -0
  27. data/opal/fron-ui/behaviors/rest.rb +121 -0
  28. data/opal/fron-ui/behaviors/selectable_children.rb +67 -0
  29. data/opal/fron-ui/behaviors/serialize.rb +32 -0
  30. data/opal/fron-ui/behaviors/shortcuts.rb +35 -0
  31. data/opal/fron-ui/behaviors/state.rb +56 -0
  32. data/opal/fron-ui/behaviors/transition.rb +63 -0
  33. data/opal/fron-ui/components/action.rb +18 -0
  34. data/opal/fron-ui/components/box.rb +17 -0
  35. data/opal/fron-ui/components/button.rb +61 -0
  36. data/opal/fron-ui/components/calendar.rb +129 -0
  37. data/opal/fron-ui/components/checkbox.rb +57 -0
  38. data/opal/fron-ui/components/chooser.rb +246 -0
  39. data/opal/fron-ui/components/color_panel.rb +235 -0
  40. data/opal/fron-ui/components/color_picker.rb +111 -0
  41. data/opal/fron-ui/components/container.rb +61 -0
  42. data/opal/fron-ui/components/date_picker.rb +141 -0
  43. data/opal/fron-ui/components/drag.rb +76 -0
  44. data/opal/fron-ui/components/dropdown.rb +72 -0
  45. data/opal/fron-ui/components/icon.rb +29 -0
  46. data/opal/fron-ui/components/image.rb +77 -0
  47. data/opal/fron-ui/components/input.rb +30 -0
  48. data/opal/fron-ui/components/label.rb +9 -0
  49. data/opal/fron-ui/components/list.rb +34 -0
  50. data/opal/fron-ui/components/loader.rb +63 -0
  51. data/opal/fron-ui/components/modal.rb +0 -0
  52. data/opal/fron-ui/components/notifications.rb +73 -0
  53. data/opal/fron-ui/components/number.rb +202 -0
  54. data/opal/fron-ui/components/progress.rb +52 -0
  55. data/opal/fron-ui/components/slider.rb +47 -0
  56. data/opal/fron-ui/components/tabs.rb +149 -0
  57. data/opal/fron-ui/components/textarea.rb +13 -0
  58. data/opal/fron-ui/components/time.rb +65 -0
  59. data/opal/fron-ui/components/title.rb +34 -0
  60. data/opal/fron-ui/examples/blog/index.rb +289 -0
  61. data/opal/fron-ui/examples/comments/components/comment.rb +75 -0
  62. data/opal/fron-ui/examples/comments/components/comments.rb +93 -0
  63. data/opal/fron-ui/examples/comments/components/footer.rb +36 -0
  64. data/opal/fron-ui/examples/comments/components/header.rb +35 -0
  65. data/opal/fron-ui/examples/comments/components/list.rb +12 -0
  66. data/opal/fron-ui/examples/comments/index.rb +6 -0
  67. data/opal/fron-ui/examples/contacts/components/contacts.rb +100 -0
  68. data/opal/fron-ui/examples/contacts/components/details.rb +92 -0
  69. data/opal/fron-ui/examples/contacts/components/item.rb +46 -0
  70. data/opal/fron-ui/examples/contacts/components/list.rb +10 -0
  71. data/opal/fron-ui/examples/contacts/components/sidebar.rb +30 -0
  72. data/opal/fron-ui/examples/contacts/index.rb +6 -0
  73. data/opal/fron-ui/examples/editor/index.rb +164 -0
  74. data/opal/fron-ui/examples/kitchensink/index.rb +193 -0
  75. data/opal/fron-ui/examples/todos/components/item.rb +84 -0
  76. data/opal/fron-ui/examples/todos/components/options.rb +26 -0
  77. data/opal/fron-ui/examples/todos/components/todos.rb +145 -0
  78. data/opal/fron-ui/examples/todos/index.rb +6 -0
  79. data/opal/fron-ui/examples/webshop/index.rb +0 -0
  80. data/opal/fron-ui/fonts/ionicons.rb +2954 -0
  81. data/opal/fron-ui/fonts/open_sans.rb +19 -0
  82. data/opal/fron-ui/lib/collection.rb +138 -0
  83. data/opal/fron-ui/lib/date.rb +23 -0
  84. data/opal/fron-ui/lib/debounce.rb +14 -0
  85. data/opal/fron-ui/lib/image_loader.rb +13 -0
  86. data/opal/fron-ui/lib/lorem.rb +93 -0
  87. data/opal/fron-ui/lib/nil.rb +29 -0
  88. data/opal/fron-ui/lib/record.rb +23 -0
  89. data/opal/fron-ui/lib/state_serializer.rb +129 -0
  90. data/opal/fron-ui/lib/storage.rb +57 -0
  91. data/opal/fron-ui/spec/setup.rb +40 -0
  92. data/opal/fron-ui/ui.rb +40 -0
  93. data/opal/fron-ui/utils/theme_roller.rb +63 -0
  94. data/opal/fron-ui/vendor/autoprefixer.js +21114 -0
  95. data/opal/fron-ui/vendor/marked.js +1291 -0
  96. data/opal/fron-ui/vendor/md5.js +274 -0
  97. data/opal/fron-ui/vendor/moment.js +3083 -0
  98. data/opal/fron-ui/vendor/uuid.js +92 -0
  99. data/opal/fron_ui.rb +13 -0
  100. data/spec/behaviors/action_spec.rb +34 -0
  101. data/spec/behaviors/actions_spec.rb +38 -0
  102. data/spec/behaviors/confirmation_spec.rb +23 -0
  103. data/spec/behaviors/dropdown_spec.rb +32 -0
  104. data/spec/behaviors/render_spec.rb +20 -0
  105. data/spec/behaviors/rest_spec.rb +70 -0
  106. data/spec/behaviors/selectable_children_spec.rb +40 -0
  107. data/spec/behaviors/serialize_spec.rb +34 -0
  108. data/spec/components/action_spec.rb +7 -0
  109. data/spec/components/base_spec.rb +19 -0
  110. data/spec/components/box_spec.rb +7 -0
  111. data/spec/components/button_spec.rb +9 -0
  112. data/spec/components/calendar_spec.rb +58 -0
  113. data/spec/components/checkbox_spec.rb +20 -0
  114. data/spec/components/chooser_spec.rb +75 -0
  115. data/spec/components/color_panel_spec.rb +49 -0
  116. data/spec/components/color_picker_spec.rb +41 -0
  117. data/spec/components/container_spec.rb +23 -0
  118. data/spec/components/date_picker_spec.rb +71 -0
  119. data/spec/components/drag_spec.rb +20 -0
  120. data/spec/components/dropdown_spec.rb +33 -0
  121. data/spec/components/image_spec.rb +33 -0
  122. data/spec/components/input_spec.rb +8 -0
  123. data/spec/components/list_spec.rb +10 -0
  124. data/spec/components/loader_spec.rb +9 -0
  125. data/spec/components/notifications_spec.rb +17 -0
  126. data/spec/components/number_spec.rb +64 -0
  127. data/spec/components/progress_spec.rb +23 -0
  128. data/spec/components/slider_spec.rb +25 -0
  129. data/spec/components/tabs_spec.rb +50 -0
  130. data/spec/components/textarea_spec.rb +7 -0
  131. data/spec/components/time_spec.rb +37 -0
  132. data/spec/components/title_spec.rb +11 -0
  133. data/spec/examples/comments_spec.rb +72 -0
  134. data/spec/examples/todos_spec.rb +39 -0
  135. data/spec/lib/collection_spec.rb +38 -0
  136. data/spec/lib/lorem_spec.rb +55 -0
  137. data/spec/lib/state_serializer_spec.rb +58 -0
  138. data/spec/lib/storage_spec.rb +39 -0
  139. data/spec/spec_helper.rb +1 -0
  140. metadata +223 -0
@@ -0,0 +1,92 @@
1
+ /*!
2
+ Math.uuid.js (v1.4)
3
+ http://www.broofa.com
4
+ mailto:robert@broofa.com
5
+
6
+ Copyright (c) 2010 Robert Kieffer
7
+ Dual licensed under the MIT and GPL licenses.
8
+ */
9
+
10
+ /*
11
+ * Generate a random uuid.
12
+ *
13
+ * USAGE: Math.uuid(length, radix)
14
+ * length - the desired number of characters
15
+ * radix - the number of allowable values for each character.
16
+ *
17
+ * EXAMPLES:
18
+ * // No arguments - returns RFC4122, version 4 ID
19
+ * >>> Math.uuid()
20
+ * "92329D39-6F5C-4520-ABFC-AAB64544E172"
21
+ *
22
+ * // One argument - returns ID of the specified length
23
+ * >>> Math.uuid(15) // 15 character ID (default base=62)
24
+ * "VcydxgltxrVZSTV"
25
+ *
26
+ * // Two arguments - returns ID of the specified length, and radix. (Radix must be <= 62)
27
+ * >>> Math.uuid(8, 2) // 8 character ID (base=2)
28
+ * "01001010"
29
+ * >>> Math.uuid(8, 10) // 8 character ID (base=10)
30
+ * "47473046"
31
+ * >>> Math.uuid(8, 16) // 8 character ID (base=16)
32
+ * "098F4D35"
33
+ */
34
+ (function() {
35
+ // Private array of chars to use
36
+ var CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
37
+
38
+ Math.uuid = function (len, radix) {
39
+ var chars = CHARS, uuid = [], i;
40
+ radix = radix || chars.length;
41
+
42
+ if (len) {
43
+ // Compact form
44
+ for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
45
+ } else {
46
+ // rfc4122, version 4 form
47
+ var r;
48
+
49
+ // rfc4122 requires these characters
50
+ uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
51
+ uuid[14] = '4';
52
+
53
+ // Fill in random data. At i==19 set the high bits of clock sequence as
54
+ // per rfc4122, sec. 4.1.5
55
+ for (i = 0; i < 36; i++) {
56
+ if (!uuid[i]) {
57
+ r = 0 | Math.random()*16;
58
+ uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
59
+ }
60
+ }
61
+ }
62
+
63
+ return uuid.join('');
64
+ };
65
+
66
+ // A more performant, but slightly bulkier, RFC4122v4 solution. We boost performance
67
+ // by minimizing calls to random()
68
+ Math.uuidFast = function() {
69
+ var chars = CHARS, uuid = new Array(36), rnd=0, r;
70
+ for (var i = 0; i < 36; i++) {
71
+ if (i==8 || i==13 || i==18 || i==23) {
72
+ uuid[i] = '-';
73
+ } else if (i==14) {
74
+ uuid[i] = '4';
75
+ } else {
76
+ if (rnd <= 0x02) rnd = 0x2000000 + (Math.random()*0x1000000)|0;
77
+ r = rnd & 0xf;
78
+ rnd = rnd >> 4;
79
+ uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
80
+ }
81
+ }
82
+ return uuid.join('');
83
+ };
84
+
85
+ // A more compact, but less performant, RFC4122v4 solution:
86
+ Math.uuidCompact = function() {
87
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
88
+ var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
89
+ return v.toString(16);
90
+ });
91
+ };
92
+ })();
@@ -0,0 +1,13 @@
1
+ require 'opal'
2
+ require 'ostruct'
3
+ require 'fron'
4
+ require 'color'
5
+
6
+ require_tree './fron-ui/fonts'
7
+ require 'fron-ui/ui'
8
+ require 'fron-ui/base'
9
+
10
+ require_tree './fron-ui/lib'
11
+ require_tree './fron-ui/vendor'
12
+ require_tree './fron-ui/behaviors'
13
+ require_tree './fron-ui/components'
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ module TestClasses
4
+ class Action < Fron::Component
5
+ include UI::Behaviors::Action
6
+ end
7
+ end
8
+
9
+ describe TestClasses::Action do
10
+ describe '#action' do
11
+ it 'should trigger click' do
12
+ subject.should receive(:trigger).with(:click)
13
+ subject.action
14
+ end
15
+ end
16
+
17
+ context 'Keys' do
18
+ before do
19
+ subject.should receive(:action)
20
+ end
21
+
22
+ context 'Enter' do
23
+ it 'should call action' do
24
+ subject.trigger :keydown, keyCode: 13
25
+ end
26
+ end
27
+
28
+ context 'Space' do
29
+ it 'should call action' do
30
+ subject.trigger :keydown, keyCode: 32
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ module TestClasses
4
+ class Actions < Fron::Component
5
+ include UI::Behaviors::Actions
6
+
7
+ component :span, :span, action: :test
8
+
9
+ def test
10
+ end
11
+ end
12
+ end
13
+
14
+ describe TestClasses::Actions do
15
+ context 'Has method' do
16
+ let(:event) { double :event, target: { action: 'test' } }
17
+
18
+ it 'should handle actions with events' do
19
+ subject.should receive(:test).with kind_of(DOM::Event)
20
+ subject.span.trigger :click
21
+ end
22
+
23
+ it 'should stop event' do
24
+ subject.should receive(:test).with event
25
+ event.should receive(:stop)
26
+ subject.handle_action event
27
+ end
28
+ end
29
+
30
+ context 'Does not have method' do
31
+ let(:event) { double :event, target: { action: 'boo' } }
32
+
33
+ it 'should not stop event if no method exists' do
34
+ event.should_not receive(:stop)
35
+ subject.handle_action event
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ module TestClasses
4
+ class Confirmation < Fron::Component
5
+ include UI::Behaviors::Confirmation
6
+
7
+ confirmation :remove!, 'Are you sure?'
8
+ end
9
+ end
10
+
11
+ describe TestClasses::Confirmation do
12
+ it 'should have confirmed method' do
13
+ subject.should respond_to(:confirm_remove!)
14
+ end
15
+
16
+ context 'Calling the confirmation' do
17
+ it 'should call the method' do
18
+ subject.should receive(:confirm).with('Are you sure?').and_return true
19
+ subject.should receive(:remove!)
20
+ subject.confirm_remove!
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ module TestClasses
4
+ class Dropdown < Fron::Component
5
+ include UI::Behaviors::Dropdown
6
+
7
+ component :input, :input
8
+ component :dropdown, UI::Dropdown
9
+
10
+ dropdown :input, :dropdown
11
+ end
12
+ end
13
+
14
+ describe TestClasses::Dropdown do
15
+ context 'Focusing the input' do
16
+ it 'should open the dropdown' do
17
+ expect {
18
+ subject.input.trigger :focus
19
+ }.to change { subject.dropdown.has_class(:open) }.from(false).to(true)
20
+ end
21
+ end
22
+
23
+ context 'Bluring the input' do
24
+ it 'should close the dropdown' do
25
+ subject.dropdown.open
26
+ expect {
27
+ subject.input.trigger :blur
28
+ subject.dropdown.trigger :animationend, animationName: 'ui-dropdown-hide'
29
+ }.to change { subject.dropdown.has_class(:open) }.from(true).to(false)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ module TestClasses
4
+ class Render < Fron::Component
5
+ include UI::Behaviors::Render
6
+
7
+ render :render_things
8
+
9
+ def render_things
10
+ end
11
+ end
12
+ end
13
+
14
+ describe TestClasses::Render do
15
+ describe '#render' do
16
+ it 'should call orginial method' do
17
+ subject.render
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ module TestClasses
4
+ class Rest < Fron::Component
5
+ include Record
6
+ include UI::Behaviors::Rest
7
+
8
+ rest url: '//test'
9
+ end
10
+ end
11
+
12
+ describe TestClasses::Rest do
13
+ let(:request) { double :request, url: 'test' }
14
+ let(:resp) { double :response, status: 200, json: {} }
15
+ let(:error_resp) { double :response, status: 0, json: {} }
16
+
17
+ before do
18
+ subject.data = { id: 0 }
19
+ end
20
+
21
+ context 'Real request' do
22
+ xit 'should return request' do
23
+ subject.create_request('/').should be_a(FakeRequest)
24
+ end
25
+ end
26
+
27
+ context 'Requests' do
28
+ before do
29
+ subject.should receive(:create_request).and_return request
30
+ end
31
+
32
+ context 'Wrong request' do
33
+ xit 'should raise error' do
34
+ subject.should receive(:warn)
35
+ request.should receive(:request).and_yield error_resp
36
+ subject.request :get, '', {}
37
+ nil
38
+ end
39
+ end
40
+
41
+ describe '#all' do
42
+ it 'should return all records' do
43
+ request.should receive(:request).with(:GET, {}).and_yield resp
44
+ subject.all
45
+ end
46
+ end
47
+
48
+ describe '#update' do
49
+ it 'should update the model' do
50
+ request.should receive(:request).with(:PATCH,
51
+ name: 'test').and_yield resp
52
+ subject.update name: 'test'
53
+ end
54
+ end
55
+
56
+ describe '#destroy' do
57
+ it 'should destroy the model' do
58
+ request.should receive(:request).with(:DELETE, {}).and_yield resp
59
+ subject.destroy {}
60
+ end
61
+ end
62
+
63
+ describe '#create' do
64
+ it 'should create the model' do
65
+ request.should receive(:request).with(:POST, name: 'test').and_yield resp
66
+ subject.create name: 'test'
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ module TestClasses
4
+ class SelectableChildren < Fron::Component
5
+ include UI::Behaviors::SelectableChildren
6
+
7
+ component :first, :span, text: 'First'
8
+ component :second, :span, text: 'Second'
9
+ component :third, :span, text: 'Third'
10
+ end
11
+ end
12
+
13
+ describe TestClasses::SelectableChildren do
14
+ describe '#select' do
15
+ it 'should select children' do
16
+ expect(subject).to receive(:trigger).with :selected_change
17
+ expect {
18
+ subject.select_first
19
+ }.to change { subject.children.first.has_class(:selected) }.from(false).to(true)
20
+ end
21
+ end
22
+
23
+ context 'Clicking on a child' do
24
+ let(:first) { subject.children.first }
25
+ let(:last) { subject.children.last }
26
+
27
+ it 'should select child' do
28
+ expect {
29
+ first.trigger :click
30
+ }.to change { first.has_class(:selected) }.from(false).to(true)
31
+ end
32
+
33
+ it 'should de select previous selection' do
34
+ first.trigger :click
35
+ expect {
36
+ last.trigger :click
37
+ }.to change { first.has_class(:selected) }.from(true).to(false)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ module TestClasses
4
+ class Serialize < Fron::Component
5
+ include UI::Behaviors::Serialize
6
+
7
+ component :test, :test, name: 'something'
8
+ component :input, :input, name: 'other'
9
+ end
10
+ end
11
+
12
+ describe TestClasses::Serialize do
13
+ let(:data) { subject.data }
14
+
15
+ before do
16
+ subject.input.value = 'Test'
17
+ end
18
+
19
+ describe '#data' do
20
+ it 'should return data' do
21
+ data.should have_key(:something)
22
+ data.should have_key(:other)
23
+ data[:other].should eq 'Test'
24
+ end
25
+ end
26
+
27
+ describe '#load' do
28
+ it 'should set data' do
29
+ expect {
30
+ subject.load other: 'some data'
31
+ }.to change { subject.input.value }.from('Test').to('some data')
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe UI::Action do
4
+ it 'should have tabindex' do
5
+ subject[:tabindex].should eq '0'
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe UI::Base do
4
+ describe '#disabled=' do
5
+ it 'should set disabled' do
6
+ expect {
7
+ subject.disabled = true
8
+ }.to change { subject.attribute?(:disabled) }.from(false).to(true)
9
+ end
10
+ end
11
+
12
+ describe '#readonly=' do
13
+ it 'should set readonly' do
14
+ expect {
15
+ subject.readonly = true
16
+ }.to change { subject.attribute?(:readonly) }.from(false).to(true)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe UI::Box do
4
+ it 'should inherit from container' do
5
+ subject.should be_a UI::Container
6
+ end
7
+ end