Sha256: ac06a1cbdc781d1bc8c1b48e39448900f0f3ba57b84e5c6ca8d3218d4d85226d

Contents?: true

Size: 1.55 KB

Versions: 11

Compression:

Stored size: 1.55 KB

Contents

require 'omf-web/theme/bright/widget_chrome'
require 'omf-web/theme/bright/layout_renderer'

module OMF::Web::Theme

  class StackedRenderer < LayoutRenderer

    def initialize(stacked_widget, widgets, active_index, opts)
      @stacked_widget = stacked_widget
      @widgets = widgets
      @active_index = active_index
      @helper = StackedRendererHelper.new(widgets, active_index, opts)
      @opts = opts
    end

    def to_html()
      wp = "w#{@helper.object_id}"
      @opts[:menu] = @widgets.each_with_index.map do |w, i|
        wc = w.widget_type.split('/').inject([]) do |a, e|
                a << (a.empty? ? e : "#{a[-1]}_#{e}")
              end
        {
          :name => w.name,
          :class => wc.join(' '),
          :is_active => (@active_index == i),
          :id => "#{wp}_l_#{i}",
          :js_function => 'OML.show_widget',
          :inner_class => wp,
          :index => i,
          :widget_id => w.dom_id
        }
      end
      WidgetChrome.new(@stacked_widget, @helper, @opts).to_html
    end
  end

  class StackedRendererHelper < Erector::Widget

    def initialize(widgets, active_index, opts)
      super opts
      @widgets = widgets
      @active_index = active_index
    end

    def content()
      #widget @active_widget
      widgets = @widgets
      prefix = "w#{self.object_id}"
      @widgets.each_with_index do |w, i|
        style = i == @active_index ? '' : 'display:none'
        div :id => "#{prefix}_#{i}", :class => prefix, :style => style do
         rawtext w.content.to_html
        end
      end
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
omf_web-1.2.9 lib/omf-web/theme/bright/stacked_renderer.rb
omf_web-1.2.8 lib/omf-web/theme/bright/stacked_renderer.rb
omf_web-1.2.7 lib/omf-web/theme/bright/stacked_renderer.rb
omf_web-1.2.6 lib/omf-web/theme/bright/stacked_renderer.rb
omf_web-1.2.5 lib/omf-web/theme/bright/stacked_renderer.rb
omf_web-1.2.4 lib/omf-web/theme/bright/stacked_renderer.rb
omf_web-1.2.3 lib/omf-web/theme/bright/stacked_renderer.rb
omf_web-1.2.2 lib/omf-web/theme/bright/stacked_renderer.rb
omf_web-1.2.1 lib/omf-web/theme/bright/stacked_renderer.rb
omf_web-1.2.0 lib/omf-web/theme/bright/stacked_renderer.rb
omf_web-1.0.0 lib/omf-web/theme/bright/stacked_renderer.rb