Created
December 26, 2013 14:13
-
-
Save gnue/8134298 to your computer and use it in GitHub Desktop.
Rails ERD が OS X Mavericks でエラーになる問題を改善するRubyコード(prepend を使用しているため Ruby 2.0 以上)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_erd/diagram/graphviz' | |
module RailsERD | |
class Diagram | |
module GraphvizFontFix | |
# font name to PostScript name table | |
FONTNAMES = { | |
'Arial' => 'ArialMT', | |
'Arial Bold' => 'Arial-BoldMT', | |
'Arial Italic' => 'Arial-ItalicMT', | |
} | |
def entity_options(entity, attributes) | |
result = super | |
# replace font name | |
result[:label].gsub!(/face="([^\"]+)"/) { | |
fontname = $1 | |
psname = FONTNAMES[fontname] || fontname | |
%Q|face="#{psname}"| | |
} | |
result | |
end | |
end | |
class Graphviz | |
prepend GraphvizFontFix | |
# replace font name | |
[GRAPH_ATTRIBUTES, NODE_ATTRIBUTES, EDGE_ATTRIBUTES].each { |attrs| | |
fontname = attrs[:fontname] | |
attrs[:fontname] = FONTNAMES[fontname] || fontname | |
} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment