diff options
author | John Hawthorn <john@hawthorn.email> | 2019-04-04 12:45:30 -0700 |
---|---|---|
committer | John Hawthorn <john@hawthorn.email> | 2019-04-04 15:07:14 -0700 |
commit | db1830a7ec5765909fadb80a8725e52cc37ade07 (patch) | |
tree | 2f561972976919251121962d2d9af0cbd68921f6 | |
parent | b8e6594181996807ea18d1209f8ee3dbd581554b (diff) | |
download | rails-db1830a7ec5765909fadb80a8725e52cc37ade07.tar.gz rails-db1830a7ec5765909fadb80a8725e52cc37ade07.tar.bz2 rails-db1830a7ec5765909fadb80a8725e52cc37ade07.zip |
Add ActionView::Template::Sources::File
-rw-r--r-- | actionview/lib/action_view/file_template.rb | 25 | ||||
-rw-r--r-- | actionview/lib/action_view/template.rb | 7 | ||||
-rw-r--r-- | actionview/lib/action_view/template/sources.rb | 13 | ||||
-rw-r--r-- | actionview/lib/action_view/template/sources/file.rb | 17 |
4 files changed, 38 insertions, 24 deletions
diff --git a/actionview/lib/action_view/file_template.rb b/actionview/lib/action_view/file_template.rb index dea02176eb..f952c364c9 100644 --- a/actionview/lib/action_view/file_template.rb +++ b/actionview/lib/action_view/file_template.rb @@ -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 diff --git a/actionview/lib/action_view/template.rb b/actionview/lib/action_view/template.rb index ae067cb73d..291cb8dd9f 100644 --- a/actionview/lib/action_view/template.rb +++ b/actionview/lib/action_view/template.rb @@ -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 diff --git a/actionview/lib/action_view/template/sources.rb b/actionview/lib/action_view/template/sources.rb new file mode 100644 index 0000000000..8b89535741 --- /dev/null +++ b/actionview/lib/action_view/template/sources.rb @@ -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 diff --git a/actionview/lib/action_view/template/sources/file.rb b/actionview/lib/action_view/template/sources/file.rb new file mode 100644 index 0000000000..2d3a7dec7f --- /dev/null +++ b/actionview/lib/action_view/template/sources/file.rb @@ -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 |