Module: ActiveTools::OnLoadActionView

Extended by:
ActiveSupport::Concern
Defined in:
lib/active_tools/bundle.rb,
lib/active_tools/misc/script_flow.rb,
lib/active_tools/misc/uniq_content.rb,
lib/active_tools/action_pack/action_view/tag_attributes.rb,
lib/active_tools/action_pack/action_view/perform_as_tree.rb,
lib/active_tools/action_pack/action_view/uniq_content_for.rb

Instance Method Summary collapse

Instance Method Details

#perform_as_tree(scope, options = {}, &block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/active_tools/action_pack/action_view/perform_as_tree.rb', line 17

def perform_as_tree(scope, options = {}, &block)
  options = options.with_indifferent_access
  children_method = options[:children_method]||:children
  parent_method = options[:parent_method]||:parent
  id_key = options[:id]||nil
  scope = case scope
  when ::ActiveRecord::Relation then
    parent_key = scope.klass.reflections[children_method].foreign_key
    scope.where(parent_key => id_key)
  when ::Array, ::Set then
    scope.select {|item| item.send(parent_method) == id_key}
  else
    raise(TypeError, "ActiveRecord::Relation, Array or Set expected, #{scope.class.name} passed!")
  end
  scope.each do |item|
    ActionPack::ActionView::PerformAsTree.line(item, children_method, 0, &block)
  end
end

#script(*args, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/active_tools/misc/script_flow.rb', line 19

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

#script_for(identifier, *args, &block) ⇒ Object



42
43
44
45
46
47
# File 'lib/active_tools/misc/script_flow.rb', line 42

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

#tag_attributes(hash = {}) ⇒ Object



50
51
52
# File 'lib/active_tools/action_pack/action_view/tag_attributes.rb', line 50

def tag_attributes(hash = {})
  ActionPack::ActionView::TagAttributes::Collect.new(hash)
end

#uniq_content(*args, &block) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/active_tools/misc/uniq_content.rb', line 60

def uniq_content(*args, &block)
  options = args.extract_options!
  content = args.first
  if content || block_given?
    if block_given?
      content = capture(&block)
    end
    if content && !uniq_content_storage.remembered?(content, options[:volume])
      uniq_content_storage.remember(content, options[:volume])
    else
      nil
    end
  end
end

#uniq_content_for(name, content = nil, options = {}, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/active_tools/action_pack/action_view/uniq_content_for.rb', line 14

def uniq_content_for(name, content = nil, options = {}, &block)
  if content || block_given?
    if block_given?
      options = content if content
      content = capture(&block)
    end
    if content && !uniq_content_storage.remembered?(content, name)
      content_for(name, uniq_content_storage.remember(content, name), options)
      nil
    end
  end
end