mirror of
https://github.com/kemko/liquid.git
synced 2026-01-02 08:15:41 +03:00
Compare commits
2 Commits
template-f
...
experiment
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f439f73ba | ||
|
|
5face68cc8 |
@@ -1,11 +1,15 @@
|
||||
language: ruby
|
||||
cache: bundler
|
||||
os: [osx, linux]
|
||||
|
||||
rvm:
|
||||
- 2.4
|
||||
- 2.5
|
||||
- &latest_ruby 2.6
|
||||
- 2.7
|
||||
- 2.7.0-preview1
|
||||
- 2.7.0-preview2
|
||||
- 2.7.0-preview3
|
||||
- ruby-head
|
||||
|
||||
matrix:
|
||||
@@ -16,6 +20,8 @@ matrix:
|
||||
allow_failures:
|
||||
- rvm: ruby-head
|
||||
- rvm: 2.7
|
||||
- rvm: 2.7.0-preview2
|
||||
- rvm: 2.7.0-preview3
|
||||
|
||||
branches:
|
||||
only:
|
||||
|
||||
@@ -80,7 +80,6 @@ require 'liquid/partial_cache'
|
||||
require 'liquid/usage'
|
||||
require 'liquid/register'
|
||||
require 'liquid/static_registers'
|
||||
require 'liquid/template_factory'
|
||||
|
||||
# Load all the tags of the standard library
|
||||
#
|
||||
|
||||
@@ -12,10 +12,7 @@ module Liquid
|
||||
|
||||
parse_context.partial = true
|
||||
|
||||
template_factory = (context.registers[:template_factory] ||= Liquid::TemplateFactory.new)
|
||||
template = template_factory.for(template_name)
|
||||
|
||||
partial = template.parse(source, parse_context)
|
||||
partial = Liquid::Template.parse(source, parse_context)
|
||||
cached_partials[template_name] = partial
|
||||
ensure
|
||||
parse_context.partial = false
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Liquid
|
||||
class TemplateFactory
|
||||
def for(_template_name)
|
||||
Liquid::Template.new
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -136,16 +136,3 @@ class StubFileSystem
|
||||
@values.fetch(template_path)
|
||||
end
|
||||
end
|
||||
|
||||
class StubTemplateFactory
|
||||
attr_reader :count
|
||||
|
||||
def initialize
|
||||
@count = 0
|
||||
end
|
||||
|
||||
def for(_template_name)
|
||||
@count += 1
|
||||
Liquid::Template.new
|
||||
end
|
||||
end
|
||||
|
||||
@@ -90,39 +90,4 @@ class PartialCacheUnitTest < Minitest::Test
|
||||
# but measuring file reads is an OK proxy for this.
|
||||
assert_equal(1, file_system.file_read_count)
|
||||
end
|
||||
|
||||
def test_uses_default_template_factory_when_no_template_factory_found_in_register
|
||||
context = Liquid::Context.build(
|
||||
registers: {
|
||||
file_system: StubFileSystem.new('my_partial' => 'my partial body'),
|
||||
}
|
||||
)
|
||||
|
||||
partial = Liquid::PartialCache.load(
|
||||
'my_partial',
|
||||
context: context,
|
||||
parse_context: Liquid::ParseContext.new
|
||||
)
|
||||
|
||||
assert_equal('my partial body', partial.render)
|
||||
end
|
||||
|
||||
def test_uses_template_factory_register_if_present
|
||||
template_factory = StubTemplateFactory.new
|
||||
context = Liquid::Context.build(
|
||||
registers: {
|
||||
file_system: StubFileSystem.new('my_partial' => 'my partial body'),
|
||||
template_factory: template_factory,
|
||||
}
|
||||
)
|
||||
|
||||
partial = Liquid::PartialCache.load(
|
||||
'my_partial',
|
||||
context: context,
|
||||
parse_context: Liquid::ParseContext.new
|
||||
)
|
||||
|
||||
assert_equal('my partial body', partial.render)
|
||||
assert_equal(1, template_factory.count)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class TemplateFactoryUnitTest < Minitest::Test
|
||||
include Liquid
|
||||
|
||||
def test_for_returns_liquid_template_instance
|
||||
template = TemplateFactory.new.for("anything")
|
||||
assert_instance_of(Liquid::Template, template)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user