Class: DcCommonRenderer

Inherits:
DcRenderer show all
Includes:
DcApplicationHelper
Defined in:
app/renderers/dc_common_renderer.rb

Overview

Renderer methods which may be useful on any site.

Instance Attribute Summary

Attributes included from DcApplicationHelper

#design, #form, #ids, #json_ld, #menu, #menu_item, #options, #page, #page_title, #part, #parts, #record, #record_footer, #site, #tables

Instance Method Summary collapse

Methods included from DcApplicationHelper

#_origin, #dc_add2_record_cookie, #dc_add_json_ld, #dc_add_meta_tag, #dc_big_table, #dc_big_table_name_for_value, #dc_choices4, #dc_choices4_all_collections, #dc_choices4_folders_list, #dc_choices4_menu, #dc_choices4_site_policies, #dc_cms_menu, #dc_deprecate, #dc_document_path, #dc_dont?, #dc_edit_mode?, #dc_edit_title, #dc_error_messages_for, #dc_flash_messages, #dc_get_json_ld, #dc_get_link_canonical_tag, #dc_get_seo_meta_tags, #dc_get_site, #dc_icon_for_link, #dc_iframe_edit, #dc_img_alt, #dc_img_alt_tag, #dc_internal_var, #dc_limit_string, #dc_link_for_create, #dc_link_for_edit, #dc_link_for_edit1, #dc_link_menu_tag, #dc_link_to, #dc_menu_class, #dc_new_title, #dc_page_bottom, #dc_page_class, #dc_page_edit_menu, #dc_page_top, #dc_render, #dc_render_design, #dc_render_design_part, #dc_render_from_site, #dc_render_partial, #dc_replace_in_design, #dc_submit_tag, #dc_table_title, #dc_user_can_view, #dc_user_has_role, #dc_warning_messages_for, #decamelize_type

Methods inherited from DcRenderer

#initialize, #render_css

Constructor Details

This class inherits a constructor from DcRenderer

Instance Method Details

#_remove_iframe_editObject

Will return html code required for open edit form in iframe. If parameters are found in url iframe will be initial loaded with url parameters thus enabling forms load on page display.



115
116
117
# File 'app/renderers/dc_common_renderer.rb', line 115

def _remove_iframe_edit()
  @parent.render(partial: 'dc_common/iframe_edit', formats: [:html])
end

#google_analyticsObject

Renderer for Google analytics code.

Parameters: Are passed through @opts hash and can therefore be set on site

or page document parameters field as ga_acc key. You may also disable sending

If eu_cookies_allowed function is defined in javascript libraries it will be called and if false is returned GA code will not be executed. This is in order with European cookie law.

Example:

dc_render(:dc_common_renderer, method: 'google_analytics', code: 'UA-12345678-9')


70
71
72
73
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
# File 'app/renderers/dc_common_renderer.rb', line 70

def google_analytics
  html = ''
  ga_acc = @opts[:code] || @opts[:ga_acc]
  if ga_acc && ga_acc != '/'
    html << %(
  <!-- Google analytics. -->
<script type="text/javascript">
  (function(i,s,o,g,r,a,m){
  if (typeof(eu_cookies_allowed) === "function" && !eu_cookies_allowed() ) return;

  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');

  if (typeof(ga) === "function") {
    ga('create', '#{ga_acc}', 'auto');
    ga('send', 'pageview')
  }
</script>
)
  end

  ga4_acc = @opts[:code4] || @opts[:ga4_acc]
  if ga4_acc && ga4_acc != '/'
    html << %(
  <!-- Global site tag (gtag.js) - Google Analytics -->
  <script async src="https://www.googletagmanager.com/gtag/js?id=#{ga4_acc}"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', '#{ga4_acc}');
</script>)
  end

  html.html_safe
end

#layout_4printObject

Renderer for printer friendly layout. Will call another renderer which should provide html code for printer friendly output.

Parameters are passed through link. There are currently two parameters, which define renderer and method to be used for creating output.

renderer

Defines renderer’s class

method

Defines renderer’s class method



43
44
45
46
47
48
49
50
51
52
53
# File 'app/renderers/dc_common_renderer.rb', line 43

def layout_4print
  return '' if @parent.params[:renderer].blank?
  opts = @opts.dup
  opts[:method] = @parent.params[:method]
  klass = (@parent.params[:renderer] + '_renderer').classify
  obj = Kernel.const_get(klass, Class.new).new(@parent, opts)
# 
  html = obj.render_html
  @css  << obj.render_css.to_s
  html
end

#render_htmlObject

Return HTML part of code.



122
123
124
125
# File 'app/renderers/dc_common_renderer.rb', line 122

def render_html
  method = @opts[:method] || 'default'
  respond_to?(method) ? send(method) : "Error DcCommonRenderer: Method #{method} doesn't exist!"
end