Module: TuneupHelper
Overview
Instance Method Summary
collapse
#build_data_url, #build_png, #build_png_chunk, #bumpspark, #normalize
Instance Method Details
#additional_step_links(step) ⇒ Object
72
73
74
75
76
77
|
# File 'lib/tuneup_helper.rb', line 72
def additional_step_links(step)
returning '' do |text|
text << sql_link(step) if step.sql
text << schema_link(step) if step.table_name
end.html_safe!
end
|
#link_to_edit_step(step) ⇒ Object
176
177
178
179
|
# File 'lib/tuneup_helper.rb', line 176
def link_to_edit_step(step)
return nil unless step.file && step.line && RUBY_PLATFORM.include?('darwin')
link_to(image_tag('/images/tuneup/edit.png', :alt => 'Edit'), "txmt://open?url=file://#{CGI.escape step.file}&line=#{step.line}", :class => 'tuneup-edit tuneup-halo', :title => 'Open in TextMate')
end
|
#link_to_schema(text, table, html_options = {}) ⇒ Object
89
90
91
|
# File 'lib/tuneup_helper.rb', line 89
def link_to_schema(text, table, html_options={})
link_to_function(text, "TuneUp.switchSchema('#{table}')", html_options.merge(:title => "View Schema"))
end
|
#link_to_show ⇒ Object
62
63
64
|
# File 'lib/tuneup_helper.rb', line 62
def link_to_show
%|<a id="tuneup-back-to-run-link" onclick="#{redisplay_last_run} return false;" href="#"><<< Back to Run</a>|.html_safe!
end
|
#open_step?(step) ⇒ Boolean
48
49
50
|
# File 'lib/tuneup_helper.rb', line 48
def open_step?(step)
[/^Around filter/, /^Invoke/].any? { |pattern| step.name =~ pattern }
end
|
#redisplay_last_run(namespaced = true) ⇒ Object
66
67
68
69
|
# File 'lib/tuneup_helper.rb', line 66
def redisplay_last_run(namespaced=true)
namespace_js = lambda { |fun| namespaced ? "TuneUpSandbox.#{fun}" : fun }
"#{namespace_js['$']}('tuneup-panel').show();"
end
|
#schema_link(step) ⇒ Object
79
80
81
|
# File 'lib/tuneup_helper.rb', line 79
def schema_link(step)
link_to_schema(image_tag('/images/tuneup/schema.png', :alt => 'Schema'), step.table_name, :class => 'tuneup-schema tuneup-halo')
end
|
#sql_link(step) ⇒ Object
83
84
85
86
87
|
# File 'lib/tuneup_helper.rb', line 83
def sql_link(step)
link_to_function(image_tag('/images/tuneup/magnify.png', :alt => 'Query'), :class => 'tuneup-sql tuneup-halo', :title => 'View Query') do |page|
page << %(TuneUpSandbox.$("#{dom_id(step, :sql)}").toggle(); return false;)
end
end
|
#trend ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/tuneup_helper.rb', line 36
def trend
numbers= if Fiveruns::Tuneup.trend.size > 50
Fiveruns::Tuneup.trend[-50..-1]
else
Fiveruns::Tuneup.trend
end
return unless numbers.size > 1
tag(:img,
:src => build_data_url("image/png",bumpspark(numbers)), :alt => '',
:title => "Trend over last #{pluralize(numbers.size, 'run')}")
end
|
#tuneup_bar(step = tuneup_data, options = {}) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/tuneup_helper.rb', line 98
def tuneup_bar(step=tuneup_data, options={})
width = options.delete(:width) || 200
bars = Fiveruns::Tuneup::Step.layers.map do |layer|
percent = step.percentages_by_layer[layer]
if percent == 0
next
else
begin
size = (percent * width).to_i
rescue
raise "Can't find percent for #{layer.inspect} from #{step.percentages_by_layer.inspect}"\
end
end
size = 1 if size.zero?
content_tag(:li, ((size >= 10 && layer != :other) ? layer.to_s[0, 1].capitalize : ''),
:class => "tuneup-layer-#{layer}",
:style => "width:#{size}px",
:title => layer.to_s.titleize)
end
content_tag(:ul, bars.compact.join, options.merge(:class => 'tuneup-bar'))
end
|
#tuneup_collecting? ⇒ Boolean
#tuneup_collection_link ⇒ Object
5
6
7
8
|
# File 'lib/tuneup_helper.rb', line 5
def tuneup_collection_link
state = tuneup_collecting? ? :off : :on
%|<a onclick="new TuneUpSandbox.Ajax.Request('/tuneup/#{state}', {asynchronous:true, evalScripts:true}); return false;" href="#">Turn #{state.to_s.titleize}</a>|.html_safe!
end
|
#tuneup_css_class_for_step(step) ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/tuneup_helper.rb', line 14
def tuneup_css_class_for_step(step)
returning [] do |classes|
if step.children.any?
classes << 'with-children'
classes << 'tuneup-opened' if step.depth == 1 || open_step?(step)
end
end.join(' ')
end
|
#tuneup_data ⇒ Object
27
28
29
30
|
# File 'lib/tuneup_helper.rb', line 27
def tuneup_data
most_recent_data = Fiveruns::Tuneup.stack.first
most_recent_data.blank? ? most_recent_data : most_recent_data['stack']
end
|
#tuneup_recording? ⇒ Boolean
#tuneup_reload_panel ⇒ Object
153
154
155
156
157
158
159
160
|
# File 'lib/tuneup_helper.rb', line 153
def tuneup_reload_panel
update_page do |page|
page << "$('tuneup-flash').removeClassName('tuneup-show');"
page << %[$('tuneup-content').update("#{escape_javascript(render(:partial => 'tuneup/panel/show.html.erb'))}");]
page << 'TuneUp.adjustAbsoluteElements(_document.body);'
page << 'TuneUp.adjustFixedElements();'
end
end
|
#tuneup_schemas ⇒ Object
32
33
34
|
# File 'lib/tuneup_helper.rb', line 32
def tuneup_schemas
Fiveruns::Tuneup.stack.first['schemas']
end
|
#tuneup_show_flash(type, locals) ⇒ Object
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/tuneup_helper.rb', line 162
def tuneup_show_flash(type, locals)
types = [:error, :notice].reject { |t| t == type }
update_page do |page|
page << %[$('tuneup-flash').update("#{escape_javascript(render(:partial => 'flash.html.erb', :locals => locals.merge(:type => type)))}");]
page << "$('tuneup-flash').addClassName('tuneup-show')"
types.each do |other_type|
page << "$('tuneup-flash').removeClassName('tuneup-#{other_type}')"
end
page << "$('tuneup-flash').addClassName('tuneup-#{type}')"
page << 'TuneUp.adjustAbsoluteElements(_document.body);'
page << 'TuneUp.adjustFixedElements();'
end
end
|
#tuneup_step_link(step) ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/tuneup_helper.rb', line 52
def tuneup_step_link(step)
name = tuneup_style_step_name(tuneup_truncate_step_name(step))
link = if step.children.any?
link_to_function(name, "TuneUpSandbox.$('#{dom_id(step, :children)}').toggle();TuneUpSandbox.$('#{dom_id(step)}').toggleClassName('tuneup-opened');", :class => "tuneup-step-link", :title => step.name)
else
content_tag(:span, name, :title => step.name)
end
link << additional_step_links(step)
end
|
#tuneup_style_step_name(name) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/tuneup_helper.rb', line 120
def tuneup_style_step_name(name)
case name
when /^Perform (\S+) action in (\S+Controller)$/
"Perform <strong>#{h $1}</strong> action in <strong>#{h $2}</strong>"
when /^Invoke (\S+) action$/
"Invoke <strong>#{h $1}</strong> action"
when /^(Find|Create|Delete|Update) ([A-Z]\S*)(.*?)$/
"#{h $1} <strong>#{h $2}</strong>#{h $3}"
when /^(Render.*?)(\S+)$/
"#{h $1}<strong>#{h $2}</strong>"
when /^(\S+ filter )(.*?)$/
"#{h $1}<strong>#{h $2}</strong>"
when 'Other'
"(<i>Other</i>)"
else
h(name)
end
end
|
#tuneup_truncate(text, max = 32) ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/tuneup_helper.rb', line 139
def tuneup_truncate(text, max=32)
if text.size > max
component = (max - 3) / 2
remainder = (max - 3) % 2
begin
text.sub(/^(.{#{component}}).*?(.{#{component + remainder}})$/s, '\1...\2')
rescue
text
end
else
text
end
end
|
#tuneup_truncate_step_name(step) ⇒ Object
93
94
95
96
|
# File 'lib/tuneup_helper.rb', line 93
def tuneup_truncate_step_name(step)
chars = 50 - (step.depth * 2)
tuneup_truncate(step.name, chars)
end
|