Class: Alula::Plugin
- Inherits:
-
Object
- Object
- Alula::Plugin
- Defined in:
- lib/alula/plugin.rb
Class Method Summary collapse
- .addon(type, content_or_block) ⇒ Object
- .addons ⇒ Object
- .cookieconsent?(name = nil) ⇒ Boolean
- .cookieconsent_types ⇒ Object
- .cookieconsented(name) ⇒ Object
- .load(name, options) ⇒ Object
- .needs_cookieconsent(type = 'analytics') ⇒ Object
- .plugins ⇒ Object
- .prepend_addon(type, content_or_block) ⇒ Object
- .register(name, klass) ⇒ Object
- .script(placement, content_or_block) ⇒ Object
- .script_load_mode ⇒ Object
- .script_load_mode=(mode) ⇒ Object
Instance Method Summary collapse
Class Method Details
.addon(type, content_or_block) ⇒ Object
26 27 28 |
# File 'lib/alula/plugin.rb', line 26 def self.addon(type, content_or_block) addons[type] << content_or_block end |
.addons ⇒ Object
22 23 24 |
# File 'lib/alula/plugin.rb', line 22 def self.addons @@addons ||= Hash.new {|hash, key| hash[key] = []} end |
.cookieconsent?(name = nil) ⇒ Boolean
60 61 62 63 64 65 66 |
# File 'lib/alula/plugin.rb', line 60 def self.(name = nil) if name.nil? @@cookieconsent.kind_of?(Hash) else @@cookieconsent.kind_of?(Hash) and @@cookieconsent.key?(name) end end |
.cookieconsent_types ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/alula/plugin.rb', line 73 def self. @@cookieconsented ||= {} if @@cookieconsented.kind_of?(Hash) @@cookieconsented.keys else [] end end |
.cookieconsented(name) ⇒ Object
68 69 70 71 |
# File 'lib/alula/plugin.rb', line 68 def self.(name) @@cookieconsented ||= {} @@cookieconsented[name] = true end |
.load(name, options) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/alula/plugin.rb', line 15 def self.load(name, ) if plugins[name] and !(!! == and !) plugin = plugins[name] return plugin if plugin.install( || Hashie::Mash.new) end end |
.needs_cookieconsent(type = 'analytics') ⇒ Object
53 54 55 56 57 58 |
# File 'lib/alula/plugin.rb', line 53 def self.(type = 'analytics') name = caller_name @@cookieconsent ||= {} @@cookieconsent[name] = type end |
.plugins ⇒ Object
7 8 9 |
# File 'lib/alula/plugin.rb', line 7 def self.plugins @@plugins ||= {} end |
.prepend_addon(type, content_or_block) ⇒ Object
30 31 32 |
# File 'lib/alula/plugin.rb', line 30 def self.prepend_addon(type, content_or_block) addons[type].unshift content_or_block end |
.register(name, klass) ⇒ Object
3 4 5 |
# File 'lib/alula/plugin.rb', line 3 def self.register(name, klass) plugins[name.to_s] = klass end |
.script(placement, content_or_block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/alula/plugin.rb', line 34 def self.script(placement, content_or_block) name = caller_name if self.(name) self.(name) end script = <<-EOS <script type="#{self.(name) ? "text/plain" : "text/javascript"}" #{self.(name) ? "class=\"cc-onconsent-#{@@cookieconsent[name].to_s}\"" : ""}> EOS if content_or_block.kind_of?(Proc) scpt = ->(context) { script + content_or_block.call(context) + "</script>" } else scpt = script + content_or_block + "</script>" end self.addon(placement, scpt) end |
.script_load_mode ⇒ Object
91 92 93 |
# File 'lib/alula/plugin.rb', line 91 def self.script_load_mode @@script_load_mode ||= :async end |
.script_load_mode=(mode) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/alula/plugin.rb', line 82 def self.script_load_mode=(mode) @@script_load_mode = case mode when :sync :sync when :defer self.script_load_mode == :sync ? :sync : :defer end end |
Instance Method Details
#plugins ⇒ Object
11 12 13 |
# File 'lib/alula/plugin.rb', line 11 def plugins self.class.plugins end |