Sha256: ff60d1fe7a26f57ab5ab5ee340082d8b4c20251cb57bf0f1aa45aa228282a7d6

Contents?: true

Size: 1.31 KB

Versions: 43

Compression:

Stored size: 1.31 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]

      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.join(' ')).to_s
    end.to_s.html_safe
  end

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

    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

43 entries across 43 versions & 1 rubygems

Version Path
noodall-ui-0.1.4 app/helpers/noodall/components_helper.rb
noodall-ui-0.1.3 app/helpers/noodall/components_helper.rb
noodall-ui-0.1.2 app/helpers/noodall/components_helper.rb
noodall-ui-0.1.1 app/helpers/noodall/components_helper.rb
noodall-ui-0.1.0 app/helpers/noodall/components_helper.rb
noodall-ui-0.0.22 app/helpers/noodall/components_helper.rb
noodall-ui-0.0.21 app/helpers/noodall/components_helper.rb
noodall-ui-0.0.20 app/helpers/noodall/components_helper.rb
noodall-ui-0.0.19 app/helpers/noodall/components_helper.rb
noodall-ui-0.0.18 app/helpers/noodall/components_helper.rb
noodall-ui-0.0.17 app/helpers/noodall/components_helper.rb
noodall-ui-0.0.16 app/helpers/noodall/components_helper.rb
noodall-ui-0.0.15 app/helpers/noodall/components_helper.rb
noodall-ui-0.0.14 app/helpers/noodall/components_helper.rb
noodall-ui-0.0.13 app/helpers/noodall/components_helper.rb
noodall-ui-0.0.12 app/helpers/noodall/components_helper.rb
noodall-ui-0.0.11 app/helpers/noodall/components_helper.rb
noodall-ui-0.0.10 app/helpers/noodall/components_helper.rb
noodall-ui-0.0.9 app/helpers/noodall/components_helper.rb
noodall-ui-0.0.8 app/helpers/noodall/components_helper.rb