hx 0.18.0 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/hx/output/liquidtemplate.rb +35 -8
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
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:
|
4
|
+
hash: 83
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 19
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.19.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- MenTaLguY
|