hx 0.18.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/hx/output/liquidtemplate.rb +35 -8
  3. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.18.0
1
+ 0.19.0
@@ -60,19 +60,45 @@ class LiquidTemplate
60
60
  end
61
61
  end
62
62
 
63
+ class TemplateSource
64
+ include Hx::Filter
65
+
66
+ def initialize(options)
67
+ # global, so all LiquidTemplate instances have to agree on the
68
+ # same template directory for things to work right
69
+ @template_dir = Hx.get_pathname(options, :template_dir)
70
+ Liquid::Template.file_system = Liquid::LocalFileSystem.new(@template_dir)
71
+ Liquid::Template.register_filter(TextFilters)
72
+ end
73
+
74
+ def each_entry_path(selector)
75
+ # enumeration currently unneeded
76
+ self
77
+ end
78
+
79
+ def get_entry(path)
80
+ template_file = @template_dir + "#{path}.liquid"
81
+ {"template" => Liquid::Template.parse(template_file.read)}
82
+ end
83
+ end
84
+
63
85
  def initialize(input, options)
64
86
  @input = input
65
87
  @options = {}
66
88
  for key, value in options
67
89
  @options[key.to_s] = value
68
90
  end
69
- template_dir = Hx.get_pathname(options, :template_dir)
70
- # global, so all LiquidTemplate instances kind of have to agree on the
71
- # same template directory for things to work right
72
- Liquid::Template.file_system = Liquid::LocalFileSystem.new(template_dir)
73
- Liquid::Template.register_filter(TextFilters)
74
- template_file = template_dir + "#{options[:template]}.liquid"
75
- @template = Liquid::Template.parse(template_file.read)
91
+ begin
92
+ LiquidTemplate.const_get(:TEMPLATE_SOURCE)
93
+ rescue NameError
94
+ # use filter cache to avoid template re-parse
95
+ # (doesn't help with partials yet)
96
+ template_source = Cache.new(TemplateSource.new(options))
97
+ LiquidTemplate.const_set(:TEMPLATE_SOURCE, template_source)
98
+ end
99
+ @template_name = options[:template]
100
+ # force early failure in case of a missing template
101
+ TEMPLATE_SOURCE.get_entry(@template_name)
76
102
  @extension = options[:extension]
77
103
  @content_type = options[:content_type]
78
104
  @strip_extension_re = nil
@@ -91,8 +117,9 @@ class LiquidTemplate
91
117
  path = path.sub(@strip_extension_re, '') if @strip_extension_re
92
118
  entry = @input.get_entry(path)
93
119
  output_entry = {}
120
+ template = TEMPLATE_SOURCE.get_entry(@template_name)["template"]
94
121
  output_entry['content'] = Hx::LazyContent.new do
95
- @template.render(
122
+ template.render(
96
123
  'now' => Time.now,
97
124
  'options' => @options,
98
125
  'path' => path,
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hx
3
3
  version: !ruby/object:Gem::Version
4
- hash: 87
4
+ hash: 83
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 18
8
+ - 19
9
9
  - 0
10
- version: 0.18.0
10
+ version: 0.19.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - MenTaLguY