Module: LazyImageTagHelper
- Includes:
- PreferencesHelper
- Defined in:
- app/helpers/lazy_image_tag_helper.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#image_tag(source, options = {}) ⇒ Object
Override the default ActionView ‘image_tag` helper to support lazy-loading accept :auto_dark boolean to enable automatic dark variant of the image (see: gitlab.com/gitlab-org/gitlab-ui/-/merge_requests/2698) accept :dark_variant path to be used as a source when dark mode is enabled.
Methods included from PreferencesHelper
#custom_diff_color_classes, #dashboard_choices, #default_preferred_language_choices, #first_day_of_week_choices, #first_day_of_week_choices_with_default, #integration_views, #language_choices, #layout_choices, #localized_dashboard_choices, #project_view_choices, #user_application_dark_mode?, #user_application_theme, #user_application_theme_css_filename, #user_color_scheme, #user_diffs_colors, #user_tab_width, #user_theme_primary_color
Class Method Details
.placeholder_image ⇒ Object
6 7 8 |
# File 'app/helpers/lazy_image_tag_helper.rb', line 6 def placeholder_image "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" end |
Instance Method Details
#image_tag(source, options = {}) ⇒ Object
Override the default ActionView ‘image_tag` helper to support lazy-loading accept :auto_dark boolean to enable automatic dark variant of the image (see: gitlab.com/gitlab-org/gitlab-ui/-/merge_requests/2698) accept :dark_variant path to be used as a source when dark mode is enabled
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/helpers/lazy_image_tag_helper.rb', line 14 def image_tag(source, = {}) source, = prepare_dark_variant(source, ) = .symbolize_keys unless .delete(:lazy) == false [:data] ||= {} [:data][:src] = path_to_image(source) # options[:class] can be either String or Array. klass_opts = Array.wrap([:class]) klass_opts << "lazy" [:class] = klass_opts.join(' ') source = placeholder_image end super(source, ) end |