Sha256: 3f8b648efc65c005f770ee081be86c2d61fb547e58a3672e616fc30970090359
Contents?: true
Size: 1.8 KB
Versions: 1
Compression:
Stored size: 1.8 KB
Contents
module Cavy module ViewHelpers extend self ## # This method makes a editable page element # # # = Example # # page_element(id: 'title', content: @page.title) def page_element(opts) # :args: id, content "<div id='#{opts[:id]}' data-mercury='full'>#{opts[:content]}</div>".html_safe end ## # This method makes a localized editable page element # # # = Example # # localized_page_element(id: 'title', page: @page) def localized_page_element(opts) # :args: id, page page_element(id: localized_title_id(opts[:id]), content: localized_text(opts)) end ## # This method gets a localized text # # # = Example # # localized_text(id: 'title', page: @page) def localized_text(opts) opts[:page].page_elements[localized_title_id(opts[:id])] end ## # This method gives the user SEO meta tags # # = Example # # meta_tags(page) def meta_tags(page) "<meta content='#{page.seo_description.to_h[I18n.locale.to_s]}' name='description'> <meta content='#{page_tags(page)}' name='keywords'>".html_safe end ## # This method creates a chart tag for the charts apiĀ“ # # = Example # # chart_tag ('page_vies', 300, 300) def chart_tag (action, width=700, height=300, params = {}) params[:format] ||= :json path = url_for controller: :statistics, action: action content_tag(:div, :'data-chart' => path, :style => "height: #{height}px;") do image_tag('', :size => '24x24', :class => 'spinner') end end private def localized_title_id(id) "#{id}_#{I18n.locale}" end def page_tags(page) page.seo_keywords.to_h.empty? ? '' : page.seo_keywords[I18n.locale.to_s].to_a.join(', ') end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cavy-0.1.0.beta1 | lib/cavy/helpers/view_helpers.rb |