Skip to content

Commit

Permalink
Allow bootstrap_text_input to take an array for the addon option.
Browse files Browse the repository at this point in the history
Make `false.present?` return false like in ActiveSupport.
  • Loading branch information
UweKubosch committed Mar 23, 2024
1 parent 13b8b91 commit 740645c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group 'no.datek'
version '0.16.1'
version '0.16.2'
final String JRUBY_VERSION = '9.4.5.0';

repositories {
Expand Down
8 changes: 7 additions & 1 deletion src/main/resources/ruby/core_ext.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
class Object
def present? = !blank?

def blank? = false

def try(method, *args)
return nil unless self.respond_to?(method)
return send(method, *args)
send(method, *args)
end
end

class NilClass
def blank? = true

def try(*) = nil
end

class FalseClass
def blank? = true
end

class String
def blank? = strip.empty?
end
10 changes: 6 additions & 4 deletions src/main/resources/ruby/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,12 @@ def bootstrap_text_input(object, field_name, **opts)
html << %{<div class="input-group flex-nowrap" >} if append
html << text_input(object, field_name, class: classes, no_break: true, **opts)
if append
if append.include?('btn')
html << append
else
html << %{<span class="input-group-text">#{append}</span>}
[*append].compact.each do |addon|
if addon.start_with?('<')
html << addon
else
html << %{<span class="input-group-text">#{addon}</span>}
end
end
html << '</div>'
end
Expand Down

0 comments on commit 740645c

Please sign in to comment.