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
- #regex ⇒ Object
-
#render(_options = nil) ⇒ String
Replaces found Global IDs matching an existing resource with a link to its show page.
Methods inherited from BaseRenderer
Constructor Details
This class inherits a constructor from Decidim::ContentRenderers::BaseRenderer
Instance Method Details
#regex ⇒ Object
25 26 27 |
# File 'lib/decidim/content_renderers/resource_renderer.rb', line 25 def regex raise "Not implemented" end |
#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) return content unless content.respond_to?(:gsub) content.gsub(regex) do |resource_gid| resource = GlobalID::Locator.locate(resource_gid) resource.presenter.display_mention rescue ActiveRecord::RecordNotFound resource_id = resource_gid.split("/").last "~#{resource_id}" end end |