Sha256: 959ff75ead0e053284fc059770e81e782c76618607371f1feee00474b3edc4a4

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

require 'frank/lorem'

module Frank
  module TemplateHelpers
    include FrankHelpers if defined? FrankHelpers

    def render_partial(path, *locals)
      pieces = path.split('/')
      partial = '_' + pieces.pop
      locals = locals.empty? ? nil : locals[0]
      render(File.join(pieces.join('/'), partial), partial = true, locals)
    end

    def lorem
      Frank::Lorem.new
    end

    def refresh
      if Frank.exporting?
        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

3 entries across 3 versions & 1 rubygems

Version Path
frank-1.0.2 lib/frank/template_helpers.rb
frank-1.0.1 lib/frank/template_helpers.rb
frank-1.0.0 lib/frank/template_helpers.rb