jekyll-rendering 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +6 -0
- data/README +1 -1
- data/lib/jekyll/rendering.rb +23 -20
- data/lib/jekyll/rendering/version.rb +1 -1
- metadata +4 -4
data/ChangeLog
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
= Revision history for jekyll-rendering
|
2
2
|
|
3
|
+
== 0.0.5 [2010-10-29]
|
4
|
+
|
5
|
+
* Refactored include_file.
|
6
|
+
* Accept hash of local assigns instead of binding.
|
7
|
+
* Denote inclusion from current directory by './'.
|
8
|
+
|
3
9
|
== 0.0.4 [2010-10-01]
|
4
10
|
|
5
11
|
* Allow inclusion of files from *current* directory.
|
data/README
CHANGED
data/lib/jekyll/rendering.rb
CHANGED
@@ -141,36 +141,39 @@ module Jekyll
|
|
141
141
|
# call-seq:
|
142
142
|
# engine.render => aString
|
143
143
|
# engine.render(content) => aString
|
144
|
-
# engine.render(content,
|
144
|
+
# engine.render(content, local_assigns) => aString
|
145
145
|
#
|
146
|
-
# Renders the +content+ as ERB template.
|
147
|
-
# if provided.
|
148
|
-
def render(content = content,
|
149
|
-
|
146
|
+
# Renders the +content+ as ERB template. Assigns optional
|
147
|
+
# +local_assigns+ for use in template if provided.
|
148
|
+
def render(content = content, local_assigns = {})
|
149
|
+
assigns = '<% ' << local_assigns.keys.map { |var|
|
150
|
+
"#{var} = local_assigns[#{var.inspect}]"
|
151
|
+
}.join("\n") << " %>\n" unless local_assigns.empty?
|
152
|
+
|
153
|
+
::ERB.new("#{assigns}#{content}").result(binding)
|
150
154
|
end
|
151
155
|
|
152
156
|
module Helpers
|
153
157
|
|
154
158
|
# call-seq:
|
155
159
|
# include_file file => aString
|
160
|
+
# include_file file, local_assigns => aString
|
156
161
|
#
|
157
162
|
# Includes file +file+ from <tt>_includes</tt> directory, or current
|
158
|
-
# directory if +
|
159
|
-
# optional +
|
160
|
-
def include_file(file,
|
161
|
-
|
162
|
-
|
163
|
-
Dir.chdir(File.join(site.source, dir)) {
|
164
|
-
@choices ||= Hash.new { |h, k|
|
165
|
-
h[k] = Dir['**/*'].reject { |x| File.symlink?(x) }
|
166
|
-
}
|
167
|
-
|
168
|
-
if @choices[dir].include?(file = file.strip)
|
169
|
-
render(File.read(file), binding)
|
170
|
-
else
|
171
|
-
"[Included file `#{file}' not found in `#{dir}'.]"
|
172
|
-
end
|
163
|
+
# directory if +file+ starts with <tt>./</tt>, rendered as ERB template.
|
164
|
+
# Passes optional +local_assigns+ on to #render.
|
165
|
+
def include_file(file, local_assigns = {})
|
166
|
+
@templates ||= Hash.new { |h, k|
|
167
|
+
h[k] = File.readable?(k) && File.read(k)
|
173
168
|
}
|
169
|
+
|
170
|
+
dir = file =~ /\A\.\// ? File.dirname(page.url) : '_includes'
|
171
|
+
|
172
|
+
if template = @templates[File.join(site.source, dir, file)]
|
173
|
+
render(template, local_assigns)
|
174
|
+
else
|
175
|
+
"[Included file `#{file}' not found in `#{dir}'.]"
|
176
|
+
end
|
174
177
|
end
|
175
178
|
|
176
179
|
# call-seq:
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-rendering
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jens Wille
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-29 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|