voom-presenters 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +54 -0
- data/.ruby-version +1 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +104 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/ROADMAP.md +21 -0
- data/Rakefile +6 -0
- data/app/demo/component_status.pom +76 -0
- data/app/demo/components.pom +19 -0
- data/app/demo/components/badges.pom +25 -0
- data/app/demo/components/buttons.pom +51 -0
- data/app/demo/components/cards.pom +79 -0
- data/app/demo/components/chips.pom +91 -0
- data/app/demo/components/dialogs.pom +27 -0
- data/app/demo/components/drawers.pom +34 -0
- data/app/demo/components/expansion_panels.pom +21 -0
- data/app/demo/components/fabs-mini.pom +18 -0
- data/app/demo/components/fabs.pom +16 -0
- data/app/demo/components/footers.pom +36 -0
- data/app/demo/components/forms.pom +30 -0
- data/app/demo/components/headers.pom +37 -0
- data/app/demo/components/hidden_fields.pom +20 -0
- data/app/demo/components/icons.pom +94 -0
- data/app/demo/components/layouts.pom +44 -0
- data/app/demo/components/lists.pom +124 -0
- data/app/demo/components/menus.pom +43 -0
- data/app/demo/components/nav/drawer.pom +5 -0
- data/app/demo/components/nav/menu.pom +15 -0
- data/app/demo/components/selects.pom +30 -0
- data/app/demo/components/snackbar.pom +24 -0
- data/app/demo/components/snackbar_attached.pom +6 -0
- data/app/demo/components/tables.pom +39 -0
- data/app/demo/components/text_areas.pom +19 -0
- data/app/demo/components/text_fields.pom +57 -0
- data/app/demo/components/toggles.pom +29 -0
- data/app/demo/components/tooltips.pom +120 -0
- data/app/demo/event/actions.rb +86 -0
- data/app/demo/event/actions/dialog/show_dialog.pom +9 -0
- data/app/demo/event/actions/dialog/trigger.pom +86 -0
- data/app/demo/event/actions/nav/drawer.pom +5 -0
- data/app/demo/event/actions/nav/menu.pom +19 -0
- data/app/demo/event/autocomplete.pom +27 -0
- data/app/demo/event/field_level.pom +22 -0
- data/app/demo/event/form_level.pom +26 -0
- data/app/demo/event/nav/drawer.pom +5 -0
- data/app/demo/event/nav/menu.pom +14 -0
- data/app/demo/event/new_text.pom +6 -0
- data/app/demo/events.pom +98 -0
- data/app/demo/helpers/indented_grid.rb +14 -0
- data/app/demo/index.pom +19 -0
- data/app/demo/markdown.pom +73 -0
- data/app/demo/nav/top_nav.pom +42 -0
- data/app/demo/shared/code.pom +20 -0
- data/app/demo/shared/context_list.pom +29 -0
- data/app/demo/shared/debug.pom +17 -0
- data/app/demo/styles.pom +26 -0
- data/bin/console +22 -0
- data/bin/setup +8 -0
- data/component-status.yml +219 -0
- data/config.ru +21 -0
- data/lib/voom-presenters.rb +9 -0
- data/lib/voom/container_methods.rb +40 -0
- data/lib/voom/logger_methods.rb +11 -0
- data/lib/voom/parameters.rb +73 -0
- data/lib/voom/presenters-engine.rb +40 -0
- data/lib/voom/presenters.rb +13 -0
- data/lib/voom/presenters/api/app.rb +53 -0
- data/lib/voom/presenters/api/router.rb +94 -0
- data/lib/voom/presenters/app.rb +55 -0
- data/lib/voom/presenters/container_item.rb +16 -0
- data/lib/voom/presenters/demo/echo.rb +29 -0
- data/lib/voom/presenters/demo/search-terms.yml +50 -0
- data/lib/voom/presenters/demo/search.rb +29 -0
- data/lib/voom/presenters/dsl.rb +60 -0
- data/lib/voom/presenters/dsl/components/action.rb +35 -0
- data/lib/voom/presenters/dsl/components/avatar.rb +27 -0
- data/lib/voom/presenters/dsl/components/badge.rb +21 -0
- data/lib/voom/presenters/dsl/components/base.rb +78 -0
- data/lib/voom/presenters/dsl/components/button.rb +49 -0
- data/lib/voom/presenters/dsl/components/card.rb +119 -0
- data/lib/voom/presenters/dsl/components/checkbox.rb +16 -0
- data/lib/voom/presenters/dsl/components/chip.rb +48 -0
- data/lib/voom/presenters/dsl/components/content.rb +33 -0
- data/lib/voom/presenters/dsl/components/date_time.rb +17 -0
- data/lib/voom/presenters/dsl/components/dialog.rb +50 -0
- data/lib/voom/presenters/dsl/components/drawer.rb +40 -0
- data/lib/voom/presenters/dsl/components/event.rb +101 -0
- data/lib/voom/presenters/dsl/components/event_base.rb +20 -0
- data/lib/voom/presenters/dsl/components/expansion_panel.rb +46 -0
- data/lib/voom/presenters/dsl/components/footer.rb +25 -0
- data/lib/voom/presenters/dsl/components/form.rb +42 -0
- data/lib/voom/presenters/dsl/components/grid.rb +64 -0
- data/lib/voom/presenters/dsl/components/header.rb +33 -0
- data/lib/voom/presenters/dsl/components/hidden_field.rb +25 -0
- data/lib/voom/presenters/dsl/components/icon.rb +21 -0
- data/lib/voom/presenters/dsl/components/icon_base.rb +24 -0
- data/lib/voom/presenters/dsl/components/icon_toggle.rb +21 -0
- data/lib/voom/presenters/dsl/components/image.rb +36 -0
- data/lib/voom/presenters/dsl/components/input.rb +19 -0
- data/lib/voom/presenters/dsl/components/list.rb +39 -0
- data/lib/voom/presenters/dsl/components/lists/action.rb +72 -0
- data/lib/voom/presenters/dsl/components/lists/line.rb +83 -0
- data/lib/voom/presenters/dsl/components/lists/separator.rb +16 -0
- data/lib/voom/presenters/dsl/components/menu.rb +66 -0
- data/lib/voom/presenters/dsl/components/mixins/append.rb +20 -0
- data/lib/voom/presenters/dsl/components/mixins/attaches.rb +18 -0
- data/lib/voom/presenters/dsl/components/mixins/avatar.rb +18 -0
- data/lib/voom/presenters/dsl/components/mixins/buttons.rb +15 -0
- data/lib/voom/presenters/dsl/components/mixins/chips.rb +21 -0
- data/lib/voom/presenters/dsl/components/mixins/common.rb +50 -0
- data/lib/voom/presenters/dsl/components/mixins/content.rb +15 -0
- data/lib/voom/presenters/dsl/components/mixins/dialogs.rb +19 -0
- data/lib/voom/presenters/dsl/components/mixins/event.rb +19 -0
- data/lib/voom/presenters/dsl/components/mixins/expansion_panels.rb +15 -0
- data/lib/voom/presenters/dsl/components/mixins/grids.rb +15 -0
- data/lib/voom/presenters/dsl/components/mixins/helpers.rb +20 -0
- data/lib/voom/presenters/dsl/components/mixins/icons.rb +17 -0
- data/lib/voom/presenters/dsl/components/mixins/images.rb +15 -0
- data/lib/voom/presenters/dsl/components/mixins/menus.rb +15 -0
- data/lib/voom/presenters/dsl/components/mixins/selects.rb +17 -0
- data/lib/voom/presenters/dsl/components/mixins/snackbars.rb +18 -0
- data/lib/voom/presenters/dsl/components/mixins/text_fields.rb +35 -0
- data/lib/voom/presenters/dsl/components/mixins/toggles.rb +40 -0
- data/lib/voom/presenters/dsl/components/mixins/tooltips.rb +18 -0
- data/lib/voom/presenters/dsl/components/mixins/typography.rb +37 -0
- data/lib/voom/presenters/dsl/components/page.rb +29 -0
- data/lib/voom/presenters/dsl/components/radio_button.rb +14 -0
- data/lib/voom/presenters/dsl/components/select.rb +64 -0
- data/lib/voom/presenters/dsl/components/snackbar.rb +32 -0
- data/lib/voom/presenters/dsl/components/switch.rb +14 -0
- data/lib/voom/presenters/dsl/components/table.rb +102 -0
- data/lib/voom/presenters/dsl/components/text_area.rb +20 -0
- data/lib/voom/presenters/dsl/components/text_field.rb +74 -0
- data/lib/voom/presenters/dsl/components/toggle_base.rb +26 -0
- data/lib/voom/presenters/dsl/components/tooltip.rb +25 -0
- data/lib/voom/presenters/dsl/components/typography.rb +25 -0
- data/lib/voom/presenters/dsl/definer.rb +13 -0
- data/lib/voom/presenters/dsl/definition.rb +31 -0
- data/lib/voom/presenters/dsl/invalid_presenter.rb +8 -0
- data/lib/voom/presenters/dsl/lockable.rb +15 -0
- data/lib/voom/presenters/dsl/user_interface.rb +135 -0
- data/lib/voom/presenters/errors/parameter_validation.rb +10 -0
- data/lib/voom/presenters/errors/unprocessable.rb +8 -0
- data/lib/voom/presenters/helpers.rb +18 -0
- data/lib/voom/presenters/helpers/currency.rb +14 -0
- data/lib/voom/presenters/helpers/date.rb +22 -0
- data/lib/voom/presenters/helpers/errors.rb +11 -0
- data/lib/voom/presenters/helpers/inflector.rb +16 -0
- data/lib/voom/presenters/helpers/rails.rb +60 -0
- data/lib/voom/presenters/helpers/route.rb +11 -0
- data/lib/voom/presenters/helpers/time.rb +27 -0
- data/lib/voom/presenters/settings.rb +35 -0
- data/lib/voom/presenters/version.rb +5 -0
- data/lib/voom/presenters/web_client/app.rb +128 -0
- data/lib/voom/presenters/web_client/markdown_render.rb +16 -0
- data/lib/voom/presenters/web_client/router.rb +96 -0
- data/lib/voom/serializer.rb +43 -0
- data/lib/voom/symbol/to_str.rb +29 -0
- data/lib/voom/trace.rb +19 -0
- data/presenters.gemspec +37 -0
- data/public/.gitignore +2 -0
- data/public/bundle.css +11413 -0
- data/public/bundle.js +16456 -0
- data/public/dialog-polyfill.js +738 -0
- data/public/favicon.ico +0 -0
- data/public/img/demo/dog.png +0 -0
- data/public/img/demo/image_card.jpg +0 -0
- data/public/img/demo/rx.png +0 -0
- data/public/img/demo/welcome_card.jpg +0 -0
- data/public/img/settings/blue.png +0 -0
- data/public/img/settings/green.png +0 -0
- data/public/img/settings/orange.png +0 -0
- data/public/img/settings/purple.png +0 -0
- data/public/img/settings/red.png +0 -0
- data/public/img/settings/teal.png +0 -0
- data/public/img/settings/white.png +0 -0
- data/public/img/settings/yellow.png +0 -0
- data/public/scripts.js +289 -0
- data/public/style-bundle.js +73 -0
- data/public/styles.css +16 -0
- data/views/mdc/.gitignore +1 -0
- data/views/mdc/assets/js/app.js +10 -0
- data/views/mdc/assets/js/components/base-component.js +5 -0
- data/views/mdc/assets/js/components/button.js +15 -0
- data/views/mdc/assets/js/components/cards.js +3 -0
- data/views/mdc/assets/js/components/checkboxes.js +15 -0
- data/views/mdc/assets/js/components/chips.js +12 -0
- data/views/mdc/assets/js/components/date-time.js +6 -0
- data/views/mdc/assets/js/components/dialogs.js +32 -0
- data/views/mdc/assets/js/components/events.js +151 -0
- data/views/mdc/assets/js/components/events/autocomplete.js +96 -0
- data/views/mdc/assets/js/components/events/base.js +41 -0
- data/views/mdc/assets/js/components/events/dialog.js +25 -0
- data/views/mdc/assets/js/components/events/errors.js +142 -0
- data/views/mdc/assets/js/components/events/loads.js +22 -0
- data/views/mdc/assets/js/components/events/navigates.js +17 -0
- data/views/mdc/assets/js/components/events/posts.js +99 -0
- data/views/mdc/assets/js/components/events/replaces.js +82 -0
- data/views/mdc/assets/js/components/events/selects.js +28 -0
- data/views/mdc/assets/js/components/events/snackbar.js +23 -0
- data/views/mdc/assets/js/components/events/toggle_visiblity.js +19 -0
- data/views/mdc/assets/js/components/forms.js +57 -0
- data/views/mdc/assets/js/components/icon-toggles.js +21 -0
- data/views/mdc/assets/js/components/initialize.js +34 -0
- data/views/mdc/assets/js/components/lists.js +4 -0
- data/views/mdc/assets/js/components/menus.js +31 -0
- data/views/mdc/assets/js/components/mixins/event-handler.js +13 -0
- data/views/mdc/assets/js/components/selects.js +45 -0
- data/views/mdc/assets/js/components/snackbar.js +32 -0
- data/views/mdc/assets/js/components/text-fields.js +77 -0
- data/views/mdc/assets/js/dialog-polyfill.js +738 -0
- data/views/mdc/assets/js/material.js +3996 -0
- data/views/mdc/assets/js/utils/urls.js +54 -0
- data/views/mdc/assets/scss/app.scss +31 -0
- data/views/mdc/assets/scss/components/avatar.scss +41 -0
- data/views/mdc/assets/scss/components/button.scss +47 -0
- data/views/mdc/assets/scss/components/card.scss +54 -0
- data/views/mdc/assets/scss/components/checkbox.scss +5 -0
- data/views/mdc/assets/scss/components/chip.scss +30 -0
- data/views/mdc/assets/scss/components/datetime.scss +0 -0
- data/views/mdc/assets/scss/components/dialog.scss +3 -0
- data/views/mdc/assets/scss/components/expansion-panel.scss +153 -0
- data/views/mdc/assets/scss/components/fab.scss +8 -0
- data/views/mdc/assets/scss/components/grid.scss +10 -0
- data/views/mdc/assets/scss/components/icon-toggles.scss +9 -0
- data/views/mdc/assets/scss/components/icon.scss +34 -0
- data/views/mdc/assets/scss/components/image.scss +24 -0
- data/views/mdc/assets/scss/components/list.scss +9 -0
- data/views/mdc/assets/scss/components/menu.scss +17 -0
- data/views/mdc/assets/scss/components/select.scss +16 -0
- data/views/mdc/assets/scss/components/snackbar.scss +5 -0
- data/views/mdc/assets/scss/components/switch.scss +6 -0
- data/views/mdc/assets/scss/components/table-pagination.scss +65 -0
- data/views/mdc/assets/scss/components/textfield.scss +1 -0
- data/views/mdc/assets/scss/components/typography.scss +25 -0
- data/views/mdc/assets/scss/material.blue_grey-orange.min.css +8 -0
- data/views/mdc/assets/scss/styles.scss +11 -0
- data/views/mdc/assets/scss/theme.scss +5 -0
- data/views/mdc/body/drawer.erb +18 -0
- data/views/mdc/body/drawers/menu.erb +25 -0
- data/views/mdc/body/footer.erb +1 -0
- data/views/mdc/body/footers/large.erb +27 -0
- data/views/mdc/body/footers/menu_item.erb +6 -0
- data/views/mdc/body/footers/small.erb +14 -0
- data/views/mdc/body/header.erb +25 -0
- data/views/mdc/body/snackbar.erb +10 -0
- data/views/mdc/components/avatar.erb +24 -0
- data/views/mdc/components/badge.erb +2 -0
- data/views/mdc/components/body.erb +2 -0
- data/views/mdc/components/button.erb +17 -0
- data/views/mdc/components/buttons/button.erb +20 -0
- data/views/mdc/components/buttons/fab.erb +22 -0
- data/views/mdc/components/buttons/icon.erb +24 -0
- data/views/mdc/components/card.erb +49 -0
- data/views/mdc/components/checkbox.erb +22 -0
- data/views/mdc/components/chip.erb +31 -0
- data/views/mdc/components/content.erb +11 -0
- data/views/mdc/components/date_time.erb +30 -0
- data/views/mdc/components/dialog.erb +27 -0
- data/views/mdc/components/display.erb +2 -0
- data/views/mdc/components/event.erb +18 -0
- data/views/mdc/components/expansion_panel.erb +11 -0
- data/views/mdc/components/form.erb +15 -0
- data/views/mdc/components/grid.erb +24 -0
- data/views/mdc/components/headline.erb +2 -0
- data/views/mdc/components/hidden_field.erb +1 -0
- data/views/mdc/components/icon.erb +30 -0
- data/views/mdc/components/icon_toggle.erb +15 -0
- data/views/mdc/components/image.erb +7 -0
- data/views/mdc/components/link.erb +14 -0
- data/views/mdc/components/list.erb +14 -0
- data/views/mdc/components/list/actions.erb +6 -0
- data/views/mdc/components/list/actions/button.erb +1 -0
- data/views/mdc/components/list/actions/checkbox.erb +1 -0
- data/views/mdc/components/list/actions/icon.erb +1 -0
- data/views/mdc/components/list/actions/icon_toggle.erb +1 -0
- data/views/mdc/components/list/actions/radio_button.erb +1 -0
- data/views/mdc/components/list/actions/switch.erb +1 -0
- data/views/mdc/components/list/avatar.erb +5 -0
- data/views/mdc/components/list/checkbox.erb +5 -0
- data/views/mdc/components/list/icon.erb +5 -0
- data/views/mdc/components/list/info.erb +1 -0
- data/views/mdc/components/list/line.erb +34 -0
- data/views/mdc/components/list/menu.erb +23 -0
- data/views/mdc/components/list/separator.erb +1 -0
- data/views/mdc/components/menu.erb +29 -0
- data/views/mdc/components/modal.erb +15 -0
- data/views/mdc/components/radio_button.erb +11 -0
- data/views/mdc/components/render.erb +4 -0
- data/views/mdc/components/select.erb +22 -0
- data/views/mdc/components/snackbar.erb +17 -0
- data/views/mdc/components/static.erb +7 -0
- data/views/mdc/components/subheading.erb +2 -0
- data/views/mdc/components/switch.erb +13 -0
- data/views/mdc/components/table.erb +13 -0
- data/views/mdc/components/table/header.erb +7 -0
- data/views/mdc/components/table/pagination.erb +24 -0
- data/views/mdc/components/table/row.erb +14 -0
- data/views/mdc/components/text_area.erb +8 -0
- data/views/mdc/components/text_field.erb +27 -0
- data/views/mdc/components/title.erb +4 -0
- data/views/mdc/components/tooltip.erb +5 -0
- data/views/mdc/components/typography.erb +13 -0
- data/views/mdc/init-depends.sh +2 -0
- data/views/mdc/layout.erb +50 -0
- data/views/mdc/package-lock.json +11524 -0
- data/views/mdc/package.json +39 -0
- data/views/mdc/web.erb +1 -0
- data/views/mdc/webpack.config.js +47 -0
- metadata +539 -0
data/config.ru
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
ENV['VOOM_ROOT'] = File.expand_path(__dir__)
|
3
|
+
libdir = File.join(ENV['VOOM_ROOT'], 'lib')
|
4
|
+
$:.unshift(libdir) unless $:.include?(libdir)
|
5
|
+
require 'voom/presenters/api/app'
|
6
|
+
require 'voom/presenters/web_client/app'
|
7
|
+
require 'voom/presenters/demo/search'
|
8
|
+
require 'voom/presenters/demo/echo'
|
9
|
+
|
10
|
+
|
11
|
+
use Voom::Presenters::Demo::Search
|
12
|
+
use Voom::Presenters::Demo::Echo
|
13
|
+
|
14
|
+
use Voom::Presenters::WebClient::App
|
15
|
+
run Voom::Presenters::Api::App
|
16
|
+
|
17
|
+
Voom::Presenters::Settings.configure do |config|
|
18
|
+
config.presenters.root = File.join(ENV['VOOM_ROOT'], 'app')
|
19
|
+
end
|
20
|
+
Voom::Presenters::App.boot!
|
21
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative 'symbol/to_str'
|
2
|
+
|
3
|
+
module Voom
|
4
|
+
module ContainerMethods
|
5
|
+
include Voom::Symbol
|
6
|
+
|
7
|
+
def registered_keys
|
8
|
+
@registered_keys ||= []
|
9
|
+
end
|
10
|
+
|
11
|
+
def registered?(presenter)
|
12
|
+
container.key?(sym_to_str(presenter))
|
13
|
+
end
|
14
|
+
|
15
|
+
def [](name)
|
16
|
+
resolve(name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def resolve(name)
|
20
|
+
container.resolve(sym_to_str(name))
|
21
|
+
end
|
22
|
+
|
23
|
+
def list
|
24
|
+
container.keys
|
25
|
+
end
|
26
|
+
alias keys list
|
27
|
+
|
28
|
+
def container
|
29
|
+
@container ||= Dry::Container.new
|
30
|
+
end
|
31
|
+
|
32
|
+
# This method empties out the container
|
33
|
+
# It should ONLY be used for testing purposes
|
34
|
+
def reset!
|
35
|
+
registered_keys.each { |key| ClassConstants.new(key).deconstantize }
|
36
|
+
@registered_keys = []
|
37
|
+
container._container.clear
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Voom
|
2
|
+
# Provides a query interface for the ruby parameters method
|
3
|
+
class Parameters
|
4
|
+
def initialize(parameters)
|
5
|
+
@params = parameters
|
6
|
+
end
|
7
|
+
|
8
|
+
def args
|
9
|
+
@params.select {|p| p.first == :req || p.first == :opt}
|
10
|
+
end
|
11
|
+
|
12
|
+
def required_args
|
13
|
+
@params.select {|p| p.first == :req}
|
14
|
+
end
|
15
|
+
|
16
|
+
def required_args?
|
17
|
+
required_args.any?
|
18
|
+
end
|
19
|
+
|
20
|
+
def optional_args
|
21
|
+
@params.select {|p| p.first == :opt}
|
22
|
+
end
|
23
|
+
|
24
|
+
def optional_args?
|
25
|
+
optional_args.any?
|
26
|
+
end
|
27
|
+
|
28
|
+
def splats_args
|
29
|
+
@params.select {|p| p.first == :rest}
|
30
|
+
end
|
31
|
+
|
32
|
+
def splats_args?
|
33
|
+
splats_args.any?
|
34
|
+
end
|
35
|
+
|
36
|
+
def options
|
37
|
+
@params.select {|p| p.first == :keyreq || p.first == :key}
|
38
|
+
end
|
39
|
+
|
40
|
+
def options?
|
41
|
+
options.any?
|
42
|
+
end
|
43
|
+
|
44
|
+
def required_options
|
45
|
+
@params.select {|p| p.first == :keyreq}
|
46
|
+
end
|
47
|
+
|
48
|
+
def required_options?
|
49
|
+
required_options.any?
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def optional_options
|
54
|
+
@params.select {|p| p.first == :key}
|
55
|
+
end
|
56
|
+
|
57
|
+
def optional_options?
|
58
|
+
optional_options.any?
|
59
|
+
end
|
60
|
+
|
61
|
+
def spalts_options
|
62
|
+
@params.select {|p| p.first == :keyrest}
|
63
|
+
end
|
64
|
+
|
65
|
+
def splats_options?
|
66
|
+
spalts_options.any?
|
67
|
+
end
|
68
|
+
|
69
|
+
def names(args_or_options)
|
70
|
+
args_or_options.map(&:last)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
if Rails.version =~ /^4/
|
2
|
+
require_dependency 'voom/presenters'
|
3
|
+
else
|
4
|
+
require 'voom/presenters'
|
5
|
+
end
|
6
|
+
|
7
|
+
module Voom
|
8
|
+
module Presenter
|
9
|
+
class Engine < ::Rails::Engine
|
10
|
+
config.autoload_paths += Dir["#{config.root}/lib/**/"]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
module Voom
|
17
|
+
module Presenter
|
18
|
+
class Railtie < ::Rails::Railtie
|
19
|
+
BOOT = ->{
|
20
|
+
Voom::Presenters::Settings.configure do |config|
|
21
|
+
config.presenters.root = Rails.root.join('app')
|
22
|
+
# config.presenters.deep_freeze = false
|
23
|
+
end
|
24
|
+
Voom::Presenters::App.boot!
|
25
|
+
}
|
26
|
+
RELOADER = ActiveSupport::FileUpdateChecker.new([], {"app" => ["pom"]}) do
|
27
|
+
Voom::Presenters::App.reset!
|
28
|
+
BOOT.call
|
29
|
+
end
|
30
|
+
|
31
|
+
initializer 'voom-presenters' do |app|
|
32
|
+
app.reloaders << RELOADER
|
33
|
+
end
|
34
|
+
|
35
|
+
config.to_prepare do
|
36
|
+
RELOADER.execute
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'dry-container'
|
2
|
+
require 'voom/container_methods'
|
3
|
+
require 'voom/logger_methods'
|
4
|
+
require 'voom/trace'
|
5
|
+
require_relative 'presenters/version'
|
6
|
+
require_relative 'presenters/settings'
|
7
|
+
require_relative 'presenters/container_item'
|
8
|
+
require_relative 'presenters/dsl'
|
9
|
+
require_relative 'presenters/dsl/definer'
|
10
|
+
require_relative 'presenters/dsl/definition'
|
11
|
+
require_relative 'presenters/helpers'
|
12
|
+
require_relative 'presenters/app'
|
13
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'json'
|
3
|
+
require_relative '../../presenters'
|
4
|
+
require_relative 'router'
|
5
|
+
|
6
|
+
module Voom
|
7
|
+
module Presenters
|
8
|
+
module Api
|
9
|
+
# This is the Rest API for voom services/component commands
|
10
|
+
class App < Sinatra::Base
|
11
|
+
set :root, File.expand_path('../../../..', __FILE__)
|
12
|
+
set :router_, Router
|
13
|
+
set :bind, '0.0.0.0'
|
14
|
+
|
15
|
+
get '/:_presenter_.pom' do
|
16
|
+
render_presenter
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def render_presenter
|
22
|
+
# puts "/presenters/api/#{params[:version]}/#{params[:presenter]}/"
|
23
|
+
# puts "Parameters: #{params.inspect}"
|
24
|
+
presenter = Voom::Presenters::App[params[:_presenter_]].call
|
25
|
+
pom = presenter.expand(router: router, context: prepare_context)
|
26
|
+
content_type :json
|
27
|
+
JSON.dump(pom.to_hash)
|
28
|
+
end
|
29
|
+
|
30
|
+
def router
|
31
|
+
settings.router_.new(base_url: "#{request.base_url}#{env['SCRIPT_NAME']}")
|
32
|
+
end
|
33
|
+
|
34
|
+
def prepare_context
|
35
|
+
prepare_context = Presenters::Settings.config.presenters.web_client.prepare_context.dup
|
36
|
+
prepare_context.push(method(:scrub_context))
|
37
|
+
context = params.dup
|
38
|
+
prepare_context.reduce(context) do |params, context_proc|
|
39
|
+
context_proc.call(params, session, env)
|
40
|
+
end
|
41
|
+
context
|
42
|
+
end
|
43
|
+
|
44
|
+
def scrub_context(params, _session, _env)
|
45
|
+
%i(splat captures _presenter_ grid_nesting).each do |key|
|
46
|
+
params.delete(key)
|
47
|
+
end
|
48
|
+
params
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'rack'
|
2
|
+
|
3
|
+
module Voom
|
4
|
+
module Presenters
|
5
|
+
module Api
|
6
|
+
class Router
|
7
|
+
|
8
|
+
attr_reader :base_url
|
9
|
+
|
10
|
+
def initialize(base_url: nil)
|
11
|
+
@base_url = base_url
|
12
|
+
end
|
13
|
+
|
14
|
+
def url(command: nil, render: nil, entity: nil, context:)
|
15
|
+
_params_ = context.dup
|
16
|
+
# if it is a local page command
|
17
|
+
# return build_local_render(command, render, entity, _params_) if local_render?(render)
|
18
|
+
return build_render_url(render, entity, _params_) unless command
|
19
|
+
_params_[:redirect]=build_render_url(render, entity, _params_) if render
|
20
|
+
build_command_url(command, entity, _params_)
|
21
|
+
end
|
22
|
+
|
23
|
+
def local_render?(render)
|
24
|
+
return unless render
|
25
|
+
render.to_s.start_with?('#')
|
26
|
+
end
|
27
|
+
|
28
|
+
def build_local_render(command, render, entity, context)
|
29
|
+
|
30
|
+
client_command = render[/(.*?)\(/m, 1]
|
31
|
+
|
32
|
+
start_params = render.index('(')
|
33
|
+
end_params = render.rindex(')')
|
34
|
+
client_params = render[start_params+1..end_params-1]
|
35
|
+
client_params = client_params.split(',')
|
36
|
+
|
37
|
+
client_command += '('
|
38
|
+
client_params.each.with_index do |p, index|
|
39
|
+
client_command += ',' if index > 0
|
40
|
+
url_var = p[/{url\((.*?)\)}/m, 1]
|
41
|
+
client_command += build_client_url(url_var.strip, entity, context) if url_var && command.nil?
|
42
|
+
client_command += p.strip unless url_var
|
43
|
+
end
|
44
|
+
client_command += ')'
|
45
|
+
end
|
46
|
+
|
47
|
+
def join_errors
|
48
|
+
'<br/>'
|
49
|
+
end
|
50
|
+
|
51
|
+
def scrub_params(_params_)
|
52
|
+
# _params_.delete('captures')
|
53
|
+
# _params_.delete('render')
|
54
|
+
# _params_.delete('view')
|
55
|
+
_params_.delete('presenter')
|
56
|
+
# _params_.delete('redirect')
|
57
|
+
_params_.delete('action')
|
58
|
+
_params_.delete('errors')
|
59
|
+
_params_
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def build_command_url(command, entity, params)
|
65
|
+
return '' unless command
|
66
|
+
"#{command}?#{build_params(params, entity)}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def build_render_url(render_, entity, params)
|
70
|
+
return '#' unless render_
|
71
|
+
render = render_.to_s
|
72
|
+
seperator = render.start_with?('/') ? '' : '/'
|
73
|
+
url = "#{base_url}#{seperator}#{render}"
|
74
|
+
query_params = build_params(params, entity)
|
75
|
+
if(query_params)
|
76
|
+
query_seperator = render.include?('?') ? '&' : '?'
|
77
|
+
url = "#{url}#{query_seperator}#{query_params}"
|
78
|
+
end
|
79
|
+
url
|
80
|
+
end
|
81
|
+
|
82
|
+
def build_client_url(render, entity, params)
|
83
|
+
return '#' unless render
|
84
|
+
"#{base_url}/web/#{render}?layout=false&#{build_params(params, entity)}"
|
85
|
+
end
|
86
|
+
|
87
|
+
def build_params(params, entity)
|
88
|
+
params = params.merge(entity_key: entity.id) if entity
|
89
|
+
Rack::Utils.build_nested_query(scrub_params(params))
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Voom
|
2
|
+
module Presenters
|
3
|
+
class App
|
4
|
+
class << self
|
5
|
+
include Voom::ContainerMethods
|
6
|
+
include Voom::LoggerMethods
|
7
|
+
include Voom::Trace
|
8
|
+
include Voom::Symbol
|
9
|
+
|
10
|
+
def boot!
|
11
|
+
logger.warn(no_roots_message) if presenter_paths.empty?
|
12
|
+
presenter_paths.each do |load_path|
|
13
|
+
Voom::Presenters::App.load('.', load_path) unless ENV['VOOM_ENV']=='testing'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def no_roots_message
|
18
|
+
<<~MESSAGE
|
19
|
+
No root defined to load presenters!
|
20
|
+
Add the following to your initializer/boot process:
|
21
|
+
|
22
|
+
Voom::Presenters::Settings.configure do |config|
|
23
|
+
config.presenters.root = Rails.root.join('app')
|
24
|
+
end
|
25
|
+
MESSAGE
|
26
|
+
end
|
27
|
+
|
28
|
+
def register(name:, presenter: nil, &block)
|
29
|
+
raise Errors::MissingArgument,
|
30
|
+
'A presenter class, proc, lambda or a block must be provided!' unless block_given? || presenter
|
31
|
+
container.register(sym_to_str(name), Voom::Presenters::ContainerItem.new(ui: block || presenter), {})
|
32
|
+
end
|
33
|
+
|
34
|
+
def load(dir='app', root=ENV['VOOM_ROOT']||File.expand_path("../../../", __FILE__))
|
35
|
+
path = File.expand_path(dir, root)
|
36
|
+
trace {"Loading Presenters from: #{path}"}
|
37
|
+
Presenters::DSL.load(File.expand_path(dir, root))
|
38
|
+
Presenters::DSL.finalize
|
39
|
+
end
|
40
|
+
|
41
|
+
def reset!
|
42
|
+
super
|
43
|
+
Presenters::DSL.reset!
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def presenter_paths
|
49
|
+
Array(Voom::Presenters::Settings.config.presenters.root)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Voom
|
2
|
+
module Presenters
|
3
|
+
# Presenters are registered in the container with this class
|
4
|
+
# You can replace this using the presenter container_item setting
|
5
|
+
class ContainerItem
|
6
|
+
def initialize(ui:)
|
7
|
+
@ui = ui
|
8
|
+
end
|
9
|
+
|
10
|
+
# Resolves the ui to an instance that can be rendered
|
11
|
+
def call
|
12
|
+
@ui
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
|
3
|
+
module Voom
|
4
|
+
module Presenters
|
5
|
+
module Demo
|
6
|
+
# Echo's back post, delete and put
|
7
|
+
# Used to demonstrate how the posts(updates), deletes and modifies actions work.
|
8
|
+
class Echo < Sinatra::Base
|
9
|
+
post('/_echo_') do
|
10
|
+
content_type :json
|
11
|
+
JSON.dump(params)
|
12
|
+
end
|
13
|
+
|
14
|
+
delete('/_echo_') do
|
15
|
+
content_type :json
|
16
|
+
JSON.dump(params)
|
17
|
+
end
|
18
|
+
|
19
|
+
put('/_echo_') do
|
20
|
+
content_type :json
|
21
|
+
JSON.dump(params)
|
22
|
+
end
|
23
|
+
|
24
|
+
# start the server if ruby file executed directly
|
25
|
+
run! if app_file == $0
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|