Module: Elabs::ShortcodesHelper

Defined in:
app/helpers/elabs/shortcodes_helper.rb

Constant Summary collapse

SHORT_CODES =
{
  /\[album:([\w-]+)\]/                                       => [:shortcode_content, { type: :album, size: :inline }],
  /\[article:([\w-]+)\]/                                     => [:shortcode_content, { type: :article, size: :inline }],
  /\[note:([\w-]+)\]/                                        => [:shortcode_content, { type: :note, size: :inline }],
  /\[project:([\w-]+)\]/                                     => [:shortcode_content, { type: :project, size: :inline }],
  /\[upload:([\w-]+)\]/                                      => [:shortcode_content, { type: :upload, size: :inline }],
  /\[user:([a-zA-Z0-9]+([_-]?[a-zA-Z0-9]+)?)\]/              => [:shortcode_content, { type: :user, size: :inline }],
  /\[album-card:([\w-]+)\]/                                  => [:shortcode_content, { type: :album, size: :large }],
  /\[article-card:([\w-]+)\]/                                => [:shortcode_content, { type: :article, size: :large }],
  /\[note-card:([\w-]+)\]/                                   => [:shortcode_content, { type: :note, size: :large }],
  /\[project-card:([\w-]+)\]/                                => [:shortcode_content, { type: :project, size: :large }],
  /\[upload-card:([\w-]+)\]/                                 => [:shortcode_content, { type: :upload, size: :large }],
  /\[user-card:([a-zA-Z0-9]+([_-]?[a-zA-Z0-9]+)?)\]/         => [:shortcode_content, { type: :user, size: :large }],
  %r{\[github-repo:([a-zA-Z0-9\-_]+/[a-zA-Z0-9\-_]+)\]}      => [:shortcode_github_repo_inline, { size: :inline }],
  %r{\[github-repo-card:([a-zA-Z0-9\-_]+/[a-zA-Z0-9\-_]+)\]} => [:shortcode_github_repo, {}],
  /\[github-user-card:([a-zA-Z0-9\-_]+)\]/                   => [:shortcode_github_user, {}],
  %r{\[gitlab-repo:(https://.*)\]}                           => [:shortcode_gitlab_repo_inline, { size: :inline }],
  %r{\[gitlab-repo-card:(https://.*)\]}                      => [:shortcode_gitlab_repo, {}],
  %r{\[gitlab-user-card:(https://.*)\]}                      => [:shortcode_gitlab_user, {}],
  %r{\[gitlab-group-card:(https://.*)\]}                     => [:shortcode_gitlab_group, {}]
}.freeze

Instance Method Summary collapse

Instance Method Details

#process_short_codes(text, original_entity = nil, display = true) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/elabs/shortcodes_helper.rb', line 25

def process_short_codes(text, original_entity = nil, display = true)
  SHORT_CODES.each do |key, method|
    text.gsub! key do |match|
      size = method[1].key?(:size) ? method[1][:size] : :inline
      if display || size == :inline
        send(method[0], original_entity, match.sub(key, '\1'), method[1])
      else
        render(partial: 'elabs/layouts/shortcodes/open_to_see') unless display
      end
    end
  end
  text.html_safe
end