Sha256: a8fc249c13e4120fceafda9b7e82a5fb2650dcab41ccf98e28c3e86ecf60f996

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

require 'frank/lorem'

module Frank
  module TemplateHelpers
    include FrankHelpers if defined? FrankHelpers
  
    def render_partial(path)
      pieces = path.split('/')
      partial = '_' + pieces.pop
      render(File.join(pieces.join('/'), partial))
    end
    
    def lorem
      Frank::Lorem.new(@environment)
    end
    
    def refresh
      if @environment == :output || @environment == :production
        nil
      else
        <<-JS
          <script type="text/javascript">
          (function(){
            var when = #{Time.now.to_i};

            function process( raw ){
              if( eval(raw)[0] > when )
                window.location.reload();
            }

            (function poll(){
              var req = new XMLHttpRequest();  
              req.open('GET', '/__refresh__', true);  
              req.onreadystatechange = function (aEvt) {  
                if ( req.readyState == 4 && req.status == 200 )
                  process(req.responseText);
              };
              req.send(null);
              setTimeout( poll, 1000 );
            })();

          })();
          </script>
        JS
      end
    end
    
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
frank-0.3.1 lib/frank/template_helpers.rb
frank-0.3.0 lib/frank/template_helpers.rb
frank-0.3.0.beta2 lib/frank/template_helpers.rb
frank-0.3.0.beta lib/frank/template_helpers.rb