Module: Merb::ChefServerSlice::ApplicationHelper

Defined in:
app/helpers/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#app_path_for(type, *segments) ⇒ String

Construct an app-level path.

Parameters:

  • The (Symbol)

    type of component.

  • *segments (Array[#to_s])

    Path segments to append.

Returns:

  • (String)

    A path within the host application, with added segments.



49
50
51
# File 'app/helpers/application_helper.rb', line 49

def app_path_for(type, *segments)
  ::ChefServerSlice.app_path_for(type, *segments)
end

#append_tree(name, html, node, count, parent, override) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'app/helpers/application_helper.rb', line 76

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 << "<tr id='#{name}-#{count}' class='collapsed #{name}"
    if parent != 0
      local_html << " child-of-#{name}-#{parent}' style='display: none;'>"
    else
      local_html << "'>"
    end
    local_html << "<td class='table-key'><span toggle='#{name}-#{count}'/>#{key}</td>"
    case value
    when Hash
      is_parent = true 
      local_html << "<td></td>"
      p = count
      to_send << Proc.new { append_tree(name, html, value, count, p, override) }
    when Array
      is_parent = true 
      local_html << "<td></td>"
      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) }
    when String,Symbol
      local_html << "<td><div class='json-attr'>#{value}</div></td>"
    else
      local_html << "<td>#{JSON.pretty_generate(value)}</td>"
    end
    local_html << "</tr>"
    local_html.sub!(/class='collapsed/, 'class=\'collapsed parent') if is_parent
    local_html.sub!(/<span/, "<span class='expander'") if is_parent
    html << local_html
    to_send.each { |s| count = s.call }
    count += to_send.length
  end
  count
end

#build_tree(name, node, default = {}, override = {}) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'app/helpers/application_helper.rb', line 64

def build_tree(name, node, default={}, override={})
  node = Chef::Mixin::DeepMerge.merge(default, node)
  node = Chef::Mixin::DeepMerge.merge(node, override)
  html = "<table id='#{name}' class='tree table'>"
  html << "<tr><th class='first'>Attribute</th><th class='last'>Value</th></tr>"
  count = 0
  parent = 0
  append_tree(name, html, node, count, parent, override)
  html << "</table>"
  html
end

#image_path(*segments) ⇒ String

Returns A path relative to the public directory, with added segments.

Parameters:

  • *segments (Array[#to_s])

    Path segments to append.

Returns:

  • (String)

    A path relative to the public directory, with added segments.



11
12
13
# File 'app/helpers/application_helper.rb', line 11

def image_path(*segments)
  public_path_for(:image, *segments)
end

#javascript_path(*segments) ⇒ String

Returns A path relative to the public directory, with added segments.

Parameters:

  • *segments (Array[#to_s])

    Path segments to append.

Returns:

  • (String)

    A path relative to the public directory, with added segments.



19
20
21
# File 'app/helpers/application_helper.rb', line 19

def javascript_path(*segments)
  public_path_for(:javascript, *segments)
end

#public_path_for(type, *segments) ⇒ String

Construct a path relative to the public directory

Parameters:

  • The (Symbol)

    type of component.

  • *segments (Array[#to_s])

    Path segments to append.

Returns:

  • (String)

    A path relative to the public directory, with added segments.



38
39
40
# File 'app/helpers/application_helper.rb', line 38

def public_path_for(type, *segments)
  ::ChefServerSlice.public_path_for(type, *segments)
end

#slice_path_for(type, *segments) ⇒ String

Construct a slice-level path.

Parameters:

  • The (Symbol)

    type of component.

  • *segments (Array[#to_s])

    Path segments to append.

Returns:

  • (String)

    A path within the slice source (Gem), with added segments.



60
61
62
# File 'app/helpers/application_helper.rb', line 60

def slice_path_for(type, *segments)
  ::ChefServerSlice.slice_path_for(type, *segments)
end

#stylesheet_path(*segments) ⇒ String

Returns A path relative to the public directory, with added segments.

Parameters:

  • *segments (Array[#to_s])

    Path segments to append.

Returns:

  • (String)

    A path relative to the public directory, with added segments.



27
28
29
# File 'app/helpers/application_helper.rb', line 27

def stylesheet_path(*segments)
  public_path_for(:stylesheet, *segments)
end