Sha256: 29bc494408ee29e8165cfc10449cdd8c6e758a2a40ef1e22bdb343446ed226d6

Contents?: true

Size: 1.59 KB

Versions: 4

Compression:

Stored size: 1.59 KB

Contents

require 'weighted_randomizer'

module Corkboard
  module ApplicationHelper
    def attributes_for(key, custom = {})
      resource = custom.delete(:resource)

      attrs = begin
        if (framework = Corkboard.presentation[:framework]) && framework.present?
          { :class => send(:"classes_for_#{framework}", key) }
        else
          { :class => classes_for_plain(key) }
        end
      end

      attrs.merge!(send(:"data_for_#{key}", resource))

      attrs.tap do |h|
        custom.each do |name, value|
          h[name] = [value, h[name]].join(' ')
        end
      end
    end

    private

      def classes_for_bootstrap(key)
        @_classes_for_bootstrap ||= {
          :filters_list => 'btn-group',
          :filters_item => 'btn'
        }

        @_classes_for_bootstrap[key]
      end

      def classes_for_plain(key)
        @_classes_for_plain ||= {
          :filters_list => nil,
          :filters_item => nil
        }

        @_classes_for_plain[key]
      end

      def data_for_filters_list(*)
        {}
      end

      def data_for_filters_item(*)
        {}
      end

      def data_for_posts_item(post)
        special = (Corkboard.interests[:scope] + [:all])
        tags    = post[:tags].reject { |t| special.include?(t.intern) }

        {
          :class => ['entry', randomizer.sample].join(' '),
          :data  => {
            :eid  => post[:eid],
            :tags => tags.join(' ')
          }
        }
      end

      def randomizer
        @randomizer ||= begin
          WeightedRandomizer.new(Corkboard.presentation[:weights])
        end
      end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
corkboard-0.1.3 app/helpers/corkboard/application_helper.rb
corkboard-0.1.2 app/helpers/corkboard/application_helper.rb
corkboard-0.1.1 app/helpers/corkboard/application_helper.rb
corkboard-0.1.0 app/helpers/corkboard/application_helper.rb