sinatra-erb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ == 1.0.0 / 2008-01-31
2
+
3
+ * 1 major enhancement
4
+ * Birthday!
5
+
@@ -0,0 +1,9 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/sinatra/renderer/erb.rb
6
+ lib/version.rb
7
+ test/test_sinatra_erb_renderer.rb
8
+ test/views/foo.erb
9
+ test/views/layout.erb
@@ -0,0 +1,49 @@
1
+ ErbSinatraRenderer
2
+ http://codebrulee.rubyforge.org
3
+ by kevin smith
4
+
5
+ == DESCRIPTION:
6
+
7
+ An Erb renderer for the Sinatra (http://sinatra.rubyforge.org) web framework.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * Supports all the rendering features of Sinatra
12
+
13
+ == SYNOPSIS:
14
+
15
+ require 'haml_sinatra_renderer'
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * Sinatra
20
+ * Erb
21
+
22
+ == INSTALL:
23
+
24
+ * sudo gem install sinatra-erb
25
+
26
+ == LICENSE:
27
+
28
+ (The MIT License)
29
+
30
+ Copyright (c) 2008
31
+
32
+ Permission is hereby granted, free of charge, to any person obtaining
33
+ a copy of this software and associated documentation files (the
34
+ 'Software'), to deal in the Software without restriction, including
35
+ without limitation the rights to use, copy, modify, merge, publish,
36
+ distribute, sublicense, and/or sell copies of the Software, and to
37
+ permit persons to whom the Software is furnished to do so, subject to
38
+ the following conditions:
39
+
40
+ The above copyright notice and this permission notice shall be
41
+ included in all copies or substantial portions of the Software.
42
+
43
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
44
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
45
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
46
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
47
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
48
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
49
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,16 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/version.rb'
6
+
7
+ Hoe.new('sinatra-erb', ErbSinatraRenderer::VERSION) do |p|
8
+ p.rubyforge_name = 'codebrulee'
9
+ p.author = 'kevin smith'
10
+ p.email = 'kevin@codebrulee.com'
11
+ p.summary = 'An Erb renderer for Sinatra'
12
+ p.description = p.summary
13
+ p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
14
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
15
+ p.extra_deps = {"sinatra" => "> 0.1.7"}
16
+ end
@@ -0,0 +1,23 @@
1
+ module Sinatra
2
+ module Erb
3
+ def erb(template, options = {})
4
+ Renderer.new.render(template,options)
5
+ end
6
+
7
+ class Renderer
8
+ require 'erb'
9
+ include Sinatra::RenderingHelpers
10
+
11
+ def ext
12
+ :erb
13
+ end
14
+ alias :erb :render # so that we can render partials w/ the erb method
15
+
16
+ private
17
+ def _evaluate_render(template, options={})
18
+ ERB.new(template).result(binding)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ Sinatra::EventContext.send(:include, Sinatra::Erb)
@@ -0,0 +1,3 @@
1
+ class ErbSinatraRenderer
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,77 @@
1
+ require "sinatra/test/helper"
2
+ require File.dirname(__FILE__) + "/../lib/sinatra/renderer/erb"
3
+
4
+ context "erb rendering" do
5
+
6
+ setup do
7
+ @layout = <<-LAYOUT_CODE
8
+ get '/inline_with_layout' do
9
+ erb "<div>erb! <%= 2 + 2 %></div>", options
10
+ end
11
+
12
+ get '/file_with_layout' do
13
+ erb :foo, options
14
+ end
15
+
16
+ get_it '/inline_with_layout'
17
+ should.be.ok
18
+ body.should.equal "<div><div>erb! 4</div></div>"
19
+
20
+ get_it '/file_with_layout'
21
+ should.be.ok
22
+ body.should.equal "<div><strong>hello erb! 4</strong></div>"
23
+ LAYOUT_CODE
24
+ end
25
+
26
+ specify "can render inline" do
27
+ get '/inline_erb' do
28
+ erb '<div>erb! <%= 2 + 2 %></div>'
29
+ end
30
+
31
+ get_it '/inline_erb'
32
+ should.be.ok
33
+ body.should.equal "<div>erb! 4</div>"
34
+ end
35
+
36
+ specify "can render from file" do
37
+ get '/file_erb' do
38
+ erb :foo, {:views_directory => File.dirname(__FILE__) + '/views'}
39
+ end
40
+
41
+ get_it '/file_erb'
42
+ should.be.ok
43
+ body.should.equal "<strong>hello erb! 4</strong>"
44
+ end
45
+
46
+ specify "can do partials" do
47
+ get '/partial_test' do
48
+ erb "<span><%= erb :foo %></span>", {:views_directory => File.dirname(__FILE__) + '/views'}
49
+ end
50
+
51
+ get_it '/partial_test'
52
+ should.be.ok
53
+ body.should.equal "<span><strong>hello erb! 4</strong></span>"
54
+ end
55
+
56
+
57
+ specify "can do file-based layout" do
58
+ options = {:views_directory => File.dirname(__FILE__) + '/views', :layout => :layout}
59
+ instance_eval(@layout)
60
+ end
61
+
62
+ specify "can do inline layout" do
63
+ options = {:views_directory => File.dirname(__FILE__) + '/views'}
64
+ layout do
65
+ %Q{<div><%= @content %></div>}
66
+ end
67
+ instance_eval(@layout)
68
+ end
69
+
70
+ specify "can do named layouts" do
71
+ options = {:views_directory => File.dirname(__FILE__) + '/views', :layout => :dude}
72
+ layout :dude do
73
+ %Q{<div><%= @content %></div>}
74
+ end
75
+ instance_eval(@layout)
76
+ end
77
+ end
@@ -0,0 +1 @@
1
+ <strong>hello erb! <%= 2 + 2 %></strong>
@@ -0,0 +1 @@
1
+ <div><%= @content %></div>
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-erb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kevin smith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-01-31 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sinatra
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">"
21
+ - !ruby/object:Gem::Version
22
+ version: 0.1.7
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: hoe
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 1.4.0
32
+ version:
33
+ description: An Erb renderer for Sinatra
34
+ email: kevin@codebrulee.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - History.txt
41
+ - Manifest.txt
42
+ - README.txt
43
+ files:
44
+ - History.txt
45
+ - Manifest.txt
46
+ - README.txt
47
+ - Rakefile
48
+ - lib/sinatra/renderer/erb.rb
49
+ - lib/version.rb
50
+ - test/test_sinatra_erb_renderer.rb
51
+ - test/views/foo.erb
52
+ - test/views/layout.erb
53
+ has_rdoc: true
54
+ homepage: http://codebrulee.rubyforge.org
55
+ post_install_message:
56
+ rdoc_options:
57
+ - --main
58
+ - README.txt
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ requirements: []
74
+
75
+ rubyforge_project: codebrulee
76
+ rubygems_version: 1.0.1
77
+ signing_key:
78
+ specification_version: 2
79
+ summary: An Erb renderer for Sinatra
80
+ test_files:
81
+ - test/test_sinatra_erb_renderer.rb