Module: Console::LayoutHelper

Defined in:
app/helpers/console/layout_helper.rb

Constant Summary collapse

AppWizardStepsCreate =
[
  {
    :name => 'Choose a type of application',
    :link => 'application_types_path'
  },
  {
    :name => 'Configure and deploy the application'
  },
  {
    :name => 'Next steps'
  }
]
CartridgeWizardStepsCreate =
[
  {
    :name => 'Choose a cartridge type',
    :link => 'application_cartridge_types_path'
  },
  {
    :name => 'Configure and deploy the cartridge'
  },
  {
    :name => 'Next steps'
  }
]
HIDDEN_TAGS =
[:featured, :framework, :web_framework, :experimental, :in_development, :cartridge]
IMPORTANT_TAGS =
[:new, :premium]

Instance Method Summary collapse

Instance Method Details

#alert_class_for(key) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/helpers/console/layout_helper.rb', line 66

def alert_class_for(key)
  case key
  when :success
    'alert alert-success'
  when :notice
    'alert alert-info'
  when :error
    'alert alert-error'
  when :info
    'alert alert-info'
  when :info_pre
    'cli'
  else
    Rails.logger.debug "Handling alert key #{key.inspect}"
    'alert'
  end
end

#app_wizard_steps_create(active, options = {}) ⇒ Object



117
118
119
# File 'app/helpers/console/layout_helper.rb', line 117

def app_wizard_steps_create(active, options={})
  wizard_steps(AppWizardStepsCreate, active, options)
end

#application_type_tags(tags) ⇒ Object



215
216
217
218
219
# File 'app/helpers/console/layout_helper.rb', line 215

def application_type_tags(tags)
  (tags - HIDDEN_TAGS).uniq.sort!.partition{ |t| IMPORTANT_TAGS.include?(t) }.flatten.map do |tag| 
    link_to tag.to_s.humanize, application_types_path(:tag => tag), :class => "label label-#{tag}"
  end.join.html_safe
end


100
101
102
# File 'app/helpers/console/layout_helper.rb', line 100

def breadcrumb_divider
  (:span, '/', :class => 'divider')
end


182
183
184
185
186
187
# File 'app/helpers/console/layout_helper.rb', line 182

def breadcrumb_for_application(application, *args)
  breadcrumbs_for_each [
    link_to('My Applications', :applications, :action => :index),
    link_to(application.name, application),
  ] + args
end


189
190
191
192
193
# File 'app/helpers/console/layout_helper.rb', line 189

def breadcrumb_for_create_application(*args)
  breadcrumbs_for_each [
    link_to('Create an application', application_types_path), 
  ] + args
end


164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'app/helpers/console/layout_helper.rb', line 164

def breadcrumbs_for_each(items)
  last_index = items.length - 1
  content_for :breadcrumbs, (
    :ul,
    items.each_with_index.map do |crumb, index|
      content = crumb
      active_tag = ""
      if index == last_index
        active_tag = "active"
      else
        content += breadcrumb_divider
      end

      (:li, content, :class => active_tag)
    end.join.html_safe,
    :class => 'breadcrumb')
end

#cartridge_wizard_steps_create(active, options = {}) ⇒ Object



134
135
136
# File 'app/helpers/console/layout_helper.rb', line 134

def cartridge_wizard_steps_create(active, options={})
  wizard_steps(CartridgeWizardStepsCreate, active, options)
end

#flash_element_for(key) ⇒ Object



57
58
59
60
61
62
63
64
# File 'app/helpers/console/layout_helper.rb', line 57

def flash_element_for(key)
  case key
  when :info_pre
    :pre
  else
    :div
  end
end

#flashesObject

Renders the flash only once. In normal rails flow templates are rendered first and so the flash will be displayed in the template - otherwise the layout has an opportunity to render it.



45
46
47
48
49
50
51
52
53
54
55
# File 'app/helpers/console/layout_helper.rb', line 45

def flashes
  return if @flashed_once || flash.nil?; @flashed_once = true
  tags = []
  flash.each do |key, value|
    (value.kind_of?(Array) ? value : [value]).each do |value|
      next if value.blank?
      tags << (flash_element_for(key), value, :class => alert_class_for(key))
    end
  end
  (:div, tags.join.html_safe, :id => 'flash') unless tags.empty?
end

#greetings_for_selectObject



204
205
206
# File 'app/helpers/console/layout_helper.rb', line 204

def greetings_for_select
  [ 'Mr.', 'Mrs.', 'Ms.', 'Miss', 'Dr.', 'Hr.', 'Sr.' ]
end

#in_balanced_columns_of(count, groups) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/console/layout_helper.rb', line 9

def in_balanced_columns_of(count, groups)
  columns = Array.new(count){ [] }
  counts = Array.new(count,0)
  groups.each do |group|
    column = counts.index(counts.min)
    columns[column] << group
    counts[column] += group[1].size
  end
  columns
end

#in_columns_of(count, arr) ⇒ Object



5
6
7
# File 'app/helpers/console/layout_helper.rb', line 5

def in_columns_of(count, arr)
  arr.enum_for(:each_with_index).inject(Array.new(count) {[]}){ |a, (item,i)| a[i % count] << item; a }
end

#map_to_sentence(items, &block) ⇒ Object



208
209
210
# File 'app/helpers/console/layout_helper.rb', line 208

def map_to_sentence(items, &block)
  items.map{ |c| capture_haml{ yield c }.strip }.to_sentence.html_safe
end


25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/console/layout_helper.rb', line 25

def navigation_tab(name, options={})
  action = options[:action]
  active = (name.to_s == controller_name) && (action.nil? || action.to_s == controller.action_name)
  (
    :li,
    link_to(
      options[:name] || ActiveSupport::Inflector.humanize(name),
      url_for({
        :action => action || :index,
        :controller => name
      })
    ),
    active ? {:class => 'active'} : nil)
end


20
21
22
23
# File 'app/helpers/console/layout_helper.rb', line 20

def navigation_tabs(options={}, &block)
  content = capture(&block)
  (:ul, content, :class => 'nav')
end

#render_thumbnails(collection, options) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/helpers/console/layout_helper.rb', line 84

def render_thumbnails( collection, options )
  unless collection.empty?
    (
      :ul,
      collection.collect { |o|
        (
          :li,
          render(options.merge(:object => o)).html_safe,
          :class => options[:grid] || 'span3'
        )
      }.join.html_safe,
      :class => 'thumbnails'
    )
  end
end

#take_action(link, text, *args) ⇒ Object



195
196
197
198
199
200
201
202
# File 'app/helpers/console/layout_helper.rb', line 195

def take_action(link, text, *args)
  options = args.extract_options!
  link_to link, {:class => (['action-call'] << options[:class]).join(' ')}.reverse_merge!(options) do
    ([(:div, text.html_safe)] <<
      args.collect { |text| (:div, text, :class => 'highlight') } <<
      (:div, '>', :class => 'highlight-arrow')).join.html_safe
  end
end

#us_states_for_selectObject



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'app/helpers/console/layout_helper.rb', line 221

def us_states_for_select
  [
    ['Alabama', 'AL'],
    ['Alaska', 'AK'],
    ['Arizona', 'AZ'],
    ['Arkansas', 'AR'],
    ['California', 'CA'],
    ['Colorado', 'CO'],
    ['Connecticut', 'CT'],
    ['Delaware', 'DE'],
    ['District of Columbia', 'DC'],
    ['Florida', 'FL'],
    ['Georgia', 'GA'],
    ['Hawaii', 'HI'],
    ['Idaho', 'ID'],
    ['Illinois', 'IL'],
    ['Indiana', 'IN'],
    ['Iowa', 'IA'],
    ['Kansas', 'KS'],
    ['Kentucky', 'KY'],
    ['Louisiana', 'LA'],
    ['Maine', 'ME'],
    ['Maryland', 'MD'],
    ['Massachusetts', 'MA'],
    ['Michigan', 'MI'],
    ['Minnesota', 'MN'],
    ['Mississippi', 'MS'],
    ['Missouri', 'MO'],
    ['Montana', 'MT'],
    ['Nebraska', 'NE'],
    ['Nevada', 'NV'],
    ['New Hampshire', 'NH'],
    ['New Jersey', 'NJ'],
    ['New Mexico', 'NM'],
    ['New York', 'NY'],
    ['North Carolina', 'NC'],
    ['North Dakota', 'ND'],
    ['Ohio', 'OH'],
    ['Oklahoma', 'OK'],
    ['Oregon', 'OR'],
    ['Pennsylvania', 'PA'],
    ['Puerto Rico', 'PR'],
    ['Rhode Island', 'RI'],
    ['South Carolina', 'SC'],
    ['South Dakota', 'SD'],
    ['Tennessee', 'TN'],
    ['Texas', 'TX'],
    ['Utah', 'UT'],
    ['Vermont', 'VT'],
    ['Virginia', 'VA'],
    ['Washington', 'WA'],
    ['West Virginia', 'WV'],
    ['Wisconsin', 'WI'],
    ['Wyoming', 'WY']
  ]
end

#wizard_steps(items, active, options = {}) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'app/helpers/console/layout_helper.rb', line 138

def wizard_steps(items, active, options={})
  (
    :ol,
    (items + [options[:and]].compact).each_with_index.map do |item, index|
      name = item[:name]
      content = if item[:link] and ((index < active and !options[:completed]) or options[:active])
        link_to(name, send("#{item[:link]}")).html_safe
      else
        name
      end

      content = (:span, [
        (:i, index+1),
        content].join.html_safe)

      classes = if index < active
        'completed'
      elsif index == active
        'active'
      end
      (:li, content, :class => classes)
    end.join.html_safe,
    :class => 'wizard'
  )
end