class Skylight::Core::Normalizers::RenderNormalizer

Base Normalizer for Rails rendering

Constants

ALT_SEPARATOR_BYTE

This is a DOSish environment

COLON_BYTE
SEPARATOR_BYTE
SEPARATOR_BYTES

Public Instance Methods

normalize_render(category, payload) click to toggle source

Generic normalizer for renders @param category [String] @param payload [Hash] @option payload [String] :identifier @return [Array]

# 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) click to toggle source
# 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
setup() click to toggle source
# 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

Private Instance Methods

absolute_path?(path) click to toggle source
# File lib/skylight/core/normalizers/render.rb, line 65
def absolute_path?(path)
  if alpha?(path.getbyte(0)) && path.getbyte(1) == COLON_BYTE
    SEPARATOR_BYTES.include?(path.getbyte(2))
  end
end
alpha?(byte) click to toggle source
# File lib/skylight/core/normalizers/render.rb, line 71
def alpha?(byte)
  (byte >= 65 && byte <= 90) || (byte >= 97 && byte <= 122)
end
relative_path?(path) click to toggle source
# File lib/skylight/core/normalizers/render.rb, line 53
def relative_path?(path)
  !absolute_path?(path)
end