Sha256: 8885227e4dc21c8e5ffb8097322ef7822f92d9b007d9c53c103d0d3ae654baa6

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

module Apotomo
  module JavascriptMethods
    # Wraps the rendered content in a replace statement targeted at your +Apotomo.js_framework+ setting.
    # Use +:selector+ to change the selector.
    #
    # Example:
    #
    # Assuming you set 
    #   Apotomo.js_framework = :jquery
    #
    # and call replace in a state
    #
    #   replace :view => :squeak, :selector => "div#mouse"
    #   #=> "$(\"div#mouse\").replaceWith(\"<div id=\\\"mum\\\">squeak!<\\/div>\")"
    def replace(*args)
      wrap_in_javascript_for(:replace, *args)
    end
    
    # Same as replace except that the content is wrapped in an update statement.
    #
    # Example for +:jquery+:
    #
    #   update :view => :squeak
    #   #=> "$(\"mum\").html(\"<div id=\\\"mum\\\">squeak!<\\/div>\")"
    def update(*args)
      wrap_in_javascript_for(:update, *args)
    end
    
  private
    def wrap_in_javascript_for(mode, *args)
      content = render(*args)
      options = args.first.is_a?(::Hash) ? args.shift : {}
      
      options[:selector] ? 
        Apotomo.js_generator.send(mode, options[:selector], content) :  # replace(:twitter)
        Apotomo.js_generator.send("#{mode}_id", name, content)          # replace_id(:twitter)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
apotomo-1.1.0.rc1 lib/apotomo/widget/javascript_methods.rb