ui_bibz 0.9.0

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 +44 -0
  3. data/.travis.yml +13 -0
  4. data/Gemfile +15 -0
  5. data/Gemfile.lock +171 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.md +728 -0
  8. data/README.rdoc +0 -0
  9. data/Rakefile +34 -0
  10. data/config/locales/en.yml +14 -0
  11. data/config/locales/fr.yml +14 -0
  12. data/doc/images/alert.png +0 -0
  13. data/doc/images/breadcrumb.png +0 -0
  14. data/doc/images/button.png +0 -0
  15. data/doc/images/button_dropdown.png +0 -0
  16. data/doc/images/button_group.png +0 -0
  17. data/doc/images/button_link.png +0 -0
  18. data/doc/images/button_split_dropdown.png +0 -0
  19. data/doc/images/glyph.png +0 -0
  20. data/doc/images/list.png +0 -0
  21. data/doc/images/nav.png +0 -0
  22. data/doc/images/panel.png +0 -0
  23. data/doc/images/table.png +0 -0
  24. data/doc/images/table_pagination_per_page.png +0 -0
  25. data/doc/images/table_panel.png +0 -0
  26. data/doc/images/table_search_field.png +0 -0
  27. data/doc/images/ui-bibz-logo-without-border.gif +0 -0
  28. data/doc/images/ui-bibz-logo.gif +0 -0
  29. data/lib/tasks/ui_bibz_tasks.rake +4 -0
  30. data/lib/ui_bibz/concerns/models/searchable.rb +93 -0
  31. data/lib/ui_bibz/helpers/meta_helper.rb +27 -0
  32. data/lib/ui_bibz/helpers/ui_helper.rb +108 -0
  33. data/lib/ui_bibz/helpers/utils_helper.rb +9 -0
  34. data/lib/ui_bibz/rails/engine.rb +39 -0
  35. data/lib/ui_bibz/ui/alert.rb +67 -0
  36. data/lib/ui_bibz/ui/breadcrumb/breadcrumb.rb +54 -0
  37. data/lib/ui_bibz/ui/breadcrumb/components/breadcrumb_link.rb +62 -0
  38. data/lib/ui_bibz/ui/button/button.rb +65 -0
  39. data/lib/ui_bibz/ui/button/button_dropdown.rb +56 -0
  40. data/lib/ui_bibz/ui/button/button_group.rb +62 -0
  41. data/lib/ui_bibz/ui/button/button_link.rb +66 -0
  42. data/lib/ui_bibz/ui/button/button_split_dropdown.rb +80 -0
  43. data/lib/ui_bibz/ui/component.rb +137 -0
  44. data/lib/ui_bibz/ui/dropdown/components/dropdown_list.rb +73 -0
  45. data/lib/ui_bibz/ui/dropdown/dropdown.rb +101 -0
  46. data/lib/ui_bibz/ui/glyph.rb +92 -0
  47. data/lib/ui_bibz/ui/grid/components/col.rb +74 -0
  48. data/lib/ui_bibz/ui/grid/components/row.rb +32 -0
  49. data/lib/ui_bibz/ui/grid/grid.rb +108 -0
  50. data/lib/ui_bibz/ui/jumbotron.rb +58 -0
  51. data/lib/ui_bibz/ui/label.rb +58 -0
  52. data/lib/ui_bibz/ui/list/components/list.rb +105 -0
  53. data/lib/ui_bibz/ui/list/list_group.rb +78 -0
  54. data/lib/ui_bibz/ui/nav/components/nav_link.rb +68 -0
  55. data/lib/ui_bibz/ui/nav/nav.rb +65 -0
  56. data/lib/ui_bibz/ui/panel.rb +101 -0
  57. data/lib/ui_bibz/ui/table/components/actions.rb +44 -0
  58. data/lib/ui_bibz/ui/table/components/column.rb +34 -0
  59. data/lib/ui_bibz/ui/table/components/columns.rb +16 -0
  60. data/lib/ui_bibz/ui/table/components/store.rb +67 -0
  61. data/lib/ui_bibz/ui/table/components/table_action.rb +21 -0
  62. data/lib/ui_bibz/ui/table/table.rb +146 -0
  63. data/lib/ui_bibz/ui/table/table_pagination.rb +29 -0
  64. data/lib/ui_bibz/ui/table/table_pagination_per_page.rb +53 -0
  65. data/lib/ui_bibz/ui/table/table_panel.rb +66 -0
  66. data/lib/ui_bibz/ui/table/table_search_field.rb +62 -0
  67. data/lib/ui_bibz/ui/table/ux/actionable.rb +59 -0
  68. data/lib/ui_bibz/ui/table/ux/paginable.rb +35 -0
  69. data/lib/ui_bibz/ui/table/ux/searchable.rb +47 -0
  70. data/lib/ui_bibz/ui/table/ux/sortable.rb +93 -0
  71. data/lib/ui_bibz/ui/ui.rb +14 -0
  72. data/lib/ui_bibz/utils/internationalization.rb +30 -0
  73. data/lib/ui_bibz/version.rb +3 -0
  74. data/lib/ui_bibz.rb +60 -0
  75. data/test/dummy/README.rdoc +28 -0
  76. data/test/dummy/Rakefile +6 -0
  77. data/test/dummy/app/assets/images/.keep +0 -0
  78. data/test/dummy/app/assets/javascripts/application.js +13 -0
  79. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  80. data/test/dummy/app/controllers/application_controller.rb +5 -0
  81. data/test/dummy/app/controllers/concerns/.keep +0 -0
  82. data/test/dummy/app/helpers/application_helper.rb +2 -0
  83. data/test/dummy/app/mailers/.keep +0 -0
  84. data/test/dummy/app/models/.keep +0 -0
  85. data/test/dummy/app/models/concerns/.keep +0 -0
  86. data/test/dummy/app/models/user.rb +5 -0
  87. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  88. data/test/dummy/bin/bundle +3 -0
  89. data/test/dummy/bin/rails +4 -0
  90. data/test/dummy/bin/rake +4 -0
  91. data/test/dummy/bin/setup +29 -0
  92. data/test/dummy/config/application.rb +26 -0
  93. data/test/dummy/config/boot.rb +5 -0
  94. data/test/dummy/config/database.yml +25 -0
  95. data/test/dummy/config/environment.rb +5 -0
  96. data/test/dummy/config/environments/development.rb +41 -0
  97. data/test/dummy/config/environments/production.rb +79 -0
  98. data/test/dummy/config/environments/test.rb +42 -0
  99. data/test/dummy/config/initializers/assets.rb +11 -0
  100. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  101. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  102. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  103. data/test/dummy/config/initializers/inflections.rb +16 -0
  104. data/test/dummy/config/initializers/mime_types.rb +4 -0
  105. data/test/dummy/config/initializers/session_store.rb +3 -0
  106. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  107. data/test/dummy/config/locales/en.yml +23 -0
  108. data/test/dummy/config/routes.rb +57 -0
  109. data/test/dummy/config/secrets.yml +22 -0
  110. data/test/dummy/config.ru +4 -0
  111. data/test/dummy/db/migrate/20150123191721_user.rb +4 -0
  112. data/test/dummy/db/migrate/20150123191805_create_users.rb +12 -0
  113. data/test/dummy/db/schema.rb +25 -0
  114. data/test/dummy/lib/assets/.keep +0 -0
  115. data/test/dummy/log/.keep +0 -0
  116. data/test/dummy/public/404.html +67 -0
  117. data/test/dummy/public/422.html +67 -0
  118. data/test/dummy/public/500.html +66 -0
  119. data/test/dummy/public/favicon.ico +0 -0
  120. data/test/dummy/test/fixtures/users.yml +13 -0
  121. data/test/dummy/test/models/user_test.rb +7 -0
  122. data/test/factories/user.rb +8 -0
  123. data/test/store_test.rb +46 -0
  124. data/test/support/factory_girl.rb +6 -0
  125. data/test/test_helper.rb +23 -0
  126. data/test/ui/button_test.rb +56 -0
  127. data/test/ui/component_test.rb +21 -0
  128. data/test/ui/dropdown_test.rb +18 -0
  129. data/test/ui/glyph_test.rb +23 -0
  130. data/test/ui/grid_test.rb +46 -0
  131. data/test/ui/list_group_test.rb +28 -0
  132. data/test/ui/nav_test.rb +27 -0
  133. data/test/ui/panel_test.rb +52 -0
  134. data/test/ui/table_test.rb +178 -0
  135. data/test/ui_bibz_test.rb +13 -0
  136. data/test/ui_helper_test.rb +44 -0
  137. data/ui_bibz.gemspec +36 -0
  138. data/vendor/assets/javascripts/ui_bibz.js.coffee +24 -0
  139. data/vendor/assets/stylesheets/ui_bibz.sass +46 -0
  140. metadata +398 -0
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ include UiBibz::Helpers
4
+ class ComponentTest < ActionView::TestCase
5
+
6
+ test 'create complex component' do
7
+ actual = UiBibz::Ui::Component.new('New component', { status: :active, glyph: 'add' }, { class: 'new-class' }).render
8
+ expected = '<i class="glyph fa fa-add"></i> New component'
9
+
10
+ assert_equal expected, actual
11
+ end
12
+
13
+ test 'create complex component with block' do
14
+ actual = UiBibz::Ui::Component.new(status: :active) do
15
+ "New content"
16
+ end.render
17
+ expected = 'New content'
18
+
19
+ assert_equal expected, actual
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+ include UiBibz::Helpers
3
+ class DropdownTest < ActionView::TestCase
4
+
5
+ test 'Dropdown' do
6
+ actual = UiBibz::Ui::Dropdown.new("Dropdown", type: :dropup, state: :success).tap do |d|
7
+ d.list 'toto'
8
+ d.list 'header', type: :header
9
+ d.list 'momo'
10
+ d.list '---'
11
+ d.list 'lolo'
12
+ end.render
13
+ expected = "<div class=\"dropup\"><button class=\"btn btn-success dropdown-toggle\" type=\"button\" data-toggle=\"dropdown\" aria-expanded=\"false\">Dropdown <span class=\"caret\"></span></button><ul class=\"dropdown-menu dropdown-menu-left\" role=\"menu\"><li role=\"presentation\">toto</li><li class=\"dropdown-header\" role=\"presentation\">header</li><li role=\"presentation\">momo</li><li class=\"divider\" role=\"presentation\"></li><li role=\"presentation\">lolo</li></ul></div>"
14
+
15
+ assert_equal expected, actual
16
+ end
17
+
18
+ end
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ include UiBibz::Helpers
4
+ class GlyphTest < ActionView::TestCase
5
+
6
+ test 'create glyph with a name' do
7
+ actual = UiBibz::Ui::Glyph.new('add').render
8
+ expected = '<i class="glyph fa fa-add"></i>'
9
+ assert_equal expected, actual
10
+ end
11
+
12
+ test 'create glyph with hash' do
13
+ actual = UiBibz::Ui::Glyph.new({ name: 'add', size: 3, type: 'li'}).render
14
+ expected = '<i class="glyph fa fa-add fa-3x fa-li"></i>'
15
+ assert_equal expected, actual
16
+ end
17
+
18
+ test 'create glyph with name and hash' do
19
+ actual = UiBibz::Ui::Glyph.new('add', { size: 3, type: 'li' }).render
20
+ expected = '<i class="glyph fa fa-add fa-3x fa-li"></i>'
21
+ assert_equal expected, actual
22
+ end
23
+ end
@@ -0,0 +1,46 @@
1
+ require 'test_helper'
2
+ include UiBibz::Helpers
3
+ class GridTest < ActionView::TestCase
4
+
5
+ test 'row' do
6
+ actual = UiBibz::Ui::Row.new() do
7
+ 'test'
8
+ end.render
9
+ expected = "<div class=\"row\">test</div>"
10
+
11
+ assert_equal expected, actual
12
+ end
13
+
14
+ test 'col with simple arg' do
15
+ actual = UiBibz::Ui::Col.new({ size: :lg, num: 1}) do
16
+ 'test'
17
+ end.render
18
+ expected = "<div class=\"col-lg-1\">test</div>"
19
+
20
+ assert_equal expected, actual
21
+ end
22
+
23
+ test 'col with multiple args' do
24
+ actual = UiBibz::Ui::Col.new([{ size: :lg, num: 1, offset: 2}, { num: 1 }], class: 'test') do
25
+ 'test'
26
+ end.render
27
+ expected = "<div class=\"test col-lg-1 col-offset-2 col-md-1\">test</div>"
28
+
29
+ assert_equal expected, actual
30
+ end
31
+
32
+ test 'grid' do
33
+ actual = UiBibz::Ui::Grid.new().tap do |g|
34
+ g.view position: :left do
35
+ 'left'
36
+ end
37
+ g.view 'center', position: :center
38
+ g.view 'right', position: :right
39
+ g.view 'bottom', position: :bottom
40
+ end.render
41
+ expected = "<div class=\"grid row\"><div class=\"col grid-left col-md-1\">left</div><div class=\"col grid-center col-md-10\">center</div><div class=\"col grid-right col-md-1\">right</div><div class=\"col grid-bottom col-md-12\">bottom</div></div>"
42
+
43
+ assert_equal expected, actual
44
+ end
45
+
46
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+ include UiBibz::Helpers
3
+ class ListGroupTest < ActionView::TestCase
4
+
5
+ test 'list_group with link' do
6
+ actual = UiBibz::Ui::ListGroup.new(type: :link).tap do |lg|
7
+ lg.list 'Momo', { state: :success, url: '#momo' }
8
+ lg.list({ tap: true, active: true, url: '#toto' }) do |l|
9
+ l.header 'My title'
10
+ l.body 'My body'
11
+ end
12
+ end.render
13
+ expected = "<div class=\"list-group\"><a href=\"#momo\" class=\"list-group-item-success list-group-item\">Momo</a><a type=\"link\" href=\"#toto\" class=\"list-group-item\"><h4 class=\"list-group-item-heading\">My title</h4><p class=\"list-group-item-text\">My body</p></a></div>"
14
+
15
+ assert_equal expected, actual
16
+ end
17
+
18
+ test 'list_group' do
19
+ actual = UiBibz::Ui::ListGroup.new().tap do |lg|
20
+ lg.list 'Lulu'
21
+ lg.list 'Toto'
22
+ end.render
23
+ expected = "<ul class=\"list-group\"><li class=\"list-group-item\">Lulu</li><li class=\"list-group-item\">Toto</li></ul>"
24
+
25
+ assert_equal expected, actual
26
+ end
27
+
28
+ end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+ include UiBibz::Helpers
3
+ class NavTest < ActionView::TestCase
4
+
5
+ test 'Nav with tab' do
6
+ actual = UiBibz::Ui::Nav.new().tap do |n|
7
+ n.link 'Home', status: :active, url: "#Home", selector: 'home'
8
+ n.link 'Profile', url: "#profile", selector: 'profile'
9
+ n.link 'Messages', url: "#messages", selector: 'messages'
10
+ end.render
11
+ expected = "<ul class=\"nav nav-tabs\"><li class=\"active\" role=\"presentation\"><a aria-controls=\"home\" role=\"tab\" data-toggle=\"tab\" href=\"#Home\">Home</a></li><li role=\"presentation\"><a aria-controls=\"profile\" role=\"tab\" data-toggle=\"tab\" href=\"#profile\">Profile</a></li><li role=\"presentation\"><a aria-controls=\"messages\" role=\"tab\" data-toggle=\"tab\" href=\"#messages\">Messages</a></li></ul>"
12
+
13
+ assert_equal expected, actual
14
+ end
15
+
16
+ test 'Nav with pills' do
17
+ actual = UiBibz::Ui::Nav.new(type: :pills, position: :justified).tap do |n|
18
+ n.link 'Home', status: :active, url: "#Home", selector: 'home'
19
+ n.link 'Profile', url: "#profile", selector: 'profile', badge: 16
20
+ n.link 'Messages', url: "#messages", selector: 'messages', status: :disabled
21
+ end.render
22
+ expected = "<ul class=\"nav nav-pills nav-justified\"><li class=\"active\" role=\"presentation\"><a href=\"#Home\">Home</a></li><li role=\"presentation\"><a href=\"#profile\">Profile<span class=\"badge\">16</span></a></li><li class=\"disabled\" role=\"presentation\"><a href=\"#messages\">Messages</a></li></ul>"
23
+
24
+ assert_equal expected, actual
25
+ end
26
+
27
+ end
@@ -0,0 +1,52 @@
1
+ require 'test_helper'
2
+ include UiBibz::Helpers
3
+ class PanelTest < ActionView::TestCase
4
+
5
+ setup do
6
+ @content = 'Example'
7
+ end
8
+
9
+ test 'simple panel' do
10
+ actual = UiBibz::Ui::Panel.new(@content).render
11
+ expected = "<div class=\"panel-default panel\"><div class=\"panel-body\">#{ @content }</div></div>"
12
+
13
+ assert_equal expected, actual
14
+ end
15
+
16
+ test 'simple panel with block' do
17
+ actual = UiBibz::Ui::Panel.new do
18
+ @content
19
+ end.render
20
+ expected = "<div class=\"panel-default panel\"><div class=\"panel-body\">#{ @content }</div></div>"
21
+
22
+ assert_equal expected, actual
23
+ end
24
+
25
+ test 'simple panel with tap' do
26
+ actual = UiBibz::Ui::Panel.new().tap do |p|
27
+ p.body @content
28
+ end.render
29
+ expected = "<div class=\"panel-default panel\"><div class=\"panel-body\">#{ @content }</div></div>"
30
+
31
+ assert_equal expected, actual
32
+ end
33
+
34
+ test 'complex panel with tap' do
35
+ actual = UiBibz::Ui::Panel.new({state: :danger}, { class: 'example'}).tap do |p|
36
+ p.header 'header', class: 'header-example'
37
+ p.body class: 'body-example' do
38
+ @content
39
+ end
40
+ p.footer do
41
+ "footer"
42
+ end
43
+ end.render
44
+ expected = "<div class=\"example panel-danger panel\">\
45
+ <div class=\"header-example panel-heading\">header</div>\
46
+ <div class=\"body-example panel-body\">#{ @content }</div>\
47
+ <div class=\"panel-footer\">footer</div></div>"
48
+
49
+ assert_equal expected, actual
50
+ end
51
+
52
+ end
@@ -0,0 +1,178 @@
1
+ require 'test_helper'
2
+ require "ui_bibz/ui/table/components/store"
3
+ require "ui_bibz/ui/table/ux/paginable"
4
+ require "ui_bibz/ui/table/ux/searchable"
5
+ require "ui_bibz/ui/table/ux/sortable"
6
+ require "ui_bibz/ui/table/ux/actionable"
7
+ include UiBibz::Helpers
8
+ class TableTest < ActionView::TestCase
9
+
10
+ setup do
11
+ create_list(:user, 25)
12
+ params = {
13
+ controller: 'users',
14
+ action: 'index',
15
+ sort: 'users.name_fr',
16
+ direction: 'asc',
17
+ search: 'Name fr',
18
+ per_page: 2,
19
+ page: 1
20
+ }
21
+ @users = User.table_search_pagination(params, session)
22
+ @store = UiBibz::Ui::Store.new @users
23
+ end
24
+
25
+ test 'table search field' do
26
+ actual = UiBibz::Ui::TableSearchField.new({ store: @users}).render
27
+ expected = "<form action=\"/users\" accept-charset=\"UTF-8\" method=\"get\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><div class=\"input-group input-group-sm table-search-field\"><span class=\"input-group-addon\"><i class=\"glyph fa fa-search\"></i></span><input type=\"search\" value=\"Name fr\" name=\"search\" class=\"form-control\" placeholder=\"Search by name_fr and name_en...\" /><span class=\"clear-search-btn input-group-addon\"><i class=\"glyph fa fa-times-circle\"></i></span></div></form>"
28
+
29
+ assert_equal expected, actual
30
+ end
31
+
32
+ test 'table pagination' do
33
+ actual = UiBibz::Ui::TablePagination.new({ store: @users}).render
34
+ expected = "<ul class=\"pagination pagination\"><li class=\"prev disabled\"><span>&#8592; Previous</span></li> <li class=\"active\"><span>1</span></li> <li><a rel=\"next\" href=\"/users?page=2\">2</a></li> <li><a href=\"/users?page=3\">3</a></li> <li><a href=\"/users?page=4\">4</a></li> <li><a href=\"/users?page=5\">5</a></li> <li><a href=\"/users?page=6\">6</a></li> <li><a href=\"/users?page=7\">7</a></li> <li><a href=\"/users?page=8\">8</a></li> <li><a href=\"/users?page=9\">9</a></li> <li class=\"disabled\"><span>&hellip;</span></li> <li><a href=\"/users?page=12\">12</a></li> <li><a href=\"/users?page=13\">13</a></li> <li class=\"next\"><a rel=\"next\" href=\"/users?page=2\">Next &#8594;</a></li></ul>"
35
+
36
+ assert_equal expected, actual
37
+ end
38
+
39
+ test 'table non sortable' do
40
+ options = { sortable: false }
41
+ actual = UiBibz::Ui::Sortable.new(@store, options).header(@store.columns.list.first)
42
+ expected = "Id"
43
+
44
+ assert_equal expected, actual
45
+ end
46
+
47
+ test 'table sortable' do
48
+ options = { sortable: true }
49
+ actual = UiBibz::Ui::Sortable.new(@store, options).header(@store.columns.list.first)
50
+ expected = "<a class=\"dropup\" href=\"/users?direction=asc&amp;search=Name+fr&amp;sort=users.id\">Id</a>"
51
+
52
+ assert_equal expected, actual
53
+ end
54
+
55
+ test 'table non paginable' do
56
+ options = { paginable: false }
57
+ pagination = UiBibz::Ui::Paginable.new(@store, options)
58
+ actual = pagination.render if pagination.paginable?
59
+ expected = nil
60
+
61
+ assert_equal expected, actual
62
+ end
63
+
64
+ test 'table paginable' do
65
+ options = { paginable: true }
66
+ pagination = UiBibz::Ui::Paginable.new(@store, options)
67
+ actual = pagination.render if pagination.paginable?
68
+ expected = "<div><ul class=\"pagination pagination\"><li class=\"prev disabled\"><span>&#8592; Previous</span></li> <li class=\"active\"><span>1</span></li> <li><a rel=\"next\" href=\"/users?page=2\">2</a></li> <li><a href=\"/users?page=3\">3</a></li> <li><a href=\"/users?page=4\">4</a></li> <li><a href=\"/users?page=5\">5</a></li> <li><a href=\"/users?page=6\">6</a></li> <li><a href=\"/users?page=7\">7</a></li> <li><a href=\"/users?page=8\">8</a></li> <li><a href=\"/users?page=9\">9</a></li> <li class=\"disabled\"><span>&hellip;</span></li> <li><a href=\"/users?page=12\">12</a></li> <li><a href=\"/users?page=13\">13</a></li> <li class=\"next\"><a rel=\"next\" href=\"/users?page=2\">Next &#8594;</a></li></ul><form action=\"/users\" accept-charset=\"UTF-8\" method=\"get\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><div class=\"table-pagination-per-page\">Displaying User <b>1&nbsp;-&nbsp;2</b> of <b>25</b> in total | Per page: <select name=\"per_page\" id=\"per_page\" class=\"form-control\"><option value=\"25\">25</option>
69
+ <option value=\"50\">50</option>
70
+ <option value=\"100\">100</option></select></div></form><br class=\"clear\" /></div>"
71
+
72
+ assert_equal expected, actual
73
+ end
74
+
75
+ test 'table non searchable' do
76
+ options = { searchable: false }
77
+ actual = UiBibz::Ui::Searchable.new(@store, options).render
78
+ expected = "<div><div class=\"title\">Users list</div><br class=\"clear\" /></div>"
79
+
80
+ assert_equal expected, actual
81
+ end
82
+
83
+ test 'table non searchable with a title and glyph' do
84
+ options = { searchable: false, glyph: 'toto', title: 'Title list' }
85
+ actual = UiBibz::Ui::Searchable.new(@store, options).render
86
+ expected = "<div><div class=\"title\"><i class=\"glyph fa fa-toto\"></i>Title list</div><br class=\"clear\" /></div>"
87
+
88
+ assert_equal expected, actual
89
+ end
90
+
91
+ test 'table searchable' do
92
+ options = { searchable: true }
93
+ actual = UiBibz::Ui::Searchable.new(@store, options).render
94
+ expected = "<div><div class=\"title\">Users list</div><div class=\"input-group input-group-sm table-search-field\"><span class=\"input-group-addon\"><i class=\"glyph fa fa-search\"></i></span><input type=\"search\" value=\"Name fr\" name=\"search\" class=\"form-control\" placeholder=\"Search by name_fr and name_en...\" /><span class=\"clear-search-btn input-group-addon\"><i class=\"glyph fa fa-times-circle\"></i></span></div><br class=\"clear\" /></div>"
95
+
96
+ assert_equal expected, actual
97
+ end
98
+
99
+ test 'table actionable header' do
100
+ options = { actionable: true }
101
+ action = UiBibz::Ui::Actionable.new(@store, options)
102
+ actual = action.header []
103
+ expected = ["<th class=\"action\"></th>"]
104
+
105
+ assert_equal expected, actual
106
+ end
107
+
108
+ test 'table actionable body' do
109
+ options = { actionable: true }
110
+ action = UiBibz::Ui::Actionable.new(@store, options)
111
+ actual = action.body @store.records.first, []
112
+ expected = ["<td><div class=\"btn-group-xs dropdown\"><button class=\"btn btn-default dropdown-toggle\" type=\"button\" data-toggle=\"dropdown\" aria-expanded=\"false\"><i class=\"glyph fa fa-ellipsis-v fa-fw\"></i> Actions <span class=\"caret\"></span></button><ul class=\"dropdown-menu dropdown-menu-right\" role=\"menu\"></ul></div></td>"]
113
+
114
+
115
+ assert_equal expected, actual
116
+ end
117
+
118
+ test 'table actionable inject_url' do
119
+ options = { actionable: true }
120
+ action = UiBibz::Ui::Actionable.new(@store, options)
121
+ actual = action.inject_url 'http://localhost/users/id/test', @store.records.first
122
+ expected = "http://localhost/users/1/test"
123
+
124
+ assert_equal expected, actual
125
+ end
126
+
127
+ test 'table non actionable header' do
128
+ options = { actionable: false }
129
+ action = UiBibz::Ui::Actionable.new(@store, options)
130
+ actual = action.header []
131
+ expected = []
132
+
133
+ assert_equal expected, actual
134
+ end
135
+
136
+ test 'table non actionable body' do
137
+ options = { actionable: false }
138
+ action = UiBibz::Ui::Actionable.new(@store, options)
139
+ actual = action.body @store.records.first, []
140
+ expected = []
141
+
142
+ assert_equal expected, actual
143
+ end
144
+
145
+ test 'simple table_panel' do
146
+ actual = UiBibz::Ui::TablePanel.new(store: @users, tap: true).render
147
+ end
148
+
149
+ test 'complex table_panel' do
150
+ actual = UiBibz::Ui::TablePanel.new({ store: @users, tap: true }, { class: 'toto' }).tap do |pane|
151
+ pane.header 'Test header'
152
+ pane.body class: 'ui' do
153
+ 'Test body'
154
+ end
155
+ end.render
156
+ end
157
+
158
+ test 'complex table_panel with custom actions' do
159
+ actual = UiBibz::Ui::TablePanel.new({ store: @users, tap: true }, { class: 'toto'}).tap do |pane|
160
+ pane.header 'Test header'
161
+ pane.body cls: 'ui' do
162
+ 'Test body'
163
+ end
164
+ pane.columns do |c|
165
+ c.column({ name: '#', data_index: 'id' })
166
+ c.column({ name: 'Name fr', data_index: 'name_fr', link: edit_user_path(:id), order: 2 })
167
+ c.column({ name: 'Name en', data_index: 'name_en', order: 1 })
168
+ c.column({ name: 'Name en', data_index: 'name_en', format: lambda{ |records, record| "name #{ record.id}"}})
169
+ end
170
+ pane.actions do |a|
171
+ a.action 'toto', url: users_path(:id), glyph: 'eye'
172
+ a.action '---'
173
+ a.action 'momo', url: users_path(:id), glyph: 'home'
174
+ end
175
+ end.render
176
+ end
177
+
178
+ end
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ class UiBibzTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, UiBibz
6
+ end
7
+
8
+ test 'setup block yields self' do
9
+ UiBibz.setup do |config|
10
+ assert_equal UiBibz, config
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,44 @@
1
+ require 'test_helper'
2
+
3
+ include UiBibz::Helpers
4
+ class UiHelperTest < ActionView::TestCase
5
+
6
+ test 'breadcrumb' do
7
+ actual = breadcrumb do |b|
8
+ b.link 'Home', url: '#home', glyph: 'home'
9
+ b.link 'Toto', { url: '#toto', status: :active }
10
+ end
11
+ expected = "<ol class=\"breadcrumb\"><li><a href=\"#home\"><i class=\"glyph fa fa-home\"></i> Home</a></li><li class=\"active\"><a href=\"#toto\">Toto</a></li></ol>"
12
+
13
+ assert_equal expected, actual
14
+ end
15
+
16
+ test 'alert' do
17
+ actual = notify 'toto'
18
+ expected = "<div class=\"alert-info alert\" role=\"alert\">toto</div>"
19
+
20
+ assert_equal expected, actual
21
+ end
22
+
23
+ test 'label' do
24
+ actual = lab 'toto', state: :success, glyph: 'pencil'
25
+ expected = "<span class=\"label-success label\"><i class=\"glyph fa fa-pencil\"></i> toto</span>"
26
+
27
+ assert_equal expected, actual
28
+ end
29
+
30
+ test 'jumbotron with full_width' do
31
+ actual = jumbotron 'toto', full_width: true
32
+ expected = "<div class=\"jumbotron\"><div class=\"container\">toto</div></div>"
33
+
34
+ assert_equal expected, actual
35
+ end
36
+
37
+ test 'jumbotron' do
38
+ actual = jumbotron 'toto'
39
+ expected = "<div class=\"jumbotron\">toto</div>"
40
+
41
+ assert_equal expected, actual
42
+ end
43
+
44
+ end
data/ui_bibz.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "ui_bibz/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "ui_bibz"
9
+ s.version = UiBibz::VERSION
10
+ s.authors = ["Thooams"]
11
+ s.email = ["thooams@gmail.com"]
12
+ s.homepage = "https://github.com/thooams/ui-bibz"
13
+ s.summary = "A Rails plugin with Boostrap framework..."
14
+ s.description = "A Rails plugin with Boostrap framework..."
15
+ s.license = "MIT"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ # rails
23
+ s.add_dependency 'rails', '~> 4.2.0'
24
+ s.add_dependency 'will_paginate', '~> 3.0.6'
25
+ s.add_dependency 'will_paginate-bootstrap'
26
+ s.add_dependency 'will-paginate-i18n'
27
+ s.add_dependency 'haml'
28
+ s.add_dependency 'haml-rails'
29
+ s.add_dependency 'sass-rails', '~> 5.0.1'
30
+
31
+ s.add_development_dependency "minitest"
32
+ s.add_development_dependency "sqlite3"
33
+ s.add_development_dependency "factory_girl_rails", "~> 4.0"
34
+ s.add_development_dependency "codeclimate-test-reporter"
35
+
36
+ end
@@ -0,0 +1,24 @@
1
+ # For turbolink
2
+ $(document).on 'ready page:load', ->
3
+
4
+ # Submit form when per_page select changing
5
+ $('.table-pagination-per-page select').change () ->
6
+ $(this).parents('form').submit()
7
+
8
+ # Clear search
9
+ $('.table-search-field .clear-search-btn').click () ->
10
+ $(this).prev().val('')
11
+ $(this).parents('form').submit()
12
+
13
+ # Resize search field
14
+ $('.table-panel input[type=search]').blur ->
15
+ $parent = $(this).parent()
16
+ $parent.removeClass('has-value') if $(this).val() == ''
17
+ $parent.removeClass('is-focused')
18
+
19
+ $('.table-panel input[type=search]').focus ->
20
+ $(this).parent().addClass('is-focused has-value')
21
+
22
+ $('.table-panel input[type=search]').each ->
23
+ $(this).parent().addClass('has-value') if $(this).val() != ''
24
+
@@ -0,0 +1,46 @@
1
+ .table-panel
2
+ .action
3
+ width: 92px
4
+ .panel-heading
5
+ background-color: #f5f5f5
6
+ .title
7
+ float: left
8
+ font-size: 20px
9
+ .has-value
10
+ width: 400px !important
11
+ .input-group
12
+ width: 300px
13
+ transition: width .5s ease-in-out
14
+ float: right
15
+ .panel-table, .panel-body
16
+ overflow-x: auto
17
+ .panel-footer
18
+ padding: 10px 10px
19
+ .pagination
20
+ margin: 0
21
+ .table-pagination-per-page
22
+ float: right
23
+ select
24
+ width: 75px
25
+ display: inline-block
26
+
27
+ .table-hover>tbody>tr:hover
28
+ td:last-child .dropdown
29
+ display: block
30
+
31
+ .table-hover>tbody>tr
32
+ td:last-child
33
+ height: 39px
34
+ .dropdown
35
+ display: none
36
+
37
+ .table-search-field
38
+ .clear-search-btn
39
+ cursor: pointer
40
+ .glyph
41
+ margin: 0
42
+
43
+ .table
44
+ .action
45
+ width: 92px
46
+