maiha-merb_inspector 0.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -3
- data/inspectors/array.rb +3 -0
- data/inspectors/data_mapper.rb +93 -0
- data/inspectors/hash.rb +3 -0
- data/mirror/public/stylesheets/merb_inspector.css +87 -0
- data/templates/_default.html.erb +1 -0
- data/templates/array/_default.html.erb +18 -0
- data/templates/data_mapper/collection/_records.html.erb +38 -0
- data/templates/data_mapper/resource/_record.html.erb +41 -0
- data/templates/hash/_default.html.erb +19 -0
- metadata +17 -1
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'merb-core'
|
|
5
5
|
require 'merb-core/tasks/merb'
|
6
6
|
|
7
7
|
GEM_NAME = "merb_inspector"
|
8
|
-
GEM_VERSION = "0.2"
|
8
|
+
GEM_VERSION = "0.2.1"
|
9
9
|
AUTHOR = "Maiha"
|
10
10
|
EMAIL = "maiha@wota.jp"
|
11
11
|
HOMEPAGE = "http://github.com/maiha/merb_inspector"
|
@@ -25,7 +25,7 @@ spec = Gem::Specification.new do |s|
|
|
25
25
|
s.homepage = HOMEPAGE
|
26
26
|
s.add_dependency('merb', '>= 1.0.7')
|
27
27
|
s.require_path = 'lib'
|
28
|
-
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
|
28
|
+
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec,inspectors,templates,mirror}/**/*")
|
29
29
|
|
30
30
|
end
|
31
31
|
|
@@ -48,4 +48,4 @@ task :gemspec do
|
|
48
48
|
File.open("#{GEM_NAME}.gemspec", "w") do |file|
|
49
49
|
file.puts spec.to_ruby
|
50
50
|
end
|
51
|
-
end
|
51
|
+
end
|
data/inspectors/array.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
class DataMapper::ResourceInspector < Merb::Inspector
|
2
|
+
model ::DataMapper::Resource
|
3
|
+
|
4
|
+
def edit(object, options = {})
|
5
|
+
@object = object
|
6
|
+
@options = options
|
7
|
+
@mode = :edit
|
8
|
+
|
9
|
+
execute
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def model
|
14
|
+
@object.class
|
15
|
+
end
|
16
|
+
|
17
|
+
def columns
|
18
|
+
model.properties
|
19
|
+
end
|
20
|
+
|
21
|
+
def record_id
|
22
|
+
oid = @object.new_record? ? "new" : @object.id
|
23
|
+
"#{resource_name}_#{oid}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def template
|
27
|
+
if @options[:action].to_s == 'new'
|
28
|
+
"new"
|
29
|
+
else
|
30
|
+
"record"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def toggle
|
35
|
+
"$('##{record_id} .record').toggle();return false;"
|
36
|
+
end
|
37
|
+
|
38
|
+
def save_action
|
39
|
+
if @object.new_record?
|
40
|
+
"/" + resource_name
|
41
|
+
else
|
42
|
+
resource(@object)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def options
|
47
|
+
{:model=>model, :record=>@object, :save_action=>save_action, :toggle=>toggle}
|
48
|
+
end
|
49
|
+
|
50
|
+
######################################################################
|
51
|
+
### Resourceful
|
52
|
+
|
53
|
+
def resource_name
|
54
|
+
Extlib::Inflection.demodulize(model.name).plural.snake_case
|
55
|
+
end
|
56
|
+
|
57
|
+
def link_to_new(label = 'New', opts = {})
|
58
|
+
link_to label, resource(resource_name, :new), opts
|
59
|
+
rescue Merb::Router::GenerationError
|
60
|
+
end
|
61
|
+
|
62
|
+
def link_to_show(record = @object, label = 'Show', opts = {})
|
63
|
+
link_to label, resource(record), opts
|
64
|
+
rescue Merb::Router::GenerationError
|
65
|
+
end
|
66
|
+
|
67
|
+
def link_to_edit(record = @object, label = 'Edit', opts = {})
|
68
|
+
link_to label, resource(record, :edit), opts
|
69
|
+
rescue Merb::Router::GenerationError
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
class DataMapper::CollectionInspector < DataMapper::ResourceInspector
|
75
|
+
model ::DataMapper::Collection
|
76
|
+
|
77
|
+
private
|
78
|
+
def model
|
79
|
+
@object.query.model
|
80
|
+
end
|
81
|
+
|
82
|
+
def columns
|
83
|
+
@object.properties
|
84
|
+
end
|
85
|
+
|
86
|
+
def options
|
87
|
+
{:model=>model, :records=>@object}
|
88
|
+
end
|
89
|
+
|
90
|
+
def template
|
91
|
+
"records"
|
92
|
+
end
|
93
|
+
end
|
data/inspectors/hash.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
table.inspector {
|
2
|
+
border-collapse:collapse;
|
3
|
+
}
|
4
|
+
|
5
|
+
|
6
|
+
table.inspector th {
|
7
|
+
background-color: #555;
|
8
|
+
text-align: left;
|
9
|
+
}
|
10
|
+
|
11
|
+
table.inspector th a,
|
12
|
+
table.inspector th p {
|
13
|
+
font: bold 11px arial, sans-serif;
|
14
|
+
display: block;
|
15
|
+
background-color: #555;
|
16
|
+
}
|
17
|
+
|
18
|
+
table.inspector th a {
|
19
|
+
color: #fff;
|
20
|
+
padding: 2px 15px 2px 5px;
|
21
|
+
}
|
22
|
+
|
23
|
+
table.inspector th p {
|
24
|
+
color: #eee;
|
25
|
+
padding: 2px 5px;
|
26
|
+
}
|
27
|
+
|
28
|
+
table.inspector th a:hover {
|
29
|
+
background-color: #000;
|
30
|
+
color: #ff8;
|
31
|
+
}
|
32
|
+
|
33
|
+
table.inspector > tbody > tr.record td {
|
34
|
+
background-color: #E6F2FF;
|
35
|
+
}
|
36
|
+
|
37
|
+
table.inspector > tbody > tr.record > td {
|
38
|
+
padding: 5px 4px;
|
39
|
+
color: #333;
|
40
|
+
font-family: Verdana, sans-serif;
|
41
|
+
font-size: 11px;
|
42
|
+
border-bottom: solid 1px #C5DBF7;
|
43
|
+
border-left: solid 1px #C5DBF7;
|
44
|
+
}
|
45
|
+
|
46
|
+
table.inspector > tbody > tr.even-record td {
|
47
|
+
background-color: #fff;
|
48
|
+
}
|
49
|
+
|
50
|
+
table.inspector > tbody > tr.even-record > td {
|
51
|
+
border-left: solid 1px #ddd;
|
52
|
+
}
|
53
|
+
|
54
|
+
table.inspector > tbody > tr.record > td.sorted {
|
55
|
+
background-color: #B9DCFF;
|
56
|
+
border-bottom: solid 1px #AFD0F5;
|
57
|
+
}
|
58
|
+
|
59
|
+
table.inspector > tbody > tr.even-record > td.sorted {
|
60
|
+
background-color: #E6F2FF;
|
61
|
+
border-bottom: solid 1px #AFD0F5;
|
62
|
+
}
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
.record table
|
67
|
+
{
|
68
|
+
background-color: #fff;
|
69
|
+
border-collapse: collapse;
|
70
|
+
border-spacing: 0px;
|
71
|
+
}
|
72
|
+
.record table th
|
73
|
+
{
|
74
|
+
background-color: #dee7ec;
|
75
|
+
border: 1px solid #8cacbb;
|
76
|
+
padding: 3px;
|
77
|
+
}
|
78
|
+
.record table td
|
79
|
+
{
|
80
|
+
border: 1px solid #8cacbb;
|
81
|
+
padding: 3px;
|
82
|
+
}
|
83
|
+
|
84
|
+
table.logical th,
|
85
|
+
table.logical td {
|
86
|
+
border: 0px;
|
87
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
<%=h @object.inspect %>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<table class="inspector">
|
2
|
+
<tr>
|
3
|
+
<th><p>index</p></th>
|
4
|
+
<th><p>value</p></th>
|
5
|
+
<th><p>type</p></th>
|
6
|
+
</tr>
|
7
|
+
<%- @object.each_with_index do |obj, i| -%>
|
8
|
+
<%-
|
9
|
+
tr_class = (i % 2 == 0) ? "even-record" : ""
|
10
|
+
tr_class += " #{list_row_class(record)}" if respond_to? :list_row_class
|
11
|
+
-%>
|
12
|
+
<tr class="record <%=tr_class%>">
|
13
|
+
<td><%=i+1%></td>
|
14
|
+
<td><%=h obj.inspect %></td>
|
15
|
+
<td><%=h obj.class.name %></td>
|
16
|
+
</tr>
|
17
|
+
<%- end -%>
|
18
|
+
</table>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<div>
|
2
|
+
<table class="inspector data-mapper-collection">
|
3
|
+
<thead>
|
4
|
+
<tr>
|
5
|
+
<%- columns.each do |p| -%>
|
6
|
+
<th><p><%= column_header(p) %></p></th>
|
7
|
+
<%- end -%>
|
8
|
+
<th></th>
|
9
|
+
</tr>
|
10
|
+
</thead>
|
11
|
+
<tbody class="records">
|
12
|
+
<%- records.each_with_index do |record, i| -%>
|
13
|
+
<%-
|
14
|
+
tr_class = (i % 2 == 0) ? "even-record" : ""
|
15
|
+
tr_class += " #{list_row_class(record)}" if respond_to? :list_row_class
|
16
|
+
-%>
|
17
|
+
<tr class="record <%=tr_class%>">
|
18
|
+
<%- columns.each do |p| -%>
|
19
|
+
<td><%=h column_value(record, p) %></td>
|
20
|
+
<%- end -%>
|
21
|
+
<td>
|
22
|
+
<table class="logical">
|
23
|
+
<tr>
|
24
|
+
<td><%= link_to_show(record) %></td>
|
25
|
+
<td><%= link_to_edit(record) %></td>
|
26
|
+
<td><%# delete_button(article, "Delete #{article.title}") %></td>
|
27
|
+
</tr>
|
28
|
+
</table>
|
29
|
+
</td>
|
30
|
+
</tr>
|
31
|
+
<%- end -%>
|
32
|
+
</tbody>
|
33
|
+
</table>
|
34
|
+
|
35
|
+
<%= link_to_new 'New' %>
|
36
|
+
|
37
|
+
</div>
|
38
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
<div id="<%=record_id%>">
|
2
|
+
<div id="<%=record_id%>_show" class="record show" style="display:<%= (@mode == :edit) ? 'none' : 'display' %>">
|
3
|
+
<table>
|
4
|
+
<tbody>
|
5
|
+
<%- columns.each do |p| -%>
|
6
|
+
<tr>
|
7
|
+
<th><%= column_header(p) %></th>
|
8
|
+
<td><%=h column_value(record, p) %></td>
|
9
|
+
</tr>
|
10
|
+
<%- end -%>
|
11
|
+
<tr>
|
12
|
+
<td colspan=2 align=center>
|
13
|
+
<%= link_to "edit", "#", :onclick=>toggle %>
|
14
|
+
</td>
|
15
|
+
</tr>
|
16
|
+
</tbody>
|
17
|
+
</table>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<div id="<%=record_id%>_edit" class="record edit" style="display:<%= (@mode == :edit) ? 'display' : 'none' %>">
|
21
|
+
<%= form_for record, :action=>save_action do %>
|
22
|
+
<table>
|
23
|
+
<tbody>
|
24
|
+
<%- columns.each do |p| -%>
|
25
|
+
<tr>
|
26
|
+
<th><%= column_header(p) %></th>
|
27
|
+
<td><%= column_form(record, p) %></td>
|
28
|
+
</tr>
|
29
|
+
<%- end -%>
|
30
|
+
<tr>
|
31
|
+
<td colspan=2 align=center>
|
32
|
+
<%= submit (record.new_record? ? "create" : "update").t %>
|
33
|
+
<%= link_to "cancel", "#", :onclick=>toggle unless record.new_record? %>
|
34
|
+
</td>
|
35
|
+
</tr>
|
36
|
+
</tbody>
|
37
|
+
</table>
|
38
|
+
<% end =%>
|
39
|
+
</div>
|
40
|
+
</div>
|
41
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<table class="inspector">
|
2
|
+
<tr>
|
3
|
+
<th><p>key</p></th>
|
4
|
+
<th><p>value</p></th>
|
5
|
+
<th><p>type</p></th>
|
6
|
+
</tr>
|
7
|
+
<%- @object.keys.each_with_index do |key, i| -%>
|
8
|
+
<%- obj = @object[key] -%>
|
9
|
+
<%-
|
10
|
+
tr_class = (i % 2 == 0) ? "even-record" : ""
|
11
|
+
tr_class += " #{list_row_class(record)}" if respond_to? :list_row_class
|
12
|
+
-%>
|
13
|
+
<tr class="record <%=tr_class%>">
|
14
|
+
<td><%=h key.inspect %></td>
|
15
|
+
<td><%=h obj.inspect %></td>
|
16
|
+
<td><%=h obj.class.name %></td>
|
17
|
+
</tr>
|
18
|
+
<%- end -%>
|
19
|
+
</table>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maiha-merb_inspector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maiha
|
@@ -44,6 +44,22 @@ files:
|
|
44
44
|
- lib/merb_inspector.rb
|
45
45
|
- spec/spec_helper.rb
|
46
46
|
- spec/merb_inspector_spec.rb
|
47
|
+
- inspectors/hash.rb
|
48
|
+
- inspectors/data_mapper.rb
|
49
|
+
- inspectors/array.rb
|
50
|
+
- templates/hash
|
51
|
+
- templates/hash/_default.html.erb
|
52
|
+
- templates/_default.html.erb
|
53
|
+
- templates/array
|
54
|
+
- templates/array/_default.html.erb
|
55
|
+
- templates/data_mapper
|
56
|
+
- templates/data_mapper/resource
|
57
|
+
- templates/data_mapper/resource/_record.html.erb
|
58
|
+
- templates/data_mapper/collection
|
59
|
+
- templates/data_mapper/collection/_records.html.erb
|
60
|
+
- mirror/public
|
61
|
+
- mirror/public/stylesheets
|
62
|
+
- mirror/public/stylesheets/merb_inspector.css
|
47
63
|
has_rdoc: true
|
48
64
|
homepage: http://github.com/maiha/merb_inspector
|
49
65
|
post_install_message:
|