Sha256: def6a95ff4b337ef39f579d03f913232a93dff54eaf4453ade23adf3197f4ccb

Contents?: true

Size: 1.47 KB

Versions: 44

Compression:

Stored size: 1.47 KB

Contents

module Noodall::ComponentsHelper


  def component_row(*args)
    node = args.shift
  raise ActiveRecord::RecordNotFound if node.nil?
    components = args.map { |slot_code| node.send(slot_code) }

    # render each slot in the row
    args.map do |slot_code|
      index = args.index(slot_code)
      component = components[index]

      #Build a string here to stop ruby 1.9 outputting a normal printed array
      additional_classes = ""
      additional_classes << ' ' + slot_code.split("_").shift + ' ' unless slot_code.split("_").shift.nil?
      additional_classes << ' penultimate ' if slot_code == args[args.size - 2]
      additional_classes << ' last ' if args.last == slot_code
      additional_classes << ' first ' if args.first == slot_code

      # pass a flag to the view to add an expanded html class
      component(node, slot_code, ( components[index + 1].nil? && index < (args.size - 1) ), additional_classes).to_s
    end.join.html_safe
  end

  def component(node, slot_code, expand = false, additional_classes = '')
    component = node.send(slot_code)

    #Use a string here to stop ruby 1.9 outputting a normal printed array
    additional_classes = ""
    additional_classes << slot_code.split("_").shift unless slot_code.split("_").shift.nil?

    render :partial => "components/#{component.class.name.underscore}", :locals => { :slot_code => slot_code, :component => component, :expand => expand, :additional_classes => additional_classes } unless component.nil?
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
noodall-ui-0.5.15 app/helpers/noodall/components_helper.rb
noodall-ui-0.5.14 app/helpers/noodall/components_helper.rb
noodall-ui-0.5.13 app/helpers/noodall/components_helper.rb
noodall-ui-0.5.12 app/helpers/noodall/components_helper.rb
noodall-ui-0.5.11 app/helpers/noodall/components_helper.rb
noodall-ui-0.4.11 app/helpers/noodall/components_helper.rb
noodall-ui-0.4.10 app/helpers/noodall/components_helper.rb
noodall-ui-0.5.10 app/helpers/noodall/components_helper.rb
noodall-ui-0.5.9 app/helpers/noodall/components_helper.rb
noodall-ui-0.4.9 app/helpers/noodall/components_helper.rb
noodall-ui-0.5.8 app/helpers/noodall/components_helper.rb
noodall-ui-0.4.8 app/helpers/noodall/components_helper.rb
noodall-ui-0.4.7 app/helpers/noodall/components_helper.rb
noodall-ui-0.5.7 app/helpers/noodall/components_helper.rb
noodall-ui-0.5.6 app/helpers/noodall/components_helper.rb
noodall-ui-0.5.5 app/helpers/noodall/components_helper.rb
noodall-ui-0.5.4 app/helpers/noodall/components_helper.rb
noodall-ui-0.5.3 app/helpers/noodall/components_helper.rb
noodall-ui-0.5.2 app/helpers/noodall/components_helper.rb
noodall-ui-0.5.1 app/helpers/noodall/components_helper.rb