Class: RubyGo::HTMLPrinter
- Inherits:
-
Object
- Object
- RubyGo::HTMLPrinter
- Defined in:
- lib/ruby-go/printers/html.rb
Constant Summary collapse
- LETTERS =
('A'..'Z').to_a.freeze
- COLORS =
{ black: 'black stone', white: 'white stone', empty: 'liberty' }.freeze
- TEMPLATE =
ERB.new("<style>\n.board { max-width: 100%; padding: 16px; }\n.row { display: flex; margin: 0; }\n.intersection { display: inline-block; height: 32px; width: 32px; border-top: 2px solid black; border-left: 2px solid black; }\n.intersection:last-child { border-top-width: 0px; height: 34px; }\n.row:last-child .intersection { border-left-width: 0px; width: 34px; }\n.row:last-child .intersection:last-child { width: 2px; height: 2px; background: black; }\n.stone, .liberty { display: inline-block; width: 30px; height: 30px; border-radius: 100%; margin: 0; position: relative; top: -18px; left: -18px; }\n.stone { border: 2px solid black; }\n.black.stone { background: black; }\n.white.stone { background: white; }\n.liberty:hover { border: 2px solid red; }\n.row-num, .column-num { display: inline-block; width: 34px; height: 34px; margin: 0; position: relative; }\n.row-num { top: -0.5em; }\n.column-num { left: -0.3em; }\n</style>\n<div class=\"game\">\n <div class=\"board\">\n <div class=\"row\">\n <div class=\"column-num row-num\"></div>\n <% size.times do |i| %>\n <div class=\"column-num\"><%= letters[i] %></div>\n <% end %>\n </div>\n <% rows.each_with_index do |row, i| %>\n <div class=\"row\">\n <div class=\"row-num\"><%= letters[i] %></div>\n <% row.each do |stn| %>\n <div class=\"intersection\">\n <div class=\"<%= colors[stn.color] %>\"></div>\n </div>\n <% end %>\n </div>\n <% end %>\n </div>\n\n <div class=\"info\">\n <table>\n <tbody>\n <tr>\n <th>Prisoners</th>\n <th>White</th>\n <td><%= captures[:black] %></td>\n <th>Black</th>\n <td><%= captures[:white] %></td>\n </tr>\n </tbody>\n </table>\n </div>\n</div>\n").freeze
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Instance Method Summary collapse
-
#initialize(io) ⇒ HTMLPrinter
constructor
A new instance of HTMLPrinter.
- #print_game(game) ⇒ Object
Constructor Details
#initialize(io) ⇒ HTMLPrinter
62 63 64 |
# File 'lib/ruby-go/printers/html.rb', line 62 def initialize(io) @io = io end |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
60 61 62 |
# File 'lib/ruby-go/printers/html.rb', line 60 def io @io end |
Instance Method Details
#print_game(game) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/ruby-go/printers/html.rb', line 66 def print_game(game) html = TEMPLATE.result_with_hash( size: game.board.size, captures: game.captures, rows: game.board.rows, colors: COLORS, letters: LETTERS ) io.write(html) end |