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
Defined Under Namespace
Modules: EnsemblLinks, GbrowseLinks, MiscDbLinks, OrderButtons, UcscLinks
Instance Method Summary (collapse)
-
- (String) content_tag(name, content, options = nil)
View helper to produce a HTML tag.
-
- (String) partial(template, options = {})
Standard partial helper - allows erb templates to easily call smaller sub-templates.
-
- (String) url_for(url_fragment, mode = :path_only)
View helper to generate a URL for a static/dynamic page/item.
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
Methods included from UcscLinks
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
- (String) content_tag(name, content, options = nil)
View helper to produce a HTML tag.
60 61 62 63 |
# File 'lib/martsearch/server_view_helpers.rb', line 60 def content_tag( name, content, =nil ) = ( ) if "<#{name}#{}>#{content}</#{name}>" end |
- (String) partial(template, options = {})
Standard partial helper - allows erb templates to easily call smaller sub-templates.
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, ={} ) template_array = template.to_s.split('/') template_array[-1].sub!("_", "") if template_array[-1] =~ /^_/ template = template_array[0..-2].join('/') + "/_#{template_array[-1]}" .merge!( :layout => false ) collection = .delete(:collection) if collection collection.inject([]) do |buffer, member| buffer << erb( :#{template}", .merge( :locals => { template_array[-1].to_sym => member } ) ) end.join("\n") else erb( :#{template}", ) end end |
- (String) url_for(url_fragment, mode = :path_only)
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.
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 |