GraphvizR 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.3.0 / 2007-02-17
2
+
3
+ * rdot view template for rails
4
+
1
5
  == 0.2.0 / 2007-02-16
2
6
 
3
7
  * rails plugin
data/Manifest.txt CHANGED
@@ -6,11 +6,15 @@ bin/graphviz_r
6
6
  lib/graphviz_r.rb
7
7
  test/test_graphviz_r.rb
8
8
  vendor/plugins/rdot
9
+ vendor/plugins/rdot/config
10
+ vendor/plugins/rdot/config/database.yml
9
11
  vendor/plugins/rdot/lib
10
12
  vendor/plugins/rdot/lib/rdot.rb
13
+ vendor/plugins/rdot/lib/rdot_template.rb
11
14
  vendor/plugins/rdot/tasks
12
15
  vendor/plugins/rdot/tasks/rdot_tasks.rake
13
16
  vendor/plugins/rdot/test/rdot_test.rb
17
+ vendor/plugins/rdot/test/log
14
18
  vendor/plugins/rdot/README
15
19
  vendor/plugins/rdot/Rakefile
16
20
  vendor/plugins/rdot/init.rb
data/lib/graphviz_r.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class GraphvizR
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  INDENT_UNIT = ' '
4
4
 
5
5
  class Attributes
@@ -248,12 +248,19 @@ class GraphvizR
248
248
  end
249
249
 
250
250
  def data(format='png')
251
- gv = IO.popen "dot -q -T#{format || 'png'}", "w+"
252
- gv.puts to_dot
253
- gv.close_write
254
- gv.read
255
- ensure
256
- gv.close
251
+ format = format.to_s
252
+ if format == 'dot'
253
+ to_dot
254
+ else
255
+ begin
256
+ gv = IO.popen "dot -q -T#{format || 'png'}", "w+"
257
+ gv.puts to_dot
258
+ gv.close_write
259
+ gv.read
260
+ ensure
261
+ gv.close
262
+ end
263
+ end
257
264
  end
258
265
 
259
266
  def output(filename=nil, format='png')
@@ -28,7 +28,7 @@ class TestGraphvizR < Test::Unit::TestCase
28
28
  :beta => :delta,
29
29
  :delta => 'size'
30
30
  )
31
- #assert_equal <<-end_of_string.gsub(/\s/, ''), gvr.gsub(/\s/, '')
31
+
32
32
  assert_equal <<-end_of_string, gvr
33
33
  digraph sample {
34
34
  graph [label = "example", size = "1.5, 2.5"];
@@ -79,7 +79,7 @@ digraph sample {
79
79
  :node2 => [:node1, :p_center],
80
80
  {:node2 => [:node1, :p_right]} => {:label => 'record'}
81
81
  )
82
- #assert_equal <<-end_of_string.gsub(/\s/, ''), gvr.gsub(/\s/, '')
82
+
83
83
  assert_equal <<-end_of_string, gvr
84
84
  digraph sample {
85
85
  graph [size = "1.5, 2.5"];
@@ -146,7 +146,7 @@ digraph sample {
146
146
  {:c => :f} => {:lhead => :cluster1},
147
147
  {:a => :f} => {:ltail => :cluster0, :lhead => :cluster1}
148
148
  )
149
- #assert_equal <<-end_of_string.gsub(/\s/, ''), gvr.gsub(/\s/, '')
149
+
150
150
  assert_equal <<-end_of_string, gvr
151
151
  digraph sample {
152
152
  subgraph cluster0 {
@@ -219,7 +219,6 @@ digraph sample {
219
219
  (gvr.beta - gvr.delta) [:label => 'label2']
220
220
  gvr.delta - gvr[:size]
221
221
 
222
- #assert_equal <<-end_of_string.gsub(/\s/, ''), gvr.to_dot.gsub(/\s/, '')
223
222
  assert_equal <<-end_of_string, gvr.to_dot
224
223
  graph sample {
225
224
  graph [label = "example", size = "1.5, 2.5"];
@@ -249,7 +248,6 @@ graph sample {
249
248
  (gvr.c - gvr.d) [:ltail => :cluster0]
250
249
  (gvr.c - gvr.f) [:lhead => :cluster1]
251
250
 
252
- #assert_equal <<-end_of_string.gsub(/\s/, ''), gvr.to_dot.gsub(/\s/, '')
253
251
  assert_equal <<-end_of_string, gvr.to_dot
254
252
  graph sample {
255
253
  subgraph cluster0 {
@@ -266,6 +264,27 @@ graph sample {
266
264
  b -- d;
267
265
  c -- d [ltail = cluster0];
268
266
  c -- f [lhead = cluster1];
267
+ }
268
+ end_of_string
269
+ end
270
+
271
+ def test_data
272
+ gvr = GraphvizR.new 'sample'
273
+ gvr.graph [:label => 'example', :size => '1.5, 2.5']
274
+ gvr.beta [:shape => :box]
275
+ gvr.alpha >> gvr.beta
276
+ (gvr.alpha >> gvr.gamma) [:label => 'label1']
277
+ (gvr.beta >> gvr.delta) [:label => 'label2']
278
+ gvr.delta >> gvr[:size]
279
+
280
+ assert_equal <<-end_of_string, gvr.data(:dot)
281
+ digraph sample {
282
+ graph [label = "example", size = "1.5, 2.5"];
283
+ beta [shape = box];
284
+ alpha -> beta;
285
+ alpha -> gamma [label = "label1"];
286
+ beta -> delta [label = "label2"];
287
+ delta -> size;
269
288
  }
270
289
  end_of_string
271
290
  end
@@ -0,0 +1,20 @@
1
+ development:
2
+ database: hoge
3
+ adapter: mysql
4
+ username: hoge
5
+ password: root
6
+ host: localhost
7
+
8
+ test:
9
+ database: hoge
10
+ adapter: mysql
11
+ username: hoge
12
+ password: hoge
13
+ host: localhost
14
+
15
+ production:
16
+ database: hoge
17
+ adapter: mysql
18
+ username: hoge
19
+ password: hoge
20
+ host: localhost
@@ -1 +1,4 @@
1
1
  require 'rdot'
2
+ require 'rdot_template'
3
+
4
+ ActionView::Base.register_template_handler 'rdot', RdotTemplate
@@ -15,9 +15,33 @@ class ActionController::Base
15
15
  def render_rdot(options=nil, &block)
16
16
  options ||= {}
17
17
  format = options[:format] || 'png'
18
- content_type = format == 'svg' ? 'application/xml' : "image/#{format}"
18
+ content_type =
19
+ case format
20
+ when 'svg'
21
+ 'application/xml'
22
+ when 'dot'
23
+ 'text/plain'
24
+ else
25
+ "image/#{format}"
26
+ end
19
27
  gvr = GraphvizR.new 'generated'
20
- gvr.instance_eval &block
28
+ if block.arity == 1
29
+ block.call gvr
30
+ else
31
+ copy_instance_variables block, gvr
32
+ gvr.instance_eval &block
33
+ end
21
34
  send_data gvr.data(format), :type => content_type #,disposition => 'inline'
22
35
  end
36
+
37
+ private
38
+
39
+ def copy_instance_variables(from_block, to_obj)
40
+ block_instance_variables = eval 'instance_variables', from_block.binding
41
+ block_instance_variables.each do |name|
42
+ to_obj.instance_variable_set name.to_sym, eval(name, from_block.binding)
43
+ #to_obj.class.__send__ :attr_accessor, name[1..-1]
44
+ #to_obj.send "#{name[1..-1]}=", eval(name, from_block.binding)
45
+ end
46
+ end
23
47
  end
@@ -0,0 +1,19 @@
1
+ class RdotTemplate
2
+ def initialize(view)
3
+ @view = view
4
+ end
5
+
6
+ def render(template, local_assigns)
7
+ params = @view.assigns['params']
8
+ format = params['format'] || 'png'
9
+ content_type = params['content_type'] || "image/#{format}"
10
+
11
+ gvr = GraphvizR.new 'generated'
12
+ @view.assigns.each do |name, value|
13
+ gvr.instance_variable_set(('@' + name).to_sym, value)
14
+ end
15
+ gvr.instance_eval template
16
+ @view.controller.__send__ :send_data, gvr.data(format), :type => content_type
17
+ end
18
+ end
19
+
@@ -1,8 +1,56 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
1
2
  require 'test/unit'
2
3
 
4
+ class RdotGenController < ActionController::Base
5
+ def call_with_gvr
6
+ local_var = 'node1_label'
7
+
8
+ render :rdot do |gvr|
9
+ gvr.graph [:size => '1.5, 2.5']
10
+ gvr.node1 [:label => local_var]
11
+ gvr.node2 [:label => 'node2_label']
12
+ gvr.node1 >> gvr.node2
13
+ end
14
+ end
15
+
16
+ def call_with_nothing
17
+ local_var = 'node1_label'
18
+ @instance_var = 'node2_label'
19
+
20
+ render :rdot do
21
+ graph [:size => '1.5, 2.5']
22
+ node1 [:label => local_var]
23
+ node2 [:label => @instance_var]
24
+ node1 >> node2
25
+ end
26
+ end
27
+ end
28
+
3
29
  class RdotTest < Test::Unit::TestCase
4
- # Replace this with your real tests.
5
- def test_this_plugin
6
- flunk
30
+ def setup
31
+ @controller = RdotGenController.new
32
+ @request = ActionController::TestRequest.new
33
+ @response = ActionController::TestResponse.new
34
+ end
35
+
36
+ def test_call_with_gvr
37
+ get_and_assert :call_with_gvr
38
+ end
39
+
40
+ def test_call_with_nothing
41
+ get_and_assert :call_with_nothing
42
+ end
43
+
44
+ def get_and_assert(action)
45
+ get action, :format => 'dot'
46
+ assert_response :success
47
+ assert <<-end_of_string, @response.body
48
+ generated {
49
+ graph [];
50
+ node1 [label = 'node1_label'];
51
+ node2 [label = 'node2_label'];
52
+ node1 -> node2;
53
+ }
54
+ end_of_string
7
55
  end
8
56
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: GraphvizR
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
7
- date: 2007-02-15 00:00:00 +09:00
6
+ version: 0.3.0
7
+ date: 2007-02-16 00:00:00 +09:00
8
8
  summary: The author was too lazy to write a summary
9
9
  require_paths:
10
10
  - lib
@@ -38,11 +38,15 @@ files:
38
38
  - lib/graphviz_r.rb
39
39
  - test/test_graphviz_r.rb
40
40
  - vendor/plugins/rdot
41
+ - vendor/plugins/rdot/config
42
+ - vendor/plugins/rdot/config/database.yml
41
43
  - vendor/plugins/rdot/lib
42
44
  - vendor/plugins/rdot/lib/rdot.rb
45
+ - vendor/plugins/rdot/lib/rdot_template.rb
43
46
  - vendor/plugins/rdot/tasks
44
47
  - vendor/plugins/rdot/tasks/rdot_tasks.rake
45
48
  - vendor/plugins/rdot/test/rdot_test.rb
49
+ - vendor/plugins/rdot/test/log
46
50
  - vendor/plugins/rdot/README
47
51
  - vendor/plugins/rdot/Rakefile
48
52
  - vendor/plugins/rdot/init.rb