# File lib/deltacloud/helpers/application_helper.rb, line 47 def action_method(action, collection) collections[collection].operations[action.to_sym].method end
# File lib/deltacloud/helpers/application_helper.rb, line 185 def action_url if [:index].include?(@operation.name) api_url_for("#{@collection.name.to_s}") elsif [:show, :stop, :start, :reboot, :attach, :detach].include?(@operation.name) api_url_for("#{@collection.name.to_s}/:id/#{@operation.name}") elsif [:destroy].include?(@operation.name) api_url_for("#{@collection.name.to_s}/:id") else api_url_for("#{@collection.name}/#{@operation.name}") end end
# File lib/deltacloud/helpers/application_helper.rb, line 24 def bread_crumb s = "<ul class='breadcrumb'><li class='first'><a href='#{settings.root_url}'>δ</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? next if "/#{level}" == settings.root_url 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(2, index-1).join("/") s += "<li class='subsequent'><a href=\"#{api_url_for(link)}\">#{level.gsub(/_/, ' ')}</a></li>\n" end end end s+="<li class='docs'>#{link_to_documentation}</li>" s+="</ul>" end
# File lib/deltacloud/helpers/application_helper.rb, line 145 def cdata(text = nil, &block) text ||= capture_haml(&block) "<![CDATA[#{text.strip}]]>" end
# File lib/deltacloud/helpers/application_helper.rb, line 59 def driver_auth_feature_name return 'key' if driver_has_feature?(:authentication_key) return 'password' if driver_has_feature?(:authentication_password) end
# File lib/deltacloud/helpers/application_helper.rb, line 55 def driver_has_auth_features? driver_has_feature?(:authentication_password) || driver_has_feature?(:authentication_key) end
# File lib/deltacloud/helpers/application_helper.rb, line 64 def driver_has_bucket_location_feature? driver.features(:buckets).each do |feat| return true if feat.name == :bucket_location end false end
# File lib/deltacloud/helpers/application_helper.rb, line 51 def driver_has_feature?(feature_name, collection_name = :instances) not driver.features(collection_name).select{ |f| f.name.eql?(feature_name) }.empty? end
Reverse the entrypoints hash for a driver from drivers.yaml; note that d is a hash, not an actual driver object
# File lib/deltacloud/helpers/application_helper.rb, line 211 def driver_provider(d) result = {} if d[:entrypoints] d[:entrypoints].each do |kind, details| details.each do |prov, url| result[prov] ||= {} result[prov][kind] = url end end end result end
# File lib/deltacloud/helpers/application_helper.rb, line 71 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 = {} if filter.keys.size.eql?(0) singular = model.to_s.singularize.to_sym @benchmark = Benchmark.measure do @elements = driver.send(model.to_sym, credentials, filter) end headers['X-Backend-Runtime'] = @benchmark.real.to_s 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
# File lib/deltacloud/helpers/application_helper.rb, line 224 def header(title, opts={}, &block) opts[:theme] ||= 'b' opts[:back] ||= 'true' capture_haml do haml_tag :div, :'data-role' => :header, :'data-theme' => opts[:theme], :'data-add-back-btn' => opts[:back] do haml_tag :a, :'data-rel' => :back do haml_concat "Back" end if opts[:back] == 'true' haml_tag :h1 do haml_concat title end block.call if block_given? end end end
# File lib/deltacloud/helpers/application_helper.rb, line 197 def image_for_state(state) state_img = "stopped" if (state!='RUNNING' or state!='PENDING') "<img src='/images/#{state.downcase}.png' title='#{state}'/>" end
# File lib/deltacloud/helpers/application_helper.rb, line 119 def instance_action(name) original_instance = driver.instance(credentials, :id => params[:id]) # If original instance doesn't include called action # return with 405 error (Method is not Allowed) unless driver.instance_actions_for(original_instance.state).include?(name.to_sym) return report_error(405) end @instance = driver.send(:"#{name}_instance", credentials, params["id"]) if name == :destroy or @instance.class!=Instance respond_to do |format| format.xml { return 204 } format.json { return 204 } format.html { return redirect(instances_url) } end end respond_to do |format| format.xml { haml :"instances/show" } format.html { haml :"instances/show" } format.json {convert_to_json(:instance, @instance) } end end
# File lib/deltacloud/helpers/application_helper.rb, line 43 def instance_action_method(action) action_method(action, :instances) end
# File lib/deltacloud/helpers/application_helper.rb, line 154 def link_to_action(action, url, method) capture_haml do haml_tag :form, :method => :post, :action => url, :class => [:link, method], :'data-ajax' => 'false' do haml_tag :input, :type => :hidden, :name => '_method', :value => method haml_tag :button, :type => :submit, :'data-ajax' => 'false', :'data-inline' => "true" do haml_concat action end end end end
# File lib/deltacloud/helpers/application_helper.rb, line 177 def link_to_documentation return '' unless request.env['REQUEST_URI'] uri = request.env['REQUEST_URI'].dup uri.gsub!(settings.root_url, api_url_for(:docs)) unless uri.include?("docs") #i.e. if already serving under /api/docs, leave it be '<a href="%s">[ Documentation ]</a>' % uri end
# File lib/deltacloud/helpers/application_helper.rb, line 165 def link_to_format(format) return '' unless request.env['REQUEST_URI'] uri = request.env['REQUEST_URI'] return if uri.include?('format=') if uri.include?('?') uri+="&format=#{format}" else uri+="?format=#{format}" end '<a data-ajax="false" data-icon="grid" href="%s">%s</a>' % [uri, "#{format}".upcase] end
# File lib/deltacloud/helpers/application_helper.rb, line 264 def new_blob_form_url(bucket) bucket_url(@bucket.name) + "/" + NEW_BLOB_FORM_ID end
# File lib/deltacloud/helpers/application_helper.rb, line 150 def render_cdata(text) "<![CDATA[#{text.strip}]]>" end
# File lib/deltacloud/helpers/application_helper.rb, line 108 def report_error(code=nil) @error, @code = request.env['sinatra.error'], code @code = 500 if not @code and not @error.class.method_defined? :code response.status = @code || @error.code respond_to do |format| format.xml { haml :"errors/#{@code || @error.code}", :layout => false } format.json { json_return_error(@error) } format.html { haml :"errors/#{@code || @error.code}", :layout => :error } end end
# File lib/deltacloud/helpers/application_helper.rb, line 91 def show(model) @benchmark = Benchmark.measure do @element = driver.send(model, credentials, { :id => params[:id]} ) end headers['X-Backend-Runtime'] = @benchmark.real.to_s 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) end end
# File lib/deltacloud/helpers/application_helper.rb, line 240 def subheader(title, opts={}) opts[:theme] ||= 'a' capture_haml do haml_tag :div, :'data-role' => :header, :'data-theme' => opts[:theme] do haml_tag :p, :class => 'inner-right' do haml_concat title end end end end
# File lib/deltacloud/helpers/application_helper.rb, line 251 def translate_error_code(code) case code when 400; { :message => "Bad Request" } when 401; { :message => "Unauthorized" } when 403; { :message => "Forbidden" } when 404; { :message => "Not Found" } when 405; { :message => "Method Not Allowed" } when 406; { :message => "Not Acceptable" } when 500; { :message => "Internal Server Error" } when 502; { :message => "Backend Server Error" } end end
# File lib/deltacloud/helpers/application_helper.rb, line 202 def truncate_words(text, length = 10) return nil unless text return text if text.length<=length end_string = "...#{text[(text.length-(length/2))..text.length]}" "#{text[0..(length/2)]}#{end_string}" end
Generated with the Darkfish Rdoc Generator 2.