class Gobstones::HtmlRenderer

Public Class Methods

new(options) click to toggle source
# File lib/render/html_renderer.rb, line 5
def initialize(options)
  @options = options
end

Public Instance Methods

render_error_check_error_failed_another_reason(result) click to toggle source
# File lib/render/html_renderer.rb, line 50
def render_error_check_error_failed_another_reason(result)
  bind_result error: :check_error_failed_another_reason,
              expected_code: result[:expected_code],
              reason: prepare_reason(result[:reason])
end
render_error_check_error_failed_expected_boom(result) click to toggle source
# File lib/render/html_renderer.rb, line 32
def render_error_check_error_failed_expected_boom(result)
  bind_result error: :check_error_failed_expected_boom,
              boards: prepare_boards([:initial, :expected, :final], result)
end
render_error_check_failed_unexpected_boom(result) click to toggle source
# File lib/render/html_renderer.rb, line 26
def render_error_check_failed_unexpected_boom(result)
  bind_result error: :check_failed_unexpected_boom,
              boards: prepare_boards([:initial, :expected, :actual], result),
              reason: prepare_reason(result[:reason])
end
render_error_check_final_board_failed_different_boards(result) click to toggle source
# File lib/render/html_renderer.rb, line 16
def render_error_check_final_board_failed_different_boards(result)
  bind_result error: :check_final_board_failed_different_boards,
              boards: prepare_boards([:initial, :expected, :actual], result)
end
render_error_check_final_board_failed_different_headers(result) click to toggle source
# File lib/render/html_renderer.rb, line 21
def render_error_check_final_board_failed_different_headers(result)
  bind_result error: :check_final_board_failed_different_headers,
              boards: prepare_boards([:initial, :expected, :actual], result)
end
render_error_check_return_failed_different_values(result) click to toggle source
# File lib/render/html_renderer.rb, line 43
def render_error_check_return_failed_different_values(result)
  bind_result error: :check_return_failed_different_values,
              boards: prepare_boards([:initial], result),
              expected_value: result[:expected_value],
              actual_value: result[:actual_value]
end
render_error_check_return_failed_no_return(result) click to toggle source
# File lib/render/html_renderer.rb, line 37
def render_error_check_return_failed_no_return(result)
  bind_result error: :check_return_failed_no_return,
              boards: prepare_boards([:initial], result),
              expected_value: result[:expected_value]
end
render_success(result) click to toggle source
# File lib/render/html_renderer.rb, line 9
def render_success(result)
  board_types = [:initial, :final]
  board_types.reject!{ |it| it === :initial } unless @options[:show_initial_board]
  bind_result boards: prepare_boards(board_types, result),
              reason: prepare_reason(result[:reason])
end

Private Instance Methods

bind_result(result) click to toggle source
# File lib/render/html_renderer.rb, line 87
def bind_result(result)
  @result = { boards: [] }.merge result
  template_file.result binding
end
prepare_boards(board_types, result) click to toggle source
# File lib/render/html_renderer.rb, line 63
def prepare_boards(board_types, result)
  visible_board_types(board_types, result).map do |it|
    struct title: "#{it}_board".to_sym,
           board: visible_board(result, it)
  end
end
prepare_reason(reason) click to toggle source
# File lib/render/html_renderer.rb, line 58
def prepare_reason(reason)
  return unless reason
  Gobstones::build_error(reason)
end
template_file() click to toggle source
# File lib/render/html_renderer.rb, line 92
def template_file
  ERB.new File.read("#{__dir__}/boards.html.erb")
end
visible_board(result, board_types) click to toggle source
# File lib/render/html_renderer.rb, line 77
def visible_board(result, board_types)
  board = result[board_types]

  if board.like? :boom
    HtmlBoard.new(result[:initial], boom: true)
  else
    HtmlBoard.new(board)
  end
end
visible_board_types(board_types, result) click to toggle source
# File lib/render/html_renderer.rb, line 70
def visible_board_types(board_types, result)
  board_types.select do |it|
    must_show = @options["show_#{it}_board".to_sym]
    result[it] && (must_show.nil? || must_show)
  end
end