Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save judofyr/b25008499799bcc007f59df4bd4cca43 to your computer and use it in GitHub Desktop.
Save judofyr/b25008499799bcc007f59df4bd4cca43 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,
&blk,
)
@href = href
@disabled = disabled
@blk = blk
end
def to_tubby
Tubby.new { |t|
t.a(
href: href,
class: css_class,
onclick: onclick
) {
@blk.call if @blk
}
}
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?
) do
t << "#{I18n.t(:sales, scope: :overview)} (#{@for_accounting[:sales]})"
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