contracto 0.0.1

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.
@@ -0,0 +1,34 @@
1
+ require 'sinatra/base'
2
+
3
+ module Sinatra
4
+ class Application < Base
5
+
6
+ # we assume that the first file that requires 'sinatra' is the
7
+ # app_file. all other path related options are calculated based
8
+ # on this path by default.
9
+ set :app_file, caller_files.first || $0
10
+
11
+ set :run, Proc.new { File.expand_path($0) == File.expand_path(app_file) }
12
+
13
+ if run? && ARGV.any?
14
+ require 'optparse'
15
+ OptionParser.new { |op|
16
+ op.on('-p port', 'set the port (default is 4567)') { |val| set :port, Integer(val) }
17
+ op.on('-o addr', "set the host (default is #{bind})") { |val| set :bind, val }
18
+ op.on('-e env', 'set the environment (default is development)') { |val| set :environment, val.to_sym }
19
+ op.on('-s server', 'specify rack server/handler (default is thin)') { |val| set :server, val }
20
+ op.on('-x', 'turn on the mutex lock (default is off)') { set :lock, true }
21
+ }.parse!(ARGV.dup)
22
+ end
23
+ end
24
+
25
+ at_exit { Application.run! if $!.nil? && Application.run? }
26
+ end
27
+
28
+ # include would include the module in Object
29
+ # extend only extends the `main` object
30
+ extend Sinatra::Delegator
31
+
32
+ class Rack::Builder
33
+ include Sinatra::Delegator
34
+ end
@@ -0,0 +1,345 @@
1
+ require 'rack/showexceptions'
2
+
3
+ module Sinatra
4
+ # Sinatra::ShowExceptions catches all exceptions raised from the app it
5
+ # wraps. It shows a useful backtrace with the sourcefile and clickable
6
+ # context, the whole Rack environment and the request data.
7
+ #
8
+ # Be careful when you use this on public-facing sites as it could reveal
9
+ # information helpful to attackers.
10
+ class ShowExceptions < Rack::ShowExceptions
11
+ @@eats_errors = Object.new
12
+ def @@eats_errors.flush(*) end
13
+ def @@eats_errors.puts(*) end
14
+
15
+ def initialize(app)
16
+ @app = app
17
+ @template = ERB.new(TEMPLATE)
18
+ end
19
+
20
+ def call(env)
21
+ @app.call(env)
22
+ rescue Exception => e
23
+ errors, env["rack.errors"] = env["rack.errors"], @@eats_errors
24
+
25
+ if prefers_plain_text?(env)
26
+ content_type = "text/plain"
27
+ body = [dump_exception(e)]
28
+ else
29
+ content_type = "text/html"
30
+ body = pretty(env, e)
31
+ end
32
+
33
+ env["rack.errors"] = errors
34
+
35
+ [500,
36
+ {"Content-Type" => content_type,
37
+ "Content-Length" => Rack::Utils.bytesize(body.join).to_s},
38
+ body]
39
+ end
40
+
41
+ private
42
+
43
+ def prefers_plain_text?(env)
44
+ !(Request.new(env).preferred_type("text/plain","text/html") == "text/html") &&
45
+ [/curl/].index{|item| item =~ env["HTTP_USER_AGENT"]}
46
+ end
47
+
48
+ def frame_class(frame)
49
+ if frame.filename =~ /lib\/sinatra.*\.rb/
50
+ "framework"
51
+ elsif (defined?(Gem) && frame.filename.include?(Gem.dir)) ||
52
+ frame.filename =~ /\/bin\/(\w+)$/
53
+ "system"
54
+ else
55
+ "app"
56
+ end
57
+ end
58
+
59
+ TEMPLATE = <<-HTML # :nodoc:
60
+ <!DOCTYPE html>
61
+ <html>
62
+ <head>
63
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
64
+ <title><%=h exception.class %> at <%=h path %></title>
65
+
66
+ <script type="text/javascript">
67
+ //<!--
68
+ function toggle(id) {
69
+ var pre = document.getElementById("pre-" + id);
70
+ var post = document.getElementById("post-" + id);
71
+ var context = document.getElementById("context-" + id);
72
+
73
+ if (pre.style.display == 'block') {
74
+ pre.style.display = 'none';
75
+ post.style.display = 'none';
76
+ context.style.background = "none";
77
+ } else {
78
+ pre.style.display = 'block';
79
+ post.style.display = 'block';
80
+ context.style.background = "#fffed9";
81
+ }
82
+ }
83
+
84
+ function toggleBacktrace(){
85
+ var bt = document.getElementById("backtrace");
86
+ var toggler = document.getElementById("expando");
87
+
88
+ if (bt.className == 'condensed') {
89
+ bt.className = 'expanded';
90
+ toggler.innerHTML = "(condense)";
91
+ } else {
92
+ bt.className = 'condensed';
93
+ toggler.innerHTML = "(expand)";
94
+ }
95
+ }
96
+ //-->
97
+ </script>
98
+
99
+ <style type="text/css" media="screen">
100
+ * {margin: 0; padding: 0; border: 0; outline: 0;}
101
+ div.clear {clear: both;}
102
+ body {background: #EEEEEE; margin: 0; padding: 0;
103
+ font-family: 'Lucida Grande', 'Lucida Sans Unicode',
104
+ 'Garuda';}
105
+ code {font-family: 'Lucida Console', monospace;
106
+ font-size: 12px;}
107
+ li {height: 18px;}
108
+ ul {list-style: none; margin: 0; padding: 0;}
109
+ ol:hover {cursor: pointer;}
110
+ ol li {white-space: pre;}
111
+ #explanation {font-size: 12px; color: #666666;
112
+ margin: 20px 0 0 100px;}
113
+ /* WRAP */
114
+ #wrap {width: 1000px; background: #FFFFFF; margin: 0 auto;
115
+ padding: 30px 50px 20px 50px;
116
+ border-left: 1px solid #DDDDDD;
117
+ border-right: 1px solid #DDDDDD;}
118
+ /* HEADER */
119
+ #header {margin: 0 auto 25px auto;}
120
+ #header img {float: left;}
121
+ #header #summary {float: left; margin: 12px 0 0 20px; width:660px;
122
+ font-family: 'Lucida Grande', 'Lucida Sans Unicode';}
123
+ h1 {margin: 0; font-size: 36px; color: #981919;}
124
+ h2 {margin: 0; font-size: 22px; color: #333333;}
125
+ #header ul {margin: 0; font-size: 12px; color: #666666;}
126
+ #header ul li strong{color: #444444;}
127
+ #header ul li {display: inline; padding: 0 10px;}
128
+ #header ul li.first {padding-left: 0;}
129
+ #header ul li.last {border: 0; padding-right: 0;}
130
+ /* BODY */
131
+ #backtrace,
132
+ #get,
133
+ #post,
134
+ #cookies,
135
+ #rack {width: 980px; margin: 0 auto 10px auto;}
136
+ p#nav {float: right; font-size: 14px;}
137
+ /* BACKTRACE */
138
+ a#expando {float: left; padding-left: 5px; color: #666666;
139
+ font-size: 14px; text-decoration: none; cursor: pointer;}
140
+ a#expando:hover {text-decoration: underline;}
141
+ h3 {float: left; width: 100px; margin-bottom: 10px;
142
+ color: #981919; font-size: 14px; font-weight: bold;}
143
+ #nav a {color: #666666; text-decoration: none; padding: 0 5px;}
144
+ #backtrace li.frame-info {background: #f7f7f7; padding-left: 10px;
145
+ font-size: 12px; color: #333333;}
146
+ #backtrace ul {list-style-position: outside; border: 1px solid #E9E9E9;
147
+ border-bottom: 0;}
148
+ #backtrace ol {width: 920px; margin-left: 50px;
149
+ font: 10px 'Lucida Console', monospace; color: #666666;}
150
+ #backtrace ol li {border: 0; border-left: 1px solid #E9E9E9;
151
+ padding: 2px 0;}
152
+ #backtrace ol code {font-size: 10px; color: #555555; padding-left: 5px;}
153
+ #backtrace-ul li {border-bottom: 1px solid #E9E9E9; height: auto;
154
+ padding: 3px 0;}
155
+ #backtrace-ul .code {padding: 6px 0 4px 0;}
156
+ #backtrace.condensed .system,
157
+ #backtrace.condensed .framework {display:none;}
158
+ /* REQUEST DATA */
159
+ p.no-data {padding-top: 2px; font-size: 12px; color: #666666;}
160
+ table.req {width: 980px; text-align: left; font-size: 12px;
161
+ color: #666666; padding: 0; border-spacing: 0;
162
+ border: 1px solid #EEEEEE; border-bottom: 0;
163
+ border-left: 0;
164
+ clear:both}
165
+ table.req tr th {padding: 2px 10px; font-weight: bold;
166
+ background: #F7F7F7; border-bottom: 1px solid #EEEEEE;
167
+ border-left: 1px solid #EEEEEE;}
168
+ table.req tr td {padding: 2px 20px 2px 10px;
169
+ border-bottom: 1px solid #EEEEEE;
170
+ border-left: 1px solid #EEEEEE;}
171
+ /* HIDE PRE/POST CODE AT START */
172
+ .pre-context,
173
+ .post-context {display: none;}
174
+
175
+ table td.code {width:750px}
176
+ table td.code div {width:750px;overflow:hidden}
177
+ </style>
178
+ </head>
179
+ <body>
180
+ <div id="wrap">
181
+ <div id="header">
182
+ <img src="<%= env['SCRIPT_NAME'] %>/__sinatra__/500.png" alt="application error" height="161" width="313" />
183
+ <div id="summary">
184
+ <h1><strong><%=h exception.class %></strong> at <strong><%=h path %>
185
+ </strong></h1>
186
+ <h2><%=h exception.message %></h2>
187
+ <ul>
188
+ <li class="first"><strong>file:</strong> <code>
189
+ <%=h frames.first.filename.split("/").last %></code></li>
190
+ <li><strong>location:</strong> <code><%=h frames.first.function %>
191
+ </code></li>
192
+ <li class="last"><strong>line:
193
+ </strong> <%=h frames.first.lineno %></li>
194
+ </ul>
195
+ </div>
196
+ <div class="clear"></div>
197
+ </div>
198
+
199
+ <div id="backtrace" class='condensed'>
200
+ <h3>BACKTRACE</h3>
201
+ <p><a href="#" id="expando"
202
+ onclick="toggleBacktrace(); return false">(expand)</a></p>
203
+ <p id="nav"><strong>JUMP TO:</strong>
204
+ <a href="#get-info">GET</a>
205
+ <a href="#post-info">POST</a>
206
+ <a href="#cookie-info">COOKIES</a>
207
+ <a href="#env-info">ENV</a>
208
+ </p>
209
+ <div class="clear"></div>
210
+
211
+ <ul id="backtrace-ul">
212
+
213
+ <% id = 1 %>
214
+ <% frames.each do |frame| %>
215
+ <% if frame.context_line && frame.context_line != "#" %>
216
+
217
+ <li class="frame-info <%= frame_class(frame) %>">
218
+ <code><%=h frame.filename %></code> in
219
+ <code><strong><%=h frame.function %></strong></code>
220
+ </li>
221
+
222
+ <li class="code <%= frame_class(frame) %>">
223
+ <% if frame.pre_context %>
224
+ <ol start="<%=h frame.pre_context_lineno + 1 %>"
225
+ class="pre-context" id="pre-<%= id %>"
226
+ onclick="toggle(<%= id %>);">
227
+ <% frame.pre_context.each do |line| %>
228
+ <li class="pre-context-line"><code><%=h line %></code></li>
229
+ <% end %>
230
+ </ol>
231
+ <% end %>
232
+
233
+ <ol start="<%= frame.lineno %>" class="context" id="<%= id %>"
234
+ onclick="toggle(<%= id %>);">
235
+ <li class="context-line" id="context-<%= id %>"><code><%=
236
+ h frame.context_line %></code></li>
237
+ </ol>
238
+
239
+ <% if frame.post_context %>
240
+ <ol start="<%=h frame.lineno + 1 %>" class="post-context"
241
+ id="post-<%= id %>" onclick="toggle(<%= id %>);">
242
+ <% frame.post_context.each do |line| %>
243
+ <li class="post-context-line"><code><%=h line %></code></li>
244
+ <% end %>
245
+ </ol>
246
+ <% end %>
247
+ <div class="clear"></div>
248
+ </li>
249
+
250
+ <% end %>
251
+
252
+ <% id += 1 %>
253
+ <% end %>
254
+
255
+ </ul>
256
+ </div> <!-- /BACKTRACE -->
257
+
258
+ <div id="get">
259
+ <h3 id="get-info">GET</h3>
260
+ <% if req.GET and not req.GET.empty? %>
261
+ <table class="req">
262
+ <tr>
263
+ <th>Variable</th>
264
+ <th>Value</th>
265
+ </tr>
266
+ <% req.GET.sort_by { |k, v| k.to_s }.each { |key, val| %>
267
+ <tr>
268
+ <td><%=h key %></td>
269
+ <td class="code"><div><%=h val.inspect %></div></td>
270
+ </tr>
271
+ <% } %>
272
+ </table>
273
+ <% else %>
274
+ <p class="no-data">No GET data.</p>
275
+ <% end %>
276
+ <div class="clear"></div>
277
+ </div> <!-- /GET -->
278
+
279
+ <div id="post">
280
+ <h3 id="post-info">POST</h3>
281
+ <% if req.POST and not req.POST.empty? %>
282
+ <table class="req">
283
+ <tr>
284
+ <th>Variable</th>
285
+ <th>Value</th>
286
+ </tr>
287
+ <% req.POST.sort_by { |k, v| k.to_s }.each { |key, val| %>
288
+ <tr>
289
+ <td><%=h key %></td>
290
+ <td class="code"><div><%=h val.inspect %></div></td>
291
+ </tr>
292
+ <% } %>
293
+ </table>
294
+ <% else %>
295
+ <p class="no-data">No POST data.</p>
296
+ <% end %>
297
+ <div class="clear"></div>
298
+ </div> <!-- /POST -->
299
+
300
+ <div id="cookies">
301
+ <h3 id="cookie-info">COOKIES</h3>
302
+ <% unless req.cookies.empty? %>
303
+ <table class="req">
304
+ <tr>
305
+ <th>Variable</th>
306
+ <th>Value</th>
307
+ </tr>
308
+ <% req.cookies.each { |key, val| %>
309
+ <tr>
310
+ <td><%=h key %></td>
311
+ <td class="code"><div><%=h val.inspect %></div></td>
312
+ </tr>
313
+ <% } %>
314
+ </table>
315
+ <% else %>
316
+ <p class="no-data">No cookie data.</p>
317
+ <% end %>
318
+ <div class="clear"></div>
319
+ </div> <!-- /COOKIES -->
320
+
321
+ <div id="rack">
322
+ <h3 id="env-info">Rack ENV</h3>
323
+ <table class="req">
324
+ <tr>
325
+ <th>Variable</th>
326
+ <th>Value</th>
327
+ </tr>
328
+ <% env.sort_by { |k, v| k.to_s }.each { |key, val| %>
329
+ <tr>
330
+ <td><%=h key %></td>
331
+ <td class="code"><div><%=h val %></div></td>
332
+ </tr>
333
+ <% } %>
334
+ </table>
335
+ <div class="clear"></div>
336
+ </div> <!-- /RACK ENV -->
337
+
338
+ <p id="explanation">You're seeing this error because you have
339
+ enabled the <code>show_exceptions</code> setting.</p>
340
+ </div> <!-- /WRAP -->
341
+ </body>
342
+ </html>
343
+ HTML
344
+ end
345
+ end
@@ -0,0 +1,3 @@
1
+ module Sinatra
2
+ VERSION = '1.4.5'
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'sinatra/base'
2
+ require 'sinatra/main'
3
+
4
+ enable :inline_templates
@@ -0,0 +1,3 @@
1
+ module Contracto
2
+ VERSION = "0.0.1"
3
+ end
data/lib/contracto.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "contracto/version"
2
+
3
+ module Contracto
4
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: contracto
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kacper Walanus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: XXX
56
+ email:
57
+ - kacper@walanus.com
58
+ executables:
59
+ - contracto
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/contracto
69
+ - contracto.gemspec
70
+ - lib/contracto.rb
71
+ - lib/contracto/command.rb
72
+ - lib/contracto/server/ruby/config.ru
73
+ - lib/contracto/server/ruby/contract.cdc.rb
74
+ - lib/contracto/server/ruby/server.rb
75
+ - lib/contracto/server/ruby/sinatra-1.4.5/lib/sinatra.rb
76
+ - lib/contracto/server/ruby/sinatra-1.4.5/lib/sinatra/base.rb
77
+ - lib/contracto/server/ruby/sinatra-1.4.5/lib/sinatra/main.rb
78
+ - lib/contracto/server/ruby/sinatra-1.4.5/lib/sinatra/show_exceptions.rb
79
+ - lib/contracto/server/ruby/sinatra-1.4.5/lib/sinatra/version.rb
80
+ - lib/contracto/version.rb
81
+ homepage: ''
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.4.6
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: XXX
105
+ test_files: []