Module: Quby::TextTransformation

Included in:
ApplicationHelper, MarkdownParser
Defined in:
lib/quby/answers/services/text_transformation.rb

Constant Summary collapse

/\~\~(?<url>.+?)\~\~(?<link_content>.+?)\~\~/
TEXT_VAR_REGEX =

Textvars: Replace {var_name} with <span class=‘textvar’ textvar=‘var_name’></span>

/\{\{(?<text_var>.+?)\}\}/

Instance Method Summary collapse

Instance Method Details



18
19
20
# File 'lib/quby/answers/services/text_transformation.rb', line 18

def link_html(url, link_content)
  "<a href='#' onclick='modalFrame(\"#{url}\");'>#{link_content}</a>"
end

#textvar_html(var_name) ⇒ Object



22
23
24
# File 'lib/quby/answers/services/text_transformation.rb', line 22

def textvar_html(var_name)
  "<span class='textvar' textvar='#{var_name}'>{{#{var_name}}}</span>"
end

#transform_special_text(text) ⇒ Object

to eventually replace maruku_extensions.rb this helper transforms ~~ links and vars} into html



13
14
15
16
# File 'lib/quby/answers/services/text_transformation.rb', line 13

def transform_special_text(text)
  text.gsub(LINK_URL_REGEX) { link_html($~[:url], $~[:link_content]) }
      .gsub(TEXT_VAR_REGEX) { textvar_html($~[:text_var]) }
end