sinatra-web-inspector 0.4.0.a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +29 -0
  2. data/lib/sinatra/web_inspector.rb +180 -0
  3. metadata +101 -0
@@ -0,0 +1,29 @@
1
+ Sinatra::WebInspector
2
+ =====================
3
+
4
+ The WebInspector allowes you to inspect a running [Sinatra](http://sinatrarb.com) app.
5
+ Just browse http://localhost:4567/\_\_inspect\_\_
6
+
7
+ When used with BigBand, it will – per default – only be activated in development mode.
8
+
9
+ BigBand
10
+ -------
11
+
12
+ Sinatra::WebInspector is part of the [BigBand](http://github.com/rkh/big_band) stack.
13
+ Check it out if you are looking for other fancy Sinatra extensions.
14
+
15
+ Usage
16
+ -----
17
+
18
+ Classic style:
19
+
20
+ require "sinatra"
21
+ configure(:development) { require "sinatra/webinspector" }
22
+
23
+ Modular style:
24
+
25
+ require "sinatra/base"
26
+ require "sinatra/webinspector"
27
+ class Foo < Sintra::Base
28
+ configure(:development) { register Sintra::WebInspector }
29
+ end
@@ -0,0 +1,180 @@
1
+ require "sinatra/base"
2
+ require "sinatra/sugar"
3
+ require "sinatra/compass"
4
+ require "haml"
5
+ require "monkey"
6
+
7
+ module Sinatra
8
+
9
+ # The WebInspector allowes you to inspect a running Sinatra app.
10
+ # Just browse http://localhost:4567/\_\_inspect\_\_
11
+ module WebInspector
12
+
13
+ attr_reader :middleware
14
+
15
+ class Middleware < Sinatra::Base
16
+
17
+ attr_accessor :sinatra_app
18
+ use_in_file_templates! __FILE__
19
+ register BasicExtensions
20
+ set :app_file, __FILE__
21
+
22
+ # If this is a git project, then it returns the path to the .git directory.
23
+ def git_directory
24
+ @git_directory ||= root_glob(".{,.,./..,./../..}/.git").first
25
+ end
26
+
27
+ # Whether or not this is a git project.
28
+ def git?
29
+ !!git_directory
30
+ end
31
+
32
+ # Figures out some URLs to public git hosts by parsing the remote urls from the git config.
33
+ # Currently detects: GitHub, Codaset and Gitorious.
34
+ def git_remotes
35
+ @git_remotes ||= (File.read(git_directory / :config).scan(/\s*url\s*=\s*(.*)\n/).flatten.collect do |url|
36
+ case url
37
+ when %r{(github.com)[:/](.+)/(.+)/?\.git$} then [$3, "GitHub", "http://#$1/#$2/#$3", "http://#$1"]
38
+ when %r{(codaset.com)[:/](.+)/(.+)?\.git$} then [$3, "Codaset", "http://#$1/#$2/#$3", "http://#$1"]
39
+ when %r{(gitorious.org)[:/](.+)/.+/?\.git$} then [$2, "Gitorious", "http://#$1/#$2", "http://#$1"]
40
+ end
41
+ end).compact
42
+ end
43
+
44
+ # Recent git log.
45
+ def git_log
46
+ @git_format ||= begin
47
+ line = ["<a href='mailto:%ae'>%an</a>", "%s", "<date>%ai</date>"].map { |e| "<td>#{e}</td>" }.join
48
+ "<tr>#{line}</tr>"
49
+ end
50
+ %x[git log -50 --pretty=format:"#{@git_format}"]
51
+ end
52
+
53
+ # webinspector stylesheet.
54
+ get "/__inspect__/screen.css" do
55
+ content_type 'text/css', :charset => 'utf-8'
56
+ sass :stylesheet, ::Compass.sass_engine_options
57
+ end
58
+
59
+ # Route for inspection. Currently we display all information on a single page. In case the amount of data
60
+ # increases, we might split this on multiple pages. Also, this would ease hooking own data into the front-end.
61
+ get "/__inspect__/?" do
62
+ ruby_env = %w[RUBY_VERSION RUBY_DESCRIPTION RUBY_PATCHLEVEL RUBY_PLATFORM RUBY_ENGINE RUBY_ENGINE_VERSION]
63
+ ruby_env.map! { |var| [var, eval("#{var}.inspect if defined? #{var}")] }
64
+ haml :inspect, {}, :ruby_env => ruby_env
65
+ end
66
+
67
+ end
68
+
69
+ def self.registered(klass)
70
+ klass.register Sugar
71
+ klass.register AdvancedRoutes
72
+ klass.use(Middleware) { |m| m.sinatra_app = klass }
73
+ end
74
+
75
+ end
76
+
77
+ register WebInspector
78
+
79
+ end
80
+
81
+ __END__
82
+
83
+ @@layout
84
+ !!!
85
+ %html
86
+ %head
87
+ %meta{:charset=>"utf-8"}/
88
+ %link{:rel => "stylesheet", :href => "/__inspect__/screen.css", :type => "text/css"}/
89
+ %title= "#{sinatra_app.name}.inspect"
90
+ %body
91
+ %header
92
+ %h1= "#{sinatra_app.name}.inspect"
93
+ Generated on
94
+ %date= Time.now
95
+ %nav
96
+ %a{:href => "/__inspect__/#routes" } Routes
97
+ %a{:href => "/__inspect__/#extensions" } Extensions
98
+ %a{:href => "/__inspect__/#middleware" } Middleware
99
+ %a{:href => "/__inspect__/#system" } System
100
+ - if git?
101
+ %a{:href => "/__inspect__/#git_log" } Git Log
102
+ %article
103
+ !=yield
104
+ %footer
105
+ powered by
106
+ %a{:href => "http://www.sinatrarb.com"} Sinatra
107
+ and
108
+ %a{:href => "http://github.com/rkh/big_band"} BigBand
109
+
110
+ @@stylesheet
111
+
112
+
113
+ @@inspect
114
+
115
+ %a{ :name => "routes" }
116
+ %h2 Routes
117
+ %table
118
+ %tr
119
+ %th Verb
120
+ %th Pattern
121
+ %th File
122
+ %th Keys
123
+ %th Conditions
124
+ - sinatra_app.each_route do |route|
125
+ %tr
126
+ %td= route.verb
127
+ %td= route.pattern.inspect
128
+ %td
129
+ - if route.file?
130
+ = route.file
131
+ %i= "(line #{route.line})" if route.line
132
+ %td= route.keys.map { |e| e.inspect }.join ", "
133
+ %td= route.conditions.map { |e| e.inspect }.join ", "
134
+
135
+ %a{ :name => "extensions" }
136
+ %h2 Extensions
137
+ %table
138
+ %tr
139
+ %th Extension
140
+ %th Status
141
+ - sinatra_app.extensions.each do |extension|
142
+ %tr
143
+ %td= extension.name
144
+ %td= extension.status if extension.respond_to? :status
145
+
146
+ %a{ :name => "middleware" }
147
+ %h2 Middleware
148
+ %table
149
+ %tr
150
+ %th Middleware
151
+ %th Arguments
152
+ %th Block Given
153
+ - sinatra_app.middleware.each do |name, arguments, block|
154
+ %tr
155
+ %td= name
156
+ %td= arguments.map { |e| e.inspect }.join ", "
157
+ %td= block ? "yes" : "no"
158
+
159
+ %a{ :name => "system" }
160
+ %h2 System
161
+ %table
162
+ %tr
163
+ %th Variable
164
+ %th Value
165
+ - ruby_env.each do |key, value|
166
+ %tr
167
+ %td= key
168
+ %td= value
169
+
170
+ - if git?
171
+ %a{ :name => "git_log" }
172
+ %h2 Recent Git Log
173
+ - git_remotes.each do |name, service, url, service_url|
174
+ .note Visit <a href="#{url}">#{name}</a> on <a href="#{service_url}">#{service}</a>.
175
+ %table
176
+ %tr
177
+ %th Author
178
+ %th Subject
179
+ %th Date
180
+ != git_log
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-web-inspector
3
+ version: &id001 !ruby/object:Gem::Version
4
+ version: 0.4.0.a
5
+ platform: ruby
6
+ authors:
7
+ - Konstantin Haase
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-15 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: monkey-lib
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "="
22
+ - *id001
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: sinatra-sugar
26
+ type: :runtime
27
+ version_requirement:
28
+ version_requirements: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "="
31
+ - *id001
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: sinatra-advanced-routes
35
+ type: :runtime
36
+ version_requirement:
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "="
40
+ - *id001
41
+ version:
42
+ - !ruby/object:Gem::Dependency
43
+ name: sinatra-compass
44
+ type: :runtime
45
+ version_requirement:
46
+ version_requirements: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - "="
49
+ - *id001
50
+ version:
51
+ - !ruby/object:Gem::Dependency
52
+ name: sinatra
53
+ type: :runtime
54
+ version_requirement:
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.9.4
60
+ version:
61
+ description: Web inspector for sinatra (part of BigBand).
62
+ email: konstantin.mailinglists@googlemail.com
63
+ executables: []
64
+
65
+ extensions: []
66
+
67
+ extra_rdoc_files: []
68
+
69
+ files:
70
+ - lib/sinatra/web_inspector.rb
71
+ - README.md
72
+ has_rdoc: yard
73
+ homepage: http://github.com/rkh/sinatra-web-inspector
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options: []
78
+
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">"
90
+ - !ruby/object:Gem::Version
91
+ version: 1.3.1
92
+ version:
93
+ requirements: []
94
+
95
+ rubyforge_project:
96
+ rubygems_version: 1.3.5
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: Web inspector for sinatra (part of BigBand).
100
+ test_files: []
101
+