class Decidim::ContentRenderers::PlanRenderer
A renderer that searches Global IDs representing plans in content and replaces it with a link to their show page.
e.g. gid://<APP_NAME>/Decidim::Plans::Plan/1
@see BaseRenderer Examples of how to use a content renderer
Constants
- GLOBAL_ID_REGEX
Matches a global id representing a Decidim::User
Public Instance Methods
render()
click to toggle source
Replaces found Global IDs matching an existing plan with a link to its show page. The Global IDs representing an invalid Decidim::Plans::Plan are replaced with '???' string.
@return [String] the content ready to display (contains HTML)
# File lib/decidim/content_renderers/plan_renderer.rb, line 20 def render content.gsub(GLOBAL_ID_REGEX) do |plan_gid| begin plan = GlobalID::Locator.locate(plan_gid) Decidim::Plans::PlanPresenter.new(plan).display_mention rescue ActiveRecord::RecordNotFound plan_gid = plan_gid.split("/").last "##{plan_gid}" end end end