Class: RMVisualizer
- Inherits:
-
Object
- Object
- RMVisualizer
- Defined in:
- lib/rails_model_visualizer.rb,
lib/rails_model_visualizer/version.rb,
lib/rails_model_visualizer/templates.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
Class Method Details
.css ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rails_model_visualizer/templates.rb', line 3 def self.css "html, body, h1, ul, li, button, div, h2, h3, p { margin: 0; padding: 0; border: 0; outline: 0; font: inherit; color: inherit; text-align: inherit; text-decoration: inherit; vertical-align: inherit; box-sizing: inherit; background: transparent; } body { display: flex; flex-direction: column } ul { list-style: none; margin-top: 10px; /* margin-right: 20px; */ font-size: 18px; width: 350px; font-size: 20px; } ul li, .list-name { text-decoration: none; padding-top: 5px; font-size: 16px; } ul li:first-child, .list-name:first-child { margin-top: 10px; } .model { border: 5px solid black; margin: 10px; padding: 10px; color: white; background-color: red; padding: 20px; text-align: center; } h1 { font-size: 40px; text-align: center; } .model-details { display: flex; justify-content: space-between; } .list-source { display: none; position: absolute; background-color: #ccc; color: black; z-index: 1; left:150px; padding: 5px; border-radius: 3px; text-align: left; } .list-name:hover > div { display: block; } .list-name { position: relative; cursor: pointer; } .superclass { display flex; border: 10px solid black; text-align: center; font-size: 40px; padding: 10px; }" end |
.html(body) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rails_model_visualizer/templates.rb', line 94 def self.html(body) start = "<!DOCTYPE html> <html> <head> <meta charset=\"utf-8\"> <title>Rails Model Visualizer</title> <link rel=\"stylesheet\" media=\"all\" href=\"./application.css\"> </head> <body>" finish = "</body> </html>" return(start + body + finish) end |
.import_models ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rails_model_visualizer.rb', line 9 def self.import_models if Rails.application Rails.application.eager_load! return ActiveRecord::Base.descendants.map do |rails_model| Model.new(rails_model) end else return [] end end |
.print_models ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rails_model_visualizer.rb', line 20 def self.print_models superclasses = {} RMVisualizer.import_models.each do |m| if superclasses[m.super_class] superclasses[m.super_class] += m.to_div else superclasses[m.super_class] = m.to_div end end body = "" superclasses.each do |superclass, model_div| body += "<div class=\"superclass\">#{superclass} #{model_div} </div>" end File.open("output.html", 'w+') do |file| file.write(RMVisualizer.html(body)) end File.open("application.css", "w+") do |file| file.write(RMVisualizer.css) end puts "output.html created at root folder" Launchy.open("./output.html") return nil end |