Skip to content

Instantly share code, notes, and snippets.

@stoivo
Last active January 7, 2019 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stoivo/462bd724e41de0f21fd3f1d79feb2c33 to your computer and use it in GitHub Desktop.
Save stoivo/462bd724e41de0f21fd3f1d79feb2c33 to your computer and use it in GitHub Desktop.
# /app/components/link_as_button.rb
class LinkAsButton
attr_reader :href
attr_reader :disabled
def initialize(
href:,
disabled: false
)
@href = href
@disabled = disabled
end
def to_tubby
Tubby.new { |t|
t.a(
href: href,
class: css_class,
onclick: onclick
) {
t << yield
}
}
end
def to_s &block
to_tubby(&block).to_s.html_safe
end
def css_class
"buttons-standard#{disabled ? " disabled" : ""}"
end
def onclick
return "return false;" if disabled
end
end
# app/components/overview_for_accounting.rb
class OverviewForAccounting
attr_reader :for_accounting
def initialize(for_accounting:)
@for_accounting = for_accounting
end
def to_tubby
Tubby.new { |t|
t << "#{I18n.t(:for_accounting, scope: :overview)}:"
t << LinkAsButton.new(
href: "/invoices/carousel_show?carousel_state=for_accounting&type=sales",
disabled: @for_accounting[:sales].zero?).to_s do
"#{I18n.t(:sales, scope: :overview)} (#{@for_accounting[:sales]})"
end
t << LinkAsButton.new(
href: "/invoices/carousel_show?carousel_state=for_accounting&type=purchases",
disabled: @for_accounting[:purchases].zero?).to_s do
"#{I18n.t(:purchases, scope: :overview)} (#{@for_accounting[:purchases]})"
end
t << LinkAsButton.new(
href: "/invoices/carousel_show?carousel_state=for_accounting&type=salaries",
disabled: @for_accounting[:salaries].zero?).to_s do
"#{I18n.t(:salaries, scope: :overview)} (#{@for_accounting[:salaries]})"
end
t << LinkAsButton.new(
href: "/invoices/carousel_show?carousel_state=for_accounting&type=salaries",
disabled: @for_accounting[:salaries].zero?).to_s do
"#{I18n.t(:salaries, scope: :overview)} (#{@for_accounting[:salaries]})"
end
t << LinkAsButton.new(
href: "/reconciliation_carousel",
disabled: @for_accounting[:reconciliations].zero?).to_s do
"#{I18n.t(:payments, scope: :overview)} (#{@for_accounting[:reconciliations]})"
end
t << LinkAsButton.new(
href: "/cash_register/not_bookkeept",
disabled: @for_accounting[:cash_register_not_bookkept].zero?).to_s do
"#{I18n.t(:cash_register_not_bookkept, scope: :overview)} (#{@for_accounting[:cash_register_not_bookkept]})"
end
t << LinkAsButton.new(
href: "/cash_register/not_bookkeept",
disabled: @for_accounting[:cash_register_not_bookkept].zero?).to_s do
"#{I18n.t(:cash_register_not_bookkept, scope: :overview)} (#{@for_accounting[:cash_register_not_bookkept]})"
end
t << LinkAsButton.new(
href: "/cash_register/not_sum_to_zero",
disabled: @for_accounting[:cash_register_not_sum_to_zero].zero?).to_s do
"#{I18n.t(:cash_register_not_sum_to_zero, scope: :overview)} (#{@for_accounting[:cash_register_not_sum_to_zero]})"
end
}
end
def to_s
to_tubby().to_s.html_safe
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment