Skip to content

Commit

Permalink
Use slots directly
Browse files Browse the repository at this point in the history
  • Loading branch information
hasarindaKI committed Feb 9, 2024
1 parent d328077 commit e49280a
Show file tree
Hide file tree
Showing 24 changed files with 298 additions and 220 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ end

group :test do
gem "capybara"
gem "compare-xml"
gem "cuprite"
gem "rack_session_access"
gem "rails-controller-testing"
gem "webmock"
gem "compare-xml"
end
24 changes: 24 additions & 0 deletions app/components/koi/tables/body/columns/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module Koi
module Tables
module Body
module Columns
class Base < Katalyst::Tables::BodyCellComponent
def before_render
# fallback if no content block is given
with_content(attribute_value) unless content?
end

def attribute_value
value.to_s
end

def inspect
"#<#{self.class.name} #{@attribute.inspect}>"
end
end
end
end
end
end
15 changes: 15 additions & 0 deletions app/components/koi/tables/body/columns/boolean_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Koi
module Tables
module Body
module Columns
class BooleanComponent < Base
def attribute_value
value ? "Yes" : "No"
end
end
end
end
end
end
21 changes: 21 additions & 0 deletions app/components/koi/tables/body/columns/date_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Koi
module Tables
module Body
module Columns
class DateComponent < Base
def initialize(table, record, attribute, format: :admin, **options)
super(table, record, attribute, **options)

@format = format
end

def attribute_value
l(value.to_date, format: @format) if value.present?
end
end
end
end
end
end
21 changes: 21 additions & 0 deletions app/components/koi/tables/body/columns/datetime_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Koi
module Tables
module Body
module Columns
class DatetimeComponent < Base
def initialize(table, record, attribute, format: :admin, **options)
super(table, record, attribute, **options)

@format = format
end

def attribute_value
l(value.to_datetime, format: @format) if value.present?
end
end
end
end
end
end
19 changes: 19 additions & 0 deletions app/components/koi/tables/body/columns/money_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Koi
module Tables
module Body
module Columns
class MoneyComponent < Base
def attribute_value
number_to_currency(value / 100.0) if value.present?
end

def default_html_attributes
{ class: "number" }
end
end
end
end
end
end
19 changes: 19 additions & 0 deletions app/components/koi/tables/body/columns/number_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Koi
module Tables
module Body
module Columns
class NumberComponent < Base
def attribute_value
number_to_human(value) if value.present?
end

def default_html_attributes
{ class: "number" }
end
end
end
end
end
end
15 changes: 15 additions & 0 deletions app/components/koi/tables/body/columns/rich_text_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Koi
module Tables
module Body
module Columns
class RichTextComponent < Base
def attribute_value
value.to_plain_text
end
end
end
end
end
end
55 changes: 55 additions & 0 deletions app/components/koi/tables/body/row_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true

module Koi
module Tables
module Body
class RowComponent < Katalyst::Tables::BodyRowComponent
# can't name this `columns` because it conflicts with the Katalyst::Tables::BodyRowComponent columns slots
renders_many :cells, types: {
boolean: {
renders: lambda do |attribute, **options, &block|
with_column(Columns::BooleanComponent.new(@table, @record, attribute, **options), &block)
end,
as: :boolean_column,
},
date: {
renders: lambda do |attribute, format: :admin, **options, &block|
with_column(Columns::DateComponent.new(@table, @record, attribute, format:, **options), &block)
end,
as: :date_column,
},
datetime: {
renders: lambda do |attribute, format: :admin, **options, &block|
with_column(Columns::DatetimeComponent.new(@table, @record, attribute, format:, **options), &block)
end,
as: :datetime_column,
},
number: {
renders: lambda do |attribute, **options, &block|
with_column(Columns::NumberComponent.new(@table, @record, attribute, **options), &block)
end,
as: :number_column,
},
money: {
renders: lambda do |attribute, **options, &block|
with_column(Columns::MoneyComponent.new(@table, @record, attribute, **options), &block)
end,
as: :money_column,
},
rich_text: {
renders: lambda do |attribute, **options, &block|
with_column(Columns::RichTextComponent.new(@table, @record, attribute, **options), &block)
end,
as: :rich_text_column,
},
text: {
renders: lambda do |attribute, **options, &block|
with_column(Columns::Base.new(@table, @record, attribute, **options), &block)
end,
as: :text_column,
},
}
end
end
end
end
44 changes: 0 additions & 44 deletions app/components/koi/tables/body_row_component.rb

This file was deleted.

22 changes: 0 additions & 22 deletions app/components/koi/tables/cell/base.rb

This file was deleted.

14 changes: 0 additions & 14 deletions app/components/koi/tables/cell/boolean_component.rb

This file was deleted.

19 changes: 0 additions & 19 deletions app/components/koi/tables/cell/date_component.rb

This file was deleted.

19 changes: 0 additions & 19 deletions app/components/koi/tables/cell/datetime_component.rb

This file was deleted.

18 changes: 0 additions & 18 deletions app/components/koi/tables/cell/money_component.rb

This file was deleted.

18 changes: 0 additions & 18 deletions app/components/koi/tables/cell/number_component.rb

This file was deleted.

13 changes: 0 additions & 13 deletions app/components/koi/tables/cell/rich_text_component.rb

This file was deleted.

12 changes: 12 additions & 0 deletions app/components/koi/tables/header/columns/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module Koi
module Tables
module Header
module Columns
class Base < Katalyst::Tables::HeaderCellComponent
end
end
end
end
end
Loading

0 comments on commit e49280a

Please sign in to comment.