aristotle 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aristotle/command.rb +1 -1
- data/lib/aristotle/presenter.rb +51 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: beb607b0e69afe31331e87b364ebe0596d446b6e
|
4
|
+
data.tar.gz: c1accdb3321d49082eaff261bda5f77995f54f46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30cebb52fa456e598a643fae0c691c070b2ad886e703e28e2a8a637926d71bd6a641947b74bb957edf631b920a99eab61bf267fbae20c81a0122fc442406d5d1
|
7
|
+
data.tar.gz: a93c35022426c2e8bd9dcbdeb51d42120ee0520875191760dba25204a49f98166ce2a78e500b099891f1ac67c18a5a8ea844db52def1dfdc3611de4e60a71821
|
data/lib/aristotle/command.rb
CHANGED
data/lib/aristotle/presenter.rb
CHANGED
@@ -4,19 +4,64 @@ module Aristotle
|
|
4
4
|
@klass = klass
|
5
5
|
end
|
6
6
|
|
7
|
-
def html_rules
|
8
|
-
@klass.commands.map do |
|
9
|
-
"<strong>#{
|
7
|
+
def html_rules(show_code: true)
|
8
|
+
@klass.commands.map do |command_title, commands|
|
9
|
+
"<strong>#{command_title}</strong>"+
|
10
10
|
"<ul>"+
|
11
|
-
|
11
|
+
commands.map do |command|
|
12
12
|
"<li>- "+
|
13
|
-
|
13
|
+
format_fragment(command, :action, show_code: show_code)+
|
14
14
|
" <strong style='color:blue'>IF</strong> "+
|
15
|
-
|
15
|
+
format_fragment(command, :condition, show_code: show_code)+
|
16
16
|
"</li>"
|
17
17
|
end.join +
|
18
18
|
"</ul>"
|
19
19
|
end.join('<br>').html_safe
|
20
20
|
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def format_fragment(fragment, part, show_code: true)
|
25
|
+
return '' if part != :action && part != :condition
|
26
|
+
|
27
|
+
text = fragment.send(part).to_s
|
28
|
+
text.gsub!(/'([^']+)'/, '<strong>\1</strong>')
|
29
|
+
|
30
|
+
proc = fragment.send("#{part}_proc")
|
31
|
+
|
32
|
+
return "<span style='color:red'>#{text}</span>" if proc.blank?
|
33
|
+
return text unless show_code
|
34
|
+
|
35
|
+
code = find_code(*proc.source_location) || 'no code found'
|
36
|
+
|
37
|
+
code_block = "<span style='color:#aaaaaa;'>#{proc.source_location.join(':')}</span>\n"+
|
38
|
+
"<span style='color:#333333'>#{code.join("\n")}</span>"
|
39
|
+
|
40
|
+
"<span style='position:relative;cursor:help;' onmouseover='this.children[0].style.display=\"block\";' onmouseout='this.children[0].style.display=\"none\";'>"+
|
41
|
+
"<pre style='position:absolute;cursor:text;display:none;background:#ffffff;margin-top:0;padding:6px 8px;box-shadow:2px 2px 8px rgba(0,0,0,0.3);z-index:30000;'>"+
|
42
|
+
"#{code_block}"+
|
43
|
+
"</pre>"+
|
44
|
+
"#{text}"+
|
45
|
+
"</span>"
|
46
|
+
end
|
47
|
+
|
48
|
+
def find_code(file, line_number)
|
49
|
+
lines = load_file(file)
|
50
|
+
first_line = lines[line_number - 1]
|
51
|
+
indention = first_line.index(/[^ ]/)
|
52
|
+
|
53
|
+
code_lines = lines[(line_number - 1)..-1]
|
54
|
+
end_regexp = Regexp.new('^' + (' ' * indention) + 'end *')
|
55
|
+
to = code_lines.find_index { |line| line =~ end_regexp } + 1
|
56
|
+
|
57
|
+
code_lines.first(to).map { |line| line[indention..-1] }
|
58
|
+
rescue
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
|
62
|
+
def load_file(file)
|
63
|
+
@files ||= {}
|
64
|
+
@files[file] ||= open(file).read.split("\n").map(&:rstrip)
|
65
|
+
end
|
21
66
|
end
|
22
67
|
end
|