Class: Excalibur::Decorator

Inherits:
Draper::Decorator
  • Object
show all
Defined in:
lib/excalibur/decorator.rb

Overview

the Decorator class helps content to be derived from application base object and turn them into Excalibur titles and meta tags. It’s main responsibilities are to make local classes configurable and it acts as a connector between the application’s objects and Excalibur.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, options = {}) ⇒ Decorator

Returns a new instance of Decorator.



54
55
56
57
58
# File 'lib/excalibur/decorator.rb', line 54

def initialize(object, options = {})
  configuration.merge!(options.delete(:config)) if options.key?(:config)

  super(object, options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object

methods: render_title, render_description



69
70
71
72
73
74
75
76
77
78
# File 'lib/excalibur/decorator.rb', line 69

def method_missing(meth, *args)
  if meth.to_s =~ /^render_(title|description+)$/
    obj = args.first || self
    subject = configuration.send($1)

    subject.to_s(obj) if subject.present?
  else
    super
  end
end

Class Attribute Details

.configurationObject



25
26
27
# File 'lib/excalibur/decorator.rb', line 25

def configuration
  @configuration ||= ::Excalibur.configuration.dup
end

Instance Attribute Details

#custom_configurationObject

Returns the value of attribute custom_configuration.



11
12
13
# File 'lib/excalibur/decorator.rb', line 11

def custom_configuration
  @custom_configuration
end

Class Method Details

.exc_init(config = configuration) ⇒ Object



16
17
18
# File 'lib/excalibur/decorator.rb', line 16

def exc_init(config = configuration)
  @configuration = config
end

.exc_meta_tag(type, name, value = nil) ⇒ Object



44
45
46
# File 'lib/excalibur/decorator.rb', line 44

def exc_meta_tag(type, name, value = nil)
  configuration.set_meta_tag(type, name, value)
end

.excalibur_init(*args) ⇒ Object



20
21
22
23
# File 'lib/excalibur/decorator.rb', line 20

def excalibur_init(*args)
  warn '[DEPRECATION] `excalibur_init` is deprecated.  Please use `exc_init` instead.'
  exc_init(*args)
end

.excalibur_set_meta_tag(*args) ⇒ Object



48
49
50
51
# File 'lib/excalibur/decorator.rb', line 48

def excalibur_set_meta_tag(*args)
  warn '[DEPRECATION] `excalibur_set_meta_tag` is deprecated.  Please use `exc_meta_tag` instead.'
  exc_meta_tag(*args)
end

.method_missing(meth, *args) ⇒ Object

methods: excalibur_set_title_content, excalibur_set_title_option, excalibur_set_title_combinator, excalibur_set_description_content, excalibur_set_description_option, excalibur_set_description_combinator



33
34
35
36
37
38
39
40
41
42
# File 'lib/excalibur/decorator.rb', line 33

def method_missing(meth, *args)
  if meth.to_s =~ /^exc_(title|description+)_(content|option|combinator+)$/
    configuration.send($1).send("update_#{$2}", *args)
  elsif meth.to_s =~ /^excalibur_set_(title|description+)_(content|option|combinator+)$/
    warn "[DEPRECATION] `excalibur_set_#{$1}_#{$2}` is deprecated.  Please use `exc_#{$1}_#{$2}` instead."
    send("exc_#{$1}_#{$2}", *args)
  else
    super
  end
end

Instance Method Details

#configurationObject



60
61
62
# File 'lib/excalibur/decorator.rb', line 60

def configuration
  @custom_configuration ||= self.class.configuration.dup
end

#customize_configuration(config) ⇒ Object



64
65
66
# File 'lib/excalibur/decorator.rb', line 64

def customize_configuration(config)
  configuration.merge!(config)
end