rails_dt 0.1.4 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.yardopts +2 -0
- data/Gemfile +14 -0
- data/MIT-LICENSE +1 -1
- data/README.md +43 -135
- data/lib/dt.rb +31 -215
- data/lib/dt/config.rb +74 -0
- data/lib/dt/instance.rb +117 -0
- data/lib/rails_dt.rb +3 -2
- data/lib/rails_dt/version.rb +4 -0
- data/rails_dt.gemspec +12 -50
- data/spec/lib/dt/config_spec.rb +76 -0
- data/spec/lib/dt/instance_spec.rb +173 -0
- data/spec/lib/dt_spec.rb +14 -0
- data/spec/lib/rails_dt_spec.rb +6 -0
- data/spec/lib/spec/alias_method_matcher_spec.rb +16 -0
- data/spec/lib/spec/context_when_spec.rb +32 -0
- data/spec/lib/spec/let_m_spec.rb +104 -0
- data/spec/lib/spec/use_custom_let_spec.rb +46 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/support/00extend_x.rb +23 -0
- data/spec/support/alias_method_matcher.rb +20 -0
- data/spec/support/context_when.rb +39 -0
- data/spec/support/let_m.rb +27 -0
- data/spec/support/use_custom_let.rb +80 -0
- metadata +43 -52
- data/README.html +0 -171
- data/Rakefile +0 -68
- data/VERSION.yml +0 -4
- data/generators/rails_dt/USAGE +0 -11
- data/generators/rails_dt/WARNING +0 -2
- data/generators/rails_dt/rails_dt_generator.rb +0 -9
- data/generators/rails_dt/templates/INSTALL +0 -20
- data/generators/rails_dt/templates/dt.css +0 -27
- data/generators/rails_dt/templates/dt.rb +0 -4
- data/init.rb +0 -2
- data/lib/dt/action_controller_extensions.rb +0 -29
- data/lib/generators/rails_dt/USAGE +0 -11
- data/lib/generators/rails_dt/rails_dt_generator.rb +0 -9
- data/lib/generators/rails_dt/templates/INSTALL +0 -20
- data/lib/generators/rails_dt/templates/dt.css +0 -27
- data/lib/generators/rails_dt/templates/dt.rb +0 -4
data/README.html
DELETED
@@ -1,171 +0,0 @@
|
|
1
|
-
<head>
|
2
|
-
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
3
|
-
<link href="dev/github.css" rel="stylesheet" type="text/css" />
|
4
|
-
</head>
|
5
|
-
<h1 id="rails-debug-toolkit">Rails Debug Toolkit</h1>
|
6
|
-
|
7
|
-
<h2 id="introduction">Introduction</h2>
|
8
|
-
|
9
|
-
<p><code>rails_dt</code> gem gives you <code>DT.p()</code> method you can use anywhere in your project to print your debug messages.</p>
|
10
|
-
|
11
|
-
<p>It’s somewhat similar to Ruby’s native <code>p()</code> with output being sent to log, console and web.</p>
|
12
|
-
|
13
|
-
<p>For example, <code>DT.p "hello, world!"</code> invoked in <code>RootController</code> will give you a:</p>
|
14
|
-
|
15
|
-
<pre><code>[DT app/controllers/root_controller.rb:3] hello, world!
|
16
|
-
</code></pre>
|
17
|
-
|
18
|
-
<h2 id="the-ideas-behind-it">The Ideas Behind It</h2>
|
19
|
-
|
20
|
-
<ul>
|
21
|
-
<li>Debug message printer must <strong>not require initialization</strong>.</li>
|
22
|
-
<li>Debug message printer must be <strong>nothing else</strong>, but a debug message printer.</li>
|
23
|
-
<li>Debug message printer must be simple and invoked <strong>always the same way</strong> regardless of where you call it from.</li>
|
24
|
-
<li>Debug message printer calls must be <strong>clearly visible</strong> in the code.</li>
|
25
|
-
<li>Debug message printer must <strong>print its location in code</strong> so you can find and modify/remove it as easy as possible.</li>
|
26
|
-
</ul>
|
27
|
-
|
28
|
-
<h2 id="express-setup-rails-3">Express Setup (Rails 3)</h2>
|
29
|
-
|
30
|
-
<p>In your <code>Gemfile</code>, add:</p>
|
31
|
-
|
32
|
-
<pre><code>gem "rails_dt"
|
33
|
-
</code></pre>
|
34
|
-
|
35
|
-
<p>Then do a <code>bundle install</code>.</p>
|
36
|
-
|
37
|
-
<p>This gives you an express (zero-conf) setup, which outputs messages to log, <code>log/dt.log</code> and console.</p>
|
38
|
-
|
39
|
-
<h2 id="express-setup-rails-2">Express Setup (Rails 2)</h2>
|
40
|
-
|
41
|
-
<pre><code>$ gem sources --add http://rubygems.org
|
42
|
-
$ gem install rails_dt
|
43
|
-
</code></pre>
|
44
|
-
|
45
|
-
<p>In your <code>config/environment.rb</code>, add:</p>
|
46
|
-
|
47
|
-
<pre><code>config.gem "rails_dt"
|
48
|
-
</code></pre>
|
49
|
-
|
50
|
-
<h2 id="setting-up-web-output-both-rails-3-and-rails-2">Setting Up Web Output (Both Rails 3 and Rails 2)</h2>
|
51
|
-
|
52
|
-
<p>In your application root, do a:</p>
|
53
|
-
|
54
|
-
<pre><code>$ rails generate rails_dt # Rails 3
|
55
|
-
$ script/generate rails_dt # Rails 2
|
56
|
-
</code></pre>
|
57
|
-
|
58
|
-
<p>Follow the instructions the generator gives you then. They are listed below.</p>
|
59
|
-
|
60
|
-
<p>Inside your <code>ApplicationController</code> class, add:</p>
|
61
|
-
|
62
|
-
<pre><code>handles_dt
|
63
|
-
</code></pre>
|
64
|
-
|
65
|
-
<p>Inside your <code>app/views/layouts/application.html.erb</code> <code><head></code> section, add:</p>
|
66
|
-
|
67
|
-
<pre><code><%= stylesheet_link_tag "dt" %>
|
68
|
-
</code></pre>
|
69
|
-
|
70
|
-
<p>Inside your <code>app/views/layouts/application.html.erb</code> <code><body></code> section, add:</p>
|
71
|
-
|
72
|
-
<pre><code><div class="DT">
|
73
|
-
<%= DT.web_messages_as_html %>
|
74
|
-
</div>
|
75
|
-
</code></pre>
|
76
|
-
|
77
|
-
<h2 id="checking-setup">Checking Setup</h2>
|
78
|
-
|
79
|
-
<p>Somewhere in your <code>app/views/layouts/application.html.erb</code>, add:</p>
|
80
|
-
|
81
|
-
<pre><code><% DT.p "hello, world!" %>
|
82
|
-
</code></pre>
|
83
|
-
|
84
|
-
<p>Refresh the page. You should see “hello, world!”:</p>
|
85
|
-
|
86
|
-
<ul>
|
87
|
-
<li>In your application log.</li>
|
88
|
-
<li>In <code>log/dt.log</code>.</li>
|
89
|
-
<li>On the web page, if you’ve set it up (see above).</li>
|
90
|
-
</ul>
|
91
|
-
|
92
|
-
<h2 id="debugging">Debugging…</h2>
|
93
|
-
|
94
|
-
<h3 id="models">…Models</h3>
|
95
|
-
|
96
|
-
<pre><code>def before_save
|
97
|
-
DT.p "in before_save"
|
98
|
-
end
|
99
|
-
</code></pre>
|
100
|
-
|
101
|
-
<h3 id="controllers">…Controllers</h3>
|
102
|
-
|
103
|
-
<pre><code>def action
|
104
|
-
DT.p "hi, I'm #{action_name}"
|
105
|
-
end
|
106
|
-
</code></pre>
|
107
|
-
|
108
|
-
<h3 id="views">…Views</h3>
|
109
|
-
|
110
|
-
<pre><code><div class="body">
|
111
|
-
<% DT.p "@users", @users %>
|
112
|
-
</div>
|
113
|
-
</code></pre>
|
114
|
-
|
115
|
-
<h3 id="filters">…Filters</h3>
|
116
|
-
|
117
|
-
<p>Insert debugging code:</p>
|
118
|
-
|
119
|
-
<pre><code>before_filter do
|
120
|
-
DT.p "in before_filter xyz"
|
121
|
-
end
|
122
|
-
|
123
|
-
after_filter do
|
124
|
-
DT.p "in after_filter xyz"
|
125
|
-
end
|
126
|
-
</code></pre>
|
127
|
-
|
128
|
-
<p>See it in action:</p>
|
129
|
-
|
130
|
-
<pre><code>$ tail -f log/dt.log
|
131
|
-
</code></pre>
|
132
|
-
|
133
|
-
<h3 id="anything">…Anything!</h3>
|
134
|
-
|
135
|
-
<p>Just use <code>DT.p</code> anywhere you want.</p>
|
136
|
-
|
137
|
-
<h2 id="customizing-output-format">Customizing Output Format</h2>
|
138
|
-
|
139
|
-
<p>Create a sample initializer, by doing a:</p>
|
140
|
-
|
141
|
-
<pre><code>$ rails generate rails_dt # Rails 3
|
142
|
-
$ script/generate rails_dt # Rails 2
|
143
|
-
</code></pre>
|
144
|
-
|
145
|
-
<p>In <code>config/initializers/dt.rb</code> you’ll see something like:</p>
|
146
|
-
|
147
|
-
<pre><code># Customize your DT output.
|
148
|
-
#DT.log_prefix = "[DT <%= file_rel %>:<%= line %>] "
|
149
|
-
#DT.console_prefix = "[DT <%= file_rel %>:<%= line %>] "
|
150
|
-
#DT.web_prefix = '<a href="txmt://open?url=file://<%= file %>&line=<%= line %>"><%= file_rel %>:<%= line %></a> '
|
151
|
-
</code></pre>
|
152
|
-
|
153
|
-
<p>Uncomment and edit lines appropriately. Restart server for changes to take effect.</p>
|
154
|
-
|
155
|
-
<p>Values are in ERB format. The following macros are available:</p>
|
156
|
-
|
157
|
-
<ul>
|
158
|
-
<li><code>file</code> – full path to file.</li>
|
159
|
-
<li><code>file_base</code> – file base name.</li>
|
160
|
-
<li><code>file_rel</code> – file name relative to Rails application root.</li>
|
161
|
-
<li><code>line</code> – line number.</li>
|
162
|
-
</ul>
|
163
|
-
|
164
|
-
<p>You can also disable particular output target by setting its prefix to <code>nil</code>:</p>
|
165
|
-
|
166
|
-
<pre><code>DT.console_prefix = nil # Disable console output.
|
167
|
-
</code></pre>
|
168
|
-
|
169
|
-
<h2 id="feedback">Feedback</h2>
|
170
|
-
|
171
|
-
<p>Send bug reports, suggestions and criticisms through <a href="http://github.com/dadooda/rails_dt">project’s page on GitHub</a>.</p>
|
data/Rakefile
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require "rake/rdoctask"
|
2
|
-
|
3
|
-
GEM_NAME = "rails_dt"
|
4
|
-
|
5
|
-
begin
|
6
|
-
require "jeweler"
|
7
|
-
Jeweler::Tasks.new do |gem|
|
8
|
-
gem.name = GEM_NAME
|
9
|
-
gem.summary = "Rails Debug Toolkit"
|
10
|
-
gem.description = "Rails Debug Toolkit"
|
11
|
-
gem.email = "alex.r@askit.org"
|
12
|
-
gem.homepage = "http://github.com/dadooda/rails_dt"
|
13
|
-
gem.authors = ["Alex Fortuna"]
|
14
|
-
gem.files = FileList[
|
15
|
-
"[A-Z]*",
|
16
|
-
"*.gemspec",
|
17
|
-
"generators/**/*",
|
18
|
-
"init.rb",
|
19
|
-
"lib/generators/**/*",
|
20
|
-
"lib/**/*.rb",
|
21
|
-
]
|
22
|
-
end
|
23
|
-
rescue LoadError
|
24
|
-
STDERR.puts "This gem requires Jeweler to be built"
|
25
|
-
end
|
26
|
-
|
27
|
-
desc "Rebuild gemspec and package"
|
28
|
-
task :rebuild => [:update_generator2, :gemspec, :build]
|
29
|
-
|
30
|
-
desc "Push (publish) gem to RubyGems (aka Gemcutter)"
|
31
|
-
task :push => :rebuild do
|
32
|
-
# NOTE: Yet found no way to ask Jeweler forge a complete version string for us.
|
33
|
-
vh = YAML.load(File.read("VERSION.yml"))
|
34
|
-
version = [vh[:major], vh[:minor], vh[:patch], vh[:build]].compact.join(".")
|
35
|
-
pkgfile = File.join("pkg", "#{GEM_NAME}-#{version}.gem")
|
36
|
-
system("gem", "push", pkgfile)
|
37
|
-
end
|
38
|
-
|
39
|
-
desc "Generate RDoc documentation"
|
40
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
41
|
-
rdoc.rdoc_dir = "doc"
|
42
|
-
rdoc.title = "DT"
|
43
|
-
#rdoc.options << "--line-numbers"
|
44
|
-
#rdoc.options << "--inline-source"
|
45
|
-
rdoc.rdoc_files.include("lib/**/*.rb")
|
46
|
-
end
|
47
|
-
|
48
|
-
desc "Update Rails 2 generator files with Rails 3 generator files"
|
49
|
-
task :update_generator2 do
|
50
|
-
puts "Updating Rails 2 generator files..."
|
51
|
-
fns = FileUtils.cp_r Dir["lib/generators/rails_dt/{USAGE,templates}"], "generators/rails_dt"
|
52
|
-
puts ": ok (fns:#{fns.inspect})"
|
53
|
-
end
|
54
|
-
|
55
|
-
desc "Compile README preview"
|
56
|
-
task :readme do
|
57
|
-
require "kramdown"
|
58
|
-
|
59
|
-
doc = Kramdown::Document.new(File.read "README.md")
|
60
|
-
|
61
|
-
fn = "README.html"
|
62
|
-
puts "Writing '#{fn}'..."
|
63
|
-
File.open(fn, "w") do |f|
|
64
|
-
f.write(File.read "dev/head.html")
|
65
|
-
f.write(doc.to_html)
|
66
|
-
end
|
67
|
-
puts ": ok"
|
68
|
-
end
|
data/VERSION.yml
DELETED
data/generators/rails_dt/USAGE
DELETED
data/generators/rails_dt/WARNING
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
|
2
|
-
Setting Up Web Output
|
3
|
-
=====================
|
4
|
-
|
5
|
-
Inside your `ApplicationController` class, add:
|
6
|
-
|
7
|
-
handles_dt
|
8
|
-
|
9
|
-
Inside your `app/views/layouts/application.html.erb` `<head>` section, add:
|
10
|
-
|
11
|
-
<%= stylesheet_link_tag "dt" %>
|
12
|
-
|
13
|
-
Inside your `app/views/layouts/application.html.erb` `<body>` section, add:
|
14
|
-
|
15
|
-
<div class="DT">
|
16
|
-
<%= DT.web_messages_as_html %>
|
17
|
-
</div>
|
18
|
-
|
19
|
-
Happy debugging!
|
20
|
-
|
@@ -1,27 +0,0 @@
|
|
1
|
-
/* DT styles. */
|
2
|
-
|
3
|
-
.DT {
|
4
|
-
margin: 10px 0 0 0;
|
5
|
-
border-top: 1px dotted;
|
6
|
-
padding: 0;
|
7
|
-
background: #dfd;
|
8
|
-
}
|
9
|
-
|
10
|
-
.DT ul {
|
11
|
-
list-style: none;
|
12
|
-
margin: 0;
|
13
|
-
padding: 0;
|
14
|
-
font-family: monospace;
|
15
|
-
font-size: 12px;
|
16
|
-
}
|
17
|
-
|
18
|
-
.DT ul li {
|
19
|
-
margin: 2px 0 2px 0;
|
20
|
-
}
|
21
|
-
|
22
|
-
.DT a {
|
23
|
-
text-decoration: none;
|
24
|
-
color: Black;
|
25
|
-
background: #edd;
|
26
|
-
padding: 0 2px 0 2px;
|
27
|
-
}
|
data/init.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module DT
|
2
|
-
module ActionControllerExtensions #:nodoc:
|
3
|
-
def self.included(owner) #:nodoc:
|
4
|
-
owner.extend MetaClassMethods
|
5
|
-
end
|
6
|
-
|
7
|
-
module MetaClassMethods
|
8
|
-
# Enable DT in the controller.
|
9
|
-
#
|
10
|
-
# class ApplicationController < ActionController::Base
|
11
|
-
# handles_dt
|
12
|
-
# end
|
13
|
-
def handles_dt
|
14
|
-
# NOTE: after_filter() is nicer and lets debug more, but... It's not getting control when there's a rendering exception, such as 404.
|
15
|
-
# Use log and console to debug complex stuff like prefilters.
|
16
|
-
before_filter {DT.clear_web_messages}
|
17
|
-
end
|
18
|
-
end # MetaClassMethods
|
19
|
-
end # ActionControllerExtensions
|
20
|
-
end # DT
|
21
|
-
|
22
|
-
# NOTE: This MUST be outside DT module, otherwise rdoc will produce ugly doc for DT module.
|
23
|
-
if defined? ::ActionController::Base
|
24
|
-
module ::ActionController #:nodoc:
|
25
|
-
class Base #:nodoc:
|
26
|
-
include DT::ActionControllerExtensions
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
class RailsDtGenerator < Rails::Generators::Base #:nodoc:
|
2
|
-
source_root File.expand_path("../templates", __FILE__)
|
3
|
-
|
4
|
-
def go
|
5
|
-
copy_file (fn = "dt.css"), "public/stylesheets/#{fn}"
|
6
|
-
copy_file (fn = "dt.rb"), "config/initializers/#{fn}"
|
7
|
-
readme "INSTALL"
|
8
|
-
end
|
9
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
|
2
|
-
Setting Up Web Output
|
3
|
-
=====================
|
4
|
-
|
5
|
-
Inside your `ApplicationController` class, add:
|
6
|
-
|
7
|
-
handles_dt
|
8
|
-
|
9
|
-
Inside your `app/views/layouts/application.html.erb` `<head>` section, add:
|
10
|
-
|
11
|
-
<%= stylesheet_link_tag "dt" %>
|
12
|
-
|
13
|
-
Inside your `app/views/layouts/application.html.erb` `<body>` section, add:
|
14
|
-
|
15
|
-
<div class="DT">
|
16
|
-
<%= DT.web_messages_as_html %>
|
17
|
-
</div>
|
18
|
-
|
19
|
-
Happy debugging!
|
20
|
-
|
@@ -1,27 +0,0 @@
|
|
1
|
-
/* DT styles. */
|
2
|
-
|
3
|
-
.DT {
|
4
|
-
margin: 10px 0 0 0;
|
5
|
-
border-top: 1px dotted;
|
6
|
-
padding: 0;
|
7
|
-
background: #dfd;
|
8
|
-
}
|
9
|
-
|
10
|
-
.DT ul {
|
11
|
-
list-style: none;
|
12
|
-
margin: 0;
|
13
|
-
padding: 0;
|
14
|
-
font-family: monospace;
|
15
|
-
font-size: 12px;
|
16
|
-
}
|
17
|
-
|
18
|
-
.DT ul li {
|
19
|
-
margin: 2px 0 2px 0;
|
20
|
-
}
|
21
|
-
|
22
|
-
.DT a {
|
23
|
-
text-decoration: none;
|
24
|
-
color: Black;
|
25
|
-
background: #edd;
|
26
|
-
padding: 0 2px 0 2px;
|
27
|
-
}
|