Class: ActionView::PathSet

Inherits:
Array
  • Object
show all
Defined in:
lib/action_view/paths.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ PathSet

Returns a new instance of PathSet.



15
16
17
# File 'lib/action_view/paths.rb', line 15

def initialize(*args)
  super(*args).map! { |obj| self.class.type_cast(obj) }
end

Class Method Details

.type_cast(obj) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/action_view/paths.rb', line 3

def self.type_cast(obj)
  if obj.is_a?(String)
    if Base.cache_template_loading?
      Template::EagerPath.new(obj.to_s)
    else
      ReloadableTemplate::ReloadablePath.new(obj.to_s)
    end
  else
    obj
  end
end

Instance Method Details

#<<(obj) ⇒ Object



19
20
21
# File 'lib/action_view/paths.rb', line 19

def <<(obj)
  super(self.class.type_cast(obj))
end

#concat(array) ⇒ Object



23
24
25
# File 'lib/action_view/paths.rb', line 23

def concat(array)
  super(array.map! { |obj| self.class.type_cast(obj) })
end

#find_template(original_template_path, format = nil, html_fallback = true) ⇒ Object

Raises:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/action_view/paths.rb', line 43

def find_template(original_template_path, format = nil, html_fallback = true)
  return original_template_path if original_template_path.respond_to?(:render)
  template_path = original_template_path.sub(/^\//, '')

  each do |load_path|
    if format && (template = load_path["#{template_path}.#{I18n.locale}.#{format}"])
      return template
    # Try the default locale version if the current locale doesn't have one
    # (i.e. you haven't translated this view to German yet, but you have the English version on hand)
    elsif format && (template = load_path["#{template_path}.#{I18n.default_locale}.#{format}"]) 
      return template
    elsif format && (template = load_path["#{template_path}.#{format}"])
      return template
    elsif template = load_path["#{template_path}.#{I18n.locale}"]
      return template
    elsif template = load_path["#{template_path}.#{I18n.default_locale}"]
      return template
    elsif template = load_path[template_path]
      return template
    # Try to find html version if the format is javascript
    elsif format == :js && html_fallback && template = load_path["#{template_path}.#{I18n.locale}.html"]
      return template
    elsif format == :js && html_fallback && template = load_path["#{template_path}.#{I18n.default_locale}.html"]
      return template
    elsif format == :js && html_fallback && template = load_path["#{template_path}.html"]
      return template
    end
  end

  return Template.new(original_template_path) if File.file?(original_template_path)

  raise MissingTemplate.new(self, original_template_path, format)
end

#insert(index, obj) ⇒ Object



27
28
29
# File 'lib/action_view/paths.rb', line 27

def insert(index, obj)
  super(index, self.class.type_cast(obj))
end

#load!Object



39
40
41
# File 'lib/action_view/paths.rb', line 39

def load!
  each(&:load!)
end

#push(*objs) ⇒ Object



31
32
33
# File 'lib/action_view/paths.rb', line 31

def push(*objs)
  super(*objs.map { |obj| self.class.type_cast(obj) })
end

#unshift(*objs) ⇒ Object



35
36
37
# File 'lib/action_view/paths.rb', line 35

def unshift(*objs)
  super(*objs.map { |obj| self.class.type_cast(obj) })
end