hellobase 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/hellobase/formtastic/datepicker_with_time_input.rb +43 -37
 - data/lib/hellobase/version.rb +1 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 58d94618d33b35eb07fa61f5a1ec5dbffaf39184dd15ba53b952864ff87bc50a
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 26ab6624cbf12e1a09e31e2e9959130f91ebf6ee4f4c237ded77d6daecfcd585
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: a94d80712b33120f7697250b4efc2410c0669ae612f87c70fbf383f69f7026635f9ef1914b4c0943416c67cc33132532f520d5f99113e7cf9e388ca31000cd15
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: a025c3bc76d3b544300087e2cfb5c2aa4c5c40ac8d0d84f7b65926f18568f899e6c5cc4d65956c0ad2cb1c0d8596b2a97d1c0ca58d0cbc47830e920f3b7e37b1
         
     | 
| 
         @@ -3,54 +3,64 @@ require 'active_admin/inputs' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            class DatepickerWithTimeInput
         
     | 
| 
       4 
4 
     | 
    
         
             
              include ::Formtastic::Inputs::Base
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
              def  
     | 
| 
       7 
     | 
    
         
            -
                 
     | 
| 
      
 6 
     | 
    
         
            +
              def self.virtual_attributes(attr)
         
     | 
| 
      
 7 
     | 
    
         
            +
                [:"_dpwt_#{attr}_d", :"_dpwt_#{attr}_t"]
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                 
     | 
| 
       11 
     | 
    
         
            -
                zone_hidden_html = Formtastic::Inputs::HiddenInput.new(builder, template, object, object_name, "#{method}_tz", {}).to_html
         
     | 
| 
       12 
     | 
    
         
            -
                value_hidden_html = Formtastic::Inputs::HiddenInput.new(builder, template, object, object_name, method, {}).to_html
         
     | 
| 
       13 
     | 
    
         
            -
                zone_span_html = template.content_tag(:span, time_zone)
         
     | 
| 
      
 10 
     | 
    
         
            +
              def self.define_virtual_attributes(klass, attr)
         
     | 
| 
      
 11 
     | 
    
         
            +
                return if klass.respond_to? :_dpwt_defined
         
     | 
| 
       14 
12 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
                 
     | 
| 
       16 
     | 
    
         
            -
                   
     | 
| 
       17 
     | 
    
         
            -
                  replace_li_tag(time_select_html),
         
     | 
| 
       18 
     | 
    
         
            -
                  replace_li_tag(zone_hidden_html),
         
     | 
| 
       19 
     | 
    
         
            -
                  replace_li_tag(value_hidden_html),
         
     | 
| 
       20 
     | 
    
         
            -
                  zone_span_html,
         
     | 
| 
       21 
     | 
    
         
            -
                  error_html,
         
     | 
| 
       22 
     | 
    
         
            -
                  hint_html,
         
     | 
| 
       23 
     | 
    
         
            -
                ].compact.join("\n").html_safe
         
     | 
| 
      
 13 
     | 
    
         
            +
                klass.class_eval <<-RUBY
         
     | 
| 
      
 14 
     | 
    
         
            +
                  def self._dpwt_defined; end
         
     | 
| 
       24 
15 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
      
 16 
     | 
    
         
            +
                  def _dpwt_#{attr}_d
         
     | 
| 
      
 17 
     | 
    
         
            +
                    self.#{attr}&.strftime('%Y-%m-%d')
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
       27 
19 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
                  def _dpwt_#{attr}_t
         
     | 
| 
      
 21 
     | 
    
         
            +
                    self.#{attr}&.strftime('%R')
         
     | 
| 
      
 22 
     | 
    
         
            +
                  end
         
     | 
| 
       29 
23 
     | 
    
         | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
                  def _dpwt_#{attr}_d=(val)
         
     | 
| 
      
 25 
     | 
    
         
            +
                    @_dpwt_#{attr}_d = val
         
     | 
| 
      
 26 
     | 
    
         
            +
                    _dpwt_set_#{attr}
         
     | 
| 
       34 
27 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
                  define_method(:#{method}_buffer) do
         
     | 
| 
       37 
     | 
    
         
            -
                    @#{method}_v ||= #{method}&.in_time_zone('#{time_zone}')
         
     | 
| 
      
 28 
     | 
    
         
            +
                    val
         
     | 
| 
       38 
29 
     | 
    
         
             
                  end
         
     | 
| 
       39 
30 
     | 
    
         | 
| 
       40 
     | 
    
         
            -
                   
     | 
| 
       41 
     | 
    
         
            -
                    #{ 
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
      
 31 
     | 
    
         
            +
                  def _dpwt_#{attr}_t=(val)
         
     | 
| 
      
 32 
     | 
    
         
            +
                    @_dpwt_#{attr}_t = val
         
     | 
| 
      
 33 
     | 
    
         
            +
                    _dpwt_set_#{attr}
         
     | 
| 
       43 
34 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
                    #{method}_buffer&.strftime('%Y-%m-%d')
         
     | 
| 
      
 35 
     | 
    
         
            +
                    val
         
     | 
| 
       46 
36 
     | 
    
         
             
                  end
         
     | 
| 
       47 
37 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
                   
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
      
 38 
     | 
    
         
            +
                  private
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                  def _dpwt_set_#{attr}
         
     | 
| 
      
 41 
     | 
    
         
            +
                    self.#{attr} = @_dpwt_#{attr}_d.blank? || @_dpwt_#{attr}_t.blank? ? nil : [@_dpwt_#{attr}_d, @_dpwt_#{attr}_t].join(' ')
         
     | 
| 
       50 
42 
     | 
    
         
             
                  end
         
     | 
| 
       51 
43 
     | 
    
         
             
                RUBY
         
     | 
| 
       52 
44 
     | 
    
         
             
              end
         
     | 
| 
       53 
45 
     | 
    
         | 
| 
      
 46 
     | 
    
         
            +
              def to_html
         
     | 
| 
      
 47 
     | 
    
         
            +
                datepicker_html = ActiveAdmin::Inputs::DatepickerInput.new(builder, template, object, object_name, :"_dpwt_#{method}_d", datepicker_options).to_html
         
     | 
| 
      
 48 
     | 
    
         
            +
                time_select_html = Formtastic::Inputs::SelectInput.new(builder, template, object, object_name, :"_dpwt_#{method}_t", time_select_options).to_html
         
     | 
| 
      
 49 
     | 
    
         
            +
                zone_display_html = options[:time_zone] ? template.content_tag(:span, options[:time_zone]) : nil
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                wrapper_contents = [
         
     | 
| 
      
 52 
     | 
    
         
            +
                  replace_li_tag(datepicker_html),
         
     | 
| 
      
 53 
     | 
    
         
            +
                  replace_li_tag(time_select_html),
         
     | 
| 
      
 54 
     | 
    
         
            +
                  zone_display_html,
         
     | 
| 
      
 55 
     | 
    
         
            +
                  error_html,
         
     | 
| 
      
 56 
     | 
    
         
            +
                  hint_html,
         
     | 
| 
      
 57 
     | 
    
         
            +
                ].compact.join("\n").html_safe
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                template.content_tag(:li, wrapper_contents, wrapper_html_options)
         
     | 
| 
      
 60 
     | 
    
         
            +
              end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
              private
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
       54 
64 
     | 
    
         
             
              def datepicker_options
         
     | 
| 
       55 
65 
     | 
    
         
             
                {
         
     | 
| 
       56 
66 
     | 
    
         
             
                  label: label_text,
         
     | 
| 
         @@ -64,10 +74,6 @@ class DatepickerWithTimeInput 
     | 
|
| 
       64 
74 
     | 
    
         
             
                }.merge(options[:time_select_options] || {})
         
     | 
| 
       65 
75 
     | 
    
         
             
              end
         
     | 
| 
       66 
76 
     | 
    
         | 
| 
       67 
     | 
    
         
            -
              def time_zone
         
     | 
| 
       68 
     | 
    
         
            -
                options[:time_zone] || 'UTC'
         
     | 
| 
       69 
     | 
    
         
            -
              end
         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
77 
     | 
    
         
             
              # formtastic inputs generate <li> with no way to override
         
     | 
| 
       72 
78 
     | 
    
         
             
              def replace_li_tag(html)
         
     | 
| 
       73 
79 
     | 
    
         
             
                html.strip.sub(/^<li /, '<span ').sub(/<\/li>$/, '</span>').html_safe
         
     | 
    
        data/lib/hellobase/version.rb
    CHANGED