rails-erd로 rails에서 ER 그림 출력 준비

15113 단어 GraphvizRails

개시하다


rails 프로그램에서 ERD pdf 같은 소문을 출력할 수 있는 rails-erd
요컨대
Gemfile
(略)
rails-Graphviz
rails-erd
(略)
ERD 생성 명령을 실행하려면 bundle install 을 내리십시오rake erd.
zsh
%rake erd
나 욕 먹었어.
zsh
%rake erd
Loading application environment...
Loading code in search of Active Record models...
Generating Entity-Relationship Diagram for 5 models...
rake aborted!
Saving diagram failed!
Verify that Graphviz is installed and in your path, or use filetype=dot.
/Library/Ruby/Gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/diagram/graphviz.rb:198:in `rescue in block in <class:Graphviz>'
/Library/Ruby/Gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/diagram/graphviz.rb:190:in `block in <class:Graphviz>'
/Library/Ruby/Gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/diagram.rb:142:in `instance_eval'
/Library/Ruby/Gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/diagram.rb:142:in `save'
/Library/Ruby/Gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/diagram.rb:120:in `create'
/Library/Ruby/Gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/diagram.rb:74:in `create'
/Library/Ruby/Gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/tasks.rake:41:in `block (2 levels) in <top (required)>'
Tasks: TOP => erd => erd:generate
(See full trace by running task with --trace)
Graphiviz가 설치되어 있는지 확인하거나 파일 유형을 선택합니다.Graphiviz라는 소프트웨어를 미리 설치해야 합니다.

준비Graphiviz 설치


Graphiviz 페이지를 탐색합니다.
http://www.graphviz.org/Download_macos.php
Note: For some reason, the Graphviz app no longer works in the 2.38 and 2.39 packages for Mountain Lion (and Maverick). If you just need the command-line tools and libraries, these still work and are installed in/usr/local as usual. If you want the app, you can get it from homebrew or macports, or use the 2.36 version below.
최신 2.38 그 녀석은 마운틴 라이언(and Maverick)에서 움직일 수 없다.아래 2.36pkg이나 홈brew나 맥포트를 넣으세요.
아무튼 여기 참고해주세요.
http://www.graphviz.org/Download..php
Mac OS X
MacPorts provides both stable and development versions of Graphviz and the Mac GUI Graphviz.app. These can be obtained via the ports "graphviz", "graphviz-devel", "graphviz-gui"and "graphviz-gui-devel".
Homebrew has a graphviz port (so just brew install graphviz, we hope).
'위홉'이라는 표현에 다소 불안감brew install graphviz이 설치됐다.잘 설치됐습니다.

준비rails-erd에서 사용하는 글꼴 변경


Graphiviz에 가입했으니까 문제 없겠죠!재도전rake erd은 또 욕을 먹었다.
%rake erd
Loading application environment...
Loading code in search of Active Record models...
Generating Entity-Relationship Diagram for 5 models...
rake aborted!
Saving diagram failed!
Graphviz produced errors. Verify it has support for filetype=pdf, or use filetype=dot.
Original error: 2014-07-26 12:32:48.605 dot[5891:d07] CoreText performance note: Client called CTFontCreateWithName() using name "Arial Italic" and got font with PostScript name "Arial-ItalicMT". For best performance, only use PostScript names when calling this API.
/Library/Ruby/Gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/diagram/graphviz.rb:195:in `rescue in block in <class:Graphviz>'
/Library/Ruby/Gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/diagram/graphviz.rb:190:in `block in <class:Graphviz>'
/Library/Ruby/Gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/diagram.rb:142:in `instance_eval'
/Library/Ruby/Gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/diagram.rb:142:in `save'
/Library/Ruby/Gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/diagram.rb:120:in `create'
/Library/Ruby/Gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/diagram.rb:74:in `create'
/Library/Ruby/Gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/tasks.rake:41:in `block (2 levels) in <top (required)>'
Tasks: TOP => erd => erd:generate
(See full trace by running task with --trace)
메시지로 볼 때 글씨체가 안 좋아요?자세히 조사하다.
https://github.com/voormedia/rails-erd/issues/61의hayduke19us(commented on11Dec2013)는 "fontname을 Postscript 글씨체로 만들어라."라고 말했다.우선 지적된 2곳을 확인한다.

rails_erd/diagram/graphviz.rb


/Library/Ruby/Gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/diagram/graphviz.rb

module RailsERD
  class Diagram
    # Create Graphviz-based diagrams based on the domain model. For easy
    # command line graph generation, you can use:
    #
    #   % rake erd
    #
    # === Options
    #
    # The following options are supported:
    #
    # filename:: The file basename of the generated diagram. Defaults to +ERD+,
    #            or any other extension based on the file type.
    # filetype:: The file type of the generated diagram. Defaults to +pdf+, which
    #            is the recommended format. Other formats may render significantly
    #            worse than a PDF file. The available formats depend on your installation
    #            of Graphviz.
    # notation:: The cardinality notation to be used. Can be +:simple+ or
    #            +:bachman+. Refer to README.rdoc or to the examples on the project
    #            homepage for more information and examples.
    # orientation:: The direction of the hierarchy of entities. Either +:horizontal+
    #               or +:vertical+. Defaults to +horizontal+. The orientation of the
    #               PDF that is generated depends on the amount of hierarchy
    #               in your models.
    # title:: The title to add at the top of the diagram. Defaults to
    #         <tt>"YourApplication domain model"</tt>.
    class Graphviz < Diagram
      NODE_LABEL_TEMPLATES = { :html => "node.html.erb", :record => "node.record.erb" } # @private :nodoc:

      NODE_WIDTH = 130 # @private :nodoc:

      # Default graph attributes.
      GRAPH_ATTRIBUTES = {
        :rankdir => :LR,
        :ranksep => 0.5,
        :nodesep => 0.4,
        :pad => "0.4,0.4",
        :margin => "0,0",
        :concentrate => true,
        :labelloc => :t,
        :fontsize => 13,
        :fontname => "Arial Bold"
      }

      # Default node attributes.
      NODE_ATTRIBUTES = {
        :shape => "Mrecord",
        :fontsize => 10,
        :fontname => "Arial",
        :margin => "0.07,0.05",
        :penwidth => 1.0
      }

      # Default edge attributes.
      EDGE_ATTRIBUTES = {
        :fontname => "Arial",
        :fontsize => 8,
        :dir => :both,

이 근처요?백업 및 수정어쨌든 글꼴은'쿠리어'다.
변경:fontname => "Courier".

rails_erd/diagram/templates/node.html.erb


보기에도 fontface가 지정한 font가 있습니다. 수정이 필요합니다.
/Library/Ruby/Gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/diagram/templates/node.html.erb
<% if options.orientation == :vertical %>{<% end %>
<table border="0" align="center" cellspacing="0.5" cellpadding="0" width="<%= NODE_WIDTH + 4 %>">
  <tr><td align="center" valign="bottom" width="<%= NODE_WIDTH %>"><font face="Arial Bold" point-size="11"><%= entity.name %></font></td></tr>
</table>
<% if attributes.any? %>
|
<table border="0" align="left" cellspacing="2" cellpadding="0" width="<%= NODE_WIDTH + 4 %>">
<%   attributes.each do |attribute| %>
  <tr><td align="left" width="<%= NODE_WIDTH %>" port="<%= attribute %>"><%= attribute %> <font face="Arial Italic" color="grey60"><%= attribute.type_description %></font></td></tr>
<%   end %>
</table>
<% else %>
<% end %>
<% if options.orientation == :vertical %>}<% end %>
font face="Courier".

성공!!


재도전
zsh
%rake erd
Loading application environment...
Loading code in search of Active Record models...
Generating Entity-Relationship Diagram for 5 models...
Done! Saved diagram to erd.pdf.
잘 됐다!프로젝트 노선 바로 아래에 pdf 파일이 나타났습니다.
%ls
Gemfile
README.rdoc
app
config
db           
lib          
public       
tmp
Gemfile.lock 
Rakefile     
bin          
config.ru    
erd.pdf      
log          
test         
vendor
이런 느낌이 들어서 (마땅한 모델이라 미안)

Courier라면 언제나 사랑스러워요.생각났어.

좋은 웹페이지 즐겨찾기