module H2ocubeRailsHelper::ActionView::Helpers
Public Instance Methods
_description(opts = {})
click to toggle source
# File lib/h2ocube_rails_helper.rb, line 149 def _description(opts = {}) if defined? @description description = @description elsif defined?(@item) && @item.respond_to?(:description) && !@item.description.blank? description = @item.description else description = opts.key?(:description) ? opts[:description] : rails_secrets[:description] end strip_tags description.to_s.strip end
_keywords(opts = {})
click to toggle source
# File lib/h2ocube_rails_helper.rb, line 129 def _keywords(opts = {}) if defined? @keywords keywords = @keywords elsif defined?(@item) && @item.respond_to?(:keywords) && !@item.keywords.blank? keywords = @item.keywords.strip.split(/(,|,)/) else keywords = opts.key?(:keywords) ? opts[:keywords] : rails_secrets[:keywords] end [keywords].flatten.compact.map{ |k| k.to_s.strip.split(/(,|,)/) }.flatten.map { |k| k.gsub(/(,|,)/, '').blank? ? nil : k }.compact.uniq end
_render_keywords(opts = {})
click to toggle source
# File lib/h2ocube_rails_helper.rb, line 140 def _render_keywords(opts = {}) strip_tags _keywords(opts).join(',') end
_render_title(opts = {})
click to toggle source
# File lib/h2ocube_rails_helper.rb, line 121 def _render_title(opts = {}) strip_tags _title(opts).join(' - ') end
_title(opts = {})
click to toggle source
# File lib/h2ocube_rails_helper.rb, line 100 def _title(opts = {}) return [@_title] if defined?(@_title) if defined?(@title) && !@title.blank? title = @title.is_a?(Array) ? @title : [ @title.to_s ] else begin title = [resource.title, resource.class.model_name.human] if defined?(resource) && resource.respond_to?(:title) && resource.class.respond_to?(:model_name) rescue end title ||= [] end if opts.key? :title title.push opts[:title] else title.push rails_secrets[:title] end title.compact.map { |t| t = t.strip; t == '' ? nil : t }.compact end
browser()
click to toggle source
# File lib/h2ocube_rails_helper.rb, line 71 def browser @_browser ||= Browser.new request.env['HTTP_USER_AGENT'], accept_language: request.env['HTTP_ACCEPT_LANGUAGE'] end
escape(text)
click to toggle source
# File lib/h2ocube_rails_helper.rb, line 63 def escape(text) CGI.escapeHTML text end
render_canonical(opts = {})
click to toggle source
# File lib/h2ocube_rails_helper.rb, line 165 def render_canonical(opts = {}) !@canonical.blank? ? "<link rel=\"canonical\" href=\"#{@canonical}\" />".html_safe : '' end
render_description(opts = {})
click to toggle source
# File lib/h2ocube_rails_helper.rb, line 160 def render_description(opts = {}) return '' if _description == '' "<meta name=\"description\" content=\"#{_description(opts)}\" />".html_safe end
render_ga(opts = {})
click to toggle source
# File lib/h2ocube_rails_helper.rb, line 173 def render_ga(opts = {}) return '' if Rails.env.development? ga = opts.key?(:ga) ? opts[:ga] : rails_secrets[:ga] domain = opts.key?(:domain) ? opts[:domain] : rails_secrets[:domain] return '' if ga.nil? "<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', '#{ga}', '#{domain}');ga('send', 'pageview');</script>".html_safe end
render_html_class()
click to toggle source
# File lib/h2ocube_rails_helper.rb, line 75 def render_html_class cls = [] if params[:controller].include?('/') cls.push params[:controller].gsub('/', '_') params[:controller].split('/').each { |c| cls.push c } else cls.push params[:controller] end cls.push params[:action] cls.push cls[0] + '_' + params[:action] if params.key?(:html_class) if params[:html_class].class != Array cls.push params[:html_class].to_s else params[:html_class].each { |c| cls.push c } end end cls.push browser.to_s cls.compact.uniq.join ' ' end
render_keywords(opts = {})
click to toggle source
# File lib/h2ocube_rails_helper.rb, line 144 def render_keywords(opts = {}) return '' if _keywords.blank? "<meta name=\"keywords\" content=\"#{_render_keywords opts}\" />".html_safe end
render_seo(opts = {})
click to toggle source
# File lib/h2ocube_rails_helper.rb, line 169 def render_seo(opts = {}) render_title(opts) << render_canonical(opts) << render_keywords(opts) << render_description(opts) << render_ga(opts) << csrf_meta_tags end
render_title(opts = {})
click to toggle source
# File lib/h2ocube_rails_helper.rb, line 125 def render_title(opts = {}) "<title>#{_render_title opts}</title>".html_safe end
unescape(text)
click to toggle source
# File lib/h2ocube_rails_helper.rb, line 67 def unescape(text) CGI.unescapeHTML text end