Class: ViewComponent::Template::File

Inherits:
Template
  • Object
show all
Defined in:
lib/view_component/template.rb

Instance Method Summary collapse

Constructor Details

#initialize(component:, details:, path:) ⇒ File

Returns a new instance of File.



23
24
25
26
27
28
29
30
31
32
# File 'lib/view_component/template.rb', line 23

def initialize(component:, details:, path:)
  # If the template file has no format (e.g. .erb instead of .html.erb),
  # assume the default format (html).
  if details.format.nil?
    Kernel.warn("WARNING: Template format for #{path} is missing, defaulting to :html.")
    details = ActionView::TemplateDetails.new(details.locale, details.handler, DEFAULT_FORMAT, details.variant)
  end

  super
end

Instance Method Details

#sourceObject

Load file each time we look up #source in case the file has been modified



39
40
41
# File 'lib/view_component/template.rb', line 39

def source
  ::File.read(@path)
end

#typeObject



34
35
36
# File 'lib/view_component/template.rb', line 34

def type
  :file
end