Sha256: 4f9ae98a1abcd8c632fe0700b1be149c2942ca943080eb32a73e1f5d1482316f

Contents?: true

Size: 1022 Bytes

Versions: 2

Compression:

Stored size: 1022 Bytes

Contents

module Jibe
  module ViewHelpers
    def jibe *args
      if args.try(:last).is_a? Hash
        strategy = args.try(:last)[:strategy]
        scope = args.try(:last)[:scope]
        restrict_to = args.try(:last)[:restrict_to]
      end
    
      strategy = "append" if strategy.blank?
      resource = "#{args.first.first.class.name}".downcase.pluralize
      data = { 
        strategy: strategy, 
        resource: resource,
        scope: scope
      }
    
      if restrict_to
        data[:restrict_to] = []
      
        if restrict_to.is_a? Array
          restrict_to.each do |restrict|
            data[:restrict_to].push "#{restrict.class.name.downcase}-#{restrict.id}"
          end
        else
          data[:restrict_to].push "#{restrict_to.class.name.downcase}-#{restrict_to.id}"
        end
      
        data[:restrict_to] = data[:restrict_to].join(",")
      end
    
      html = content_tag :script, nil, type: "x-jibe", data: data
      html += render *args
      html.html_safe
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jibe-0.0.3 lib/jibe/view_helpers.rb
jibe-0.0.2 lib/jibe/view_helpers.rb