Class: Roadie::Rails::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/roadie/rails/options.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Options

Returns a new instance of Options.



15
16
17
18
19
20
21
22
23
# File 'lib/roadie/rails/options.rb', line 15

def initialize(options = {})
  complain_about_unknown_keys options.keys
  self.after_transformation     = options[:after_transformation]
  self.asset_providers          = options[:asset_providers]
  self.before_transformation    = options[:before_transformation]
  self.external_asset_providers = options[:external_asset_providers]
  self.keep_uninlinable_css     = options[:keep_uninlinable_css]
  self.url_options              = options[:url_options]
end

Instance Method Details

#after_transformation=(callback) ⇒ Object



33
34
35
# File 'lib/roadie/rails/options.rb', line 33

def after_transformation=(callback)
  @after_transformation = callback
end

#apply_to(document) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/roadie/rails/options.rb', line 59

def apply_to(document)
  document.url_options = url_options
  document.before_transformation = before_transformation
  document.after_transformation = after_transformation

  document.asset_providers = asset_providers if asset_providers
  document.external_asset_providers = external_asset_providers if external_asset_providers

  document.keep_uninlinable_css = keep_uninlinable_css unless keep_uninlinable_css.nil?
end

#asset_providers=(providers) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/roadie/rails/options.rb', line 41

def asset_providers=(providers)
  if providers
    @asset_providers = ProviderList.wrap providers
  # TODO: Raise an error when setting to nil in order to make this not a silent error.
  # else
  #   raise ArgumentError, "Cannot set asset_providers to nil. Set to Roadie::NullProvider if you want no external assets inlined."
  end
end

#before_transformation=(callback) ⇒ Object



29
30
31
# File 'lib/roadie/rails/options.rb', line 29

def before_transformation=(callback)
  @before_transformation = callback
end

#combine(options) ⇒ Object



81
82
83
# File 'lib/roadie/rails/options.rb', line 81

def combine(options)
  dup.combine! options
end

#combine!(options) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/roadie/rails/options.rb', line 85

def combine!(options)
  self.after_transformation = combine_callable(
    after_transformation, options[:after_transformation]
  )

  self.asset_providers = combine_providers(
    asset_providers, options[:asset_providers]
  )

  self.before_transformation = combine_callable(
    before_transformation, options[:before_transformation]
  )

  self.external_asset_providers = combine_providers(
    external_asset_providers, options[:external_asset_providers]
  )

  self.keep_uninlinable_css =
    options[:keep_uninlinable_css] if options.has_key?(:keep_uninlinable_css)

  self.url_options = combine_hash(
    url_options, options[:url_options]
  )

  self
end

#external_asset_providers=(providers) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/roadie/rails/options.rb', line 50

def external_asset_providers=(providers)
  if providers
    @external_asset_providers = ProviderList.wrap providers
  # TODO: Raise an error when setting to nil in order to make this not a silent error.
  # else
  #   raise ArgumentError, "Cannot set asset_providers to nil. Set to Roadie::NullProvider if you want no external assets inlined."
  end
end

#keep_uninlinable_css=(bool) ⇒ Object



37
38
39
# File 'lib/roadie/rails/options.rb', line 37

def keep_uninlinable_css=(bool)
  @keep_uninlinable_css = bool
end

#merge(options) ⇒ Object



70
71
72
# File 'lib/roadie/rails/options.rb', line 70

def merge(options)
  dup.merge! options
end

#merge!(options) ⇒ Object



74
75
76
77
78
79
# File 'lib/roadie/rails/options.rb', line 74

def merge!(options)
  ATTRIBUTE_NAMES.each do |attribute|
    send "#{attribute}=", options.fetch(attribute, send(attribute))
  end
  self
end

#url_options=(options) ⇒ Object



25
26
27
# File 'lib/roadie/rails/options.rb', line 25

def url_options=(options)
  @url_options = options
end