sinatra-default-templates 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2010 Julio Cesar Ody
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # sinatra-default-templates
2
+
3
+ To avoid repetitive routes like
4
+
5
+ get '/foo' do
6
+ haml :foo
7
+ end
8
+
9
+ get '/bar' do
10
+ haml :bar
11
+ end
12
+
13
+ if you have the templates in place (views/foo.haml, views/bar.haml in the above case), they'll get
14
+ rendered automagically.
15
+
16
+ # How to use
17
+
18
+ Because of a bug in Sinatra 0.9.4, extensions cannot set routes, or for that matter, define
19
+ not_found or error blocks. And since I decided to turn this into one, you'll have to use
20
+ Sinatra 1.0.a (or above). In which case, simply:
21
+
22
+ require 'sinatra'
23
+ require 'sinatra/default_templates'
24
+
25
+ And you're set.
26
+
27
+ # Specs
28
+
29
+ Just run
30
+
31
+ $ spec spec/default_templates_spec.rb
32
+
33
+ Presumes rspec 1.3.0 is installed.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,26 @@
1
+ require 'sinatra/base'
2
+
3
+ module Sinatra
4
+ module DefaultTemplates
5
+
6
+ module Helpers
7
+ def render_template_if_exists!
8
+ name = File.basename(request.path)
9
+ Dir["#{options.views}/#{name}.*"].each do |match|
10
+ @_format = File.extname(match).sub(/^./, '')
11
+ @_template = File.basename(match, File.extname(match))
12
+ end
13
+ eval("#{@_format} :#{@_template}") if @_format and @_template
14
+ end
15
+ end
16
+
17
+ def self.registered(app)
18
+ app.helpers DefaultTemplates::Helpers;
19
+
20
+ app.not_found do
21
+ render_template_if_exists!
22
+ end
23
+ end
24
+ end
25
+ register Sinatra::DefaultTemplates
26
+ end
@@ -0,0 +1,21 @@
1
+ require File.join(File.dirname(__FILE__), 'dummy')
2
+ gem 'rspec', '>= 1.3.0'; require 'spec'
3
+ gem 'rack-test', '>= 0.5.3'; require 'rack/test'
4
+ require 'spec/interop/test'
5
+
6
+ set :environment, :test
7
+ set :run, :false
8
+ set :logging, false
9
+
10
+ def app
11
+ @app ||= Sinatra::Application
12
+ end
13
+
14
+ describe 'a Sinatra app' do
15
+ include Rack::Test::Methods
16
+ it 'should render views/test.haml despite the absence of a get "/test" block if views/test.haml exists' do
17
+ get '/test'
18
+ last_response.body.should =~ /Buongiorno principessa!/
19
+ end
20
+ end
21
+
@@ -0,0 +1,7 @@
1
+ gem 'sinatra', '>= 1.0.a'; require 'sinatra'
2
+ gem 'haml', '>= 2.2.17'; require 'haml'
3
+
4
+ require File.join(File.dirname(__FILE__), *%w(.. lib sinatra default_templates))
5
+
6
+ # if views/test.haml exists, it'll get rendered
7
+ # regardless if there's an associated block or not
@@ -0,0 +1,2 @@
1
+ %p
2
+ Buongiorno principessa!
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-default-templates
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Julio Cesar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-09 00:00:00 +11:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sinatra
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.a
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rack-test
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.5.3
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: haml
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "="
52
+ - !ruby/object:Gem::Version
53
+ version: 2.2.17
54
+ version:
55
+ description: Saves you from having to write routes just to render templates with the same name. Rails-style.
56
+ email: julio.ody@gmail.com
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ extra_rdoc_files:
62
+ - LICENSE
63
+ files:
64
+ - Readme.txt
65
+ - VERSION
66
+ - lib/sinatra/default_templates.rb
67
+ - spec/default_templates_spec.rb
68
+ - spec/dummy.rb
69
+ - spec/views/test.haml
70
+ - LICENSE
71
+ has_rdoc: true
72
+ homepage: http://github.com/juliocesar/sinatra-default-templates
73
+ licenses: []
74
+
75
+ post_install_message:
76
+ rdoc_options:
77
+ - --charset=UTF-8
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ version:
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ version:
92
+ requirements: []
93
+
94
+ rubyforge_project:
95
+ rubygems_version: 1.3.5
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Render a template in the absence of a route if one exists
99
+ test_files:
100
+ - spec/default_templates_spec.rb
101
+ - spec/dummy.rb