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
- #perform_as_tree(scope, options = {}, &block) ⇒ Object
- #script(*args, &block) ⇒ Object
- #script_for(identifier, *args, &block) ⇒ Object
- #tag_attributes(hash = {}) ⇒ Object
- #uniq_content(*args, &block) ⇒ Object
- #uniq_content_for(name, content = nil, options = {}, &block) ⇒ Object
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, = {}, &block) = .with_indifferent_access children_method = [:children_method]||:children parent_method = [:parent_method]||:parent id_key = [: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) = args. 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 = .delete(:volume) unless uniq_content_storage.remembered?(content, volume) flow = uniq_content_storage.remember(content, volume) [:javascript_tag] == false ? flow : javascript_tag(flow, ) 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) = args. content_for(identifier) do script(args, .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) = args. content = args.first if content || block_given? if block_given? content = capture(&block) end if content && !uniq_content_storage.remembered?(content, [:volume]) uniq_content_storage.remember(content, [: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, = {}, &block) if content || block_given? if block_given? = content if content content = capture(&block) end if content && !uniq_content_storage.remembered?(content, name) content_for(name, uniq_content_storage.remember(content, name), ) nil end end end |