trestle 0.9.9 → 0.10.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +26 -0
- data/.github/workflows/rspec.yml +37 -5
- data/.gitignore +3 -0
- data/Gemfile +14 -1
- data/README.md +2 -1
- data/app/assets/bundle/trestle/admin.css +23 -0
- data/app/assets/bundle/trestle/admin.js +83 -0
- data/app/assets/bundle/trestle/fa-brands-400.ttf +0 -0
- data/app/assets/bundle/trestle/fa-brands-400.woff2 +0 -0
- data/app/assets/bundle/trestle/fa-regular-400.ttf +0 -0
- data/app/assets/bundle/trestle/fa-regular-400.woff2 +0 -0
- data/app/assets/bundle/trestle/fa-solid-900.ttf +0 -0
- data/app/assets/bundle/trestle/fa-solid-900.woff2 +0 -0
- data/app/assets/bundle/trestle/locale/cs.js +110 -0
- data/app/assets/bundle/trestle/locale/de.js +116 -0
- data/app/assets/bundle/trestle/locale/en.js +329 -0
- data/app/assets/bundle/trestle/locale/es-MX.js +109 -0
- data/app/assets/bundle/trestle/locale/es.js +109 -0
- data/app/assets/bundle/trestle/locale/fr.js +111 -0
- data/app/assets/bundle/trestle/locale/ko.js +111 -0
- data/app/assets/bundle/trestle/locale/lv.js +109 -0
- data/app/assets/bundle/trestle/locale/nl.js +96 -0
- data/app/assets/bundle/trestle/locale/pl.js +99 -0
- data/app/assets/bundle/trestle/locale/pt-BR.js +98 -0
- data/app/assets/bundle/trestle/locale/vi.js +116 -0
- data/app/assets/bundle/trestle/locale/zh-CN.js +109 -0
- data/app/assets/bundle/trestle/photoswipe-7aa1aec9c3c1fd65c382.digested.js +6 -0
- data/app/assets/sprockets/trestle/custom.css +1 -0
- data/app/assets/sprockets/trestle/icons/font-awesome.css.erb +32 -0
- data/app/assets/sprockets/trestle/manifest.js +4 -0
- data/app/assets/stylesheets/trestle/custom.css +6 -1
- data/app/controllers/concerns/trestle/controller/helpers.rb +2 -0
- data/app/controllers/concerns/trestle/controller/location.rb +1 -6
- data/app/controllers/concerns/trestle/controller/modal.rb +23 -0
- data/app/controllers/concerns/trestle/controller/turbo_stream.rb +12 -0
- data/app/controllers/concerns/trestle/resource/controller/actions.rb +39 -28
- data/app/controllers/concerns/trestle/resource/controller/redirection.rb +5 -5
- data/app/controllers/trestle/application_controller.rb +2 -1
- data/app/helpers/trestle/flash_helper.rb +10 -0
- data/app/helpers/trestle/form_helper.rb +3 -2
- data/app/helpers/trestle/format_helper.rb +2 -1
- data/app/helpers/trestle/i18n_helper.rb +46 -7
- data/app/helpers/trestle/modal_helper.rb +29 -0
- data/app/helpers/trestle/tab_helper.rb +1 -1
- data/app/helpers/trestle/turbo/frame_helper.rb +29 -0
- data/app/helpers/trestle/turbo/stream_helper.rb +9 -0
- data/app/helpers/trestle/turbo/tag_builder.rb +21 -0
- data/app/helpers/trestle/url_helper.rb +7 -4
- data/app/views/layouts/trestle/admin.html.erb +16 -18
- data/app/views/layouts/trestle/admin.turbo_stream.erb +4 -0
- data/app/views/layouts/trestle/modal.html.erb +5 -0
- data/app/views/trestle/_i18n.html.erb +12 -0
- data/app/views/trestle/_theme.html.erb +15 -0
- data/app/views/trestle/application/_header.html.erb +12 -10
- data/app/views/trestle/application/_layout.html.erb +6 -3
- data/app/views/trestle/application/_modal.html.erb +36 -0
- data/app/views/trestle/application/_tabs.html.erb +4 -4
- data/app/views/trestle/flash/_alert.html.erb +1 -1
- data/app/views/trestle/flash/_debug.html.erb +1 -1
- data/app/views/trestle/resource/_form.html.erb +5 -0
- data/app/views/trestle/resource/create.turbo_stream.erb +1 -0
- data/app/views/trestle/resource/destroy.turbo_stream.erb +1 -0
- data/app/views/trestle/resource/edit.html.erb +6 -2
- data/app/views/trestle/resource/index.html.erb +17 -10
- data/app/views/trestle/resource/new.html.erb +9 -2
- data/app/views/trestle/resource/show.html.erb +6 -2
- data/app/views/trestle/resource/update.turbo_stream.erb +1 -0
- data/app/views/trestle/shared/_sidebar.html.erb +10 -10
- data/frontend/css/components/_alerts.scss +41 -37
- data/frontend/css/components/_avatar.scss +12 -12
- data/frontend/css/components/_background.scss +8 -36
- data/frontend/css/components/_badges.scss +31 -0
- data/frontend/css/components/_breadcrumbs.scss +9 -30
- data/frontend/css/components/_buttons.scss +8 -7
- data/frontend/css/components/_datepicker.scss +15 -11
- data/frontend/css/components/_dropdown.scss +21 -9
- data/frontend/css/components/{_fields.scss → _forms.scss} +18 -5
- data/frontend/css/components/_grid.scss +29 -0
- data/frontend/css/components/_media-grid.scss +52 -44
- data/frontend/css/components/_modal.scss +37 -8
- data/frontend/css/components/_pagination.scss +5 -9
- data/frontend/css/components/_photoswipe.scss +8 -0
- data/frontend/css/components/_popover.scss +2 -1
- data/frontend/css/components/_scopes.scss +5 -11
- data/frontend/css/components/_select.scss +160 -31
- data/frontend/css/components/_sort.scss +1 -1
- data/frontend/css/components/_table.scss +61 -66
- data/frontend/css/components/_tabs.scss +20 -20
- data/frontend/css/components/_tags.scss +80 -15
- data/frontend/css/components/_toolbars.scss +18 -13
- data/frontend/css/components/_turbo.scss +3 -0
- data/frontend/css/core/_bootstrap.scss +46 -0
- data/frontend/css/core/_dependencies.scss +4 -3
- data/frontend/css/core/_functions.scss +31 -0
- data/frontend/css/core/_mixins.scss +2 -36
- data/frontend/css/core/_theme.scss +261 -0
- data/frontend/css/core/_typography.scss +16 -14
- data/frontend/css/icons/_fontawesome.scss +3 -15
- data/frontend/css/index.scss +15 -7
- data/frontend/css/layout/_base.scss +6 -4
- data/frontend/css/layout/_content-header.scss +71 -0
- data/frontend/css/layout/_footer.scss +5 -7
- data/frontend/css/layout/_header.scss +5 -3
- data/frontend/css/layout/_main-content.scss +107 -0
- data/frontend/css/layout/_navigation.scss +112 -50
- data/frontend/css/layout/_sidebar.scss +70 -36
- data/frontend/css/support/_sprockets.scss +2 -0
- data/frontend/css/support/_webpack.scss +2 -0
- data/frontend/css/variables/_bootstrap.scss +158 -55
- data/frontend/css/variables/_maps.scss +15 -0
- data/frontend/css/variables/_trestle.scss +68 -39
- data/frontend/js/controllers/application_controller.js +17 -0
- data/frontend/js/controllers/batch_action_controller.js +59 -0
- data/frontend/js/controllers/checkbox_select_controller.js +46 -0
- data/frontend/js/controllers/confirm_controller.js +115 -0
- data/frontend/js/controllers/confirm_delete_controller.js +11 -0
- data/frontend/js/controllers/datepicker_controller.js +12 -0
- data/frontend/js/controllers/datetimepicker_controller.js +13 -0
- data/frontend/js/controllers/deprecated/init_controller.js +9 -0
- data/frontend/js/controllers/flatpickr_controller.js +50 -0
- data/frontend/js/controllers/follow_url_controller.js +36 -0
- data/frontend/js/controllers/form_error_controller.js +24 -0
- data/frontend/js/controllers/form_loading_controller.js +50 -0
- data/frontend/js/controllers/gallery_controller.js +10 -0
- data/frontend/js/controllers/index.js +19 -0
- data/frontend/js/controllers/keyboard_submit_controller.js +25 -0
- data/frontend/js/controllers/lightbox_controller.js +160 -0
- data/frontend/js/controllers/mobile_sidebar_controller.js +30 -0
- data/frontend/js/controllers/modal_controller.js +36 -0
- data/frontend/js/controllers/modal_frame_controller.js +11 -0
- data/frontend/js/controllers/modal_trigger_controller.js +74 -0
- data/frontend/js/{components/navigation.js → controllers/navigation_controller.js} +14 -10
- data/frontend/js/controllers/navigation_tooltip_controller.js +32 -0
- data/frontend/js/controllers/popover_controller.js +87 -0
- data/frontend/js/controllers/reloadable_controller.js +34 -0
- data/frontend/js/controllers/select_controller.js +49 -0
- data/frontend/js/controllers/sidebar_controller.js +33 -0
- data/frontend/js/controllers/tab_errors_controller.js +45 -0
- data/frontend/js/controllers/tabs_controller.js +45 -0
- data/frontend/js/controllers/timepicker_controller.js +14 -0
- data/frontend/js/controllers/toggle_attr_controller.js +27 -0
- data/frontend/js/controllers/toggle_class_controller.js +27 -0
- data/frontend/js/controllers/tooltip_controller.js +13 -0
- data/frontend/js/controllers/wrapper_controller.js +43 -0
- data/frontend/js/core/backdrop.js +100 -0
- data/frontend/js/core/error_modal.js +65 -0
- data/frontend/js/core/fetch.js +32 -0
- data/frontend/js/core/i18n.js +24 -10
- data/frontend/js/core/modal.js +52 -0
- data/frontend/js/core/stream_actions.js +56 -0
- data/frontend/js/core/turbo_errors.js +9 -0
- data/frontend/js/{core → deprecated}/events.js +1 -8
- data/frontend/js/deprecated/tooltip.js +8 -0
- data/frontend/js/index.js +28 -40
- data/frontend/js/mixins/index.js +5 -0
- data/frontend/js/mixins/photoswipe.js +10 -0
- data/frontend/js/util/bootstrap.js +93 -0
- data/i18n/config.yml +14 -0
- data/i18n/environment.rb +8 -0
- data/i18n/export +3 -0
- data/i18n/template.erb +1 -0
- data/lib/generators/trestle/install/install_generator.rb +3 -8
- data/lib/generators/trestle/install/templates/trestle.rb.erb +5 -5
- data/lib/trestle/color.rb +113 -0
- data/lib/trestle/configuration.rb +16 -8
- data/lib/trestle/engine.rb +28 -20
- data/lib/trestle/form/fields/check_box_helpers.rb +7 -18
- data/lib/trestle/form/fields/collection_select.rb +1 -1
- data/lib/trestle/form/fields/color_field.rb +4 -0
- data/lib/trestle/form/fields/date_field.rb +4 -0
- data/lib/trestle/form/fields/date_picker.rb +10 -4
- data/lib/trestle/form/fields/date_select.rb +1 -1
- data/lib/trestle/form/fields/datetime_field.rb +4 -0
- data/lib/trestle/form/fields/datetime_select.rb +1 -1
- data/lib/trestle/form/fields/file_field.rb +3 -28
- data/lib/trestle/form/fields/form_control.rb +2 -2
- data/lib/trestle/form/fields/form_group.rb +1 -1
- data/lib/trestle/form/fields/grouped_collection_select.rb +1 -1
- data/lib/trestle/form/fields/radio_button_helpers.rb +5 -17
- data/lib/trestle/form/fields/range_field.rb +1 -5
- data/lib/trestle/form/fields/select.rb +17 -1
- data/lib/trestle/form/fields/time_field.rb +4 -0
- data/lib/trestle/form/fields/time_select.rb +1 -1
- data/lib/trestle/form/fields/time_zone_select.rb +1 -1
- data/lib/trestle/form/renderer.rb +3 -0
- data/lib/trestle/form.rb +16 -1
- data/lib/trestle/resource/toolbar.rb +18 -8
- data/lib/trestle/sprockets_compressor.rb +16 -0
- data/lib/trestle/table/actions_column.rb +2 -2
- data/lib/trestle/table/row.rb +2 -1
- data/lib/trestle/table/select_column.rb +3 -6
- data/lib/trestle/table.rb +6 -1
- data/lib/trestle/toolbar/context.rb +7 -4
- data/lib/trestle/toolbar/item.rb +1 -1
- data/lib/trestle/toolbar/menu.rb +11 -11
- data/lib/trestle/version.rb +1 -1
- data/lib/trestle.rb +2 -23
- data/package.json +31 -27
- data/trestle.gemspec +6 -11
- data/webpack.config.js +10 -10
- data/yarn.lock +1480 -1233
- metadata +175 -208
- data/app/assets/bundle/trestle/bundle.css +0 -12
- data/app/assets/bundle/trestle/bundle.js +0 -89
- data/app/assets/bundle/trestle/fa-brands-400.eot +0 -0
- data/app/assets/bundle/trestle/fa-brands-400.svg +0 -3717
- data/app/assets/bundle/trestle/fa-brands-400.woff +0 -0
- data/app/assets/bundle/trestle/fa-regular-400.eot +0 -0
- data/app/assets/bundle/trestle/fa-regular-400.svg +0 -801
- data/app/assets/bundle/trestle/fa-regular-400.woff +0 -0
- data/app/assets/bundle/trestle/fa-solid-900.eot +0 -0
- data/app/assets/bundle/trestle/fa-solid-900.svg +0 -5034
- data/app/assets/bundle/trestle/fa-solid-900.woff +0 -0
- data/app/assets/javascripts/trestle/admin.js +0 -3
- data/app/assets/javascripts/trestle/i18n.js.erb +0 -8
- data/app/assets/stylesheets/trestle/admin.css +0 -2
- data/app/assets/stylesheets/trestle/icons/_font-awesome.css.erb +0 -40
- data/app/controllers/concerns/trestle/controller/dialog.rb +0 -16
- data/app/views/trestle/application/_dialog.html.erb +0 -34
- data/frontend/css/components/_color-vars.scss +0 -10
- data/frontend/css/components/_custom-forms.scss +0 -35
- data/frontend/css/components/_magnific-popup.scss +0 -36
- data/frontend/css/components/_turbolinks.scss +0 -3
- data/frontend/css/layout/_content.scss +0 -169
- data/frontend/js/components/confirmation.js +0 -32
- data/frontend/js/components/datepicker.js +0 -69
- data/frontend/js/components/dialog.js +0 -149
- data/frontend/js/components/file.js +0 -7
- data/frontend/js/components/form.js +0 -100
- data/frontend/js/components/gallery.js +0 -33
- data/frontend/js/components/pagination.js +0 -51
- data/frontend/js/components/select.js +0 -18
- data/frontend/js/components/sidebar.js +0 -75
- data/frontend/js/components/table.js +0 -61
- data/frontend/js/components/tabs.js +0 -59
- data/frontend/js/components/tooltips.js +0 -25
- data/frontend/js/core/contexts.js +0 -17
- data/frontend/js/core/turbolinks.js +0 -3
- data/frontend/js/core/visit.js +0 -16
- data/frontend/theme/trestle/_theme.scss +0 -4
- data/frontend/theme/trestle/_variables.scss +0 -4
- data/frontend/theme/trestle/theme/_defaults.scss +0 -152
- data/frontend/theme/trestle/theme/_functions.scss +0 -44
- data/frontend/theme/trestle/theme/_variables.scss +0 -15
- data/frontend/theme/trestle/theme/bootstrap/_alert.scss +0 -19
- data/frontend/theme/trestle/theme/bootstrap/_badge.scss +0 -25
- data/frontend/theme/trestle/theme/bootstrap/_buttons.scss +0 -93
- data/frontend/theme/trestle/theme/bootstrap/_color-vars.scss +0 -11
- data/frontend/theme/trestle/theme/bootstrap/_custom-forms.scss +0 -93
- data/frontend/theme/trestle/theme/bootstrap/_dropdown.scss +0 -6
- data/frontend/theme/trestle/theme/bootstrap/_forms.scss +0 -6
- data/frontend/theme/trestle/theme/bootstrap/_links.scss +0 -7
- data/frontend/theme/trestle/theme/bootstrap/_list-group.scss +0 -31
- data/frontend/theme/trestle/theme/bootstrap/_nav.scss +0 -6
- data/frontend/theme/trestle/theme/bootstrap/_pagination.scss +0 -18
- data/frontend/theme/trestle/theme/bootstrap/_progress.scss +0 -3
- data/frontend/theme/trestle/theme/bootstrap/_tables.scss +0 -41
- data/frontend/theme/trestle/theme/bootstrap/_utilities.scss +0 -3
- data/frontend/theme/trestle/theme/bootstrap/utilities/_background.scss +0 -17
- data/frontend/theme/trestle/theme/bootstrap/utilities/_borders.scss +0 -5
- data/frontend/theme/trestle/theme/bootstrap/utilities/_text.scss +0 -18
- data/frontend/theme/trestle/theme/trestle/_background.scss +0 -61
- data/frontend/theme/trestle/theme/trestle/_datepicker.scss +0 -58
- data/frontend/theme/trestle/theme/trestle/_headers.scss +0 -4
- data/frontend/theme/trestle/theme/trestle/_navbar.scss +0 -15
- data/frontend/theme/trestle/theme/trestle/_navigation.scss +0 -5
- data/frontend/theme/trestle/theme/trestle/_select2.scss +0 -22
- data/frontend/theme/trestle/theme/trestle/_tags.scss +0 -12
- data/frontend/theme/trestle/theme/trestle/_turbolinks.scss +0 -3
- data/frontend/theme/trestle/theme.scss +0 -29
- data/lib/generators/trestle/install/templates/_theme.scss +0 -13
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/ar-dz.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/ar.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/at.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/az.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/be.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/bg.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/bn.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/bs.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/cat.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/ckb.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/cs.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/cy.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/da.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/de.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/default.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/eo.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/es.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/et.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/fa.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/fi.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/fo.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/fr.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/ga.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/gr.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/he.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/hi.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/hr.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/hu.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/hy.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/id.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/is.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/it.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/ja.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/ka.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/km.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/ko.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/kz.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/lt.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/lv.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/mk.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/mn.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/ms.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/my.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/nl.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/nn.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/no.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/pa.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/pl.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/pt.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/ro.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/ru.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/si.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/sk.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/sl.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/sq.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/sr-cyr.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/sr.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/sv.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/th.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/tr.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/uk.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/uz.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/uz_latn.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/vn.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/zh-tw.js +0 -0
- /data/app/assets/bundle/trestle/{flatpickr → locale/flatpickr}/zh.js +0 -0
- /data/app/assets/{stylesheets → sprockets}/trestle/_custom.css +0 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
/* global DOMParser */
|
2
|
+
|
3
|
+
import { i18n } from '../core/i18n'
|
4
|
+
|
5
|
+
const TEMPLATE = () => `
|
6
|
+
<div class="modal fade error-modal" tabindex="-1" data-controller="modal">
|
7
|
+
<div class="modal-dialog modal-xl">
|
8
|
+
<div class="modal-content">
|
9
|
+
<div class="modal-header">
|
10
|
+
<h4 class="modal-title"></h4>
|
11
|
+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div class="modal-body">
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<div class="modal-footer">
|
18
|
+
<button type="button" class="btn btn-light" data-bs-dismiss="modal" aria-label="OK">${i18n.t('admin.buttons.ok', { defaultValue: 'OK' })}</button>
|
19
|
+
</div
|
20
|
+
</div>
|
21
|
+
</div>
|
22
|
+
</div>
|
23
|
+
`
|
24
|
+
|
25
|
+
export default class ErrorModal {
|
26
|
+
static show ({ title, content }) {
|
27
|
+
new ErrorModal({ title, content }).show()
|
28
|
+
}
|
29
|
+
|
30
|
+
constructor ({ title, content }) {
|
31
|
+
this.title = title
|
32
|
+
this.content = content
|
33
|
+
}
|
34
|
+
|
35
|
+
show () {
|
36
|
+
this._append(this._buildModal())
|
37
|
+
}
|
38
|
+
|
39
|
+
// Private
|
40
|
+
|
41
|
+
_buildModal () {
|
42
|
+
const el = this._buildWrapper()
|
43
|
+
el.querySelector('.modal-title').textContent = this.title
|
44
|
+
|
45
|
+
const iframe = this._buildIframe(this.content)
|
46
|
+
el.querySelector('.modal-body').append(iframe)
|
47
|
+
|
48
|
+
return el
|
49
|
+
}
|
50
|
+
|
51
|
+
_buildWrapper () {
|
52
|
+
return new DOMParser().parseFromString(TEMPLATE(), 'text/html').body.childNodes[0]
|
53
|
+
}
|
54
|
+
|
55
|
+
_buildIframe () {
|
56
|
+
const iframe = document.createElement('iframe')
|
57
|
+
iframe.className = 'error-iframe'
|
58
|
+
iframe.srcdoc = this.content
|
59
|
+
return iframe
|
60
|
+
}
|
61
|
+
|
62
|
+
_append (el) {
|
63
|
+
document.getElementById('modal').append(el)
|
64
|
+
}
|
65
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/* global fetch */
|
2
|
+
|
3
|
+
import { renderStreamMessage } from '@hotwired/turbo'
|
4
|
+
|
5
|
+
import ErrorModal from './error_modal'
|
6
|
+
|
7
|
+
export function fetchWithErrorHandling (url, options = {}) {
|
8
|
+
return fetch(url, options)
|
9
|
+
.then(response => {
|
10
|
+
if (!response.ok) { throw response }
|
11
|
+
return response
|
12
|
+
})
|
13
|
+
.catch(response => {
|
14
|
+
const title = `${response.status} (${response.statusText})`
|
15
|
+
response.text().then(content => ErrorModal.show({ title, content }))
|
16
|
+
})
|
17
|
+
}
|
18
|
+
|
19
|
+
export function fetchTurboStream (url, options = {}) {
|
20
|
+
options = {
|
21
|
+
...options,
|
22
|
+
|
23
|
+
headers: {
|
24
|
+
Accept: 'text/vnd.turbo-stream.html',
|
25
|
+
...options.headers
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
return fetchWithErrorHandling(url, options)
|
30
|
+
.then(response => response.text())
|
31
|
+
.then(html => renderStreamMessage(html))
|
32
|
+
}
|
data/frontend/js/core/i18n.js
CHANGED
@@ -1,20 +1,24 @@
|
|
1
|
+
import { I18n } from 'i18n-js'
|
1
2
|
import flatpickr from 'flatpickr'
|
2
3
|
|
3
4
|
// Container for i18n translations
|
4
|
-
export const i18n =
|
5
|
+
export const i18n = new I18n()
|
6
|
+
|
7
|
+
function localizeTrestle (locale, fallbacks) {
|
8
|
+
// Set up i18n fallbacks
|
9
|
+
i18n.enableFallback = true
|
10
|
+
i18n.locales.register(locale, [locale, ...fallbacks])
|
11
|
+
|
12
|
+
// Set current locale
|
13
|
+
i18n.locale = locale
|
14
|
+
}
|
5
15
|
|
6
16
|
// Some of Flatpickr's locale names differ from Rails. This maps the Rails I18n locale to their Flatpickr equivalent.
|
7
17
|
const FlatpickrLocaleConversions = { ca: 'cat', el: 'gr', nb: 'no', vi: 'vn' }
|
8
18
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
// Trestle.localize('es-MX', 'es', 'en')
|
13
|
-
//
|
14
|
-
export function localize () {
|
15
|
-
for (var i = 0; i < arguments.length; ++i) {
|
16
|
-
var locale = arguments[i]
|
17
|
-
var flatpickrLocale = FlatpickrLocaleConversions[locale] || locale
|
19
|
+
function localizeFlatpickr (...locales) {
|
20
|
+
for (const locale of locales) {
|
21
|
+
const flatpickrLocale = FlatpickrLocaleConversions[locale] || locale
|
18
22
|
|
19
23
|
if (flatpickr.l10ns[flatpickrLocale]) {
|
20
24
|
flatpickr.localize(flatpickr.l10ns[flatpickrLocale])
|
@@ -22,3 +26,13 @@ export function localize () {
|
|
22
26
|
}
|
23
27
|
}
|
24
28
|
}
|
29
|
+
|
30
|
+
// Sets up localization for Trestle and its dependencies, in particular Flatpickr.
|
31
|
+
// This method accepts a list of locales in descending order of priority.
|
32
|
+
//
|
33
|
+
// Trestle.localize('es-MX', 'es', 'en')
|
34
|
+
//
|
35
|
+
export function localize (locale, ...fallbacks) {
|
36
|
+
localizeTrestle(locale, fallbacks)
|
37
|
+
localizeFlatpickr(locale, ...fallbacks)
|
38
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import { Modal as BootstrapModal } from 'bootstrap'
|
2
|
+
|
3
|
+
import Backdrop from './backdrop'
|
4
|
+
import { fetchTurboStream } from './fetch'
|
5
|
+
|
6
|
+
export default class Modal extends BootstrapModal {
|
7
|
+
static load (url, fetchParams) {
|
8
|
+
const backdrop = Backdrop.getInstance()
|
9
|
+
backdrop.loading(true)
|
10
|
+
backdrop.show()
|
11
|
+
|
12
|
+
Modal.existing.forEach((modal) => modal.classList.add('background'))
|
13
|
+
|
14
|
+
return new Promise((resolve) => {
|
15
|
+
document.addEventListener('modal:render', (e) => {
|
16
|
+
resolve(e.detail)
|
17
|
+
}, { capture: true, once: true })
|
18
|
+
|
19
|
+
fetchTurboStream(url, {
|
20
|
+
...fetchParams,
|
21
|
+
|
22
|
+
headers: {
|
23
|
+
'X-Trestle-Modal': true
|
24
|
+
}
|
25
|
+
})
|
26
|
+
})
|
27
|
+
}
|
28
|
+
|
29
|
+
static get existing () {
|
30
|
+
return document.querySelectorAll('.modal.show')
|
31
|
+
}
|
32
|
+
|
33
|
+
static restorePrevious () {
|
34
|
+
const previousModal = document.querySelector('.modal.show:last-child')
|
35
|
+
|
36
|
+
if (previousModal) {
|
37
|
+
previousModal.classList.remove('background')
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
constructor (element) {
|
42
|
+
super(element)
|
43
|
+
|
44
|
+
element.addEventListener('show.bs.modal', () => {
|
45
|
+
this._backdrop.loading(false)
|
46
|
+
})
|
47
|
+
}
|
48
|
+
|
49
|
+
_initializeBackDrop () {
|
50
|
+
return Backdrop.getInstance()
|
51
|
+
}
|
52
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
/* global CustomEvent */
|
2
|
+
|
3
|
+
import { StreamActions, visit } from '@hotwired/turbo'
|
4
|
+
|
5
|
+
import { Modal } from 'bootstrap'
|
6
|
+
|
7
|
+
const buildModalEvent = (modal) => {
|
8
|
+
return new CustomEvent('modal:render', { detail: modal })
|
9
|
+
}
|
10
|
+
|
11
|
+
StreamActions.modal = function () {
|
12
|
+
const target = document.getElementById('modal')
|
13
|
+
const modal = this.templateContent.querySelector('*')
|
14
|
+
|
15
|
+
target.appendChild(modal)
|
16
|
+
target.dispatchEvent(buildModalEvent(modal))
|
17
|
+
}
|
18
|
+
|
19
|
+
StreamActions.closeModal = function () {
|
20
|
+
this.targetElements.forEach((e) => {
|
21
|
+
const modalEl = e.closest('.modal')
|
22
|
+
const modal = Modal.getInstance(modalEl)
|
23
|
+
if (modal) { modal.hide() }
|
24
|
+
})
|
25
|
+
}
|
26
|
+
|
27
|
+
StreamActions.flash = function () {
|
28
|
+
const flashTarget = document.querySelector('.modal.show .modal-flash') || document.querySelector('#flash')
|
29
|
+
|
30
|
+
flashTarget.innerHTML = ""
|
31
|
+
flashTarget.append(this.templateContent)
|
32
|
+
}
|
33
|
+
|
34
|
+
StreamActions.reload = function () {
|
35
|
+
let reloadables
|
36
|
+
|
37
|
+
if (this.target || this.targets) {
|
38
|
+
reloadables = this.targetElements
|
39
|
+
} else {
|
40
|
+
reloadables = document.querySelectorAll('[data-controller="reloadable"]')
|
41
|
+
}
|
42
|
+
|
43
|
+
reloadables.forEach((frame) => {
|
44
|
+
const modal = frame.closest('.modal')
|
45
|
+
if (modal && !modal.classList.contains('show')) {
|
46
|
+
return
|
47
|
+
}
|
48
|
+
|
49
|
+
const controller = Stimulus.getControllerForElementAndIdentifier(frame, 'reloadable')
|
50
|
+
if (controller) { controller.reload() }
|
51
|
+
})
|
52
|
+
}
|
53
|
+
|
54
|
+
StreamActions.redirect = function () {
|
55
|
+
visit(this.target)
|
56
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import ErrorModal from './error_modal'
|
2
|
+
|
3
|
+
document.addEventListener('turbo:frame-missing', async (e) => {
|
4
|
+
e.preventDefault()
|
5
|
+
|
6
|
+
const response = e.detail.response
|
7
|
+
const title = `${response.status} (${response.statusText})`
|
8
|
+
response.text().then(content => ErrorModal.show({ title, content }))
|
9
|
+
})
|
@@ -1,7 +1,5 @@
|
|
1
1
|
import $ from 'jquery'
|
2
2
|
|
3
|
-
import turbolinks from './turbolinks'
|
4
|
-
|
5
3
|
// The ready function sets up a callback to run on each page load.
|
6
4
|
//
|
7
5
|
// Trestle.ready(function() {
|
@@ -42,9 +40,4 @@ ready(function () {
|
|
42
40
|
triggerInit(document)
|
43
41
|
})
|
44
42
|
|
45
|
-
|
46
|
-
if (turbolinks) {
|
47
|
-
$(document).on('turbolinks:load', triggerReady)
|
48
|
-
} else {
|
49
|
-
$(document).ready(triggerReady)
|
50
|
-
}
|
43
|
+
document.addEventListener('turbo:load', () => triggerReady())
|
data/frontend/js/index.js
CHANGED
@@ -1,62 +1,50 @@
|
|
1
|
-
// Dependencies
|
2
|
-
|
3
|
-
import 'jquery'
|
4
|
-
import Rails from '@rails/ujs'
|
1
|
+
// Global Dependencies
|
5
2
|
|
3
|
+
import '@hotwired/turbo'
|
6
4
|
import 'bootstrap'
|
7
|
-
import 'bootstrap-confirmation2'
|
8
|
-
|
9
|
-
import 'magnific-popup'
|
10
|
-
|
11
|
-
import 'flatpickr'
|
12
5
|
|
13
|
-
|
6
|
+
// Core Functionality
|
14
7
|
|
15
|
-
|
8
|
+
import './core/stream_actions'
|
9
|
+
import './core/turbo_errors'
|
16
10
|
|
17
|
-
import { refreshContext, refreshMainContext } from './core/contexts'
|
18
11
|
import cookie from './core/cookie'
|
19
|
-
import { init, ready, triggerInit, triggerReady } from './core/events'
|
20
12
|
import { i18n, localize } from './core/i18n'
|
21
|
-
import turbolinks from './core/turbolinks'
|
22
|
-
import visit from './core/visit'
|
23
13
|
|
24
|
-
|
14
|
+
import Modal from './core/modal'
|
15
|
+
import ErrorModal from './core/error_modal'
|
25
16
|
|
26
|
-
|
27
|
-
import './components/datepicker'
|
28
|
-
import Dialog from './components/dialog'
|
29
|
-
import './components/file'
|
30
|
-
import './components/form'
|
31
|
-
import './components/gallery'
|
32
|
-
import './components/pagination'
|
33
|
-
import './components/select'
|
34
|
-
import './components/sidebar'
|
35
|
-
import './components/table'
|
36
|
-
import { focusTab, focusActiveTab } from './components/tabs'
|
37
|
-
import './components/tooltips'
|
17
|
+
// Stimulus Controllers
|
38
18
|
|
39
|
-
|
19
|
+
import { ApplicationController, Controllers } from './controllers'
|
20
|
+
import Mixins from './mixins'
|
40
21
|
|
41
|
-
|
22
|
+
// Deprecated Functionality
|
23
|
+
|
24
|
+
import { init, ready, triggerInit, triggerReady } from './deprecated/events'
|
25
|
+
import './deprecated/tooltip'
|
42
26
|
|
43
27
|
// Export
|
44
28
|
|
45
29
|
const Trestle = {
|
46
|
-
refreshContext,
|
47
|
-
refreshMainContext,
|
48
30
|
cookie,
|
31
|
+
i18n,
|
32
|
+
localize,
|
33
|
+
|
34
|
+
// Stimulus
|
35
|
+
ApplicationController,
|
36
|
+
Controllers,
|
37
|
+
Mixins,
|
38
|
+
|
39
|
+
// Modals
|
40
|
+
Modal,
|
41
|
+
ErrorModal,
|
42
|
+
|
43
|
+
// Deprecated
|
49
44
|
init,
|
50
45
|
ready,
|
51
46
|
triggerInit,
|
52
|
-
triggerReady
|
53
|
-
i18n,
|
54
|
-
localize,
|
55
|
-
turbolinks,
|
56
|
-
visit,
|
57
|
-
Dialog,
|
58
|
-
focusTab,
|
59
|
-
focusActiveTab
|
47
|
+
triggerReady
|
60
48
|
}
|
61
49
|
|
62
50
|
export default Trestle
|
@@ -0,0 +1,93 @@
|
|
1
|
+
/**
|
2
|
+
* --------------------------------------------------------------------------
|
3
|
+
* Bootstrap (v5.1.3): util/index.js
|
4
|
+
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
5
|
+
* --------------------------------------------------------------------------
|
6
|
+
*/
|
7
|
+
|
8
|
+
const MILLISECONDS_MULTIPLIER = 1000
|
9
|
+
const TRANSITION_END = 'transitionend'
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Trick to restart an element's animation
|
13
|
+
*
|
14
|
+
* @param {HTMLElement} element
|
15
|
+
* @return void
|
16
|
+
*
|
17
|
+
* @see https://www.charistheo.io/blog/2021/02/restart-a-css-animation-with-javascript/#restarting-a-css-animation
|
18
|
+
*/
|
19
|
+
const reflow = element => {
|
20
|
+
// eslint-disable-next-line no-unused-expressions
|
21
|
+
element.offsetHeight
|
22
|
+
}
|
23
|
+
|
24
|
+
const execute = callback => {
|
25
|
+
if (typeof callback === 'function') {
|
26
|
+
callback()
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
const getTransitionDurationFromElement = element => {
|
31
|
+
if (!element) {
|
32
|
+
return 0
|
33
|
+
}
|
34
|
+
|
35
|
+
// Get transition-duration of the element
|
36
|
+
let { transitionDuration, transitionDelay } = window.getComputedStyle(element)
|
37
|
+
|
38
|
+
const floatTransitionDuration = Number.parseFloat(transitionDuration)
|
39
|
+
const floatTransitionDelay = Number.parseFloat(transitionDelay)
|
40
|
+
|
41
|
+
// Return 0 if element or transition duration is not found
|
42
|
+
if (!floatTransitionDuration && !floatTransitionDelay) {
|
43
|
+
return 0
|
44
|
+
}
|
45
|
+
|
46
|
+
// If multiple durations are defined, take the first
|
47
|
+
transitionDuration = transitionDuration.split(',')[0]
|
48
|
+
transitionDelay = transitionDelay.split(',')[0]
|
49
|
+
|
50
|
+
return (Number.parseFloat(transitionDuration) + Number.parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER
|
51
|
+
}
|
52
|
+
|
53
|
+
const triggerTransitionEnd = element => {
|
54
|
+
// eslint-disable-next-line no-undef
|
55
|
+
element.dispatchEvent(new Event(TRANSITION_END))
|
56
|
+
}
|
57
|
+
|
58
|
+
const executeAfterTransition = (callback, transitionElement, waitForTransition = true) => {
|
59
|
+
if (!waitForTransition) {
|
60
|
+
execute(callback)
|
61
|
+
return
|
62
|
+
}
|
63
|
+
|
64
|
+
const durationPadding = 5
|
65
|
+
const emulatedDuration = getTransitionDurationFromElement(transitionElement) + durationPadding
|
66
|
+
|
67
|
+
let called = false
|
68
|
+
|
69
|
+
const handler = ({ target }) => {
|
70
|
+
if (target !== transitionElement) {
|
71
|
+
return
|
72
|
+
}
|
73
|
+
|
74
|
+
called = true
|
75
|
+
transitionElement.removeEventListener(TRANSITION_END, handler)
|
76
|
+
execute(callback)
|
77
|
+
}
|
78
|
+
|
79
|
+
transitionElement.addEventListener(TRANSITION_END, handler)
|
80
|
+
setTimeout(() => {
|
81
|
+
if (!called) {
|
82
|
+
triggerTransitionEnd(transitionElement)
|
83
|
+
}
|
84
|
+
}, emulatedDuration)
|
85
|
+
}
|
86
|
+
|
87
|
+
export {
|
88
|
+
getTransitionDurationFromElement,
|
89
|
+
triggerTransitionEnd,
|
90
|
+
reflow,
|
91
|
+
execute,
|
92
|
+
executeAfterTransition
|
93
|
+
}
|
data/i18n/config.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
---
|
2
|
+
translations:
|
3
|
+
- file: i18n/locale/:locale.json
|
4
|
+
patterns:
|
5
|
+
- "*"
|
6
|
+
- "!*.activerecord"
|
7
|
+
- "!*.errors"
|
8
|
+
- "!*.number.nth"
|
9
|
+
|
10
|
+
export_files:
|
11
|
+
enabled: true
|
12
|
+
files:
|
13
|
+
- template: i18n/template.erb
|
14
|
+
output: app/assets/bundle/trestle/locale/%{base_name}.js
|
data/i18n/environment.rb
ADDED
data/i18n/export
ADDED
data/i18n/template.erb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Trestle.i18n.store(<%= JSON.pretty_generate(translations) %>);
|
@@ -10,14 +10,9 @@ module Trestle
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def create_assets
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
else
|
17
|
-
template "_custom.css", "app/assets/stylesheets/trestle/_custom.css"
|
18
|
-
end
|
19
|
-
|
20
|
-
template "custom.js", "app/assets/javascripts/trestle/custom.js"
|
13
|
+
css = (defined?(Sass) || defined?(SassC)) ? "scss" : "css"
|
14
|
+
template "_custom.#{css}", "app/assets/stylesheets/trestle/_custom.#{css}"
|
15
|
+
template "custom.js", "app/assets/javascripts/trestle/custom.js"
|
21
16
|
end
|
22
17
|
|
23
18
|
def create_directory
|
@@ -15,6 +15,11 @@ Trestle.configure do |config|
|
|
15
15
|
#
|
16
16
|
# config.site_logo_small = "logo-small.png"
|
17
17
|
|
18
|
+
# Define primary and secondary theme colors. Color values may be specified
|
19
|
+
# as either 3- or 6-digit hex codes, or rgb/hsl() triplets.
|
20
|
+
#
|
21
|
+
# config.theme = { primary: "#338ab7", secondary: "#719dc3" }
|
22
|
+
|
18
23
|
# Specify a favicon to be used within the admin.
|
19
24
|
#
|
20
25
|
# config.favicon = "favicon.ico"
|
@@ -94,11 +99,6 @@ Trestle.configure do |config|
|
|
94
99
|
# stylesheet_link_tag "custom"
|
95
100
|
# end
|
96
101
|
|
97
|
-
# Toggle whether Turbolinks is enabled within the admin.
|
98
|
-
# Defaults to true if Turbolinks is available.
|
99
|
-
#
|
100
|
-
# config.turbolinks = false
|
101
|
-
|
102
102
|
# Specify the parameters that should persist across requests when
|
103
103
|
# paginating or reordering. Defaults to [:sort, :order, :scope].
|
104
104
|
#
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module Trestle
|
2
|
+
class Color
|
3
|
+
attr_reader :r, :g, :b
|
4
|
+
|
5
|
+
def initialize(r, g, b)
|
6
|
+
@r, @g, @b = r, g, b
|
7
|
+
end
|
8
|
+
|
9
|
+
def hex
|
10
|
+
"##{[r, g, b].map { |i| i < 16 ? "0#{i.to_s(16)}" : i.to_s(16) }.join}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def rgb
|
14
|
+
[r, g, b]
|
15
|
+
end
|
16
|
+
|
17
|
+
def hsl
|
18
|
+
r = @r / 255.0
|
19
|
+
g = @g / 255.0
|
20
|
+
b = @b / 255.0
|
21
|
+
|
22
|
+
min = [r, g, b].min
|
23
|
+
max = [r, g, b].max
|
24
|
+
|
25
|
+
h = s = l = (max + min) / 2.0
|
26
|
+
|
27
|
+
if max == min
|
28
|
+
h = 0
|
29
|
+
s = 0
|
30
|
+
else
|
31
|
+
d = max - min
|
32
|
+
s = l >= 0.5 ? d / (2 - max - min) : d / (max + min)
|
33
|
+
|
34
|
+
case max
|
35
|
+
when r
|
36
|
+
h = (g - b) / d + (g < b ? 6 : 0)
|
37
|
+
when g
|
38
|
+
h = (b - r) / d + 2
|
39
|
+
when b
|
40
|
+
h = (r - g) / d + 4
|
41
|
+
end
|
42
|
+
|
43
|
+
h /= 6.0
|
44
|
+
end
|
45
|
+
|
46
|
+
[(h*360).round, (s*100).round, (l*100).round]
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.parse(str)
|
50
|
+
if str.starts_with?("#") && str.length.in?([4, 7])
|
51
|
+
parse_hex(str)
|
52
|
+
elsif str.starts_with?("rgb")
|
53
|
+
parse_rgb(str)
|
54
|
+
elsif str.starts_with?("hsl")
|
55
|
+
parse_hsl(str)
|
56
|
+
else
|
57
|
+
raise ArgumentError, "Could not parse color code: #{str}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.parse_hex(str)
|
62
|
+
str = str.sub(/^#/, "")
|
63
|
+
|
64
|
+
if str.length == 3
|
65
|
+
str = str[0] * 2 + str[1] * 2 + str[2] * 2
|
66
|
+
end
|
67
|
+
|
68
|
+
new(str[0, 2].hex, str[2, 2].hex, str[4, 2].hex)
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.parse_rgb(str)
|
72
|
+
match = str.match(/^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/)
|
73
|
+
new(match[1].to_i, match[2].to_i, match[3].to_i)
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.parse_hsl(str)
|
77
|
+
match = str.match(/^hsl\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/)
|
78
|
+
h, s, l = match[1].to_f, match[2].to_f, match[3].to_f
|
79
|
+
|
80
|
+
h /= 360
|
81
|
+
s /= 100
|
82
|
+
l /= 100
|
83
|
+
|
84
|
+
if s == 0
|
85
|
+
r = g = b = l.to_f
|
86
|
+
else
|
87
|
+
q = l < 0.5 ? l * (1 + s) : l + s - l * s
|
88
|
+
p = 2 * l - q
|
89
|
+
|
90
|
+
r = hue_to_rgb(p, q, h + 1/3.0)
|
91
|
+
g = hue_to_rgb(p, q, h)
|
92
|
+
b = hue_to_rgb(p, q, h - 1/3.0)
|
93
|
+
end
|
94
|
+
|
95
|
+
new((r * 255).round, (g * 255).round, (b * 255).round)
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.hue_to_rgb(p, q, t)
|
99
|
+
t += 1 if t < 0
|
100
|
+
t -= 1 if t > 1
|
101
|
+
|
102
|
+
if t < 1 / 6.0
|
103
|
+
p + (q - p) * 6 * t
|
104
|
+
elsif t < 1 / 2.0
|
105
|
+
q
|
106
|
+
elsif t < 2 / 3.0
|
107
|
+
p + (q - p) * (2 / 3.0 - t) * 6
|
108
|
+
else
|
109
|
+
p
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|