Module: ApplicationHelper
- Defined in:
- lib/deltacloud/helpers/application_helper.rb
Overview
Methods added to this helper will be available to all templates in the application.
Instance Method Summary collapse
- #bread_crumb ⇒ Object
- #cdata(&block) ⇒ Object
- #driver_auth_feature_name ⇒ Object
- #driver_has_auth_features? ⇒ Boolean
- #driver_has_feature?(feature_name) ⇒ Boolean
- #filter_all(model) ⇒ Object
- #instance_action(name) ⇒ Object
- #instance_action_method(action) ⇒ Object
- #report_error(status, template) ⇒ Object
- #show(model) ⇒ Object
Instance Method Details
#bread_crumb ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/deltacloud/helpers/application_helper.rb', line 22 def bread_crumb s = "<ul class='breadcrumb'><li class='first'><a href='#{url_for('/')}'>δ</a></li>" url = request.path_info.split('?') #remove extra query string parameters levels = url[0].split('/') #break up url into different levels levels.each_with_index do |level, index| unless level.blank? if index == levels.size-1 || (level == levels[levels.size-2] && levels[levels.size-1].to_i > 0) s += "<li class='subsequent'>#{level.gsub(/_/, ' ')}</li>\n" unless level.to_i > 0 else link = levels.slice(0, index+1).join("/") s += "<li class='subsequent'><a href=\"#{url_for(link)}\">#{level.gsub(/_/, ' ')}</a></li>\n" end end end s+="</ul>" end |
#cdata(&block) ⇒ Object
109 110 111 112 113 |
# File 'lib/deltacloud/helpers/application_helper.rb', line 109 def cdata(&block) text = capture_haml(&block) text.gsub!("\n", "\n ") "<![CDATA[\n #{text}\n]]>" end |
#driver_auth_feature_name ⇒ Object
52 53 54 55 |
# File 'lib/deltacloud/helpers/application_helper.rb', line 52 def driver_auth_feature_name return 'key' if driver_has_feature?(:authentication_key) return 'password' if driver_has_feature?(:authentication_password) end |
#driver_has_auth_features? ⇒ Boolean
48 49 50 |
# File 'lib/deltacloud/helpers/application_helper.rb', line 48 def driver_has_auth_features? driver_has_feature?(:authentication_password) || driver_has_feature?(:authentication_key) end |
#driver_has_feature?(feature_name) ⇒ Boolean
44 45 46 |
# File 'lib/deltacloud/helpers/application_helper.rb', line 44 def driver_has_feature?(feature_name) not driver.features(:instances).select{ |f| f.name.eql?(feature_name) }.empty? end |
#filter_all(model) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/deltacloud/helpers/application_helper.rb', line 57 def filter_all(model) filter = {} filter.merge!(:id => params[:id]) if params[:id] filter.merge!(:architecture => params[:architecture]) if params[:architecture] filter.merge!(:owner_id => params[:owner_id]) if params[:owner_id] filter.merge!(:state => params[:state]) if params[:state] filter = nil if filter.keys.size.eql?(0) singular = model.to_s.singularize.to_sym @elements = driver.send(model.to_sym, credentials, filter) instance_variable_set(:"@#{model}", @elements) respond_to do |format| format.html { haml :"#{model}/index" } format.xml { haml :"#{model}/index" } format.json { convert_to_json(singular, @elements) } end end |
#instance_action(name) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/deltacloud/helpers/application_helper.rb', line 97 def instance_action(name) @instance = driver.send(:"#{name}_instance", credentials, params["id"]) return redirect(instances_url) if name.eql?(:destroy) or @instance.class!=Instance respond_to do |format| format.html { haml :"instances/show" } format.xml { haml :"instances/show" } format.json {convert_to_json(:instance, @instance) } end end |
#instance_action_method(action) ⇒ Object
40 41 42 |
# File 'lib/deltacloud/helpers/application_helper.rb', line 40 def instance_action_method(action) collections[:instances].operations[action.to_sym].method end |
#report_error(status, template) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/deltacloud/helpers/application_helper.rb', line 88 def report_error(status, template) @error = request.env['sinatra.error'] response.status = status respond_to do |format| format.xml { haml :"errors/#{template}", :layout => false } format.html { haml :"errors/#{template}" } end end |
#show(model) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/deltacloud/helpers/application_helper.rb', line 74 def show(model) @element = driver.send(model, credentials, { :id => params[:id]} ) instance_variable_set("@#{model}", @element) if @element respond_to do |format| format.html { haml :"#{model.to_s.pluralize}/show" } format.xml { haml :"#{model.to_s.pluralize}/show" } format.json { convert_to_json(model, @element) } end else report_error(404, 'not_found') end end |