Class: Skylight::Core::Normalizers::RenderNormalizer Private

Inherits:
Normalizer
  • Object
show all
Includes:
Util::AllocationFree
Defined in:
lib/skylight/core/normalizers/render.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Base Normalizer for Rails rendering

Instance Attribute Summary

Attributes inherited from Normalizer

#config

Instance Method Summary collapse

Methods included from Util::AllocationFree

#array_find

Methods inherited from Normalizer

#initialize, #normalize, #normalize_after, register

Constructor Details

This class inherits a constructor from Skylight::Core::Normalizers::Normalizer

Instance Method Details

#normalize_render(category, payload) ⇒ Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Generic normalizer for renders

Parameters:

  • category (String)
  • payload (Hash)

Options Hash (payload):

  • :identifier (String)

Returns:

  • (Array)

24
25
26
27
28
29
30
# File 'lib/skylight/core/normalizers/render.rb', line 24

def normalize_render(category, payload)
  if (path = payload[:identifier])
    title = relative_path(path)
  end

  [category, title, nil]
end

#relative_path(path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/skylight/core/normalizers/render.rb', line 32

def relative_path(path)
  return path if relative_path?(path)

  if (root = array_find(@paths) { |p| path.start_with?(p) })
    start = root.size
    start += 1 if path.getbyte(start) == SEPARATOR_BYTE

    path[start, path.size].sub(
      # Matches a Gem Version or 12-digit hex (sha)
      # that is preceeded by a `-` and followed by `/`
      # Also matches 'app/views/' if it exists
      %r{-(?:#{Gem::Version::VERSION_PATTERN}|[0-9a-f]{12})\/(?:app\/views\/)*},
      ": ".freeze
    )
  else
    "Absolute Path".freeze
  end
end

#setupObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


7
8
9
10
11
12
13
14
15
16
17
# File 'lib/skylight/core/normalizers/render.rb', line 7

def setup
  @paths = []

  Gem.path.each do |path|
    @paths << "#{path}/bundler/gems".freeze
    @paths << "#{path}/gems".freeze
    @paths << path
  end

  @paths.concat(Array(config["normalizers.render.view_paths"]))
end