rails-erd-d3 0.0.18 → 0.0.19

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38658c61efe4ebf8e29642a91806d706365cf314
4
- data.tar.gz: 81fa3ad4a2cce8318fbd77a78948a5491630e3ee
3
+ metadata.gz: ad72e9ff1d52dcf6df66fbd7048f0bfe1aea4cfc
4
+ data.tar.gz: 7aff46e82e02896d25b07d71f31f91fad586f3cd
5
5
  SHA512:
6
- metadata.gz: e424c6190f20e55c88520a523fff2a478b2b3c06d0acc2369686c08827e40b987aae1441f3bba94c88cfd6a45391597feb67226f6cc706ffbbb74c032712f26f
7
- data.tar.gz: 8611e2c176c733f876b4c25f3f14e608f3c7c2be3c17fa983acea95c9ab38936d3610ee4b42fd69a1c927f35aa9ebf211b5413d0ff39cd38a0be9751f3880856
6
+ metadata.gz: bdb5e01b5e24ec23d22b57bef68ad5074472f37bc297d9b5c325397070f6b149e996213e0133c5cc14c568d82cdef7e1fc969dbd81c1552238f100a58f70105c
7
+ data.tar.gz: b2e8891f5788fa788a1842b9375f2cc763d0e3104368248e98b08846586ed693f772b6dfb52371e69ff8f34a6c14484c3aa3556f741ec66a596c0d885a4e7bda
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/rails-erd-d3.svg)](https://badge.fury.io/rb/rails-erd-d3)
2
+ [![Code Climate](https://codeclimate.com/github/RomanKrasavtsev/rails-erd-d3/badges/gpa.svg)](https://codeclimate.com/github/RomanKrasavtsev/rails-erd-d3)
3
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/RomanKrasavtsev/rails-erd-d3/master/LICENSE.txt)
2
4
 
3
5
  # Rails-ERD-D3
4
6
 
@@ -21,14 +23,21 @@ And then execute for creating file erd.html:
21
23
 
22
24
  ## Todo
23
25
 
26
+ - Optimize get_modals
27
+ - Change button and header colour
28
+ - Add to Gemfile for test environment
29
+ - activerecord
30
+ - sqlite3 (ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:")
31
+ - Add tests
24
32
  - Sort nodes by label
25
- - Check all associations
33
+ - Check associations
26
34
  - [X] belongs_to
27
35
  - [X] has_one
28
36
  - [x] has_many
29
37
  - has_many :through
30
38
  - has_one :through
31
39
  - has_and_belongs_to_many
40
+ - Polymorphic associations
32
41
  - Hide model
33
42
  - Show model attributes
34
43
  - Safe as jpg, png
data/lib/rails_erd_d3.rb CHANGED
@@ -28,11 +28,15 @@ class RailsErdD3
28
28
  nodes = []
29
29
  links = []
30
30
  @@models.each do |model|
31
- nodes << { label: model.name.capitalize, r: 30 }
32
- model.reflections.keys.each do |key|
31
+ nodes << { label: model.name, r: 30 }
32
+
33
+ model.reflections.each do |refl_name, refl_data|
34
+ next if refl_data.options[:polymorphic]
35
+ refl_model = (refl_data.options[:class_name] || refl_name).underscore
36
+
33
37
  links << {
34
38
  source: models_list[model.model_name.plural.capitalize],
35
- target: models_list[key.pluralize.capitalize]
39
+ target: models_list[refl_model.pluralize.capitalize]
36
40
  }
37
41
  end
38
42
  end
@@ -95,52 +99,13 @@ class RailsErdD3
95
99
  end
96
100
 
97
101
  def self.get_modals
98
- modals = ""
99
- @@models.each do |model|
100
- name = model.name.capitalize
101
- modals += "<div class='modal fade' id='#{name}' tabindex='-1' role='dialog'>"\
102
- "<div class='modal-dialog' role='document'>"\
103
- "<div class='modal-content'>"\
104
- "<div class='modal-header'>"\
105
- "<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>"\
106
- "<h4 class='modal-title'>#{name}</h4>"\
107
- "</div>"\
108
- "<div class='modal-body'>"\
109
- "<div class='panel panel-primary'>"\
110
- "<div class='panel-heading'>Associations</div>"\
111
- "<table class='table table-hover'>"\
112
- "<thead>"\
113
- "<tr>"\
114
- "<th>#</th>"\
115
- "<th>name</th>"\
116
- "<th>macro</th>"\
117
- "<th>foreign_key</th>"\
118
- "</tr>"\
119
- "</thead>"\
120
- "<tbody>"
121
-
122
- model.reflections.each_with_index do |r, index|
123
- name = r[0]
124
- modals += "<tr>"\
125
- "<th>#{index + 1}</th>"\
126
- "<td>#{name.capitalize}</td>"\
127
- "<td>#{model.reflections[name].macro}</td>"\
128
- "<td>#{model.reflections[name].foreign_key}</td>"\
129
- "</tr>"
130
- end
131
-
132
- modals += "</tbody>"\
133
- "</table>"\
134
- "</div>"\
135
- "</div>"\
136
- "<div class='modal-footer'>"\
137
- "<button type='button' class='btn btn-default' data-dismiss='modal'>Close</button>"\
138
- "</div>"\
139
- "</div>"\
140
- "</div>"\
141
- "</div>"
142
- end
143
-
144
- modals
102
+ ERB.new(
103
+ File.read(
104
+ File.expand_path(
105
+ "templates/modals.html.erb",
106
+ File.dirname(__FILE__)
107
+ )
108
+ )
109
+ ).result(binding)
145
110
  end
146
111
  end
@@ -2,58 +2,58 @@
2
2
  var data = <%= get_data %>;
3
3
 
4
4
  var width = window.innerWidth
5
- || document.documentElement.clientWidth
6
- || document.body.clientWidth;
5
+ || document.documentElement.clientWidth
6
+ || document.body.clientWidth;
7
7
  var height = window.innerHeight
8
- || document.documentElement.clientHeight
9
- || document.body.clientHeight;
8
+ || document.documentElement.clientHeight
9
+ || document.body.clientHeight;
10
10
 
11
11
  var colorScale = d3.scaleOrdinal(d3.schemeCategory20);
12
12
 
13
13
  var svg = d3.select('#erd').append('svg')
14
- .attr('height', height)
15
- .attr('width', width)
16
- .style('background', 'white');
14
+ .attr('height', height)
15
+ .attr('width', width)
16
+ .style('background', 'white');
17
17
 
18
18
  var simulation = d3.forceSimulation()
19
- .force('link', d3.forceLink().id(function(d) { return d.index }))
20
- .force('collide',d3.forceCollide( function(d){return d.r + 20 }).iterations(30) )
21
- .force('charge', d3.forceManyBody())
22
- .force('center', d3.forceCenter(width / 2, height / 2))
23
- .force('y', d3.forceY(0))
24
- .force('x', d3.forceX(0));
19
+ .force('link', d3.forceLink().id(function(d) { return d.index }))
20
+ .force('collide',d3.forceCollide( function(d){return d.r + 20 }).iterations(30) )
21
+ .force('charge', d3.forceManyBody())
22
+ .force('center', d3.forceCenter(width / 2, height / 2))
23
+ .force('y', d3.forceY(0))
24
+ .force('x', d3.forceX(0));
25
25
 
26
26
  var link = svg.append('g')
27
- .classed('links', true)
28
- .selectAll('line')
29
- .data(data.links)
30
- .enter()
31
- .append('line')
32
- .attr('stroke', 'black');
27
+ .classed('links', true)
28
+ .selectAll('line')
29
+ .data(data.links)
30
+ .enter()
31
+ .append('line')
32
+ .attr('stroke', 'black');
33
33
 
34
34
  var node = svg.selectAll('.node')
35
- .data(data.nodes)
36
- .enter()
37
- .append('g')
38
- .classed('node', true)
39
- .style('cursor', 'pointer')
40
- .attr('data-toggle', 'modal')
41
- .attr('data-target', function(d, i){ return '#' + data.nodes[i].label })
42
- .call(d3.drag()
43
- .on('start', dragstarted)
44
- .on('drag', dragged)
45
- .on('end', dragended));
35
+ .data(data.nodes)
36
+ .enter()
37
+ .append('g')
38
+ .classed('node', true)
39
+ .style('cursor', 'pointer')
40
+ .attr('data-toggle', 'modal')
41
+ .attr('data-target', function(d, i){ return '#' + data.nodes[i].label })
42
+ .call(d3.drag()
43
+ .on('start', dragstarted)
44
+ .on('drag', dragged)
45
+ .on('end', dragended));
46
46
 
47
47
  node.append('circle')
48
- .classed('circle', true)
49
- .attr('r', function(d){ return d.r })
50
- .attr('fill', function(d, i){ return colorScale(i) });
48
+ .classed('circle', true)
49
+ .attr('r', function(d){ return d.r })
50
+ .attr('fill', function(d, i){ return colorScale(i) });
51
51
 
52
52
  node.append('text')
53
- .classed('text', true)
54
- .text(function(d) {
55
- return d.label;
56
- });
53
+ .classed('text', true)
54
+ .text(function(d) {
55
+ return d.label;
56
+ });
57
57
 
58
58
  var ticked = function() {
59
59
  link
@@ -1,40 +1,43 @@
1
- <div class="modal fade" id="<%= name %>" tabindex="-1" role="dialog">
2
- <div class="modal-dialog" role="document">
3
- <div class="modal-content">
4
- <div class="modal-header">
5
- <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
6
- <h4 class="modal-title">
7
- <%= name %>
8
- </h4>
9
- </div>
10
- <div class="modal-body">
11
- <div class="panel panel-primary">
12
- <div class="panel-heading">Associations</div>
13
- <table class="table table-hover">
14
- <thead>
15
- <tr>
16
- <th>#</th>
17
- <th>name</th>
18
- <th>macro</th>
19
- <th>foreign_key</th>
20
- </tr>
21
- </thead>
22
- <tbody>
23
- <% model.reflections.each_with_index do |r, index| %>
1
+ <% @@models.each do |model| %>
2
+ <div class="modal fade" id="<%= model.name %>" tabindex="-1" role="dialog">
3
+ <div class="modal-dialog" role="document">
4
+ <div class="modal-content">
5
+ <div class="modal-header">
6
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
7
+ <h4 class="modal-title">
8
+ <%= model.name %>
9
+ </h4>
10
+ </div>
11
+ <div class="modal-body">
12
+ <div class="panel panel-primary">
13
+ <div class="panel-heading">Associations</div>
14
+ <table class="table table-hover">
15
+ <thead>
24
16
  <tr>
25
- <th><%= index + 1 %></th>
26
- <td><%= r[0].capitalize %></td>
27
- <td><%= model.reflections[r[0]].macro %></td>
28
- <td><%= model.reflections[r[0]].foreign_key %></td>
17
+ <th>#</th>
18
+ <th>name</th>
19
+ <th>macro</th>
20
+ <th>foreign_key</th>
29
21
  </tr>
30
- <% end %>
31
- </tbody>
32
- </table>
22
+ </thead>
23
+ <tbody>
24
+ <% model.reflections.each_with_index do |r, index| %>
25
+ <% name = r[0] %>
26
+ <tr>
27
+ <th><%= index + 1 %></th>
28
+ <td><%= name.camelize %></td>
29
+ <td><%= model.reflections[name].macro %></td>
30
+ <td><%= model.reflections[name].foreign_key %></td>
31
+ </tr>
32
+ <% end %>
33
+ </tbody>
34
+ </table>
35
+ </div>
36
+ </div>
37
+ <div class="modal-footer">
38
+ <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
33
39
  </div>
34
- </div>
35
- <div class="modal-footer">
36
- <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
37
40
  </div>
38
41
  </div>
39
42
  </div>
40
- </div>
43
+ <% end %>
data/rails-erd-d3.gemspec CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
6
6
  spec.name = "rails-erd-d3"
7
7
  spec.authors = ["Roman Krasavtsev"]
8
8
  spec.email = ["mr.krasavtsev@gmail.com"]
9
- spec.version = "0.0.18"
9
+ spec.version = "0.0.19"
10
10
  spec.summary = "Entity–relationship diagram with D3.js for Rails application"
11
11
  spec.description = "This gem creates entity–relationship diagram with D3.js for your Rails application"
12
12
  spec.homepage = "https://github.com/RomanKrasavtsev/rails-erd-d3"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-erd-d3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Krasavtsev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-02 00:00:00.000000000 Z
11
+ date: 2016-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  version: '0'
97
97
  requirements: []
98
98
  rubyforge_project:
99
- rubygems_version: 2.5.1
99
+ rubygems_version: 2.6.6
100
100
  signing_key:
101
101
  specification_version: 4
102
102
  summary: Entity–relationship diagram with D3.js for Rails application