Sha256: ebabede6eb17aaacf1991ff5901b6c5e961441849e5c0dc58a392f9b565d431d

Contents?: true

Size: 1.32 KB

Versions: 12

Compression:

Stored size: 1.32 KB

Contents

require 'active_tools/misc/uniq_content'

module ActiveTools
  module Misc
    DEFAULT_JS_FLOW_KEY = :_script_flow
  end
  
  module OnLoadActionController
    def _render_template(options)
      if lookup_context.rendered_format == :js
         super + uniq_content_storage.render_content(Misc::DEFAULT_JS_FLOW_KEY)
      else
        super
      end
    end
  end
  
  module OnLoadActionView
    def script(*args, &block)
      options = args.extract_options!
      content = args.first
      if content || block_given?
        if block_given?
          content = capture(&block)
        end
        if content
          case request.format
          when Mime::JS then
            uniq_content_storage.append_content(content, Misc::DEFAULT_JS_FLOW_KEY)
            nil
          when Mime::HTML then
            volume = options.delete(:volume)
            unless uniq_content_storage.remembered?(content, volume)
              flow = uniq_content_storage.remember(content, volume)
              options[:javascript_tag] == false ? flow : javascript_tag(flow, options)
            end
          end
        end
      end
    end

    def script_for(identifier, *args, &block)
      options = args.extract_options!
      content_for(identifier) do
        script(args, options.merge(:volume => identifier), &block)
      end
    end
  end
  
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
active_tools-0.0.22 lib/active_tools/misc/script_flow.rb
active_tools-0.0.21 lib/active_tools/misc/script_flow.rb
active_tools-0.0.20 lib/active_tools/misc/script_flow.rb
active_tools-0.0.19 lib/active_tools/misc/script_flow.rb
active_tools-0.0.18 lib/active_tools/misc/script_flow.rb
active_tools-0.0.17 lib/active_tools/misc/script_flow.rb
active_tools-0.0.16 lib/active_tools/misc/script_flow.rb
active_tools-0.0.15 lib/active_tools/misc/script_flow.rb
active_tools-0.0.14 lib/active_tools/misc/script_flow.rb
active_tools-0.0.13 lib/active_tools/misc/script_flow.rb
active_tools-0.0.12 lib/active_tools/misc/script_flow.rb
active_tools-0.0.11 lib/active_tools/misc/script_flow.rb