require 'chef/mixin/deep_merge' module Merb module ChefServerWebui module ApplicationHelper # @param *segments Path segments to append. # # @return # A path relative to the public directory, with added segments. def image_path(*segments) public_path_for(:image, *segments) end # @param *segments Path segments to append. # # @return # A path relative to the public directory, with added segments. def javascript_path(*segments) public_path_for(:javascript, *segments) end # @param *segments Path segments to append. # # @return # A path relative to the public directory, with added segments. def stylesheet_path(*segments) public_path_for(:stylesheet, *segments) end # Construct a path relative to the public directory # # @param The type of component. # @param *segments Path segments to append. # # @return # A path relative to the public directory, with added segments. def public_path_for(type, *segments) ::ChefServerWebui.public_path_for(type, *segments) end # Construct an app-level path. # # @param The type of component. # @param *segments Path segments to append. # # @return # A path within the host application, with added segments. def app_path_for(type, *segments) ::ChefServerWebui.app_path_for(type, *segments) end # Construct a slice-level path. # # @param The type of component. # @param *segments Path segments to append. # # @return # A path within the slice source (Gem), with added segments. def slice_path_for(type, *segments) ::ChefServerWebui.slice_path_for(type, *segments) end def build_tree(name, node, default={}, override={}) node = Chef::Mixin::DeepMerge.merge(default, node) node = Chef::Mixin::DeepMerge.merge(node, override) html = "" html << "" count = 0 parent = 0 append_tree(name, html, node, count, parent, override) html << "
AttributeValue
" html end def append_tree(name, html, node, count, parent, override) node.sort{ |a,b| a[0] <=> b[0] }.each do |key, value| to_send = Array.new count += 1 is_parent = false local_html = "" local_html << "" else local_html << "'>" end local_html << "#{key}" case value when Hash is_parent = true local_html << "" p = count to_send << Proc.new { append_tree(name, html, value, count, p, override) } when Array is_parent = true local_html << "" as_hash = {} value.each_index { |i| as_hash[i] = value[i] } p = count to_send << Proc.new { append_tree(name, html, as_hash, count, p, override) } else local_html << "
#{value}
" end local_html << "" local_html.sub!(/class='collapsed/, 'class=\'collapsed parent') if is_parent local_html.sub!(/" # walk = lambda do |key,value| # case value # when Hash, Array # list << "\n" # list << "\n
#{key}
" # list << "
" # list << "\t
\n" # value.each(&walk) # list << "\t
\n" # list << "
" # list << "\n" # # else # list << "\n
#{key}
" # list << "
#{value}
" # end # end # node.sort{ |a,b| a[0] <=> b[0] }.each(&walk) # list << "" #end end end end