Class: Decidim::ContentRenderers::ResourceRenderer

Inherits:
BaseRenderer
  • Object
show all
Defined in:
lib/decidim/content_renderers/resource_renderer.rb

Instance Attribute Summary

Attributes inherited from BaseRenderer

#content

Instance Method Summary collapse

Methods inherited from BaseRenderer

#initialize

Methods included from Decidim::ContentProcessor::Common

#html_content?, #html_fragment

Constructor Details

This class inherits a constructor from Decidim::ContentRenderers::BaseRenderer

Instance Method Details

#render(_options = nil) ⇒ String

Replaces found Global IDs matching an existing resource with a link to its show page. The Global IDs representing an invalid Resource are replaced with ‘???’ string.

Returns:

  • (String)

    the content ready to display (contains HTML)



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/decidim/content_renderers/resource_renderer.rb', line 13

def render(_options = nil)
  replace_pattern_by_context(content, regex, on_missing: proc { |match, _| "~#{match.split("/").last}" }) do |resource_gid, context|
    resource = GlobalID::Locator.locate(resource_gid)

    if context.attribute?
      resource_attribute_value(resource)
    else
      resource.presenter.display_mention
    end
  end
end