Browse Source

ansi_dimensions imporvement #1

main
pvincent 4 months ago
parent
commit
c8d04d1c62
  1. 3
      app/controllers/scores_controller.rb
  2. 4
      app/views/scores/_score.html.erb
  3. 10
      app/views/scores/index.html.erb
  4. 12
      lib/formatters/ansi_dimensions.rb
  5. 24
      test/formatters/wrapper2_test.rb

3
app/controllers/scores_controller.rb

@ -8,6 +8,9 @@ class ScoresController < ApplicationController
def index def index
@pagy, @scores = pagy(Score.all) @pagy, @scores = pagy(Score.all)
# logger.info("#{HotConstants.boolean}") # logger.info("#{HotConstants.boolean}")
logger.info('start', dimensions: AnsiDimensions.start)
logger.info('end', dimensions: AnsiDimensions.end)
logger.info('around', dimensions: AnsiDimensions.around)
end end
# GET /scores/1 # GET /scores/1

4
app/views/scores/_score.html.erb

@ -1,4 +1,4 @@
<tr id="<%= dom_id score %>">
<tr id="<%= dom_id score %>" class=''>
<td class="my-5"> <td class="my-5">
<%= score.name %> <%= score.name %>
</td> </td>
@ -7,7 +7,7 @@
<%= score.grade %> <%= score.grade %>
</td> </td>
<td class='flex items-end'>
<td class=''>
<% if action_name != "show" %> <% if action_name != "show" %>
<%= link_to score, 'data-tooltip': 'show',class: 'mr-1 border rounded-lg border-purple-800 p-2 bg-white' do %><%=fa_icon :eye %><% end %> <%= link_to score, 'data-tooltip': 'show',class: 'mr-1 border rounded-lg border-purple-800 p-2 bg-white' do %><%=fa_icon :eye %><% end %>
<%= link_to edit_score_path(score), 'data-tooltip': 'edit', class: 'mr-1 border rounded-lg border-purple-800 p-2 bg-white' do %><%=fa_icon :edit %><% end %> <%= link_to edit_score_path(score), 'data-tooltip': 'edit', class: 'mr-1 border rounded-lg border-purple-800 p-2 bg-white' do %><%=fa_icon :edit %><% end %>

10
app/views/scores/index.html.erb

@ -5,12 +5,12 @@
<%= link_to "New score", new_score_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %> <%= link_to "New score", new_score_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %>
</div> </div>
<table class="min-w-full divide-y divide-gray-300">
<table class="table-auto w-full">
<thead> <thead>
<tr>
<th>Name</th>
<th>Grade</th>
<th>Actions</th>
<tr class=''>
<th class=''>Name</th>
<th class=''>Grade</th>
<th class=''>Actions</th>
</tr> </tr>
</thead> </thead>
<%= render @scores %> <%= render @scores %>

12
lib/formatters/ansi_dimensions.rb

@ -5,4 +5,16 @@ module AnsiDimensions
def self.new(rails: '╣x╠', before: 0, after: 0, terminus: false) def self.new(rails: '╣x╠', before: 0, after: 0, terminus: false)
OpenStruct.new(rails:, before:, after:, terminus:) # rubocop:disable Style/OpenStructUse OpenStruct.new(rails:, before:, after:, terminus:) # rubocop:disable Style/OpenStructUse
end end
def self.start
OpenStruct.new(rails: '╓─╖') # rubocop:disable Style/OpenStructUse
end
def self.end
OpenStruct.new(rails: '╣ ╠') # rubocop:disable Style/OpenStructUse
end
def self.around
OpenStruct.new(rails: '╣ ╠') # rubocop:disable Style/OpenStructUse
end
end end

24
test/formatters/wrapper2_test.rb

@ -1,24 +1,30 @@
require_relative '../../lib/formatters/wrapper'
require_relative '../../lib/formatters/ansi_wrapper'
require 'minitest/autorun' require 'minitest/autorun'
class Wrapper2Test < Minitest::Test class Wrapper2Test < Minitest::Test
def test_wrap_score def test_wrap_score
assert_wrap("\ assert_wrap("\
********************\n\
********************\n\
**********",
********************\e[0m\n\
********************\e[0m\n\
**********\e[0m",
('*' * 50), 20) ('*' * 50), 20)
assert_wrap("\ assert_wrap("\
> ******************\n\
> ******************\n\
> **************",
> ******************\e[0m\n\
> ******************\e[0m\n\
> **************\e[0m",
('*' * 50), 20, '> ') ('*' * 50), 20, '> ')
end end
def test_wrap_sql def test_wrap_sql
assert_wrap("\ assert_wrap("\
\e[0m\e[0;36mELECT \"scores\".* FRO\e[0m
+\e[0m\e[0;36mM \"scores\" WHERE \"sc\e[0m
+\e[0m\e[0;36mores\".\"id\" = $1 LIMI\e[0m
+\e[0m\e[0;36mT $2\e[0m [[\"id\", 2], [\"L
IMIT\", 1]]
\e[0;35mScore Load (0.6ms)\e[0m \e[0;36mS\e[0m\n\ \e[0;35mScore Load (0.6ms)\e[0m \e[0;36mS\e[0m\n\
\e[0;36mELECT \"scores\".* FRO\e[0m\n\ \e[0;36mELECT \"scores\".* FRO\e[0m\n\
\e[0;36mM \"scores\" WHERE \"sc\e[0m\n\ \e[0;36mM \"scores\" WHERE \"sc\e[0m\n\
@ -43,11 +49,11 @@ IMIT\", 1]]", "\
def assert_wrap(expectation, text, length, prefix = '') def assert_wrap(expectation, text, length, prefix = '')
show_with_style(text, length, prefix) show_with_style(text, length, prefix)
assert_equal(expectation, prefix + Wrapper.wrap(text, prefix, length - prefix.length))
assert_equal(expectation, prefix + AnsiWrapper.wrap(text, length - prefix.length, prefix))
end end
def show_with_style(text, length, prefix = '') def show_with_style(text, length, prefix = '')
expectation = Wrapper.wrap(text, prefix, length - prefix.length)
expectation = AnsiWrapper.wrap(text, length - prefix.length, prefix)
puts "original_o is:\n#{prefix}[#{text}]\e[0m" puts "original_o is:\n#{prefix}[#{text}]\e[0m"
puts "original_i is:\n#{prefix}[#{text.inspect}]\e[0m" puts "original_i is:\n#{prefix}[#{text.inspect}]\e[0m"
puts puts

Loading…
Cancel
Save