jekyll-rendering 0.0.1 → 0.0.2

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,12 @@
1
1
  = Revision history for jekyll-rendering
2
2
 
3
+ == 0.0.2 [2010-07-01]
4
+
5
+ * Refactoring and documentation.
6
+ * Introduced Jekyll::Engine::Erb::Helpers module
7
+ * Provide aliases to original methods
8
+ * Credits.
9
+
3
10
  == 0.0.1 [2010-06-30]
4
11
 
5
12
  * Birthday :-)
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to jekyll-rendering version 0.0.1
5
+ This documentation refers to jekyll-rendering version 0.0.2
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -16,6 +16,11 @@ Add the following to your <tt>_plugins/ext.rb</tt> file:
16
16
  Then set +engine+ in your <tt>_config.yml</tt>. The default engine is +liquid+.
17
17
 
18
18
 
19
+ == TODO
20
+
21
+ * Automatic engine detection by file extension? (<tt><NAME>.<FORMAT>.<ENGINE></tt>)
22
+
23
+
19
24
  == LINKS
20
25
 
21
26
  <b></b>
@@ -29,6 +34,12 @@ RubyGem:: <http://rubygems.org/gems/jekyll-rendering>
29
34
  * Jens Wille <mailto:jens.wille@uni-koeln.de>
30
35
 
31
36
 
37
+ == CREDITS
38
+
39
+ * Arne Eilermann <mailto:arne.eilermann@uni-koeln.de> for the original idea
40
+ and implementation.
41
+
42
+
32
43
  == LICENSE AND COPYRIGHT
33
44
 
34
45
  Copyright (C) 2010 University of Cologne,
@@ -6,7 +6,7 @@ module Jekyll
6
6
 
7
7
  MAJOR = 0
8
8
  MINOR = 0
9
- TINY = 1
9
+ TINY = 2
10
10
 
11
11
  class << self
12
12
 
@@ -36,6 +36,9 @@ module Jekyll
36
36
 
37
37
  module Convertible
38
38
 
39
+ alias_method :_rendering_original_do_layout, :do_layout
40
+
41
+ # Overwrites the original method to use the configured rendering engine.
39
42
  def do_layout(payload, layouts)
40
43
  info = { :filters => [Jekyll::Filters], :registers => { :site => site } }
41
44
 
@@ -58,6 +61,11 @@ module Jekyll
58
61
  end
59
62
  end
60
63
 
64
+ # call-seq:
65
+ # engine => aClass
66
+ #
67
+ # Returns the Engine class according to the configuration setting for
68
+ # +engine+ (see subclasses of Engine::Base). Defaults to Engine::Liquid.
61
69
  def engine
62
70
  @engine ||= Engine[site.config['engine'] ||= 'liquid']
63
71
  end
@@ -66,12 +74,20 @@ module Jekyll
66
74
 
67
75
  module Engine
68
76
 
77
+ # call-seq:
78
+ # Engine[engine] => aClass
79
+ #
80
+ # Returns the subclass whose name corresponds to +engine+.
69
81
  def self.[](engine)
70
82
  const_get(engine.capitalize)
71
83
  end
72
84
 
73
85
  class Base
74
86
 
87
+ # call-seq:
88
+ # Engine::Base.render(*args)
89
+ #
90
+ # Renders the output. Defers to engine's render method.
75
91
  def self.render(payload, content, info, layout = nil)
76
92
  new(payload, content, info).render(layout || content)
77
93
  end
@@ -83,6 +99,10 @@ module Jekyll
83
99
  @payload, @content, @info = payload, content, info
84
100
  end
85
101
 
102
+ # call-seq:
103
+ # render
104
+ #
105
+ # Renders the output. Must be implemented by subclass.
86
106
  def render
87
107
  raise NotImplementedError
88
108
  end
@@ -91,6 +111,12 @@ module Jekyll
91
111
 
92
112
  class Liquid < Base
93
113
 
114
+ # call-seq:
115
+ # engine.render
116
+ # engine.render(content)
117
+ #
118
+ # Renders the +content+ using ::Liquid::Template::parse and then
119
+ # calling ::Liquid::Template#render with +payload+ and +info+.
94
120
  def render(content = content)
95
121
  ::Liquid::Template.parse(content).render(payload, info)
96
122
  end
@@ -104,7 +130,7 @@ module Jekyll
104
130
  def initialize(*args)
105
131
  super
106
132
 
107
- info[:filters].each { |filter| extend filter }
133
+ [Helpers, *info[:filters]].each { |mod| extend mod }
108
134
 
109
135
  %w[site page paginator].each { |key|
110
136
  value = payload[key] or next
@@ -112,58 +138,81 @@ module Jekyll
112
138
  }
113
139
  end
114
140
 
141
+ # call-seq:
142
+ # engine.render => aString
143
+ # engine.render(content) => aString
144
+ # engine.render(content, binding) => aString
145
+ #
146
+ # Renders the +content+ as ERB template. Uses optional +binding+
147
+ # if provided.
115
148
  def render(content = content, binding = binding)
116
149
  ::ERB.new(content).result(binding)
117
150
  end
118
151
 
119
- def include_file(file, binding = binding)
120
- Dir.chdir(File.join(site.source, '_includes')) {
121
- @choices ||= Dir['**/*'].reject { |x| File.symlink?(x) }
152
+ module Helpers
153
+
154
+ # call-seq:
155
+ # include_file file => aString
156
+ # include_file file, binding => aString
157
+ #
158
+ # Includes file +file+ from <tt>_includes</tt> directory rendered
159
+ # as ERB template. Uses optional +binding+ if provided.
160
+ def include_file(file, binding = binding)
161
+ Dir.chdir(File.join(site.source, '_includes')) {
162
+ @choices ||= Dir['**/*'].reject { |x| File.symlink?(x) }
163
+
164
+ if @choices.include?(file = file.strip)
165
+ render(File.read(file), binding)
166
+ else
167
+ "Included file '#{file}' not found in _includes directory"
168
+ end
169
+ }
170
+ end
122
171
 
123
- if @choices.include?(file = file.strip)
124
- render(File.read(file), binding)
172
+ # call-seq:
173
+ # highlight text => aString
174
+ # highlight text, lang => aString
175
+ #
176
+ # Highlights +text+ according to +lang+ (defaults to Ruby).
177
+ def highlight(text, lang = :ruby)
178
+ if site.pygments
179
+ render_pygments(text, lang)
125
180
  else
126
- "Included file '#{file}' not found in _includes directory"
181
+ render_codehighlighter(text, lang)
127
182
  end
128
- }
129
- end
130
-
131
- def highlight(text, lang = :ruby)
132
- if site.pygments
133
- render_pygments(text, lang)
134
- else
135
- render_codehighlighter(text, lang)
136
183
  end
137
- end
138
184
 
139
- protected
185
+ protected
140
186
 
141
- def render_pygments(text, lang)
142
- output = add_code_tags(Albino.new(text, lang).to_s, lang)
143
- "#{payload['pygments_prefix']}#{output}#{payload['pygments_suffix']}"
144
- end
187
+ def render_pygments(text, lang)
188
+ output = add_code_tags(Albino.new(text, lang).to_s, lang)
189
+ "#{payload['pygments_prefix']}#{output}#{payload['pygments_suffix']}"
190
+ end
145
191
 
146
- def render_codehighlighter(text, lang)
147
- #The div is required because RDiscount blows ass
148
- <<-HTML
149
- <div>
150
- <pre>
151
- <code class="#{lang}">#{h(text).strip}</code>
152
- </pre>
153
- </div>
154
- HTML
155
- end
192
+ def render_codehighlighter(text, lang)
193
+ #The div is required because RDiscount blows ass
194
+ <<-HTML
195
+ <div>
196
+ <pre>
197
+ <code class="#{lang}">#{h(text).strip}</code>
198
+ </pre>
199
+ </div>
200
+ HTML
201
+ end
202
+
203
+ def add_code_tags(code, lang)
204
+ # Add nested <code> tags to code blocks
205
+ code.sub(%r{<pre>}, %Q{<pre><code class="#{lang}">}).
206
+ sub(%r{</pre>}, %q{</code></pre>})
207
+ end
156
208
 
157
- def add_code_tags(code, lang)
158
- # Add nested <code> tags to code blocks
159
- code.sub(%r{<pre>}, %Q{<pre><code class="#{lang}">}).
160
- sub(%r{</pre>}, %q{</code></pre>})
161
209
  end
162
210
 
163
211
  end
164
212
 
165
213
  end
166
214
 
215
+ # Provide an engine-agnostic name for the hash representation.
167
216
  [Post, Page, Pager].each { |klass|
168
217
  klass.send(:alias_method, :to_hash, :to_liquid)
169
218
  }
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: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
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-06-30 00:00:00 +02:00
18
+ date: 2010-07-01 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21