metaruby 1.0.0.rc1 → 1.0.0.rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/Rakefile +9 -36
- data/{.gemtest → bin/.gitattributes} +0 -0
- data/lib/metaruby/class.rb +5 -0
- data/lib/metaruby/gui/exception_view.rb +58 -15
- data/lib/metaruby/gui/html/collection.rb +10 -3
- data/lib/metaruby/gui/html/fragment.rhtml +5 -0
- data/lib/metaruby/gui/html/list.rhtml +1 -1
- data/lib/metaruby/gui/html/page.css +2 -0
- data/lib/metaruby/gui/html/page.rb +39 -19
- data/lib/metaruby/gui/html/page.rhtml +4 -1
- data/lib/metaruby/gui/html/page_body.rhtml +3 -10
- data/lib/metaruby/gui/model_browser.rb +55 -24
- data/lib/metaruby/gui/model_selector.rb +6 -6
- data/lib/metaruby/gui/ruby_constants_item_model.rb +12 -3
- data/lib/metaruby/inherited_attribute.rb +6 -0
- data/lib/metaruby/module.rb +2 -2
- data/lib/metaruby/registration.rb +3 -3
- data/lib/metaruby/test.rb +4 -20
- data/lib/metaruby/version.rb +3 -0
- data/lib/yard-metaruby.rb +117 -0
- data/manifest.xml +1 -4
- data/metaruby.gemspec +26 -0
- metadata +50 -48
- data/History.txt +0 -1
- data/Manifest.txt +0 -40
- data/test/suite.rb +0 -15
- data/test/test_attributes.rb +0 -323
- data/test/test_class.rb +0 -68
- data/test/test_dsls.rb +0 -49
- data/test/test_module.rb +0 -105
- data/test/test_registration.rb +0 -182
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edefd7e59dcbf75b2cd69877ae482a9cb6838b96
|
4
|
+
data.tar.gz: 4d1263ce781eec239a82dbf30c470e95b9e5030d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e687ba3e7144b5f21f6ce767ed38364b9baf863ca8bc0b03ee353fbc159265f79569e1f8c7819365f78443e4a2650b40bdb96ae2e2d6653e2b23c6e5bf0643e
|
7
|
+
data.tar.gz: 7da81dcac85b7e7546734d5eafebe64fa280d59fa5eb579d1ee15b71b2282db7c7aeb09d6c53fa0d018dd2b0368b79a061a30d449b77ada89b9f5ed7ff4e0e95
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Rakefile
CHANGED
@@ -1,39 +1,12 @@
|
|
1
|
-
|
2
|
-
require
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
3
|
|
4
|
-
|
5
|
-
Utilrb.doc :include => ['lib/**/*.rb']
|
4
|
+
task :default
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
config = Hoe.spec 'metaruby' do
|
12
|
-
self.version = MetaRuby::VERSION
|
13
|
-
self.developer "Sylvain Joyeux", "sylvain.joyeux@m4x.org"
|
14
|
-
self.summary = 'Modelling using the Ruby language as a metamodel'
|
15
|
-
self.description = paragraphs_of('README.md', 3..6).join("\n\n")
|
16
|
-
self.changes = paragraphs_of('History.txt', 0..1).join("\n\n")
|
17
|
-
self.readme_file = 'README.md'
|
18
|
-
self.history_file = 'History.txt'
|
19
|
-
self.license 'LGPLv3+'
|
20
|
-
|
21
|
-
extra_deps <<
|
22
|
-
['utilrb', '>= 1.3.4']
|
23
|
-
extra_dev_deps <<
|
24
|
-
['rake', '>= 0.8'] <<
|
25
|
-
['hoe-yard', '>= 0.1.2']
|
26
|
-
end
|
27
|
-
|
28
|
-
Rake.clear_tasks(/^default$/)
|
29
|
-
task :default => []
|
30
|
-
task :doc => :yard
|
31
|
-
rescue LoadError
|
32
|
-
STDERR.puts "cannot load the Hoe gem. Distribution is disabled"
|
33
|
-
rescue Exception => e
|
34
|
-
puts e.backtrace
|
35
|
-
if e.message !~ /\.rubyforge/
|
36
|
-
STDERR.puts "WARN: cannot load the Hoe gem, or Hoe fails. Publishing tasks are disabled"
|
37
|
-
STDERR.puts "WARN: error message is: #{e.message}"
|
38
|
-
end
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "lib"
|
8
|
+
t.libs << "."
|
9
|
+
t.test_files = FileList['test/suite.rb']
|
39
10
|
end
|
11
|
+
|
12
|
+
task :gem => :build
|
File without changes
|
data/lib/metaruby/class.rb
CHANGED
@@ -115,6 +115,11 @@ module MetaRuby
|
|
115
115
|
def provides(model_as_module)
|
116
116
|
include model_as_module
|
117
117
|
end
|
118
|
+
|
119
|
+
# Tests whether the given model-as-module is provided by self
|
120
|
+
def provides?(model_as_module)
|
121
|
+
self <= model_as_module
|
122
|
+
end
|
118
123
|
end
|
119
124
|
end
|
120
125
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'metaruby/gui/html'
|
2
|
+
|
1
3
|
module MetaRuby
|
2
4
|
module GUI
|
3
5
|
# Widget that allows to display a list of exceptions
|
@@ -5,9 +7,12 @@ module MetaRuby
|
|
5
7
|
RESSOURCES_DIR = File.expand_path('html', File.dirname(__FILE__))
|
6
8
|
|
7
9
|
attr_reader :displayed_exceptions
|
10
|
+
attr_reader :metaruby_page
|
8
11
|
|
9
12
|
def initialize(parent = nil)
|
10
13
|
super
|
14
|
+
@metaruby_page = HTML::Page.new(self.page)
|
15
|
+
connect(@metaruby_page, SIGNAL('fileOpenClicked(const QUrl&)'), self, SLOT('fileOpenClicked(const QUrl&)'))
|
11
16
|
@displayed_exceptions = []
|
12
17
|
self.focus_policy = Qt::NoFocus
|
13
18
|
end
|
@@ -22,11 +27,15 @@ module MetaRuby
|
|
22
27
|
update_html
|
23
28
|
end
|
24
29
|
|
30
|
+
def each_exception(&block)
|
31
|
+
@displayed_exceptions.each(&block)
|
32
|
+
end
|
33
|
+
|
25
34
|
TEMPLATE = <<-EOD
|
26
|
-
<
|
35
|
+
<head>
|
27
36
|
<link rel="stylesheet" href="file://#{File.join(RESSOURCES_DIR, 'exception_view.css')}" type="text/css" />
|
28
37
|
<script type="text/javascript" src="file://#{File.join(RESSOURCES_DIR, 'jquery.min.js')}"></script>
|
29
|
-
</
|
38
|
+
</head>
|
30
39
|
<script type="text/javascript">
|
31
40
|
$(document).ready(function () {
|
32
41
|
$("tr.backtrace").hide()
|
@@ -46,7 +55,7 @@ module MetaRuby
|
|
46
55
|
</script>
|
47
56
|
<body>
|
48
57
|
<table class="exception_list">
|
49
|
-
<%=
|
58
|
+
<%= each_exception.each_with_index.map { |(e, reason), idx| render_exception(e, reason, idx) }.join("\\n") %>
|
50
59
|
</table>
|
51
60
|
</body>
|
52
61
|
EOD
|
@@ -57,21 +66,31 @@ module MetaRuby
|
|
57
66
|
|
58
67
|
class BacktraceParser
|
59
68
|
def initialize(backtrace)
|
60
|
-
@backtrace = backtrace
|
69
|
+
@backtrace = backtrace || []
|
61
70
|
end
|
62
71
|
|
63
72
|
def parse
|
64
73
|
call_stack(0)
|
65
74
|
end
|
66
75
|
|
76
|
+
def pp_callstack(level)
|
77
|
+
@backtrace[level..-1]
|
78
|
+
end
|
79
|
+
|
67
80
|
def pp_call_stack(level)
|
68
81
|
@backtrace[level..-1]
|
69
82
|
end
|
70
83
|
end
|
71
84
|
|
72
|
-
|
85
|
+
EXCEPTION_TEMPLATE_WITHOUT_BACKTRACE = <<-EOF
|
86
|
+
<tr class="message">
|
87
|
+
<td id="<%= idx %>"><%= escape_html(reason) if reason %><pre><%= message.join("\n") %></pre></td>
|
88
|
+
</tr>
|
89
|
+
EOF
|
90
|
+
|
91
|
+
EXCEPTION_TEMPLATE_WITH_BACKTRACE = <<-EOF
|
73
92
|
<tr class="message">
|
74
|
-
<td id="<%= idx %>"><%= escape_html(reason) if reason %><pre><%= message.join("\n") %></pre>
|
93
|
+
<td id="<%= idx %>"><%= escape_html(reason) if reason %><pre><%= message.join("\n") %></pre>
|
75
94
|
<span class="backtrace_links">
|
76
95
|
(show: <a class="backtrace_toggle_filtered" id="<%= idx %>">filtered backtrace</a>,
|
77
96
|
<a class=\"backtrace_toggle_full\" id="<%= idx %>">full backtrace</a>)
|
@@ -79,7 +98,7 @@ module MetaRuby
|
|
79
98
|
</td>
|
80
99
|
</tr>
|
81
100
|
<tr class="backtrace_summary">
|
82
|
-
<td>from <%=
|
101
|
+
<td>from <%= origin_file %>:<%= origin_line %>:in <%= escape_html(origin_method.to_s) %></td>
|
83
102
|
</tr>
|
84
103
|
<tr class="backtrace" id="backtrace_filtered_<%= idx %>">
|
85
104
|
<td><%= render_backtrace(filtered_backtrace) %></td>
|
@@ -89,22 +108,40 @@ module MetaRuby
|
|
89
108
|
</tr>
|
90
109
|
EOF
|
91
110
|
|
111
|
+
def filter_backtrace(backtrace)
|
112
|
+
backtrace
|
113
|
+
end
|
114
|
+
|
115
|
+
def user_file?(file)
|
116
|
+
true
|
117
|
+
end
|
118
|
+
|
92
119
|
def render_exception(e, reason, idx)
|
93
120
|
message = PP.pp(e, "").split("\n").map { |line| escape_html(line) }
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
121
|
+
|
122
|
+
if e.backtrace && !e.backtrace.empty?
|
123
|
+
filtered_backtrace = BacktraceParser.new(filter_backtrace(e.backtrace)).parse
|
124
|
+
full_backtrace = BacktraceParser.new(e.backtrace).parse
|
125
|
+
origin_file, origin_line, origin_method =
|
126
|
+
filtered_backtrace.find { |file, _| user_file?(file) } ||
|
127
|
+
filtered_backtrace.first ||
|
128
|
+
full_backtrace.first
|
129
|
+
|
130
|
+
origin_file = metaruby_page.link_to(Pathname.new(origin_file), origin_file, lineno: origin_line)
|
131
|
+
ERB.new(EXCEPTION_TEMPLATE_WITH_BACKTRACE).result(binding)
|
132
|
+
else
|
133
|
+
ERB.new(EXCEPTION_TEMPLATE_WITHOUT_BACKTRACE).result(binding)
|
134
|
+
end
|
99
135
|
end
|
100
136
|
|
101
137
|
def render_backtrace(backtrace)
|
102
138
|
result = []
|
103
139
|
backtrace.each do |file, line, method|
|
104
|
-
|
105
|
-
|
140
|
+
file_link = metaruby_page.link_to(Pathname.new(file), file, lineno: line)
|
141
|
+
if user_file?(file)
|
142
|
+
result << " <span class=\"app_file\">#{file_link}:#{line}:in #{escape_html(method.to_s)}</span><br/>"
|
106
143
|
else
|
107
|
-
result << " #{
|
144
|
+
result << " #{file_link}:#{line}:in #{escape_html(method.to_s)}<br/>"
|
108
145
|
end
|
109
146
|
end
|
110
147
|
result.join("\n")
|
@@ -118,6 +155,12 @@ module MetaRuby
|
|
118
155
|
@displayed_exceptions = list.dup
|
119
156
|
update_html
|
120
157
|
end
|
158
|
+
|
159
|
+
def contents_height
|
160
|
+
self.page.main_frame.contents_size.height
|
161
|
+
end
|
162
|
+
|
163
|
+
signals 'fileOpenClicked(const QUrl&)'
|
121
164
|
end
|
122
165
|
end
|
123
166
|
end
|
@@ -15,7 +15,7 @@ module MetaRuby::GUI
|
|
15
15
|
# @return [<Exception>] exceptions caught during element rendering
|
16
16
|
attr_reader :registered_exceptions
|
17
17
|
|
18
|
-
Element = Struct.new :object, :format, :url, :text, :rendering_options
|
18
|
+
Element = Struct.new :object, :format, :url, :text, :rendering_options, :attributes
|
19
19
|
|
20
20
|
def initialize(page)
|
21
21
|
super()
|
@@ -52,7 +52,7 @@ module MetaRuby::GUI
|
|
52
52
|
|
53
53
|
def element_link_target(object, interactive)
|
54
54
|
if interactive
|
55
|
-
id = "
|
55
|
+
id = "link://metaruby/#{namespace}#{object.object_id}"
|
56
56
|
else
|
57
57
|
id = "##{object.object_id}"
|
58
58
|
end
|
@@ -63,7 +63,10 @@ module MetaRuby::GUI
|
|
63
63
|
object_id_to_object[el.object.object_id] = el.object
|
64
64
|
end
|
65
65
|
|
66
|
-
links = links.map
|
66
|
+
links = links.map do |el|
|
67
|
+
a_node = el.format % ["<a href=\"#{el.url}\">#{el.text}</a>"]
|
68
|
+
[a_node, el.attributes || Hash.new]
|
69
|
+
end
|
67
70
|
page.render_list(title, links, push_options)
|
68
71
|
end
|
69
72
|
|
@@ -80,6 +83,8 @@ module MetaRuby::GUI
|
|
80
83
|
if url.host == "metaruby" && url.path =~ /^\/#{Regexp.quote(namespace)}(\d+)/
|
81
84
|
object = object_id_to_object[Integer($1)]
|
82
85
|
render_element(object)
|
86
|
+
else
|
87
|
+
super
|
83
88
|
end
|
84
89
|
end
|
85
90
|
slots 'linkClicked(const QUrl&)'
|
@@ -87,12 +92,14 @@ module MetaRuby::GUI
|
|
87
92
|
def render_element(object, options = Hash.new)
|
88
93
|
page.restore
|
89
94
|
registered_exceptions.clear
|
95
|
+
options = Hash[id: "#{namespace}/currently_rendered_element"].merge(options)
|
90
96
|
begin
|
91
97
|
manager.render(object, options)
|
92
98
|
rescue ::Exception => e
|
93
99
|
registered_exceptions << e
|
94
100
|
end
|
95
101
|
emit updated
|
102
|
+
page.page.current_frame.scrollToAnchor(options[:id])
|
96
103
|
end
|
97
104
|
|
98
105
|
signals :updated
|
@@ -10,7 +10,7 @@
|
|
10
10
|
<%
|
11
11
|
items.each_with_index do |(data, attributes), index|
|
12
12
|
if attributes
|
13
|
-
div_attributes = attributes.map { |k, v| "
|
13
|
+
div_attributes = attributes.map { |k, v| " #{k}=\"#{v}\"" }.join("")
|
14
14
|
end
|
15
15
|
%>
|
16
16
|
<div class="short_doc<%= " list_alt" if index % 2 == 0 %>"<%= div_attributes %>>
|
@@ -41,6 +41,8 @@ display: block;
|
|
41
41
|
.doc-above { margin-bottom: -.3em; padding-bottom: 0em; font-style: italic; }
|
42
42
|
.doc-above p { margin-top: .1em; margin-bottom: .1em; }
|
43
43
|
|
44
|
+
.preformatted { white-space: pre; }
|
45
|
+
|
44
46
|
div.short_doc {
|
45
47
|
margin-top: .2em;
|
46
48
|
background-color: rgb(238,237,249);
|
@@ -15,6 +15,7 @@ module MetaRuby::GUI
|
|
15
15
|
attr_reader :fragments
|
16
16
|
attr_reader :view
|
17
17
|
attr_accessor :object_uris
|
18
|
+
attr_reader :javascript
|
18
19
|
|
19
20
|
class Fragment
|
20
21
|
attr_accessor :title
|
@@ -32,13 +33,23 @@ module MetaRuby::GUI
|
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
|
-
def
|
36
|
-
|
36
|
+
def load_javascript(file)
|
37
|
+
javascript << File.expand_path(file)
|
38
|
+
end
|
39
|
+
|
40
|
+
def link_to(object, text = nil, args = Hash.new)
|
41
|
+
text = HTML.escape_html(text || object.name || "<anonymous>")
|
37
42
|
if uri = uri_for(object)
|
38
|
-
if uri
|
39
|
-
uri
|
43
|
+
if uri !~ /^\w+:\/\//
|
44
|
+
if uri[0, 1] != '/'
|
45
|
+
uri = "/#{uri}"
|
46
|
+
end
|
47
|
+
uri = Qt::Url.new("link://metaruby#{uri}")
|
48
|
+
else
|
49
|
+
uri = Qt::Url.new(uri)
|
40
50
|
end
|
41
|
-
|
51
|
+
args.each { |k, v| uri.add_query_item(k.to_s, v.to_s) }
|
52
|
+
"<a href=\"#{uri.to_string}\">#{text}</a>"
|
42
53
|
else text
|
43
54
|
end
|
44
55
|
end
|
@@ -58,6 +69,7 @@ module MetaRuby::GUI
|
|
58
69
|
|
59
70
|
PAGE_TEMPLATE = File.join(RESSOURCES_DIR, "page.rhtml")
|
60
71
|
PAGE_BODY_TEMPLATE = File.join(RESSOURCES_DIR, "page_body.rhtml")
|
72
|
+
FRAGMENT_TEMPLATE = File.join(RESSOURCES_DIR, "fragment.rhtml")
|
61
73
|
LIST_TEMPLATE = File.join(RESSOURCES_DIR, "list.rhtml")
|
62
74
|
ASSETS = %w{page.css jquery.min.js jquery.selectfilter.js}
|
63
75
|
|
@@ -86,6 +98,7 @@ module MetaRuby::GUI
|
|
86
98
|
@fragments = []
|
87
99
|
@templates = Hash.new
|
88
100
|
@auto_id = 0
|
101
|
+
@javascript = Array.new
|
89
102
|
|
90
103
|
if page.kind_of?(Qt::WebPage)
|
91
104
|
page.link_delegation_policy = Qt::WebPage::DelegateAllLinks
|
@@ -94,8 +107,13 @@ module MetaRuby::GUI
|
|
94
107
|
@object_uris = Hash.new
|
95
108
|
end
|
96
109
|
|
110
|
+
|
97
111
|
def uri_for(object)
|
98
|
-
|
112
|
+
if object.kind_of?(Pathname)
|
113
|
+
"file://#{object.expand_path}"
|
114
|
+
else
|
115
|
+
object_uris[object]
|
116
|
+
end
|
99
117
|
end
|
100
118
|
|
101
119
|
# Removes all existing displays
|
@@ -114,18 +132,18 @@ module MetaRuby::GUI
|
|
114
132
|
page.main_frame.html = html
|
115
133
|
end
|
116
134
|
|
117
|
-
def html(
|
118
|
-
options = Kernel.validate_options options, :ressource_dir => RESSOURCES_DIR
|
119
|
-
ressource_dir = options[:ressource_dir]
|
135
|
+
def html(ressource_dir: RESSOURCES_DIR)
|
120
136
|
load_template(PAGE_TEMPLATE).result(binding)
|
121
137
|
end
|
122
138
|
|
123
|
-
def html_body(
|
124
|
-
options = Kernel.validate_options options, :ressource_dir => RESSOURCES_DIR
|
125
|
-
ressource_dir = options[:ressource_dir]
|
139
|
+
def html_body(ressource_dir: RESSOURCES_DIR)
|
126
140
|
load_template(PAGE_BODY_TEMPLATE).result(binding)
|
127
141
|
end
|
128
142
|
|
143
|
+
def html_fragment(fragment, ressource_dir: RESSOURCES_DIR)
|
144
|
+
load_template(FRAGMENT_TEMPLATE).result(binding)
|
145
|
+
end
|
146
|
+
|
129
147
|
def find_button_by_url(url)
|
130
148
|
id = url.path
|
131
149
|
fragments.each do |fragment|
|
@@ -141,9 +159,7 @@ module MetaRuby::GUI
|
|
141
159
|
end
|
142
160
|
|
143
161
|
def pageLinkClicked(url)
|
144
|
-
|
145
|
-
|
146
|
-
if url.scheme == 'btn'
|
162
|
+
if url.scheme == 'btn' && url.host == 'metaruby'
|
147
163
|
if btn = find_button_by_url(url)
|
148
164
|
new_state = if url.fragment == 'on' then true
|
149
165
|
else false
|
@@ -156,14 +172,18 @@ module MetaRuby::GUI
|
|
156
172
|
|
157
173
|
emit buttonClicked(btn.id, new_state)
|
158
174
|
else
|
159
|
-
MetaRuby.warn "invalid button URI #{url}: could not find corresponding handler"
|
175
|
+
MetaRuby.warn "invalid button URI #{url.to_string}: could not find corresponding handler (known buttons are #{fragments.flat_map { |f| f.buttons.map { |btn| btn.id.to_string } }.sort.join(", ")})"
|
160
176
|
end
|
161
|
-
elsif url.scheme == 'link'
|
177
|
+
elsif url.scheme == 'link' && url.host == 'metaruby'
|
162
178
|
emit linkClicked(url)
|
179
|
+
elsif url.scheme == "file"
|
180
|
+
emit fileOpenClicked(url)
|
181
|
+
else
|
182
|
+
MetaRuby.warn "MetaRuby::GUI::HTML::Page: ignored link #{url.toString}"
|
163
183
|
end
|
164
184
|
end
|
165
185
|
slots 'pageLinkClicked(const QUrl&)'
|
166
|
-
signals 'linkClicked(const QUrl&)', 'buttonClicked(const QString&,bool)'
|
186
|
+
signals 'linkClicked(const QUrl&)', 'buttonClicked(const QString&,bool)', 'fileOpenClicked(const QUrl&)'
|
167
187
|
|
168
188
|
# Save the current state of the page, so that it can be restored by
|
169
189
|
# calling {restore}
|
@@ -215,7 +235,7 @@ module MetaRuby::GUI
|
|
215
235
|
if fragment
|
216
236
|
fragment.html = html
|
217
237
|
element = find_first_element("div##{fragment.id}")
|
218
|
-
element.replace(
|
238
|
+
element.replace(html_fragment(fragment))
|
219
239
|
return
|
220
240
|
end
|
221
241
|
end
|