sinatra_fedora 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ =begin
2
+ sinatra_fedora.rb - Foundation of Sinatra/Fedora
3
+ *
4
+ * Copyright (c) 2011, Daniel Durante <officedebo at gmail dot com>
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions are met:
9
+ *
10
+ * * Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * * Redistributions in binary form must reproduce the above copyright
13
+ * notice, this list of conditions and the following disclaimer in the
14
+ * documentation and/or other materials provided with the distribution.
15
+ * * Neither the name of Redis nor the names of its contributors may be used
16
+ * to endorse or promote products derived from this software without
17
+ * specific prior written permission.
18
+ *
19
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ * POSSIBILITY OF SUCH DAMAGE.
30
+ =end
31
+
32
+ require File.join(File.dirname(__FILE__), 'sinatra_fedora', 'fedora')
@@ -0,0 +1,105 @@
1
+ =begin
2
+ fedora.rb - Sinatra::Fedora class
3
+ *
4
+ * Copyright (c) 2011, Daniel Durante <officedebo at gmail dot com>
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions are met:
9
+ *
10
+ * * Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * * Redistributions in binary form must reproduce the above copyright
13
+ * notice, this list of conditions and the following disclaimer in the
14
+ * documentation and/or other materials provided with the distribution.
15
+ * * Neither the name of Redis nor the names of its contributors may be used
16
+ * to endorse or promote products derived from this software without
17
+ * specific prior written permission.
18
+ *
19
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ * POSSIBILITY OF SUCH DAMAGE.
30
+ =end
31
+
32
+ require 'sinatra/base'
33
+
34
+ module Sinatra
35
+ module Templates
36
+ def render(engine, data, options={}, locals={}, &block)
37
+ # merge app-level options
38
+ options = settings.send(engine).merge(options) if settings.respond_to?(engine)
39
+ options[:outvar] ||= '@_out_buf'
40
+ options[:default_encoding] ||= settings.default_encoding
41
+
42
+ # extract generic options
43
+ locals = options.delete(:locals) || locals || {}
44
+ views = options.delete(:views) || settings.views || "./views"
45
+ @default_layout = :layout if @default_layout.nil?
46
+ layout = options.delete(:layout)
47
+ eat_errors = layout.nil?
48
+ layout = @default_layout if layout.nil? or layout == true
49
+ content_type = options.delete(:content_type) || options.delete(:default_content_type)
50
+ layout_engine = options.delete(:layout_engine) || engine
51
+ scope = options.delete(:scope) || self
52
+
53
+ # Fedora views
54
+ if data != :layout and options[:views_directory].nil?
55
+ look_in = (scope.class.name.downcase || scope.class.views_from) if scope.class.views_from.nil?
56
+ data = "#{look_in}/#{data.to_s}".to_sym
57
+ end
58
+
59
+ # compile and render template
60
+ layout_was = @default_layout
61
+ @default_layout = false
62
+ template = compile_template(engine, data, options, views)
63
+ output = template.render(scope, locals, &block)
64
+ @default_layout = layout_was
65
+
66
+ # render layout
67
+ if layout
68
+ options = options.merge(:views => views, :layout => false, :eat_errors => eat_errors, :scope => scope)
69
+ catch(:layout_missing) { return render(layout_engine, layout, options, locals) { output } }
70
+ end
71
+
72
+ output.extend(ContentTyped).content_type = content_type if content_type
73
+ output
74
+ end
75
+ end
76
+ end
77
+
78
+ class Fedora < Sinatra::Base
79
+ def self.inherited(klass)
80
+ super
81
+ descendents.push(klass)
82
+ end
83
+
84
+ def self.descendents
85
+ @descendents ||= []
86
+ end
87
+
88
+ def self.map
89
+ Hash[descendents.map { |d| [(d.namespace), d] }]
90
+ end
91
+
92
+ def self.views_from(value=nil)
93
+ return (@views_from || nil) if value.nil?
94
+ @views_from = value
95
+ end
96
+
97
+ def self.namespace(value=nil)
98
+ return (@namespace || "/#{name}") if value.nil?
99
+ @namespace = value
100
+ end
101
+
102
+ def self.url(value=nil)
103
+ self.namespace value
104
+ end
105
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra_fedora
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Durante
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-06-27 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sinatra
16
+ requirement: &5129610 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *5129610
25
+ description: Converts class names intro controllers and automatically maps them. Same
26
+ thing with views and both, views and controllers, can be configured to your liking.
27
+ It combines the best of both Padrino and Sinatra.
28
+ email: officedebo@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/sinatra_fedora.rb
34
+ - lib/sinatra_fedora/fedora.rb
35
+ homepage: https://github.com/dangerousdickdan/Sinatra_Fedora
36
+ licenses:
37
+ - MIT
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 1.8.5
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: An even classier way to use Sinatra.
60
+ test_files: []