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)


16
17
18
19
20
21
22
23
# File 'lib/skylight/core/normalizers/render.rb', line 16

def normalize_render(category, payload)
  if path = payload[:identifier]
    title = relative_path(path)
    path = nil if path == title
  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.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/skylight/core/normalizers/render.rb', line 25

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

  root = array_find(@paths) { |p| path.start_with?(p) }
  type = :project

  unless root
    root = array_find(Gem.path) { |p| path.start_with?(p) }
    type = :gem
  end

  if root
    start = root.size
    start += 1 if path.getbyte(start) == SEPARATOR_BYTE
    if type == :gem
      "$GEM_PATH/#{path[start, path.size]}"
    else
      path[start, path.size]
    end
  else
    "Absolute Path"
  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
# File 'lib/skylight/core/normalizers/render.rb', line 7

def setup
  @paths = config['normalizers.render.view_paths'] || []
end