Module: ChiliPDF::Config

Extended by:
Config
Included in:
Config
Defined in:
lib/chili_pdf/config.rb

Constant Summary collapse

PLUGIN_KEYNAME =
'plugin_chili_pdf'
ENABLED_VALUE =
'1'
DISABLED_VALUE =
'0'
'footer_enabled'
HEADER_ENABLED_KEYNAME =
'header_enabled'
CUSTOM_CSS_KEYNAME =
'custom_css'
CUSTOM_JS_KEYNAME =
'custom_javascript'
HEADER_LEFT_KEYNAME =
:header_content_left
HEADER_CENTER_KEYNAME =
:header_content_center
HEADER_RIGHT_KEYNAME =
:header_content_right
:footer_content_left
:footer_content_center
:footer_content_right
LOGO_KEYNAME =
:watermarks_logo
HEADER_LEFT_DEFAULT_VALUE =
'{{page_title}}'
HEADER_CENTER_DEFAULT_VALUE =
''
HEADER_RIGHT_DEFAULT_VALUE =
''
'{{datestamp}}'
''
'{{current_page}}/{{total_pages}}'
CUSTOM_CSS_DEFAULT_VALUE =
<<END_OF_CSS_DEF
<!-- stylesheet link example, uncomment & modify if you like -->
<!-- <link href='/stylesheets/your_custom.css' rel='stylesheet' type='text/css' />

<!-- inline example -->
<style type="text/css">
  //#custom-pdf-styles h2 {color: red;}
</style>
END_OF_CSS_DEF
CUSTOM_JS_DEFAULT_VALUE =
<<END_OF_JS_DEF
<!-- Script tag link example. Uncomment & modify if you like.  -->
<!-- <script src='/javascripts/your_custom.js' type='text/javascript' />

<!-- Inline JavaScript example -->
<script type="text/javascript">
  // Your custom-inline JS here
</script>
END_OF_JS_DEF

Instance Method Summary collapse

Instance Method Details

#custom_cssObject



100
101
102
103
104
105
106
# File 'lib/chili_pdf/config.rb', line 100

def custom_css
  if plugin_settings[CUSTOM_CSS_KEYNAME].blank?
    CUSTOM_CSS_DEFAULT_VALUE
  else
    plugin_settings[CUSTOM_CSS_KEYNAME]
  end
end

#custom_jsObject



108
109
110
111
112
113
114
# File 'lib/chili_pdf/config.rb', line 108

def custom_js
  if plugin_settings[CUSTOM_JS_KEYNAME].blank?
    CUSTOM_JS_DEFAULT_VALUE
  else
    plugin_settings[CUSTOM_JS_KEYNAME]
  end
end

#defaultsObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/chili_pdf/config.rb', line 47

def defaults
  {
    FOOTER_ENABLED_KEYNAME => ENABLED_VALUE,
    HEADER_ENABLED_KEYNAME => ENABLED_VALUE,
    HEADER_LEFT_KEYNAME    => HEADER_LEFT_DEFAULT_VALUE,
    HEADER_CENTER_KEYNAME  => HEADER_CENTER_DEFAULT_VALUE,
    HEADER_RIGHT_KEYNAME   => HEADER_RIGHT_DEFAULT_VALUE,
    FOOTER_LEFT_KEYNAME    => FOOTER_LEFT_DEFAULT_VALUE,
    FOOTER_CENTER_KEYNAME  => FOOTER_CENTER_DEFAULT_VALUE,
    FOOTER_RIGHT_KEYNAME   => FOOTER_RIGHT_DEFAULT_VALUE,
    CUSTOM_CSS_KEYNAME     => CUSTOM_CSS_DEFAULT_VALUE,
    CUSTOM_JS_KEYNAME      => CUSTOM_JS_DEFAULT_VALUE,
    LOGO_KEYNAME           => ''
  }
end

Public: Returns whether the footer will be printed when exporting

a PDF.

Returns either true or false.

Returns:

  • (Boolean)


67
68
69
# File 'lib/chili_pdf/config.rb', line 67

def footer_enabled?
  footer_enabled == ENABLED_VALUE
end


96
97
98
# File 'lib/chili_pdf/config.rb', line 96

def footer_values
  default_footer_values.merge(stored_footer_settings)
end

#header_enabled?Boolean

Public: Returns whether the header will be printed when exporting

a PDF.

Returns either true or false.

Returns:

  • (Boolean)


75
76
77
# File 'lib/chili_pdf/config.rb', line 75

def header_enabled?
  header_enabled == ENABLED_VALUE
end

#header_valuesObject



92
93
94
# File 'lib/chili_pdf/config.rb', line 92

def header_values
  default_header_values.merge(stored_header_settings)
end

#logo_urlObject



116
117
118
# File 'lib/chili_pdf/config.rb', line 116

def logo_url
  plugin_settings[LOGO_KEYNAME]
end

#logo_url?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/chili_pdf/config.rb', line 120

def logo_url?
  !logo_url.blank?
end

#update(options) ⇒ Object

Public: Accepts anything which responds to ‘[]’ and ‘.has_key?’

(ie: Hash-like objects)

Utilizes following keys (values of):

- HEADER_ENABLED_KEYNAME
- FOOTER_ENABLED_KEYNAME

Returns true. Always.



87
88
89
90
# File 'lib/chili_pdf/config.rb', line 87

def update(options)
  Setting[PLUGIN_KEYNAME] = defaults.merge(options)
  true
end