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/field_name.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
- #field_name(builder, *args) ⇒ Object
- #object_name_to_field_id(val) ⇒ Object
- #perform_as_tree(scope, options = {}, &block) ⇒ Object
- #script(*args, &block) ⇒ Object
- #script_flow! ⇒ 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
#field_name(builder, *args) ⇒ Object
12 13 14 |
# File 'lib/active_tools/action_pack/action_view/field_name.rb', line 12 def field_name(builder, *args) [object_name_to_field_id(builder.object_name), *args].join("_") end |
#object_name_to_field_id(val) ⇒ Object
16 17 18 |
# File 'lib/active_tools/action_pack/action_view/field_name.rb', line 16 def object_name_to_field_id(val) val.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "") end |
#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.to_s].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
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/active_tools/misc/script_flow.rb', line 24 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_flow! ⇒ Object
20 21 22 |
# File 'lib/active_tools/misc/script_flow.rb', line 20 def script_flow! uniq_content_storage.render_content(Misc::DEFAULT_JS_FLOW_KEY) end |
#script_for(identifier, *args, &block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/active_tools/misc/script_flow.rb', line 47 def script_for(identifier, *args, &block) = args. if block_given? content_for(identifier) do script(args, .merge(:volume => identifier), &block) end else content_for(identifier, script(args, .merge(:volume => identifier)).join("\n").html_safe) 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
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/active_tools/misc/uniq_content.rb', line 62 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 |