Module: Frank::TemplateHelpers

Includes:
FrankHelpers
Included in:
Base
Defined in:
lib/frank/template_helpers.rb

Instance Method Summary collapse

Instance Method Details

#capture(&block) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/frank/template_helpers.rb', line 32

def capture(&block)
  erbout        = eval('_erbout', block.binding)
  erbout_length = erbout.length

  block.call
  
  erbout_addition = erbout[erbout_length..-1]
  erbout[erbout_length..-1] = ''

  erbout_addition
end

#content_for(name, &block) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/frank/template_helpers.rb', line 18

def content_for(name, &block)
  @content_for ||= {}
  
  if block_given?
    @content_for[name.to_sym] = capture(&block)
  else
    @content_for[name.to_sym]
  end
end

#content_for?(name) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/frank/template_helpers.rb', line 28

def content_for?(name)
  !@content_for[name.to_sym].nil?
end

#loremObject



14
15
16
# File 'lib/frank/template_helpers.rb', line 14

def lorem
  Frank::Lorem.new
end

#refreshObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/frank/template_helpers.rb', line 44

def refresh
  if Frank.exporting?
    nil
  else
    <<-JS
      <script type="text/javascript">
      (function(){
        var when = #{Time.now.to_i};

        function process( raw ){
          if( parseInt(raw) > when ) {
            window.location.reload();
          }
        }
        
        (function (){
          var req = (typeof XMLHttpRequest !== "undefined") ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
          req.onreadystatechange = function (aEvt) {
            if ( req.readyState === 4 ) {
              process( req.responseText );
            }
          };
          req.open('GET', '/__refresh__', true);
          req.send( null );
          setTimeout( arguments.callee, 1000 );
        })();

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

#render_partial(path, *locals) ⇒ Object



7
8
9
10
11
12
# File 'lib/frank/template_helpers.rb', line 7

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