Skip to content

Commit 90a0dcd

Browse files
author
Jason Fleetwood-Boldt
committed
html render first implementation
1 parent 64c6fe3 commit 90a0dcd

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

htmlrender-0.0.0.gem

4.5 KB
Binary file not shown.

htmlrender.gemspec

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Gem::Specification.new do |s|
2+
s.name = 'htmlrender'
3+
s.version = '0.0.0'
4+
s.date = '2014-08-06'
5+
s.summary = ""
6+
s.description = ""
7+
s.authors = ["Jason Fleetwood-Boldt"]
8+
s.email = '[email protected]'
9+
s.files = ["lib/htmlrender.rb"]
10+
s.homepage =
11+
'http://rubygems.org/gems/htmlrender'
12+
s.license = 'MIT'
13+
end

lib/htmlrender.rb

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module HtmlRender
2+
def render_html_content(*args, &block)
3+
temp_render_args = HtmlRender._normalized_args(*args, &block)
4+
temp_render_args[:formats] ||= []
5+
temp_render_args[:formats] += [:html] unless temp_render_args[:formats].include?(:html)
6+
7+
# declare so below reference is not block-local
8+
content = ""
9+
10+
_render_with_format :html do
11+
content = render_to_string(temp_render_args).html_safe
12+
end
13+
content
14+
end
15+
16+
def _render_with_format(format, &block)
17+
old_formats = formats
18+
self.formats = [format]
19+
block.call
20+
self.formats = old_formats
21+
nil
22+
end
23+
24+
class HtmlRender
25+
def self._normalized_args(action=nil, options={}, &blk) #:nodoc:
26+
case action
27+
when NilClass
28+
when Hash
29+
options = action
30+
when String, Symbol
31+
action = action.to_s
32+
key = action.include?(?/) ? :file : :action
33+
options[key] = action
34+
else
35+
options[:partial] = action
36+
end
37+
38+
options[:update] = blk if block_given?
39+
40+
options
41+
end
42+
end
43+
end

0 commit comments

Comments
 (0)