Class: ProsemirrorToHtml::GlobalIdToLinksFormatter
- Inherits:
-
Object
- Object
- ProsemirrorToHtml::GlobalIdToLinksFormatter
- Defined in:
- app/formatters/prosemirror_to_html/global_id_to_links_formatter.rb
Constant Summary collapse
- GLOBAL_ID_REGEX =
The app segment allows hyphens and dots: GlobalID derives it from the Rails application name (e.g. "au-poste").
%r{(gid://[\w.-]+/[\w:]+/[\w-]+)}
Instance Method Summary collapse
-
#initialize(str) ⇒ GlobalIdToLinksFormatter
constructor
A new instance of GlobalIdToLinksFormatter.
- #to_s ⇒ Object
Constructor Details
#initialize(str) ⇒ GlobalIdToLinksFormatter
Returns a new instance of GlobalIdToLinksFormatter.
9 10 11 |
# File 'app/formatters/prosemirror_to_html/global_id_to_links_formatter.rb', line 9 def initialize(str) @str = str end |
Instance Method Details
#to_s ⇒ Object
13 14 15 16 17 |
# File 'app/formatters/prosemirror_to_html/global_id_to_links_formatter.rb', line 13 def to_s gids = @str.scan(GLOBAL_ID_REGEX).flatten objects = GlobalID::Locator.locate_many(gids).index_by { |o| o.to_global_id.to_s } @str.gsub(GLOBAL_ID_REGEX) { |gid| url_for(objects[gid]) } end |