Class: HtmlSlicer::Helpers::Slicer

Inherits:
Tag
  • Object
show all
Includes:
ActionView::Context
Defined in:
lib/html_slicer/helpers/slicer.rb

Defined Under Namespace

Classes: SliceProxy

Instance Method Summary collapse

Methods inherited from Tag

#slice_url_for

Constructor Details

#initialize(template, options) ⇒ Slicer

:nodoc:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/html_slicer/helpers/slicer.rb', line 26

def initialize(template, options) #:nodoc:
  @window_options = {}.tap do |h|
    h[:window] = options.delete(:window) || options.delete(:inner_window)
    outer_window = options.delete(:outer_window)
    h[:left] = options.delete(:left)
    h[:left] = outer_window if h[:left] == 0
    h[:right] = options.delete(:right)
    h[:right] = outer_window if h[:right] == 0
  end
  @template, @options = template, options
  @theme = @options[:theme] ? "#{@options[:theme]}/" : ''
  @options[:current_slice] = SliceProxy.new @window_options.merge(@options), @options[:current_slice], nil
  # initialize the output_buffer for Context
  @output_buffer = ActionView::OutputBuffer.new
end

Instance Method Details

#each_relevant_sliceObject Also known as: each_slice

enumerate each slice providing sliceProxy object as the block parameter Because of performance reason, this doesn’t actually enumerate all slices but slices that are seemingly relevant to the paginator. “Relevant” slices are:

  • slices inside the left outer window plus one for showing the gap tag

  • slices inside the inner window plus one on the left plus one on the right for showing the gap tags

  • slices inside the right outer window plus one for showing the gap tag



54
55
56
57
58
59
60
# File 'lib/html_slicer/helpers/slicer.rb', line 54

def each_relevant_slice
  return to_enum(:each_relevant_slice) unless block_given?

  relevant_slices(@window_options.merge(@options)).each do |i|
    yield SliceProxy.new(@window_options.merge(@options), i, @last)
  end
end

#render(&block) ⇒ Object

render given block as a view template



43
44
45
46
# File 'lib/html_slicer/helpers/slicer.rb', line 43

def render(&block)
  instance_eval &block if @options[:slice_number] > 1
  @output_buffer
end

#slice_tag(slice) ⇒ Object



72
73
74
# File 'lib/html_slicer/helpers/slicer.rb', line 72

def slice_tag(slice)
  @last = Slice.new @template, @options.merge(:slice => slice)
end

#to_sObject

:nodoc:



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/html_slicer/helpers/slicer.rb', line 84

def to_s #:nodoc:
  subscriber = ActionView::LogSubscriber.log_subscribers.detect {|ls| ls.is_a? ActionView::LogSubscriber}
  return super @window_options.merge(@options).merge :slicer => self unless subscriber

  # dirty hack to suppress logging render_partial
  class << subscriber
    alias_method :render_partial_with_logging, :render_partial
    # do nothing
    def render_partial(event); end
  end

  ret = super @window_options.merge(@options).merge :slicer => self

  class << subscriber
    alias_method :render_partial, :render_partial_with_logging
    undef :render_partial_with_logging
  end
  ret
end