voom-presenters 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (313) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +54 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +11 -0
  5. data/Gemfile.lock +104 -0
  6. data/LICENSE +21 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +45 -0
  9. data/ROADMAP.md +21 -0
  10. data/Rakefile +6 -0
  11. data/app/demo/component_status.pom +76 -0
  12. data/app/demo/components.pom +19 -0
  13. data/app/demo/components/badges.pom +25 -0
  14. data/app/demo/components/buttons.pom +51 -0
  15. data/app/demo/components/cards.pom +79 -0
  16. data/app/demo/components/chips.pom +91 -0
  17. data/app/demo/components/dialogs.pom +27 -0
  18. data/app/demo/components/drawers.pom +34 -0
  19. data/app/demo/components/expansion_panels.pom +21 -0
  20. data/app/demo/components/fabs-mini.pom +18 -0
  21. data/app/demo/components/fabs.pom +16 -0
  22. data/app/demo/components/footers.pom +36 -0
  23. data/app/demo/components/forms.pom +30 -0
  24. data/app/demo/components/headers.pom +37 -0
  25. data/app/demo/components/hidden_fields.pom +20 -0
  26. data/app/demo/components/icons.pom +94 -0
  27. data/app/demo/components/layouts.pom +44 -0
  28. data/app/demo/components/lists.pom +124 -0
  29. data/app/demo/components/menus.pom +43 -0
  30. data/app/demo/components/nav/drawer.pom +5 -0
  31. data/app/demo/components/nav/menu.pom +15 -0
  32. data/app/demo/components/selects.pom +30 -0
  33. data/app/demo/components/snackbar.pom +24 -0
  34. data/app/demo/components/snackbar_attached.pom +6 -0
  35. data/app/demo/components/tables.pom +39 -0
  36. data/app/demo/components/text_areas.pom +19 -0
  37. data/app/demo/components/text_fields.pom +57 -0
  38. data/app/demo/components/toggles.pom +29 -0
  39. data/app/demo/components/tooltips.pom +120 -0
  40. data/app/demo/event/actions.rb +86 -0
  41. data/app/demo/event/actions/dialog/show_dialog.pom +9 -0
  42. data/app/demo/event/actions/dialog/trigger.pom +86 -0
  43. data/app/demo/event/actions/nav/drawer.pom +5 -0
  44. data/app/demo/event/actions/nav/menu.pom +19 -0
  45. data/app/demo/event/autocomplete.pom +27 -0
  46. data/app/demo/event/field_level.pom +22 -0
  47. data/app/demo/event/form_level.pom +26 -0
  48. data/app/demo/event/nav/drawer.pom +5 -0
  49. data/app/demo/event/nav/menu.pom +14 -0
  50. data/app/demo/event/new_text.pom +6 -0
  51. data/app/demo/events.pom +98 -0
  52. data/app/demo/helpers/indented_grid.rb +14 -0
  53. data/app/demo/index.pom +19 -0
  54. data/app/demo/markdown.pom +73 -0
  55. data/app/demo/nav/top_nav.pom +42 -0
  56. data/app/demo/shared/code.pom +20 -0
  57. data/app/demo/shared/context_list.pom +29 -0
  58. data/app/demo/shared/debug.pom +17 -0
  59. data/app/demo/styles.pom +26 -0
  60. data/bin/console +22 -0
  61. data/bin/setup +8 -0
  62. data/component-status.yml +219 -0
  63. data/config.ru +21 -0
  64. data/lib/voom-presenters.rb +9 -0
  65. data/lib/voom/container_methods.rb +40 -0
  66. data/lib/voom/logger_methods.rb +11 -0
  67. data/lib/voom/parameters.rb +73 -0
  68. data/lib/voom/presenters-engine.rb +40 -0
  69. data/lib/voom/presenters.rb +13 -0
  70. data/lib/voom/presenters/api/app.rb +53 -0
  71. data/lib/voom/presenters/api/router.rb +94 -0
  72. data/lib/voom/presenters/app.rb +55 -0
  73. data/lib/voom/presenters/container_item.rb +16 -0
  74. data/lib/voom/presenters/demo/echo.rb +29 -0
  75. data/lib/voom/presenters/demo/search-terms.yml +50 -0
  76. data/lib/voom/presenters/demo/search.rb +29 -0
  77. data/lib/voom/presenters/dsl.rb +60 -0
  78. data/lib/voom/presenters/dsl/components/action.rb +35 -0
  79. data/lib/voom/presenters/dsl/components/avatar.rb +27 -0
  80. data/lib/voom/presenters/dsl/components/badge.rb +21 -0
  81. data/lib/voom/presenters/dsl/components/base.rb +78 -0
  82. data/lib/voom/presenters/dsl/components/button.rb +49 -0
  83. data/lib/voom/presenters/dsl/components/card.rb +119 -0
  84. data/lib/voom/presenters/dsl/components/checkbox.rb +16 -0
  85. data/lib/voom/presenters/dsl/components/chip.rb +48 -0
  86. data/lib/voom/presenters/dsl/components/content.rb +33 -0
  87. data/lib/voom/presenters/dsl/components/date_time.rb +17 -0
  88. data/lib/voom/presenters/dsl/components/dialog.rb +50 -0
  89. data/lib/voom/presenters/dsl/components/drawer.rb +40 -0
  90. data/lib/voom/presenters/dsl/components/event.rb +101 -0
  91. data/lib/voom/presenters/dsl/components/event_base.rb +20 -0
  92. data/lib/voom/presenters/dsl/components/expansion_panel.rb +46 -0
  93. data/lib/voom/presenters/dsl/components/footer.rb +25 -0
  94. data/lib/voom/presenters/dsl/components/form.rb +42 -0
  95. data/lib/voom/presenters/dsl/components/grid.rb +64 -0
  96. data/lib/voom/presenters/dsl/components/header.rb +33 -0
  97. data/lib/voom/presenters/dsl/components/hidden_field.rb +25 -0
  98. data/lib/voom/presenters/dsl/components/icon.rb +21 -0
  99. data/lib/voom/presenters/dsl/components/icon_base.rb +24 -0
  100. data/lib/voom/presenters/dsl/components/icon_toggle.rb +21 -0
  101. data/lib/voom/presenters/dsl/components/image.rb +36 -0
  102. data/lib/voom/presenters/dsl/components/input.rb +19 -0
  103. data/lib/voom/presenters/dsl/components/list.rb +39 -0
  104. data/lib/voom/presenters/dsl/components/lists/action.rb +72 -0
  105. data/lib/voom/presenters/dsl/components/lists/line.rb +83 -0
  106. data/lib/voom/presenters/dsl/components/lists/separator.rb +16 -0
  107. data/lib/voom/presenters/dsl/components/menu.rb +66 -0
  108. data/lib/voom/presenters/dsl/components/mixins/append.rb +20 -0
  109. data/lib/voom/presenters/dsl/components/mixins/attaches.rb +18 -0
  110. data/lib/voom/presenters/dsl/components/mixins/avatar.rb +18 -0
  111. data/lib/voom/presenters/dsl/components/mixins/buttons.rb +15 -0
  112. data/lib/voom/presenters/dsl/components/mixins/chips.rb +21 -0
  113. data/lib/voom/presenters/dsl/components/mixins/common.rb +50 -0
  114. data/lib/voom/presenters/dsl/components/mixins/content.rb +15 -0
  115. data/lib/voom/presenters/dsl/components/mixins/dialogs.rb +19 -0
  116. data/lib/voom/presenters/dsl/components/mixins/event.rb +19 -0
  117. data/lib/voom/presenters/dsl/components/mixins/expansion_panels.rb +15 -0
  118. data/lib/voom/presenters/dsl/components/mixins/grids.rb +15 -0
  119. data/lib/voom/presenters/dsl/components/mixins/helpers.rb +20 -0
  120. data/lib/voom/presenters/dsl/components/mixins/icons.rb +17 -0
  121. data/lib/voom/presenters/dsl/components/mixins/images.rb +15 -0
  122. data/lib/voom/presenters/dsl/components/mixins/menus.rb +15 -0
  123. data/lib/voom/presenters/dsl/components/mixins/selects.rb +17 -0
  124. data/lib/voom/presenters/dsl/components/mixins/snackbars.rb +18 -0
  125. data/lib/voom/presenters/dsl/components/mixins/text_fields.rb +35 -0
  126. data/lib/voom/presenters/dsl/components/mixins/toggles.rb +40 -0
  127. data/lib/voom/presenters/dsl/components/mixins/tooltips.rb +18 -0
  128. data/lib/voom/presenters/dsl/components/mixins/typography.rb +37 -0
  129. data/lib/voom/presenters/dsl/components/page.rb +29 -0
  130. data/lib/voom/presenters/dsl/components/radio_button.rb +14 -0
  131. data/lib/voom/presenters/dsl/components/select.rb +64 -0
  132. data/lib/voom/presenters/dsl/components/snackbar.rb +32 -0
  133. data/lib/voom/presenters/dsl/components/switch.rb +14 -0
  134. data/lib/voom/presenters/dsl/components/table.rb +102 -0
  135. data/lib/voom/presenters/dsl/components/text_area.rb +20 -0
  136. data/lib/voom/presenters/dsl/components/text_field.rb +74 -0
  137. data/lib/voom/presenters/dsl/components/toggle_base.rb +26 -0
  138. data/lib/voom/presenters/dsl/components/tooltip.rb +25 -0
  139. data/lib/voom/presenters/dsl/components/typography.rb +25 -0
  140. data/lib/voom/presenters/dsl/definer.rb +13 -0
  141. data/lib/voom/presenters/dsl/definition.rb +31 -0
  142. data/lib/voom/presenters/dsl/invalid_presenter.rb +8 -0
  143. data/lib/voom/presenters/dsl/lockable.rb +15 -0
  144. data/lib/voom/presenters/dsl/user_interface.rb +135 -0
  145. data/lib/voom/presenters/errors/parameter_validation.rb +10 -0
  146. data/lib/voom/presenters/errors/unprocessable.rb +8 -0
  147. data/lib/voom/presenters/helpers.rb +18 -0
  148. data/lib/voom/presenters/helpers/currency.rb +14 -0
  149. data/lib/voom/presenters/helpers/date.rb +22 -0
  150. data/lib/voom/presenters/helpers/errors.rb +11 -0
  151. data/lib/voom/presenters/helpers/inflector.rb +16 -0
  152. data/lib/voom/presenters/helpers/rails.rb +60 -0
  153. data/lib/voom/presenters/helpers/route.rb +11 -0
  154. data/lib/voom/presenters/helpers/time.rb +27 -0
  155. data/lib/voom/presenters/settings.rb +35 -0
  156. data/lib/voom/presenters/version.rb +5 -0
  157. data/lib/voom/presenters/web_client/app.rb +128 -0
  158. data/lib/voom/presenters/web_client/markdown_render.rb +16 -0
  159. data/lib/voom/presenters/web_client/router.rb +96 -0
  160. data/lib/voom/serializer.rb +43 -0
  161. data/lib/voom/symbol/to_str.rb +29 -0
  162. data/lib/voom/trace.rb +19 -0
  163. data/presenters.gemspec +37 -0
  164. data/public/.gitignore +2 -0
  165. data/public/bundle.css +11413 -0
  166. data/public/bundle.js +16456 -0
  167. data/public/dialog-polyfill.js +738 -0
  168. data/public/favicon.ico +0 -0
  169. data/public/img/demo/dog.png +0 -0
  170. data/public/img/demo/image_card.jpg +0 -0
  171. data/public/img/demo/rx.png +0 -0
  172. data/public/img/demo/welcome_card.jpg +0 -0
  173. data/public/img/settings/blue.png +0 -0
  174. data/public/img/settings/green.png +0 -0
  175. data/public/img/settings/orange.png +0 -0
  176. data/public/img/settings/purple.png +0 -0
  177. data/public/img/settings/red.png +0 -0
  178. data/public/img/settings/teal.png +0 -0
  179. data/public/img/settings/white.png +0 -0
  180. data/public/img/settings/yellow.png +0 -0
  181. data/public/scripts.js +289 -0
  182. data/public/style-bundle.js +73 -0
  183. data/public/styles.css +16 -0
  184. data/views/mdc/.gitignore +1 -0
  185. data/views/mdc/assets/js/app.js +10 -0
  186. data/views/mdc/assets/js/components/base-component.js +5 -0
  187. data/views/mdc/assets/js/components/button.js +15 -0
  188. data/views/mdc/assets/js/components/cards.js +3 -0
  189. data/views/mdc/assets/js/components/checkboxes.js +15 -0
  190. data/views/mdc/assets/js/components/chips.js +12 -0
  191. data/views/mdc/assets/js/components/date-time.js +6 -0
  192. data/views/mdc/assets/js/components/dialogs.js +32 -0
  193. data/views/mdc/assets/js/components/events.js +151 -0
  194. data/views/mdc/assets/js/components/events/autocomplete.js +96 -0
  195. data/views/mdc/assets/js/components/events/base.js +41 -0
  196. data/views/mdc/assets/js/components/events/dialog.js +25 -0
  197. data/views/mdc/assets/js/components/events/errors.js +142 -0
  198. data/views/mdc/assets/js/components/events/loads.js +22 -0
  199. data/views/mdc/assets/js/components/events/navigates.js +17 -0
  200. data/views/mdc/assets/js/components/events/posts.js +99 -0
  201. data/views/mdc/assets/js/components/events/replaces.js +82 -0
  202. data/views/mdc/assets/js/components/events/selects.js +28 -0
  203. data/views/mdc/assets/js/components/events/snackbar.js +23 -0
  204. data/views/mdc/assets/js/components/events/toggle_visiblity.js +19 -0
  205. data/views/mdc/assets/js/components/forms.js +57 -0
  206. data/views/mdc/assets/js/components/icon-toggles.js +21 -0
  207. data/views/mdc/assets/js/components/initialize.js +34 -0
  208. data/views/mdc/assets/js/components/lists.js +4 -0
  209. data/views/mdc/assets/js/components/menus.js +31 -0
  210. data/views/mdc/assets/js/components/mixins/event-handler.js +13 -0
  211. data/views/mdc/assets/js/components/selects.js +45 -0
  212. data/views/mdc/assets/js/components/snackbar.js +32 -0
  213. data/views/mdc/assets/js/components/text-fields.js +77 -0
  214. data/views/mdc/assets/js/dialog-polyfill.js +738 -0
  215. data/views/mdc/assets/js/material.js +3996 -0
  216. data/views/mdc/assets/js/utils/urls.js +54 -0
  217. data/views/mdc/assets/scss/app.scss +31 -0
  218. data/views/mdc/assets/scss/components/avatar.scss +41 -0
  219. data/views/mdc/assets/scss/components/button.scss +47 -0
  220. data/views/mdc/assets/scss/components/card.scss +54 -0
  221. data/views/mdc/assets/scss/components/checkbox.scss +5 -0
  222. data/views/mdc/assets/scss/components/chip.scss +30 -0
  223. data/views/mdc/assets/scss/components/datetime.scss +0 -0
  224. data/views/mdc/assets/scss/components/dialog.scss +3 -0
  225. data/views/mdc/assets/scss/components/expansion-panel.scss +153 -0
  226. data/views/mdc/assets/scss/components/fab.scss +8 -0
  227. data/views/mdc/assets/scss/components/grid.scss +10 -0
  228. data/views/mdc/assets/scss/components/icon-toggles.scss +9 -0
  229. data/views/mdc/assets/scss/components/icon.scss +34 -0
  230. data/views/mdc/assets/scss/components/image.scss +24 -0
  231. data/views/mdc/assets/scss/components/list.scss +9 -0
  232. data/views/mdc/assets/scss/components/menu.scss +17 -0
  233. data/views/mdc/assets/scss/components/select.scss +16 -0
  234. data/views/mdc/assets/scss/components/snackbar.scss +5 -0
  235. data/views/mdc/assets/scss/components/switch.scss +6 -0
  236. data/views/mdc/assets/scss/components/table-pagination.scss +65 -0
  237. data/views/mdc/assets/scss/components/textfield.scss +1 -0
  238. data/views/mdc/assets/scss/components/typography.scss +25 -0
  239. data/views/mdc/assets/scss/material.blue_grey-orange.min.css +8 -0
  240. data/views/mdc/assets/scss/styles.scss +11 -0
  241. data/views/mdc/assets/scss/theme.scss +5 -0
  242. data/views/mdc/body/drawer.erb +18 -0
  243. data/views/mdc/body/drawers/menu.erb +25 -0
  244. data/views/mdc/body/footer.erb +1 -0
  245. data/views/mdc/body/footers/large.erb +27 -0
  246. data/views/mdc/body/footers/menu_item.erb +6 -0
  247. data/views/mdc/body/footers/small.erb +14 -0
  248. data/views/mdc/body/header.erb +25 -0
  249. data/views/mdc/body/snackbar.erb +10 -0
  250. data/views/mdc/components/avatar.erb +24 -0
  251. data/views/mdc/components/badge.erb +2 -0
  252. data/views/mdc/components/body.erb +2 -0
  253. data/views/mdc/components/button.erb +17 -0
  254. data/views/mdc/components/buttons/button.erb +20 -0
  255. data/views/mdc/components/buttons/fab.erb +22 -0
  256. data/views/mdc/components/buttons/icon.erb +24 -0
  257. data/views/mdc/components/card.erb +49 -0
  258. data/views/mdc/components/checkbox.erb +22 -0
  259. data/views/mdc/components/chip.erb +31 -0
  260. data/views/mdc/components/content.erb +11 -0
  261. data/views/mdc/components/date_time.erb +30 -0
  262. data/views/mdc/components/dialog.erb +27 -0
  263. data/views/mdc/components/display.erb +2 -0
  264. data/views/mdc/components/event.erb +18 -0
  265. data/views/mdc/components/expansion_panel.erb +11 -0
  266. data/views/mdc/components/form.erb +15 -0
  267. data/views/mdc/components/grid.erb +24 -0
  268. data/views/mdc/components/headline.erb +2 -0
  269. data/views/mdc/components/hidden_field.erb +1 -0
  270. data/views/mdc/components/icon.erb +30 -0
  271. data/views/mdc/components/icon_toggle.erb +15 -0
  272. data/views/mdc/components/image.erb +7 -0
  273. data/views/mdc/components/link.erb +14 -0
  274. data/views/mdc/components/list.erb +14 -0
  275. data/views/mdc/components/list/actions.erb +6 -0
  276. data/views/mdc/components/list/actions/button.erb +1 -0
  277. data/views/mdc/components/list/actions/checkbox.erb +1 -0
  278. data/views/mdc/components/list/actions/icon.erb +1 -0
  279. data/views/mdc/components/list/actions/icon_toggle.erb +1 -0
  280. data/views/mdc/components/list/actions/radio_button.erb +1 -0
  281. data/views/mdc/components/list/actions/switch.erb +1 -0
  282. data/views/mdc/components/list/avatar.erb +5 -0
  283. data/views/mdc/components/list/checkbox.erb +5 -0
  284. data/views/mdc/components/list/icon.erb +5 -0
  285. data/views/mdc/components/list/info.erb +1 -0
  286. data/views/mdc/components/list/line.erb +34 -0
  287. data/views/mdc/components/list/menu.erb +23 -0
  288. data/views/mdc/components/list/separator.erb +1 -0
  289. data/views/mdc/components/menu.erb +29 -0
  290. data/views/mdc/components/modal.erb +15 -0
  291. data/views/mdc/components/radio_button.erb +11 -0
  292. data/views/mdc/components/render.erb +4 -0
  293. data/views/mdc/components/select.erb +22 -0
  294. data/views/mdc/components/snackbar.erb +17 -0
  295. data/views/mdc/components/static.erb +7 -0
  296. data/views/mdc/components/subheading.erb +2 -0
  297. data/views/mdc/components/switch.erb +13 -0
  298. data/views/mdc/components/table.erb +13 -0
  299. data/views/mdc/components/table/header.erb +7 -0
  300. data/views/mdc/components/table/pagination.erb +24 -0
  301. data/views/mdc/components/table/row.erb +14 -0
  302. data/views/mdc/components/text_area.erb +8 -0
  303. data/views/mdc/components/text_field.erb +27 -0
  304. data/views/mdc/components/title.erb +4 -0
  305. data/views/mdc/components/tooltip.erb +5 -0
  306. data/views/mdc/components/typography.erb +13 -0
  307. data/views/mdc/init-depends.sh +2 -0
  308. data/views/mdc/layout.erb +50 -0
  309. data/views/mdc/package-lock.json +11524 -0
  310. data/views/mdc/package.json +39 -0
  311. data/views/mdc/web.erb +1 -0
  312. data/views/mdc/webpack.config.js +47 -0
  313. metadata +539 -0
@@ -0,0 +1,26 @@
1
+ require_relative 'mixins/event'
2
+ require_relative 'input'
3
+ require_relative 'mixins/tooltips'
4
+
5
+ module Voom
6
+ module Presenters
7
+ module DSL
8
+ module Components
9
+ # Base class used by toggle classes
10
+ class ToggleBase < Input
11
+ include Mixins::Tooltips
12
+
13
+ attr_accessor :text, :checked, :value, :disabled
14
+
15
+ def initialize(**attribs_, &block)
16
+ super(**attribs_, &block)
17
+ @text = attribs.delete(:text)
18
+ @checked = attribs.delete(:checked) || false
19
+ @value = attribs.delete(:value)
20
+ @disabled = attribs.delete(:disabled) || false
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ module Voom
2
+ module Presenters
3
+ module DSL
4
+ module Components
5
+ class Tooltip < Base
6
+ attr_reader :position
7
+
8
+ def initialize(**attribs_, &block)
9
+ super(type: :tooltip,
10
+ context: context,
11
+ **attribs_, &block)
12
+ @position = attribs.delete(:position){ :left }
13
+ self.text(attribs.delete(:text)) if attribs.key?(:text)
14
+ expand!
15
+ end
16
+
17
+ def text(*text, **attribs, &block)
18
+ return @text if locked?
19
+ @text = Components::Typography.new(parent: self, type: :text, text: text, context: context, **attribs, &block)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require_relative 'mixins/event'
2
+ require_relative 'mixins/tooltips'
3
+
4
+ module Voom
5
+ module Presenters
6
+ module DSL
7
+ module Components
8
+ class Typography < EventBase
9
+ include Mixins::Tooltips
10
+
11
+ attr_accessor :text, :level, :color, :position
12
+
13
+ def initialize(parent:, **attribs_, &block)
14
+ super(type: :text, parent: parent, **attribs_, &block)
15
+ @text = Array(attribs.delete(:text)||'').flatten.join("\n\n").split("\n\n")
16
+ @level = attribs.delete(:level){1}
17
+ @color = attribs.delete(:color)
18
+ @position = Array(attribs.delete(:position)).compact
19
+ expand!
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ require_relative 'components/base'
2
+ require_relative 'components/event_base'
3
+ Dir[__dir__ + "/components/*.rb"].each {|file| require file }
4
+
5
+ module Voom
6
+ module Presenters
7
+ module DSL
8
+ # The default dsl for ui
9
+ module Definer
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,31 @@
1
+ require_relative 'user_interface'
2
+
3
+ module Voom
4
+ module Presenters
5
+ module DSL
6
+ # The default dsl for ui
7
+ # This class is held in the container. When a request to render a UI comes in
8
+ # It creates a new UserInterface instance, binding it to the router and context of the request
9
+ class Definition
10
+ def initialize(&block)
11
+ @block = block
12
+ end
13
+
14
+ def build
15
+ self
16
+ end
17
+
18
+ def expand(router: , context:{}, &block)
19
+ presenter = UserInterface.new(router: router, context: context, &@block)
20
+ yield(presenter) if block
21
+ presenter.expand_instance
22
+ end
23
+
24
+ def expand_child(parent:, context: {})
25
+ presenter = UserInterface.new(parent: parent, context: context, &@block)
26
+ presenter.expand_instance(freeze: false)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,8 @@
1
+ module Voom
2
+ module Presenters
3
+ module DSL
4
+ class InvalidPresenter < StandardError
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ module Voom
2
+ module Presenters
3
+ module DSL
4
+ module Lockable
5
+ def lock!
6
+ @locked = true
7
+ end
8
+
9
+ def locked?
10
+ @locked || frozen?
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,135 @@
1
+ require 'ice_nine'
2
+ require_relative 'definer'
3
+ require_relative 'components/mixins/common'
4
+ require_relative 'components/mixins/helpers'
5
+ require_relative 'components/mixins/dialogs'
6
+ require_relative 'components/mixins/snackbars'
7
+ require_relative 'invalid_presenter'
8
+
9
+ require 'voom/serializer'
10
+ require 'voom/trace'
11
+
12
+
13
+ module Voom
14
+ module Presenters
15
+ module DSL
16
+ class UserInterface
17
+ include DSL::Definer
18
+ include Lockable
19
+ include Components::Mixins::Common
20
+ include Components::Mixins::Helpers
21
+ include Components::Mixins::Dialogs
22
+ include Components::Mixins::Snackbars
23
+ include Components::Mixins::Icons
24
+
25
+ include Voom::Serializer
26
+ include Voom::Trace
27
+
28
+ attr_reader :router, :context, :components
29
+ private :context, :router
30
+ alias params context
31
+
32
+ def initialize(parent: nil, router: nil, context:, &block)
33
+ @parent = parent
34
+ @router = router || @parent&.send(:router)
35
+ @context = context
36
+ @block = block
37
+ @header = nil
38
+ @drawer = nil
39
+ @components = []
40
+ @footer = nil
41
+ add_global_helpers
42
+ end
43
+
44
+ def page(title=nil, **attribs, &block)
45
+ return @page if locked?
46
+ @page = Components::Page.new(parent: self, context: context,
47
+ **attribs, &block)
48
+ end
49
+
50
+ def header(title=nil, **attribs, &block)
51
+ return @header if locked?
52
+ @header = Components::Header.new(parent: self, title: title,
53
+ context: context,
54
+ **attribs, &block)
55
+ end
56
+
57
+ def drawer(name=nil, **attribs, &block)
58
+ return @drawer if locked?
59
+ @drawer = Components::Drawer.new(parent: self, title: name,
60
+ context: context,
61
+ **attribs, &block)
62
+ end
63
+
64
+
65
+
66
+ def footer(**attribs, &block)
67
+ return @footer if locked?
68
+ @footer = Components::Footer.new(parent: self,
69
+ context: context,
70
+ **attribs, &block)
71
+ end
72
+
73
+ def attach(presenter, **context_, &yield_block)
74
+ @_yield_block_ = yield_block
75
+ pom = Voom::Presenters::App[presenter].call.expand_child(parent: self, context: context.merge(context_))
76
+ @header ||= pom.header
77
+ @drawer ||= pom.drawer
78
+ @footer ||= pom.footer
79
+ @components += pom.components
80
+ end
81
+
82
+ # Called by the definition.expand method to evaluate a user interface with a different context
83
+ # This should be made unavailable to the dsl
84
+ def expand_instance(freeze: true)
85
+ instance_eval(&@block)
86
+ lock!
87
+ deep_freeze if freeze
88
+ self
89
+ end
90
+
91
+ def url(**context_)
92
+ return '#' unless @router
93
+ context = context_.dup
94
+ link_to = context.delete(:link)
95
+ post_to = context.delete(:command)
96
+ @router.url(render: link_to, command: post_to, context: context)
97
+ end
98
+
99
+ def type
100
+ :presenter
101
+ end
102
+
103
+ private
104
+
105
+ def deep_freeze
106
+ IceNine.deep_freeze(self) if Presenters::Settings.config.presenters.deep_freeze
107
+ self
108
+ end
109
+
110
+ private
111
+
112
+ def parent(for_type)
113
+ nil
114
+ end
115
+
116
+ def _helpers_
117
+ return @helpers if @helpers
118
+ end
119
+
120
+ def yield_block
121
+ return @_yield_block_ if @_yield_block_
122
+ @parent.send(:yield_block) if @parent
123
+ end
124
+
125
+ def add_global_helpers
126
+ Presenters::Settings.config.presenters.helpers.each do |helper|
127
+ self.helpers(helper)
128
+ end
129
+ end
130
+
131
+ end
132
+ end
133
+ end
134
+ end
135
+
@@ -0,0 +1,10 @@
1
+ require_relative 'unprocessable'
2
+
3
+ module Voom
4
+ module Presenters
5
+ module Errors
6
+ class ParameterValidation < Unprocessable
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module Voom
2
+ module Presenters
3
+ module Errors
4
+ class Unprocessable < StandardError
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'helpers/date'
2
+ require_relative 'helpers/time'
3
+ require_relative 'helpers/inflector'
4
+ require_relative 'helpers/errors'
5
+
6
+ module Voom
7
+ module Presenters
8
+ module Helpers
9
+ include Helpers::Time
10
+ include Helpers::Date
11
+ include Helpers::Errors
12
+ if defined?(Rails)
13
+ require_relative 'helpers/rails'
14
+ include Voom::Presenters::Helpers::Rails
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ module Voom
2
+ module Presenters
3
+ module Helpers
4
+ module Currency
5
+ include ActionView::Helpers::NumberHelper
6
+
7
+ def cents_to_currency(amount)
8
+ number_to_currency(amount.to_f / 100)
9
+ end
10
+
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ module Voom
2
+ module Presenters
3
+ module Helpers
4
+ module Date
5
+ LONG_FORMAT='%m/%d/%Y'
6
+ SHORT_FORMAT='%d %b %Y'
7
+
8
+ def format_date(date, format: '%m/%d/%Y')
9
+ date ? date.strftime(format) : ''
10
+ end
11
+
12
+ def format_date_long(time, format: nil)
13
+ format_date(time, format: format||LONG_FORMAT)
14
+ end
15
+
16
+ def format_date_short(time, format: nil)
17
+ format_date(time, format: format||SHORT_FORMAT)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ module Voom
2
+ module Presenters
3
+ module Helpers
4
+ module Errors
5
+ def raise_parameter_validation(msg)
6
+ raise Voom::Presenters::Errors::ParameterValidation, msg
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ module Voom
2
+ module Presenters
3
+ module Helpers
4
+ module Inflector
5
+ def inflector
6
+ @inflector ||= Dry::Inflector.new
7
+ end
8
+
9
+ def humanize(text)
10
+ inflector.humanize(text)
11
+ end
12
+ alias titleize humanize
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,60 @@
1
+ if defined?(Rails)
2
+ require_relative 'currency'
3
+
4
+ module Voom
5
+ module Presenters
6
+ module Helpers
7
+ module Rails
8
+ include ActionView::Helpers::AssetUrlHelper
9
+ include Voom::Presenters::Helpers::Currency
10
+
11
+ def default_url_options
12
+ {}
13
+ end
14
+
15
+ def presenters_path(presenter, **params)
16
+ path = voom_presenters_web_client_app_path(params)
17
+ if path.include?('?')
18
+ path = path.sub('?', "#{presenter}?")
19
+ else
20
+ path = "#{path}/" unless path.end_with?('/')
21
+ # replace last / with the presenter
22
+ path.reverse.sub('/', "/#{presenter}".reverse).reverse
23
+ end
24
+ end
25
+
26
+ def table_for(query_,
27
+ empty_icon: nil,
28
+ except: [:id, :created_at, :updated_at],
29
+ selectable: false, &block)
30
+ row1 = query_.first
31
+ if row1
32
+ __columns__ = row1.class.columns
33
+ table selectable: selectable do
34
+ header do
35
+ __columns__.each do |col|
36
+ column col.name.titleize unless except.include?(col.name.to_sym)
37
+ end
38
+ end
39
+
40
+ query_.each do |item_|
41
+ row do
42
+ __columns__.each do |col|
43
+ next if except.include?(col.name.to_sym)
44
+ column item_.send(col.name.to_sym) do
45
+ self.instance_exec(item_, col.name.to_sym, &block) if block
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ else
52
+ body "You have no #{query_.arel_table.name.pluralize}", level: 2
53
+ icon empty_icon, size: '10rem' if empty_icon
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end