jekyll-rendering 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to jekyll-rendering version 0.0.4
5
+ This documentation refers to jekyll-rendering version 0.0.5
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -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, binding) => aString
144
+ # engine.render(content, local_assigns) => aString
145
145
  #
146
- # Renders the +content+ as ERB template. Uses optional +binding+
147
- # if provided.
148
- def render(content = content, binding = binding)
149
- ::ERB.new(content).result(binding)
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 +current+ is true, rendered as ERB template. Uses
159
- # optional +binding+ if provided.
160
- def include_file(file, current = false, binding = binding)
161
- dir = current ? File.dirname(page.url) : '_includes'
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:
@@ -6,7 +6,7 @@ module Jekyll
6
6
 
7
7
  MAJOR = 0
8
8
  MINOR = 0
9
- TINY = 4
9
+ TINY = 5
10
10
 
11
11
  class << self
12
12
 
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: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
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-01 00:00:00 +02:00
18
+ date: 2010-10-29 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21