Class: Decidim::ContentRenderers::ResourceRenderer
- Inherits:
-
BaseRenderer
- Object
- BaseRenderer
- Decidim::ContentRenderers::ResourceRenderer
- Defined in:
- lib/decidim/content_renderers/resource_renderer.rb
Instance Attribute Summary
Attributes inherited from BaseRenderer
Instance Method Summary collapse
-
#render(_options = nil) ⇒ String
Replaces found Global IDs matching an existing resource with a link to its show page.
Methods inherited from BaseRenderer
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.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/decidim/content_renderers/resource_renderer.rb', line 13 def render( = 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 |