Module: MartSearch::ServerViewHelpers

Includes:
EnsemblLinks, GbrowseLinks, MiscDbLinks, OrderButtons, UcscLinks
Included in:
ProjectUtils
Defined in:
lib/martsearch/server_view_helpers.rb,
lib/martsearch/server_view_helpers/ucsc_links.rb,
lib/martsearch/server_view_helpers/ensembl_links.rb,
lib/martsearch/server_view_helpers/order_buttons.rb,
lib/martsearch/server_view_helpers/misc_db_links.rb,
lib/martsearch/server_view_helpers/gbrowse_links.rb

Overview

View helpers for the web app code.

As we use Sinatra::StaticAssets the following helpers are also available in the views:

  • image_tag

  • stylesheet_link_tag

  • javascript_script_tag

  • link_to

Author:

  • Darren Oakley

Defined Under Namespace

Modules: EnsemblLinks, GbrowseLinks, MiscDbLinks, OrderButtons, UcscLinks

Instance Method Summary collapse

Methods included from OrderButtons

#emma_mouse_order_button, #escell_order_button, #mouse_order_button, #vector_order_button

Methods included from MiscDbLinks

#emma_link_url, #htgt_design_url, #interpro_link_url

Methods included from GbrowseLinks

#mgi_gbrowse_img

Methods included from UcscLinks

#ucsc_link_url

Methods included from EnsemblLinks

#ensembl_link_url_from_coords, #ensembl_link_url_from_exon, #ensembl_link_url_from_gene, #ensembl_link_url_from_transcript, #vega_link_url_from_exon, #vega_link_url_from_gene

Instance Method Details

#content_tag(name, content, options = nil) ⇒ String

View helper to produce a HTML tag.

Parameters:

  • name (String)

    The name for the HTML tag (i.e. 'p', 'h1' etc.)

  • content (String)

    The content that goes inside the tag

  • options (Hash) (defaults to: nil)

    A hash representing the HTML attributes to apply to the tag

Returns:



60
61
62
63
# File 'lib/martsearch/server_view_helpers.rb', line 60

def ( name, content, options=nil )
  tag_options = tag_options( options ) if options
  "<#{name}#{tag_options}>#{content}</#{name}>"
end

#partial(template, options = {}) ⇒ String

Standard partial helper - allows erb templates to easily call smaller sub-templates.

Parameters:

  • template (String)

    The location/name of the template to call

  • options (Hash) (defaults to: {})

    Options hash to pass to the template

Returns:

  • (String)

    The processed sub-template



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/martsearch/server_view_helpers.rb', line 36

def partial( template, options={} )
  template_array = template.to_s.split('/')
  template_array[-1].sub!("_", "") if template_array[-1] =~ /^_/
  
  template = template_array[0..-2].join('/') + "/_#{template_array[-1]}"
  
  options.merge!( :layout => false )
  collection = options.delete(:collection)
  
  if collection
    collection.inject([]) do |buffer, member|
      buffer << erb( :#{template}", options.merge( :locals => { template_array[-1].to_sym => member } ) )
    end.join("\n")
  else
    erb( :#{template}", options )
  end
end

#url_for(url_fragment, mode = :path_only) ⇒ String

View helper to generate a URL for a static/dynamic page/item. Will automagically cope if the app is not hosted at the root of the domain. ALWAYS use this function (or functions such as 'link_to' that call this under the covers), to link to assets/pages in the app.

Parameters:

  • url_fragment (String/Hash)

    The url string to link to, or a Hash containing :path and any other parameters that are desired

  • mode (Symbol) (defaults to: :path_only)

    Do we want a full url (i.e. for RSS feeds etc) or a relative link. Can be either :path_only or :full

Returns:

  • (String)

    The generated url

Raises:

  • TypeError if an unkown url mode is passed



74
75
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
# File 'lib/martsearch/server_view_helpers.rb', line 74

def url_for( url_fragment, mode=:path_only )
  case mode
  when :path_only
    base = request.script_name
  when :full
    scheme = request.scheme
    if (scheme == 'http' && request.port == 80) || (scheme == 'https' && request.port == 443)
      port = ""
    else
      port = ":#{request.port}"
    end
    base = "#{scheme}://#{request.host}#{port}#{request.script_name}"
  else
    raise TypeError, "Unknown url_for mode #{mode}"
  end
  
  url = "#{base}"
        
  if url_fragment.is_a?(Hash)
    url_fragment.stringify_keys!
    path = ''
    
    unless url_fragment['path'].nil?
      path = url + url_fragment.delete('path')
    else
      path = request.path_info
    end
    
    params.delete('captures')
    params.delete('page')
    url = path + "?" + build_query( params.merge(url_fragment) )
  else
    url << url_fragment
  end
  
  return url
end