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
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'tzinfo'
|
2
|
+
|
3
|
+
module Voom
|
4
|
+
module Presenters
|
5
|
+
module Helpers
|
6
|
+
module Time
|
7
|
+
LONG_FORMAT='%m/%d/%Y %I:%M:%S %p %Z'
|
8
|
+
SHORT_FORMAT='%d %b %H:%M %Z'
|
9
|
+
|
10
|
+
def format_time(time, format: '%m/%d/%Y %I:%M:%S %p %Z', timezone: nil)
|
11
|
+
return '' unless time
|
12
|
+
time = time.in_time_zone(timezone) if timezone
|
13
|
+
time.strftime(format)
|
14
|
+
end
|
15
|
+
|
16
|
+
def format_time_long(time, format: nil, timezone: nil)
|
17
|
+
format_time(time, format: format||LONG_FORMAT, timezone: timezone)
|
18
|
+
end
|
19
|
+
|
20
|
+
def format_time_short(time, format: nil, timezone: nil)
|
21
|
+
format_time(time, format: format||SHORT_FORMAT, timezone: timezone)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
include Voom::Trace
|
2
|
+
trace {"Loading Presenters Settings"}
|
3
|
+
require_relative 'helpers/route'
|
4
|
+
|
5
|
+
module Voom
|
6
|
+
module Presenters
|
7
|
+
class Settings
|
8
|
+
extend Dry::Configurable
|
9
|
+
setting :presenters do
|
10
|
+
setting :root, []
|
11
|
+
# You can add helpers that will automatically be included
|
12
|
+
# For example:
|
13
|
+
# For example:
|
14
|
+
# Voom::Presenters::Settings.configure do |config|
|
15
|
+
# config.presenters.helpers << YourHelperModule # Passing a module
|
16
|
+
# config.presenters.helpers << &->{ def foo; :foo; end } # Passing a block
|
17
|
+
# end
|
18
|
+
setting :helpers, [Voom::Presenters::Helpers::Route]
|
19
|
+
setting :deep_freeze, true
|
20
|
+
setting :id_generator, ->(node) {"id-#{SecureRandom.hex}"}
|
21
|
+
setting :web_client do
|
22
|
+
# Add lambda's to modify the context for the presenters
|
23
|
+
# For example:
|
24
|
+
# Voom::Presenters::Settings.configure do |config|
|
25
|
+
# config.presenters.web_client.prepare_context << ->(context, session, _env){
|
26
|
+
# identity_id = session[:aaa_identity]
|
27
|
+
# context.merge(aaa_identity: identity_id)
|
28
|
+
# }
|
29
|
+
# end
|
30
|
+
setting :prepare_context, []
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'uri'
|
3
|
+
require 'redcarpet'
|
4
|
+
require 'voom/trace'
|
5
|
+
require 'voom/presenters/app'
|
6
|
+
require "dry/inflector"
|
7
|
+
|
8
|
+
require_relative 'router'
|
9
|
+
require_relative 'markdown_render'
|
10
|
+
require_relative '../errors/unprocessable'
|
11
|
+
|
12
|
+
module Voom
|
13
|
+
module Presenters
|
14
|
+
module WebClient
|
15
|
+
class App < Sinatra::Base
|
16
|
+
include Trace
|
17
|
+
set :root, File.expand_path('../../../../..', __FILE__)
|
18
|
+
set :router_, Router
|
19
|
+
set :bind, '0.0.0.0'
|
20
|
+
set :views, Proc.new {File.join(root, "views", ENV['VIEW_ENGINE']||'mdc')}
|
21
|
+
|
22
|
+
helpers do
|
23
|
+
def markdown(text)
|
24
|
+
unless @markdown
|
25
|
+
renderer = CustomRender.new(hard_wrap: false, filter_html: true)
|
26
|
+
options = {
|
27
|
+
autolink: false,
|
28
|
+
no_intra_emphasis: true,
|
29
|
+
fenced_code_blocks: true,
|
30
|
+
lax_html_blocks: true,
|
31
|
+
strikethrough: true,
|
32
|
+
superscript: true,
|
33
|
+
disable_indented_code_blocks: true
|
34
|
+
}
|
35
|
+
@markdown = Redcarpet::Markdown.new(renderer, options)
|
36
|
+
end
|
37
|
+
|
38
|
+
@markdown.render(text)
|
39
|
+
end
|
40
|
+
|
41
|
+
def inflector
|
42
|
+
@inflector ||= Dry::Inflector.new
|
43
|
+
end
|
44
|
+
|
45
|
+
def eq(attrib, value)
|
46
|
+
attrib.to_s == value.to_s
|
47
|
+
end
|
48
|
+
|
49
|
+
def unique_id(comp)
|
50
|
+
"#{comp.id}-#{SecureRandom.hex(4)}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def expand_text(text)
|
54
|
+
self.markdown(Array(text).join("\n\n"))#.gsub("\n\n", "<br/>")
|
55
|
+
end
|
56
|
+
|
57
|
+
def color_classname(comp)
|
58
|
+
return "v-#{comp.type}__primary" if eq(comp.color, :primary)
|
59
|
+
"v-#{comp.type}__secondary" if eq(comp.color, :secondary)
|
60
|
+
end
|
61
|
+
|
62
|
+
def color_style(comp, affects=nil)
|
63
|
+
"#{affects}color: #{comp.color};" unless %w(primary secondary).include?(comp.color.to_s) || comp.color.nil?
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
get '/' do
|
69
|
+
pass unless Presenters::App.registered?('index')
|
70
|
+
presenter = Presenters::App['index'].call
|
71
|
+
render_presenter(presenter)
|
72
|
+
end
|
73
|
+
|
74
|
+
get '/:_presenter_' do
|
75
|
+
pass unless Presenters::App.registered?(params[:_presenter_])
|
76
|
+
presenter = Presenters::App[params[:_presenter_]].call
|
77
|
+
render_presenter(presenter)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Forms engine demo
|
81
|
+
post '/__post__/:presenter' do
|
82
|
+
@pom = JSON.parse(request.body.read, object_class: OpenStruct)
|
83
|
+
@grid_nesting = Integer(params[:grid_nesting] || 0)
|
84
|
+
layout = !(request.env['HTTP_X_NO_LAYOUT'] == 'true')
|
85
|
+
erb :web, layout: layout
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def render_presenter(presenter)
|
91
|
+
@grid_nesting = Integer(params[:grid_nesting] || 0)
|
92
|
+
|
93
|
+
begin
|
94
|
+
@pom = presenter.expand(router: router, context: prepare_context)
|
95
|
+
layout = !(request.env['HTTP_X_NO_LAYOUT'] == 'true')
|
96
|
+
response.headers['X-Frame-Options'] = 'ALLOWALL' if ENV['ALLOWALL_FRAME_OPTIONS']
|
97
|
+
erb :web, layout: layout
|
98
|
+
rescue Errors::Unprocessable => e
|
99
|
+
content_type :json
|
100
|
+
status 422
|
101
|
+
JSON.dump({error: e.message})
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def router
|
106
|
+
settings.router_.new(base_url: "#{request.base_url}#{env['SCRIPT_NAME']}")
|
107
|
+
end
|
108
|
+
|
109
|
+
def prepare_context
|
110
|
+
prepare_context = Presenters::Settings.config.presenters.web_client.prepare_context.dup
|
111
|
+
prepare_context.push(method(:scrub_context))
|
112
|
+
context = params.dup
|
113
|
+
prepare_context.reduce(context) do |params, context_proc|
|
114
|
+
context_proc.call(params, session, env)
|
115
|
+
end
|
116
|
+
context
|
117
|
+
end
|
118
|
+
|
119
|
+
def scrub_context(params, _session, _env)
|
120
|
+
%i(splat captures _presenter_ grid_nesting).each do |key|
|
121
|
+
params.delete(key)
|
122
|
+
end
|
123
|
+
params
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CustomRender < Redcarpet::Render::Safe
|
2
|
+
include Redcarpet::Render::SmartyPants
|
3
|
+
|
4
|
+
def initialize(extensions = {})
|
5
|
+
super(extensions)
|
6
|
+
end
|
7
|
+
|
8
|
+
def paragraph(text)
|
9
|
+
text + '<br/>'
|
10
|
+
end
|
11
|
+
|
12
|
+
def postprocess(full_document)
|
13
|
+
full_document.
|
14
|
+
gsub(/{c:([#\w]\w+)}([^{]+){\/c}/) {|m| "<span style=\"color:#{$1};\">#{$2}</span>"} # color
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'rack'
|
2
|
+
|
3
|
+
module Voom
|
4
|
+
module Presenters
|
5
|
+
module WebClient
|
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
|
+
seperator = command.include?('?') ? '&' : '?'
|
67
|
+
"#{command}#{seperator}#{build_params(params, entity)}"
|
68
|
+
end
|
69
|
+
|
70
|
+
def build_render_url(render_, entity, params)
|
71
|
+
return '#' unless render_
|
72
|
+
render = render_.to_s
|
73
|
+
return render if render.start_with?('http')
|
74
|
+
seperator = render.start_with?('/') ? '' : '/'
|
75
|
+
url = "#{base_url}#{seperator}#{render}"
|
76
|
+
query_params = build_params(params, entity)
|
77
|
+
if(query_params)
|
78
|
+
query_seperator = render.include?('?') ? '&' : '?'
|
79
|
+
url = "#{url}#{query_seperator}#{query_params}"
|
80
|
+
end
|
81
|
+
url
|
82
|
+
end
|
83
|
+
|
84
|
+
def build_client_url(render, entity, params)
|
85
|
+
return '#' unless render
|
86
|
+
"#{base_url}/web/#{render}?layout=false&#{build_params(params, entity)}"
|
87
|
+
end
|
88
|
+
|
89
|
+
def build_params(params, entity)
|
90
|
+
params = params.merge(entity_key: entity.id) if entity
|
91
|
+
Rack::Utils.build_nested_query(scrub_params(params))
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require_relative 'parameters'
|
2
|
+
require_relative 'trace'
|
3
|
+
|
4
|
+
module Voom
|
5
|
+
# Simple serializer that will build add a to_hash method to an object by inspecting
|
6
|
+
# the intersection of its instance variables and public accessor methods.
|
7
|
+
module Serializer
|
8
|
+
include Trace
|
9
|
+
|
10
|
+
def to_hash(serializer=true)
|
11
|
+
trace {self.class.to_s}
|
12
|
+
return build_hash unless serializer
|
13
|
+
begin
|
14
|
+
serializer_name = "#{self.class.to_s}Serializer"
|
15
|
+
serializer = Module.const_get(serializer_name)
|
16
|
+
serializer.new(self).to_hash
|
17
|
+
rescue NameError
|
18
|
+
build_hash
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def build_hash
|
24
|
+
accessable = instance_variables.map {|i| i.to_s.gsub('@', '').to_sym} & methods
|
25
|
+
accessable.reduce({}) do |hash, v|
|
26
|
+
trace {"#{v}:#{params.inspect}"}
|
27
|
+
params = Parameters.new(method(v).parameters)
|
28
|
+
unless params.required_args? || params.required_options?
|
29
|
+
value = self.send(v)
|
30
|
+
value = if value.kind_of?(Array)
|
31
|
+
value.map {|v_| v_.respond_to?(:to_hash) ? v_.to_hash : v_}
|
32
|
+
elsif value.kind_of?(Hash)
|
33
|
+
value.map {|k, v_| v_.respond_to?(:to_hash) ? [k, v_.to_hash] : [k, v_]}.to_h
|
34
|
+
else
|
35
|
+
value.respond_to?(:to_hash) ? value.to_hash : value
|
36
|
+
end
|
37
|
+
hash[v]= value
|
38
|
+
end
|
39
|
+
hash
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "dry/inflector"
|
2
|
+
|
3
|
+
module Voom
|
4
|
+
# Helper module for converting symbol naming to string.
|
5
|
+
# It provides common conversions for variable naming (snake_case) and class naming (class_name)
|
6
|
+
module Symbol
|
7
|
+
# Maps symbols to strings
|
8
|
+
def sym_to_str(name)
|
9
|
+
return name if name.is_a? ::String
|
10
|
+
name.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
# Converts a namespaced string or symbol to snake_case
|
14
|
+
def snake_case(str)
|
15
|
+
inflector.underscore(sym_to_str(str).tr('.', '_'))
|
16
|
+
end
|
17
|
+
|
18
|
+
# Converts a namespaced symbol or string to a proper class name with modules
|
19
|
+
def class_name(classname)
|
20
|
+
classname = sym_to_str(classname)
|
21
|
+
classname.split('.').map { |m| inflector.camelize(m) }.join('::')
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def inflector
|
26
|
+
@inflector ||= Dry::Inflector.new
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/voom/trace.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'logger_methods'
|
2
|
+
|
3
|
+
module Voom
|
4
|
+
module Trace
|
5
|
+
include Voom::LoggerMethods
|
6
|
+
|
7
|
+
private
|
8
|
+
# Use a regex on your classes to enable debug logging
|
9
|
+
# For example:
|
10
|
+
# In your .env
|
11
|
+
# export VOOM_TRACE_LOG_REGEX="^.*$"
|
12
|
+
# In your code
|
13
|
+
# trace {"What is it doing?" }
|
14
|
+
def trace(&block)
|
15
|
+
return unless ENV['VOOM_TRACE_LOG_REGEX']
|
16
|
+
logger.info {"T:#{self.class}:#{block.call}"} if /#{ENV['VOOM_TRACE_LOG_REGEX']}/.match(self.class.name)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/presenters.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'voom/presenters/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'voom-presenters'
|
8
|
+
spec.version = Voom::Presenters::VERSION
|
9
|
+
spec.authors = ['Russell Edens']
|
10
|
+
spec.email = ["russell@voomify.com\n"]
|
11
|
+
|
12
|
+
spec.summary = 'Presenters Gem.'
|
13
|
+
spec.homepage = 'http://github.com/rx/presenters'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = 'exe'
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_runtime_dependency 'ice_nine', '~>0.11'
|
24
|
+
spec.add_runtime_dependency 'dry-container', '~>0.6'
|
25
|
+
spec.add_runtime_dependency 'dry-configurable', '~>0.7'
|
26
|
+
spec.add_runtime_dependency 'dry-inflector', '~>0.1'
|
27
|
+
spec.add_runtime_dependency 'sinatra', '~>2.0'
|
28
|
+
spec.add_runtime_dependency 'tzinfo', '~>1.2'
|
29
|
+
spec.add_runtime_dependency 'tzinfo-data', '~>1.2018'
|
30
|
+
spec.add_runtime_dependency 'redcarpet', '~>3.4'
|
31
|
+
|
32
|
+
spec.add_development_dependency 'rack-test', '~>0.8'
|
33
|
+
spec.add_development_dependency 'pry', '~>0.10'
|
34
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
35
|
+
spec.add_development_dependency 'rake', '~> 11.3'
|
36
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
37
|
+
end
|