Sha256: dae44f9a258a91e83920b4497289051ad708780dfec950c1e02fa1ec8c44e3dd

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 KB

Contents

module SpaghettiHelpers
  def spaghetti name, path_or_items, options = {}
    output = ''.html_safe
    if path_or_items.class.name == 'String'
      output << "<div class=\"#{ name } spaghetti spaghetti-empty\" data-spaghetti-enabled=\"1\" data-spaghetti-url=\"#{ path_or_items }\" data-spaghetti-next-page=\"1\"><div class=\"#{ name }-items\"></div><div class=\"throbber\">#{ image_tag 'throbber.gif' }</div></div>".html_safe
    else
      if path_or_items.any?
        if options[:partial]
          items = j(render(:partial => options[:partial], :collection => path_or_items))
        else
          items = j(render(path_or_items))
        end
          output << "$('.#{ name } .#{ name }-items').append('#{ items }');".html_safe
        output << "$('.#{ name }').data('spaghetti-next-page', #{ params[:page].to_i + 1 });".html_safe
        output << "$('.#{ name }').data('spaghetti-enabled', '1');".html_safe
      else
        output << "$('.#{ name }').data('spaghetti-enabled', '0');".html_safe
        output << "$('.#{ name }').append($('<div class=\"spaghetti-disabled\"></div>'));".html_safe
      end
      output << "$('.#{ name }').removeClass('spaghetti-loading');".html_safe
    end
    output
  end  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spaghetti-0.5.1 app/helpers/spaghetti_helpers.rb
spaghetti-0.5.0 app/helpers/spaghetti_helpers.rb
spaghetti-0.4.3 app/helpers/spaghetti_helpers.rb
spaghetti-0.4.2 app/helpers/spaghetti_helpers.rb
spaghetti-0.4.1 app/helpers/spaghetti_helpers.rb