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
- #alert_class_for(key) ⇒ Object
- #app_wizard_steps_create(active, options = {}) ⇒ Object
- #application_type_tags(tags) ⇒ Object
- #breadcrumb_divider ⇒ Object
- #breadcrumb_for_application(application, *args) ⇒ Object
- #breadcrumb_for_create_application(*args) ⇒ Object
- #breadcrumbs_for_each(items) ⇒ Object
- #cartridge_wizard_steps_create(active, options = {}) ⇒ Object
- #flash_element_for(key) ⇒ Object
-
#flashes ⇒ Object
Renders the flash only once.
- #greetings_for_select ⇒ Object
- #in_balanced_columns_of(count, groups) ⇒ Object
- #in_columns_of(count, arr) ⇒ Object
- #map_to_sentence(items, &block) ⇒ Object
- #navigation_tab(name, options = {}) ⇒ Object
- #navigation_tabs(options = {}, &block) ⇒ Object
- #render_thumbnails(collection, options) ⇒ Object
- #take_action(link, text, *args) ⇒ Object
- #us_states_for_select ⇒ Object
- #wizard_steps(items, active, options = {}) ⇒ Object
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, ={}) wizard_steps(AppWizardStepsCreate, active, ) end |
#application_type_tags(tags) ⇒ Object
215 216 217 218 219 |
# File 'app/helpers/console/layout_helper.rb', line 215 def () ( - 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 |
#breadcrumb_divider ⇒ Object
100 101 102 |
# File 'app/helpers/console/layout_helper.rb', line 100 def content_tag(:span, '/', :class => 'divider') end |
#breadcrumb_for_application(application, *args) ⇒ Object
182 183 184 185 186 187 |
# File 'app/helpers/console/layout_helper.rb', line 182 def (application, *args) [ link_to('My Applications', :applications, :action => :index), link_to(application.name, application), ] + args end |
#breadcrumb_for_create_application(*args) ⇒ Object
189 190 191 192 193 |
# File 'app/helpers/console/layout_helper.rb', line 189 def (*args) [ link_to('Create an application', application_types_path), ] + args end |
#breadcrumbs_for_each(items) ⇒ Object
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 (items) last_index = items.length - 1 content_for :breadcrumbs, content_tag( :ul, items.each_with_index.map do |crumb, index| content = crumb active_tag = "" if index == last_index active_tag = "active" else content += end content_tag(: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, ={}) wizard_steps(CartridgeWizardStepsCreate, active, ) 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 |
#flashes ⇒ Object
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 = [] flash.each do |key, value| (value.kind_of?(Array) ? value : [value]).each do |value| next if value.blank? << content_tag(flash_element_for(key), value, :class => alert_class_for(key)) end end content_tag(:div, .join.html_safe, :id => 'flash') unless .empty? end |
#greetings_for_select ⇒ Object
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 |
#navigation_tab(name, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/helpers/console/layout_helper.rb', line 25 def (name, ={}) action = [:action] active = (name.to_s == controller_name) && (action.nil? || action.to_s == controller.action_name) content_tag( :li, link_to( [:name] || ActiveSupport::Inflector.humanize(name), url_for({ :action => action || :index, :controller => name }) ), active ? {:class => 'active'} : nil) end |
#navigation_tabs(options = {}, &block) ⇒ Object
20 21 22 23 |
# File 'app/helpers/console/layout_helper.rb', line 20 def (={}, &block) content = capture(&block) content_tag(: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, ) unless collection.empty? content_tag( :ul, collection.collect { |o| content_tag( :li, render(.merge(:object => o)).html_safe, :class => [: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) = args. link_to link, {:class => (['action-call'] << [:class]).join(' ')}.reverse_merge!() do ([content_tag(:div, text.html_safe)] << args.collect { |text| content_tag(:div, text, :class => 'highlight') } << content_tag(:div, '>', :class => 'highlight-arrow')).join.html_safe end end |
#us_states_for_select ⇒ Object
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, ={}) content_tag( :ol, (items + [[:and]].compact).each_with_index.map do |item, index| name = item[:name] content = if item[:link] and ((index < active and ![:completed]) or [:active]) link_to(name, send("#{item[:link]}")).html_safe else name end content = content_tag(:span, [ content_tag(:i, index+1), content].join.html_safe) classes = if index < active 'completed' elsif index == active 'active' end content_tag(:li, content, :class => classes) end.join.html_safe, :class => 'wizard' ) end |