mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add ActionView::Template::Sources::File
This commit is contained in:
parent
b8e6594181
commit
db1830a7ec
4 changed files with 38 additions and 24 deletions
|
@ -5,29 +5,8 @@ require "action_view/template"
|
|||
module ActionView
|
||||
class FileTemplate < Template
|
||||
def initialize(filename, handler, details)
|
||||
@filename = filename
|
||||
|
||||
super(nil, filename, handler, details)
|
||||
end
|
||||
|
||||
def source
|
||||
File.binread @filename
|
||||
end
|
||||
|
||||
def refresh(_)
|
||||
self
|
||||
end
|
||||
|
||||
# Exceptions are marshalled when using the parallel test runner with DRb, so we need
|
||||
# to ensure that references to the template object can be marshalled as well. This means forgoing
|
||||
# the marshalling of the compiler mutex and instantiating that again on unmarshalling.
|
||||
def marshal_dump # :nodoc:
|
||||
[ @identifier, @handler, @compiled, @locals, @virtual_path, @updated_at, @format, @variant ]
|
||||
end
|
||||
|
||||
def marshal_load(array) # :nodoc:
|
||||
@identifier, @handler, @compiled, @locals, @virtual_path, @updated_at, @format, @variant = *array
|
||||
@compile_mutex = Mutex.new
|
||||
source = ActionView::Template::Sources::File.new(filename)
|
||||
super(source, filename, handler, details)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -117,13 +117,14 @@ module ActionView
|
|||
autoload :Handlers
|
||||
autoload :HTML
|
||||
autoload :Inline
|
||||
autoload :Sources
|
||||
autoload :Text
|
||||
autoload :Types
|
||||
end
|
||||
|
||||
extend Template::Handlers
|
||||
|
||||
attr_reader :source, :identifier, :handler, :original_encoding, :updated_at
|
||||
attr_reader :identifier, :handler, :original_encoding, :updated_at
|
||||
attr_reader :variable, :format, :variant, :locals, :virtual_path
|
||||
|
||||
def initialize(source, identifier, handler, format: nil, variant: nil, locals: nil, virtual_path: nil, updated_at: nil)
|
||||
|
@ -217,6 +218,10 @@ module ActionView
|
|||
"#<#{self.class.name} #{short_identifier} locals=#{@locals.inspect}>"
|
||||
end
|
||||
|
||||
def source
|
||||
@source.to_s
|
||||
end
|
||||
|
||||
# This method is responsible for properly setting the encoding of the
|
||||
# source. Until this point, we assume that the source is BINARY data.
|
||||
# If no additional information is supplied, we assume the encoding is
|
||||
|
|
13
actionview/lib/action_view/template/sources.rb
Normal file
13
actionview/lib/action_view/template/sources.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ActionView
|
||||
class Template
|
||||
module Sources
|
||||
extend ActiveSupport::Autoload
|
||||
|
||||
eager_autoload do
|
||||
autoload :File
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
actionview/lib/action_view/template/sources/file.rb
Normal file
17
actionview/lib/action_view/template/sources/file.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ActionView
|
||||
class Template
|
||||
module Sources
|
||||
class File
|
||||
def initialize(filename)
|
||||
@filename = filename
|
||||
end
|
||||
|
||||
def to_s
|
||||
::File.binread @filename
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue