Module: Maglev::ApplicationHelper
- Defined in:
- app/helpers/maglev/application_helper.rb
Instance Method Summary collapse
-
#maglev_button_classes ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#maglev_button_label(label, options = {}) ⇒ Object
UI helpers.
- #maglev_client_javascript_tags ⇒ Object
- #maglev_delayed_stream_tag ⇒ Object
- #maglev_editor_javascript_tags ⇒ Object
- #maglev_editor_logo_url ⇒ Object
-
#maglev_editor_title ⇒ Object
Editor helpers.
- #maglev_favicon_url ⇒ Object
- #maglev_flash_message ⇒ Object
-
#maglev_icon_button_classes ⇒ Object
rubocop:enable Metrics/MethodLength.
- #maglev_importmap_tags(namespace, entry_point) ⇒ Object
- #maglev_live_preview_client_javascript_tag ⇒ Object
- #maglev_page_icon(page, size: '1.15rem', wrapper_class_names: nil) ⇒ Object
- #maglev_page_preview_reload_data ⇒ Object
- #maglev_primary_hex_color ⇒ Object
- #maglev_primary_rgb_color ⇒ Object
-
#turbo_stream ⇒ Object
“system” helpers.
Instance Method Details
#maglev_button_classes ⇒ Object
rubocop:disable Metrics/MethodLength
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/helpers/maglev/application_helper.rb', line 105 def (...) ClassVariants.build( base: %( rounded-sm transition-colors transition-background duration-200 text-center cursor-pointer group-[.is-success]/form:bg-green-500 group-[.is-success]/form:hover:bg-green-500/90 group-[.is-success]/form:disabled:bg-green-500/75 group-[.is-error]/form:bg-red-500 group-[.is-error]/form:hover:bg-red-500/90 group-[.is-error]/form:disabled:bg-red-500/75 ), variants: { color: { primary: 'text-white bg-editor-primary hover:bg-editor-primary/90 disabled:bg-editor-primary/75', secondary: 'text-gray-800 hover:bg-gray-100' }, size: { big: 'flex items-center justify-center w-full px-6 h-14', medium: 'inline-flex items-center justify-center px-4 h-10' } }, defaults: { color: :primary, size: :medium } ).render(...) end |
#maglev_button_label(label, options = {}) ⇒ Object
UI helpers
95 96 97 98 99 100 101 102 |
# File 'app/helpers/maglev/application_helper.rb', line 95 def (label, = {}) = ( || {}).with_indifferent_access render 'maglev/editor/shared/button_label', label: label, pending_label: [:pending] || label, success_label: [:success] || label, error_label: [:error] || label end |
#maglev_client_javascript_tags ⇒ Object
16 17 18 19 20 |
# File 'app/helpers/maglev/application_helper.rb', line 16 def return '' unless maglev_rendering_mode == :editor (:client, 'maglev-client') end |
#maglev_delayed_stream_tag ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'app/helpers/maglev/application_helper.rb', line 30 def maglev_delayed_stream_tag # since we set the turbo request id before the build of the fetch request, Turbo will set # the X-TURBO-REQUEST-ID header to a comma-separated list of request ids # we only want to use the first request id (ours), so we split the header value and take the first part safe_join [ tag.(name: 'turbo-request-id', content: ::Turbo.current_request_id.split(',').first), tag.(name: 'turbo-delayed-stream', content: 'true') ], "\n" end |
#maglev_editor_javascript_tags ⇒ Object
12 13 14 |
# File 'app/helpers/maglev/application_helper.rb', line 12 def (:editor, 'editor') end |
#maglev_editor_logo_url ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'app/helpers/maglev/application_helper.rb', line 52 def maglev_editor_logo_url case maglev_config.logo when nil asset_path('maglev/logo.svg') when String asset_path(maglev_config.logo) when Proc instance_exec(maglev_site, &maglev_config.logo) end end |
#maglev_editor_title ⇒ Object
Editor helpers
41 42 43 44 45 46 47 48 49 50 |
# File 'app/helpers/maglev/application_helper.rb', line 41 def maglev_editor_title case maglev_config.title when nil 'Maglev - EDITOR' when String maglev_config.title when Proc instance_exec(maglev_site, &maglev_config.title) end end |
#maglev_favicon_url ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'app/helpers/maglev/application_helper.rb', line 63 def maglev_favicon_url case maglev_config.favicon when nil asset_path('maglev/favicon.svg') when String asset_path(maglev_config.favicon) when Proc instance_exec(maglev_site, &maglev_config.favicon) end end |
#maglev_flash_message ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'app/helpers/maglev/application_helper.rb', line 140 def , color, icon_name = if flash[:notice].present? [flash[:notice], :green, 'checkbox_circle'] elsif flash[:alert].present? [flash[:alert], :red, 'error_warning'] end return '' if .blank? render Maglev::Uikit::BadgeComponent.new(color: color, icon_name: icon_name, disappear_after: 3.seconds).with_content() end |
#maglev_icon_button_classes ⇒ Object
rubocop:enable Metrics/MethodLength
132 133 134 135 136 137 138 |
# File 'app/helpers/maglev/application_helper.rb', line 132 def (...) ClassVariants.build( base: %(h-7 w-7 flex items-center justify-center rounded-full focus:outline-none transition-colors duration-200 cursor-pointer bg-gray-600/0 text-gray-800 hover:bg-gray-600/10 hover:text-gray-900) ).render(...) end |
#maglev_importmap_tags(namespace, entry_point) ⇒ Object
22 23 24 25 26 27 28 |
# File 'app/helpers/maglev/application_helper.rb', line 22 def (namespace, entry_point) safe_join [ javascript_inline_importmap_tag(Maglev::Engine.importmaps[namespace].to_json(resolver: self)), (Maglev::Engine.importmaps[namespace]), javascript_import_module_tag(entry_point) ], "\n" end |
#maglev_live_preview_client_javascript_tag ⇒ Object
173 174 175 176 177 178 |
# File 'app/helpers/maglev/application_helper.rb', line 173 def maglev_live_preview_client_javascript_tag # rubocop:disable Layout/LineLength Rails.logger.warn '🚨 maglev_live_preview_client_javascript_tag is deprecated, use maglev_client_javascript_tags instead' # rubocop:enable Layout/LineLength end |
#maglev_page_icon(page, size: '1.15rem', wrapper_class_names: nil) ⇒ Object
154 155 156 157 158 159 160 161 162 163 |
# File 'app/helpers/maglev/application_helper.rb', line 154 def maglev_page_icon(page, size: '1.15rem', wrapper_class_names: nil) icon_name = page.index? ? 'home' : 'file' content_tag :span, class: class_names('shrink-0 relative', wrapper_class_names) do if page.need_to_be_published? concat(content_tag(:span, '', class: 'absolute -bottom-0.25 right-0 bg-yellow-600 rounded-full w-1.5 h-1.5')) end concat render(Maglev::Uikit::IconComponent.new(name: icon_name, size: size)) end end |
#maglev_page_preview_reload_data ⇒ Object
165 166 167 168 169 170 171 |
# File 'app/helpers/maglev/application_helper.rb', line 165 def maglev_page_preview_reload_data { controller: 'dispatcher', action: 'click->dispatcher#trigger', dispatcher_event_name_value: 'page-preview:reload' } end |
#maglev_primary_hex_color ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/helpers/maglev/application_helper.rb', line 74 def maglev_primary_hex_color color = maglev_config.primary_color if color =~ /^\#(\d)(\d)(\d)$/ r_value = ''.rjust(2, Regexp.last_match(1)) g_value = ''.rjust(2, Regexp.last_match(2)) b_value = ''.rjust(2, Regexp.last_match(3)) "##{r_value}#{g_value}#{b_value}" else color end end |
#maglev_primary_rgb_color ⇒ Object
86 87 88 89 90 91 |
# File 'app/helpers/maglev/application_helper.rb', line 86 def maglev_primary_rgb_color maglev_primary_hex_color .gsub('#', '') .scan(/.{2}/) .map { |value| value.to_i(16) } end |
#turbo_stream ⇒ Object
“system” helpers
7 8 9 10 |
# File 'app/helpers/maglev/application_helper.rb', line 7 def turbo_stream # we don't want to pollute the global Turbo::Streams::TagBuilder Maglev::Turbo::Streams::TagBuilder.new(self) end |