wallaby 4.1.6

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.
Files changed (209) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +29 -0
  4. data/app/assets/javascripts/wallaby/application.js +15 -0
  5. data/app/assets/javascripts/wallaby/form.js +8 -0
  6. data/app/assets/stylesheets/wallaby/application.scss +51 -0
  7. data/app/assets/stylesheets/wallaby/base/_functions.scss +0 -0
  8. data/app/assets/stylesheets/wallaby/base/_layout.scss +14 -0
  9. data/app/assets/stylesheets/wallaby/base/_mixins.scss +0 -0
  10. data/app/assets/stylesheets/wallaby/base/_normalize.scss +0 -0
  11. data/app/assets/stylesheets/wallaby/base/_reset.scss +0 -0
  12. data/app/assets/stylesheets/wallaby/base/_vars.scss +5 -0
  13. data/app/assets/stylesheets/wallaby/components/_forms.scss +53 -0
  14. data/app/assets/stylesheets/wallaby/components/_nav.scss +19 -0
  15. data/app/assets/stylesheets/wallaby/components/_pagination.scss +105 -0
  16. data/app/assets/stylesheets/wallaby/components/_tables.scss +78 -0
  17. data/app/assets/stylesheets/wallaby/components/_text.scss +11 -0
  18. data/app/assets/stylesheets/wallaby/form.scss +11 -0
  19. data/app/assets/stylesheets/wallaby/summernote.scss.erb +7 -0
  20. data/app/controllers/wallaby/application_controller.rb +21 -0
  21. data/app/controllers/wallaby/core_controller.rb +28 -0
  22. data/app/controllers/wallaby/resources_controller.rb +134 -0
  23. data/app/controllers/wallaby/secure_controller.rb +42 -0
  24. data/app/routes/wallaby/resources_router.rb +52 -0
  25. data/app/security/ability.rb +33 -0
  26. data/app/views/layouts/wallaby/_footer.html.erb +2 -0
  27. data/app/views/layouts/wallaby/_header.html.erb +57 -0
  28. data/app/views/layouts/wallaby/_navs.html.erb +1 -0
  29. data/app/views/layouts/wallaby/application.html.erb +22 -0
  30. data/app/views/layouts/wallaby/error.html.erb +20 -0
  31. data/app/views/wallaby/core/home.html.erb +5 -0
  32. data/app/views/wallaby/errors/access_denied.html.erb +1 -0
  33. data/app/views/wallaby/errors/not_authenticated.html.erb +1 -0
  34. data/app/views/wallaby/errors/not_found.html.erb +6 -0
  35. data/app/views/wallaby/errors/unprocessable_entity.erb +1 -0
  36. data/app/views/wallaby/resources/_form.html.erb +12 -0
  37. data/app/views/wallaby/resources/_index_actions.html.erb +1 -0
  38. data/app/views/wallaby/resources/_resource_actions.html.erb +3 -0
  39. data/app/views/wallaby/resources/edit.html.erb +14 -0
  40. data/app/views/wallaby/resources/form/_belongs_to.html.erb +21 -0
  41. data/app/views/wallaby/resources/form/_bigint.html.erb +9 -0
  42. data/app/views/wallaby/resources/form/_binary.html.erb +12 -0
  43. data/app/views/wallaby/resources/form/_bit.html.erb +9 -0
  44. data/app/views/wallaby/resources/form/_bit_varying.html.erb +9 -0
  45. data/app/views/wallaby/resources/form/_boolean.html.erb +14 -0
  46. data/app/views/wallaby/resources/form/_cidr.html.erb +9 -0
  47. data/app/views/wallaby/resources/form/_citext.html.erb +21 -0
  48. data/app/views/wallaby/resources/form/_color.html.erb +20 -0
  49. data/app/views/wallaby/resources/form/_date.html.erb +29 -0
  50. data/app/views/wallaby/resources/form/_daterange.html.erb +37 -0
  51. data/app/views/wallaby/resources/form/_datetime.html.erb +30 -0
  52. data/app/views/wallaby/resources/form/_decimal.html.erb +9 -0
  53. data/app/views/wallaby/resources/form/_email.html.erb +5 -0
  54. data/app/views/wallaby/resources/form/_float.html.erb +9 -0
  55. data/app/views/wallaby/resources/form/_has_and_belongs_to_many.html.erb +13 -0
  56. data/app/views/wallaby/resources/form/_has_many.html.erb +13 -0
  57. data/app/views/wallaby/resources/form/_has_one.html.erb +7 -0
  58. data/app/views/wallaby/resources/form/_hstore.html.erb +25 -0
  59. data/app/views/wallaby/resources/form/_inet.html.erb +9 -0
  60. data/app/views/wallaby/resources/form/_int4range.html.erb +18 -0
  61. data/app/views/wallaby/resources/form/_int8range.html.erb +18 -0
  62. data/app/views/wallaby/resources/form/_integer.html.erb +9 -0
  63. data/app/views/wallaby/resources/form/_json.html.erb +23 -0
  64. data/app/views/wallaby/resources/form/_jsonb.html.erb +23 -0
  65. data/app/views/wallaby/resources/form/_ltree.html.erb +5 -0
  66. data/app/views/wallaby/resources/form/_macaddr.html.erb +9 -0
  67. data/app/views/wallaby/resources/form/_money.html.erb +12 -0
  68. data/app/views/wallaby/resources/form/_numrange.html.erb +18 -0
  69. data/app/views/wallaby/resources/form/_password.html.erb +5 -0
  70. data/app/views/wallaby/resources/form/_point.html.erb +18 -0
  71. data/app/views/wallaby/resources/form/_string.html.erb +5 -0
  72. data/app/views/wallaby/resources/form/_text.html.erb +21 -0
  73. data/app/views/wallaby/resources/form/_time.html.erb +29 -0
  74. data/app/views/wallaby/resources/form/_tsrange.html.erb +38 -0
  75. data/app/views/wallaby/resources/form/_tstzrange.html.erb +38 -0
  76. data/app/views/wallaby/resources/form/_tsvector.html.erb +5 -0
  77. data/app/views/wallaby/resources/form/_uuid.html.erb +9 -0
  78. data/app/views/wallaby/resources/form/_xml.html.erb +23 -0
  79. data/app/views/wallaby/resources/index/_belongs_to.html.erb +1 -0
  80. data/app/views/wallaby/resources/index/_bigint.html.erb +1 -0
  81. data/app/views/wallaby/resources/index/_binary.html.erb +1 -0
  82. data/app/views/wallaby/resources/index/_bit.html.erb +5 -0
  83. data/app/views/wallaby/resources/index/_bit_varying.html.erb +5 -0
  84. data/app/views/wallaby/resources/index/_boolean.html.erb +5 -0
  85. data/app/views/wallaby/resources/index/_cidr.html.erb +6 -0
  86. data/app/views/wallaby/resources/index/_citext.html.erb +12 -0
  87. data/app/views/wallaby/resources/index/_color.html.erb +5 -0
  88. data/app/views/wallaby/resources/index/_date.html.erb +7 -0
  89. data/app/views/wallaby/resources/index/_daterange.html.erb +8 -0
  90. data/app/views/wallaby/resources/index/_datetime.html.erb +7 -0
  91. data/app/views/wallaby/resources/index/_decimal.html.erb +1 -0
  92. data/app/views/wallaby/resources/index/_email.html.erb +1 -0
  93. data/app/views/wallaby/resources/index/_float.html.erb +1 -0
  94. data/app/views/wallaby/resources/index/_has_and_belongs_to_many.html.erb +11 -0
  95. data/app/views/wallaby/resources/index/_has_many.html.erb +11 -0
  96. data/app/views/wallaby/resources/index/_has_one.html.erb +1 -0
  97. data/app/views/wallaby/resources/index/_hstore.html.erb +12 -0
  98. data/app/views/wallaby/resources/index/_inet.html.erb +6 -0
  99. data/app/views/wallaby/resources/index/_int4range.html.erb +7 -0
  100. data/app/views/wallaby/resources/index/_int8range.html.erb +7 -0
  101. data/app/views/wallaby/resources/index/_integer.html.erb +1 -0
  102. data/app/views/wallaby/resources/index/_json.html.erb +12 -0
  103. data/app/views/wallaby/resources/index/_jsonb.html.erb +12 -0
  104. data/app/views/wallaby/resources/index/_ltree.html.erb +12 -0
  105. data/app/views/wallaby/resources/index/_macaddr.html.erb +5 -0
  106. data/app/views/wallaby/resources/index/_money.html.erb +1 -0
  107. data/app/views/wallaby/resources/index/_numrange.html.erb +7 -0
  108. data/app/views/wallaby/resources/index/_point.html.erb +6 -0
  109. data/app/views/wallaby/resources/index/_string.html.erb +12 -0
  110. data/app/views/wallaby/resources/index/_text.html.erb +12 -0
  111. data/app/views/wallaby/resources/index/_time.html.erb +6 -0
  112. data/app/views/wallaby/resources/index/_tsrange.html.erb +8 -0
  113. data/app/views/wallaby/resources/index/_tstzrange.html.erb +8 -0
  114. data/app/views/wallaby/resources/index/_tsvector.html.erb +12 -0
  115. data/app/views/wallaby/resources/index/_uuid.html.erb +12 -0
  116. data/app/views/wallaby/resources/index/_xml.html.erb +12 -0
  117. data/app/views/wallaby/resources/index.html.erb +66 -0
  118. data/app/views/wallaby/resources/new.html.erb +14 -0
  119. data/app/views/wallaby/resources/shared/_resource_nav.html.erb +29 -0
  120. data/app/views/wallaby/resources/show/_belongs_to.html.erb +7 -0
  121. data/app/views/wallaby/resources/show/_bigint.html.erb +1 -0
  122. data/app/views/wallaby/resources/show/_binary.html.erb +1 -0
  123. data/app/views/wallaby/resources/show/_bit.html.erb +5 -0
  124. data/app/views/wallaby/resources/show/_bit_varying.html.erb +5 -0
  125. data/app/views/wallaby/resources/show/_boolean.html.erb +5 -0
  126. data/app/views/wallaby/resources/show/_cidr.html.erb +6 -0
  127. data/app/views/wallaby/resources/show/_citext.html.erb +1 -0
  128. data/app/views/wallaby/resources/show/_color.html.erb +5 -0
  129. data/app/views/wallaby/resources/show/_date.html.erb +7 -0
  130. data/app/views/wallaby/resources/show/_daterange.html.erb +7 -0
  131. data/app/views/wallaby/resources/show/_datetime.html.erb +6 -0
  132. data/app/views/wallaby/resources/show/_decimal.html.erb +1 -0
  133. data/app/views/wallaby/resources/show/_email.html.erb +1 -0
  134. data/app/views/wallaby/resources/show/_float.html.erb +1 -0
  135. data/app/views/wallaby/resources/show/_has_and_belongs_to_many.html.erb +5 -0
  136. data/app/views/wallaby/resources/show/_has_many.html.erb +5 -0
  137. data/app/views/wallaby/resources/show/_has_one.html.erb +1 -0
  138. data/app/views/wallaby/resources/show/_hstore.html.erb +5 -0
  139. data/app/views/wallaby/resources/show/_inet.html.erb +6 -0
  140. data/app/views/wallaby/resources/show/_int4range.html.erb +7 -0
  141. data/app/views/wallaby/resources/show/_int8range.html.erb +7 -0
  142. data/app/views/wallaby/resources/show/_integer.html.erb +1 -0
  143. data/app/views/wallaby/resources/show/_json.html.erb +5 -0
  144. data/app/views/wallaby/resources/show/_jsonb.html.erb +5 -0
  145. data/app/views/wallaby/resources/show/_ltree.html.erb +1 -0
  146. data/app/views/wallaby/resources/show/_macaddr.html.erb +5 -0
  147. data/app/views/wallaby/resources/show/_money.html.erb +1 -0
  148. data/app/views/wallaby/resources/show/_numrange.html.erb +7 -0
  149. data/app/views/wallaby/resources/show/_point.html.erb +6 -0
  150. data/app/views/wallaby/resources/show/_string.html.erb +1 -0
  151. data/app/views/wallaby/resources/show/_text.html.erb +1 -0
  152. data/app/views/wallaby/resources/show/_time.html.erb +6 -0
  153. data/app/views/wallaby/resources/show/_tsrange.html.erb +7 -0
  154. data/app/views/wallaby/resources/show/_tstzrange.html.erb +7 -0
  155. data/app/views/wallaby/resources/show/_tsvector.html.erb +1 -0
  156. data/app/views/wallaby/resources/show/_uuid.html.erb +5 -0
  157. data/app/views/wallaby/resources/show/_xml.html.erb +5 -0
  158. data/app/views/wallaby/resources/show.html.erb +31 -0
  159. data/app/views/wallaby/shared/_flash_messages.html.erb +13 -0
  160. data/config/locales/en.yml +29 -0
  161. data/config/routes.rb +34 -0
  162. data/lib/adaptors/wallaby/active_record/model_decorator/fields_builder.rb +105 -0
  163. data/lib/adaptors/wallaby/active_record/model_decorator/title_field_finder.rb +18 -0
  164. data/lib/adaptors/wallaby/active_record/model_decorator.rb +81 -0
  165. data/lib/adaptors/wallaby/active_record/model_finder.rb +12 -0
  166. data/lib/adaptors/wallaby/active_record/model_operator/normalizer.rb +44 -0
  167. data/lib/adaptors/wallaby/active_record/model_operator/permitter.rb +50 -0
  168. data/lib/adaptors/wallaby/active_record/model_operator/querier.rb +47 -0
  169. data/lib/adaptors/wallaby/active_record/model_operator/validator.rb +16 -0
  170. data/lib/adaptors/wallaby/active_record/model_operator.rb +82 -0
  171. data/lib/adaptors/wallaby/active_record.rb +2 -0
  172. data/lib/decorators/wallaby/resource_decorator.rb +78 -0
  173. data/lib/errors/wallaby/deprecated.rb +4 -0
  174. data/lib/errors/wallaby/general_error.rb +4 -0
  175. data/lib/errors/wallaby/invalid_error.rb +4 -0
  176. data/lib/errors/wallaby/model_not_found.rb +4 -0
  177. data/lib/errors/wallaby/not_authenticated.rb +4 -0
  178. data/lib/errors/wallaby/not_implemented.rb +4 -0
  179. data/lib/errors/wallaby/operation_not_found.rb +4 -0
  180. data/lib/errors/wallaby/resource_not_found.rb +4 -0
  181. data/lib/forms/wallaby/form_builder.rb +30 -0
  182. data/lib/handlers/wallaby/cached_compiled_erb.rb +14 -0
  183. data/lib/helpers/wallaby/application_helper.rb +30 -0
  184. data/lib/helpers/wallaby/core_helper.rb +50 -0
  185. data/lib/helpers/wallaby/form_helper.rb +21 -0
  186. data/lib/helpers/wallaby/links_helper.rb +83 -0
  187. data/lib/helpers/wallaby/paginatable_helper.rb +9 -0
  188. data/lib/helpers/wallaby/resources_helper.rb +55 -0
  189. data/lib/helpers/wallaby/secure_helper.rb +25 -0
  190. data/lib/helpers/wallaby/sorting_helper.rb +43 -0
  191. data/lib/helpers/wallaby/styling_helper.rb +57 -0
  192. data/lib/interfaces/wallaby/mode.rb +18 -0
  193. data/lib/interfaces/wallaby/model_decorator.rb +58 -0
  194. data/lib/interfaces/wallaby/model_finder.rb +5 -0
  195. data/lib/interfaces/wallaby/model_operator.rb +31 -0
  196. data/lib/services/wallaby/decorator_finder.rb +16 -0
  197. data/lib/services/wallaby/lookup_context_wrapper.rb +40 -0
  198. data/lib/services/wallaby/map.rb +53 -0
  199. data/lib/services/wallaby/model_servicer.rb +38 -0
  200. data/lib/services/wallaby/servicer_finder.rb +5 -0
  201. data/lib/tasks/wallaby_tasks.rake +4 -0
  202. data/lib/utils/wallaby/utils.rb +31 -0
  203. data/lib/wallaby/configuration/models.rb +17 -0
  204. data/lib/wallaby/configuration/security.rb +30 -0
  205. data/lib/wallaby/configuration.rb +49 -0
  206. data/lib/wallaby/engine.rb +89 -0
  207. data/lib/wallaby/version.rb +3 -0
  208. data/lib/wallaby.rb +5 -0
  209. metadata +459 -0
@@ -0,0 +1,12 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <% max = metadata[:max] || 20 %>
5
+ <% value = value.to_s %>
6
+ <% if value.length > max %>
7
+ <code><%= value.truncate max %></code>
8
+ <%= imodal metadata[:label], "<pre>#{ h value }</pre>".html_safe %>
9
+ <% else %>
10
+ <code><%= value %></code>
11
+ <% end %>
12
+ <% end %>
@@ -0,0 +1,66 @@
1
+ <%
2
+ # decorate first on every page or partial
3
+ decorated_collection = decorate collection
4
+ %>
5
+ <section>
6
+ <% # Search form %>
7
+ <div class="search-form <%= params[:sort].present? && 'sort' || '' %>">
8
+ <div class="right">
9
+ <%= index_link(current_model_class, class: 'btn btn-default') { ct 'link.clear_sort' } if params[:sort].present? %>
10
+ <%= render 'index_actions' %>
11
+ </div>
12
+ <%= form_tag wallaby_engine.resources_path, method: :get do %>
13
+ <%= text_field_tag :q, request.query_parameters[:q], placeholder: "Press enter to search. Example: 'text_keyword1 text_keyword2 field_name:value'" %>
14
+ <% end %>
15
+ </div>
16
+ <% # /Search form %>
17
+ <%= render 'wallaby/shared/flash_messages' %>
18
+ <% # Data table %>
19
+ <table class="data-table">
20
+ <thead>
21
+ <tr>
22
+ <% current_model_decorator.index_field_names.each do |field_name| %>
23
+ <th class="<%= sort_class field_name %>">
24
+ <%= sort_link field_name %>
25
+ </th>
26
+ <% end %>
27
+ <th>Actions</th>
28
+ </tr>
29
+ </thead>
30
+ <tbody>
31
+ <% if decorated_collection.present? %>
32
+ <% decorated_collection.each do |decorated| %>
33
+ <tr>
34
+ <% current_model_decorator.index_field_names.each do |field_name| %>
35
+ <td>
36
+ <%= index_type_partial_render decorated.index_type_of(field_name), object: decorated, field_name: field_name %>
37
+ </td>
38
+ <% end %>
39
+ <td>
40
+ <%= render 'resource_actions', decorated: decorated %>
41
+ </td>
42
+ </tr>
43
+ <% end %>
44
+ <% else %>
45
+ <tr>
46
+ <td colspan="<%= current_model_decorator.index_field_names.length + 1 %>">
47
+ <%= t 'collection.not_found' %>
48
+ </td>
49
+ </tr>
50
+ <% end %>
51
+ </tbody>
52
+ </table>
53
+ <% # /Data table %>
54
+ <% # Kaminari pagination %>
55
+ <% if paginatable? collection %>
56
+ <div class="kaminari clearfix">
57
+ <div class="pull-left pagination-info">
58
+ <%= page_entries_info collection rescue custom_pagination_stats collection %>
59
+ </div>
60
+ <% _with_routes wallaby_engine do %>
61
+ <%= paginate collection rescue nil %>
62
+ <% end %>
63
+ </div>
64
+ <% end %>
65
+ <% # /Kaminari pagination %>
66
+ </section>
@@ -0,0 +1,14 @@
1
+ <% decorated = decorate resource %>
2
+ <section>
3
+ <%= render 'wallaby/resources/shared/resource_nav' %>
4
+ <div class="page-header">
5
+ <h1>Create a <%= to_model_label current_resources_name %></h1>
6
+ </div>
7
+ <%= render 'wallaby/shared/flash_messages' %>
8
+ <%= form_for decorated, url: wallaby_engine.resources_path, method: :post, html: { :multipart => true }, builder: Wallaby::FormBuilder do |form| %>
9
+ <%= render 'form', form: form, decorated: decorated %>
10
+ <% end %>
11
+ </section>
12
+
13
+ <% content_for :custom_stylesheet, stylesheet_link_tag('wallaby/form', media: 'all', 'data-turbolinks-track' => true) %>
14
+ <% content_for :custom_javascript, javascript_include_tag('wallaby/form', 'data-turbolinks-track' => true) %>
@@ -0,0 +1,29 @@
1
+ <nav class="pull-right">
2
+ <ul class="nav nav-pills">
3
+ <%# list %>
4
+ <li role="presentation">
5
+ <%= index_link { ct 'link.list' } %>
6
+ </li>
7
+
8
+ <%# show %>
9
+ <% if action_name == 'edit' %>
10
+ <li role="presentation">
11
+ <%= show_link(resource) { ct 'link.show' } %>
12
+ </li>
13
+ <% end %>
14
+
15
+ <%# edit %>
16
+ <% if action_name == 'show' %>
17
+ <li role="presentation">
18
+ <%= edit_link(resource) { ct 'link.edit' } %>
19
+ </li>
20
+ <% end %>
21
+
22
+ <%# delete %>
23
+ <% if action_name == 'show' %>
24
+ <li role="presentation">
25
+ <%= delete_link resource %>
26
+ </li>
27
+ <% end %>
28
+ </ul>
29
+ </nav>
@@ -0,0 +1,7 @@
1
+ <% if value.present? %>
2
+ <%= show_link value %>
3
+ <% elsif !metadata[:is_polymorphic] %>
4
+ <%= new_link metadata[:class] %>
5
+ <% else %>
6
+ <%= null %>
7
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= value || null %>
@@ -0,0 +1 @@
1
+ <%= value ? na : null %>
@@ -0,0 +1,5 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <code><%= value %></code>
5
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <code><%= value %></code>
5
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <%= value ? icon('check') : icon('unchecked') %>
5
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <code><%= value %></code>
5
+ <%= link_to icon('new-window'), "http://ip-api.com/##{ value }", target: :_blank, class: 'text-info' %>
6
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= value || null %>
@@ -0,0 +1,5 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <%= content_tag :span, nil, style: "background-color: #{ value };", class: 'color-square' %><span class="text-uppercase"><%= value %></span>
5
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <% value = Time.zone.parse value if value.is_a? String %>
5
+ <% value = value.to_date if value.is_a? Time %>
6
+ <%= I18n.l value %>
7
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <span class="from"><%= I18n.l value.first %></span>
5
+ ...
6
+ <span class="to"><%= I18n.l value.last %></span>
7
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <% value = Time.zone.parse value if value.is_a? String %>
5
+ <%= I18n.l value %>
6
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= value || null %>
@@ -0,0 +1 @@
1
+ <%= value.nil? ? null : mail_to(value) %>
@@ -0,0 +1 @@
1
+ <%= value.try(:to_f) || null %>
@@ -0,0 +1,5 @@
1
+ <% unique_collection = value.uniq %>
2
+ <% if unique_collection.present? %>
3
+ <%= raw unique_collection.map { |item| show_link item }.to_sentence %>
4
+ <% end %>
5
+ <%= new_link metadata[:class], prepend: unique_collection.present? && 'or' %>
@@ -0,0 +1,5 @@
1
+ <% unique_collection = value.uniq %>
2
+ <% if unique_collection.present? %>
3
+ <%= raw unique_collection.map { |item| show_link item }.to_sentence %>
4
+ <% end %>
5
+ <%= new_link metadata[:class], prepend: unique_collection.present? && 'or' %>
@@ -0,0 +1 @@
1
+ <%= value.present? ? show_link(value) : new_link(metadata[:class]) %>
@@ -0,0 +1,5 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <pre><%= value %></pre>
5
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <code><%= value %></code>
5
+ <%= link_to icon('new-window'), "http://ip-api.com/##{ value }", target: :_blank, class: 'text-info' %>
6
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <span class="from"><%= value.first %></span>
5
+ ...
6
+ <span class="to"><%= value.last %></span>
7
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <span class="from"><%= value.first %></span>
5
+ ...
6
+ <span class="to"><%= value.last %></span>
7
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= value || null %>
@@ -0,0 +1,5 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <pre><%= value %></pre>
5
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <pre><%= value %></pre>
5
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= value || null %>
@@ -0,0 +1,5 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <code><%= value %></code>
5
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= value || null %>
@@ -0,0 +1,7 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <span class="from"><%= value.first %></span>
5
+ ...
6
+ <span class="to"><%= value.last %></span>
7
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ (<span class="x"><%= value.first %></span>,
5
+ <span class="y"><%= value.last %></span>)
6
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= value || null %>
@@ -0,0 +1 @@
1
+ <%= value || null %>
@@ -0,0 +1,6 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <% value = Time.zone.parse value if value.is_a? String %>
5
+ <%= value.strftime '%H:%M:%S' %>
6
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <span class="from"><%= I18n.l value.first %></span>
5
+ ...
6
+ <span class="to"><%= I18n.l value.last %></span>
7
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <span class="from"><%= I18n.l value.first %></span>
5
+ ...
6
+ <span class="to"><%= I18n.l value.last %></span>
7
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= value || null %>
@@ -0,0 +1,5 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <code><%= value %></code>
5
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <% if value.nil? %>
2
+ <%= null %>
3
+ <% else %>
4
+ <pre><%= value %></pre>
5
+ <% end %>
@@ -0,0 +1,31 @@
1
+ <%
2
+ # decorate first on every page or partial
3
+ decorated = decorate resource
4
+ %>
5
+ <article>
6
+ <%= render 'wallaby/resources/shared/resource_nav' %>
7
+ <div class="page-header">
8
+ <h1>
9
+ <%= show_title decorated %>
10
+ </h1>
11
+ </div>
12
+ <%= render 'wallaby/shared/flash_messages' %>
13
+ <section class="fields">
14
+ <table class="detail-table">
15
+ <thead>
16
+ <tr>
17
+ <th>Field</th>
18
+ <th>Value</th>
19
+ </tr>
20
+ </thead>
21
+ <tbody>
22
+ <% decorated.show_field_names.each do |field_name| %>
23
+ <tr>
24
+ <th><%= decorated.show_label_of field_name %></th>
25
+ <td><%= type_partial_render decorated.show_type_of(field_name).to_s, object: decorated, field_name: field_name %></td>
26
+ </tr>
27
+ <% end %>
28
+ </tbody>
29
+ </table>
30
+ </section>
31
+ </article>
@@ -0,0 +1,13 @@
1
+ <% flash_classes = {
2
+ 'alert' => 'danger',
3
+ 'error' => 'danger',
4
+ 'notice' => 'success',
5
+ 'success' => 'success',
6
+ 'warning' => 'warning'
7
+ } %>
8
+ <% flash.each do |type, message| %>
9
+ <div class="alert alert-<%= flash_classes[type.to_s] || type %> alert-dismissible" role="alert">
10
+ <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
11
+ <%= raw message %>
12
+ </div>
13
+ <% end %>
@@ -0,0 +1,29 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
21
+
22
+ en:
23
+ link:
24
+ new: Create
25
+ show: Show
26
+ edit: Edit
27
+ delete: Delete
28
+ confirm:
29
+ delete: Please confirm to delete
data/config/routes.rb ADDED
@@ -0,0 +1,34 @@
1
+ Wallaby::Engine.routes.draw do
2
+ root to: 'wallaby/core#home'
3
+
4
+ get 'status', to: 'wallaby/core#status'
5
+
6
+ scope path: ':resources' do
7
+ with_options to: Wallaby::ResourcesRouter.new do |route|
8
+ begin # resourceful routes
9
+ route.get '',
10
+ defaults: { action: 'index' },
11
+ as: :resources
12
+ route.get 'new',
13
+ defaults: { action: 'new' },
14
+ as: :new_resource
15
+ route.get ':id/edit',
16
+ defaults: { action: 'edit' },
17
+ as: :edit_resource
18
+ route.get ':id',
19
+ defaults: { action: 'show' },
20
+ as: :resource
21
+
22
+ route.post '',
23
+ defaults: { action: 'create' }
24
+ route.match ':id',
25
+ via: %i( patch put ),
26
+ defaults: { action: 'update' }
27
+ route.delete ':id',
28
+ defaults: { action: 'destroy' }
29
+ end
30
+ route.match ':id/:action', via: :all, as: :member
31
+ route.match ':action', via: :all, as: :collection
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,105 @@
1
+ class Wallaby::ActiveRecord::ModelDecorator::FieldsBuilder
2
+ def initialize(model_class)
3
+ @model_class = model_class
4
+ end
5
+
6
+ def general_fields
7
+ @model_class.columns.inject({}) do |fields, column|
8
+ fields[column.name] = {
9
+ name: column.name,
10
+ type: column.type.to_s,
11
+ label: @model_class.human_attribute_name(column.name),
12
+ is_origin: true
13
+ }
14
+ fields
15
+ end
16
+ end
17
+
18
+ def association_fields
19
+ @model_class.reflections.inject({}) do |fields, (field_name, reflection)|
20
+ type = extract_type_from reflection
21
+
22
+ fields[field_name] = {
23
+ name: field_name,
24
+ type: type,
25
+ label: field_name.titleize,
26
+ is_origin: true,
27
+ is_association: true,
28
+ is_polymorphic: is_polymorphic?(reflection),
29
+ is_through: is_through?(reflection),
30
+ has_scope: has_scope?(reflection),
31
+ foreign_key: foreign_key_for(reflection, type),
32
+ polymorphic_type: polymorphic_type_for(reflection, type),
33
+ polymorphic_list: polymorphic_list_for(reflection),
34
+ class: class_for(reflection)
35
+ }
36
+ fields
37
+ end
38
+ end
39
+
40
+ protected
41
+ def has_scope?(reflection)
42
+ reflection.scope.present?
43
+ end
44
+
45
+ def is_through?(reflection)
46
+ reflection.respond_to? :delegate_reflection
47
+ end
48
+
49
+ def is_polymorphic?(reflection)
50
+ reflection.options[:polymorphic].present?
51
+ end
52
+
53
+ def extract_type_from(reflection)
54
+ target = if is_through?(reflection)
55
+ reflection.delegate_reflection
56
+ else
57
+ reflection
58
+ end
59
+ target.class.name.match(/([^:]+)Reflection/)[1].underscore
60
+ end
61
+
62
+ def foreign_key_for(reflection, type)
63
+ if 'belongs_to' == type
64
+ reflection.foreign_key
65
+ else
66
+ reflection.association_foreign_key.try do |foreign_key|
67
+ /many/ =~ type ? "#{ foreign_key }s" : foreign_key
68
+ end
69
+ end
70
+ end
71
+
72
+ def polymorphic_type_for(reflection, type)
73
+ if is_polymorphic? reflection
74
+ foreign_key = foreign_key_for reflection, type
75
+ foreign_key.gsub %r(_ids?$), '_type'
76
+ end
77
+ end
78
+
79
+ def polymorphic_list_for(reflection)
80
+ if is_polymorphic? reflection
81
+ available_model_class.inject([]) do |list, model_class|
82
+ if model_defined_polymorphic_name? model_class, reflection.name
83
+ list << model_class
84
+ end
85
+ list
86
+ end
87
+ end || []
88
+ end
89
+
90
+ def model_defined_polymorphic_name?(model_class, polymorphic_name)
91
+ model_class.reflections.any? do |field_name, reflection|
92
+ reflection.options[:as].to_s == polymorphic_name.to_s
93
+ end
94
+ end
95
+
96
+ def available_model_class
97
+ Wallaby::Map.mode_map.select do |_, mode|
98
+ mode == Wallaby::ActiveRecord
99
+ end.keys
100
+ end
101
+
102
+ def class_for(reflection)
103
+ reflection.class_name.constantize if !is_polymorphic? reflection
104
+ end
105
+ end
@@ -0,0 +1,18 @@
1
+ class Wallaby::ActiveRecord::ModelDecorator::TitleFieldFinder
2
+ def initialize(model_class, fields)
3
+ @model_class = model_class
4
+ @fields = fields
5
+ end
6
+
7
+ def find
8
+ possible_title_fields = @fields.select do |field_name, metadata|
9
+ %w( string ).include? metadata[:type]
10
+ end
11
+ target_field = possible_title_fields.values.find do |metadata|
12
+ %w( name title string text ).any?{ |v| metadata[:name].index v }
13
+ end
14
+ target_field ||= possible_title_fields.values.first
15
+ target_field ||= { name: @model_class.primary_key }
16
+ target_field[:name]
17
+ end
18
+ end