Sha256: 9668f22beb6253d3c28c02b7e41c1798f1596f157fad402cc83f5bff22573e08

Contents?: true

Size: 1.3 KB

Versions: 12

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module Decidim
  # This helper includes some methods to help with generating short links within
  # the Decidim engine views.
  module ShortLinkHelper
    # A helper method to get a short URL in the current context where this
    # method is called from. This helper automatically fetches the "target" for
    # the short link, such as the component or the participatory process. This
    # also resolves the current mounted route name to make it possible to refer
    # to the same context when redirecting the short URL to correct full URL.
    #
    # @option kwargs [Boolean] :route_name the route name to which the short
    #   link should link to
    # @option kwargs [Float] :params the URL query parameters that should be
    #   included in the URL where the short link redirects to
    # @return [String] The short URL
    def short_url(**kwargs)
      target = respond_to?(:current_component) && current_component
      target ||= respond_to?(:current_participatory_space) && current_participatory_space
      target ||= respond_to?(:current_organization) && current_organization
      target ||= Rails.application

      mounted_engine = target.try(:mounted_engine) || EngineResolver.new(_routes).mounted_name
      ShortLink.to(target, mounted_engine, **kwargs).short_url
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-core-0.28.4 app/helpers/decidim/short_link_helper.rb
decidim-core-0.27.9 app/helpers/decidim/short_link_helper.rb
decidim-core-0.28.3 app/helpers/decidim/short_link_helper.rb
decidim-core-0.27.8 app/helpers/decidim/short_link_helper.rb
decidim-core-0.28.2 app/helpers/decidim/short_link_helper.rb
decidim-core-0.27.7 app/helpers/decidim/short_link_helper.rb
decidim-core-0.28.1 app/helpers/decidim/short_link_helper.rb
decidim-core-0.27.6 app/helpers/decidim/short_link_helper.rb
decidim-core-0.28.0 app/helpers/decidim/short_link_helper.rb
decidim-core-0.27.5 app/helpers/decidim/short_link_helper.rb
decidim-core-0.28.0.rc5 app/helpers/decidim/short_link_helper.rb
decidim-core-0.28.0.rc4 app/helpers/decidim/short_link_helper.rb