Class: Wedge::Config
Instance Attribute Summary collapse
-
#opts ⇒ OpenStruct
Stores the options for the config.
Instance Method Summary collapse
-
#dom ⇒ Object
Used to set and update the dom.
- #get_requires(requires = false, previous_requires = []) ⇒ Object
-
#html(html) ⇒ Object
Set the raw html.
-
#initialize(opts = {}) ⇒ Config
constructor
Setup initial opts values.
- #is_plugin? ⇒ Boolean
-
#name(*names) ⇒ Object
Set the unique name of the component.
- #opts_dup ⇒ Object
- #plugin(name) ⇒ Object
- #requires(*args) ⇒ Object
Methods included from Methods
Constructor Details
#initialize(opts = {}) ⇒ Config
Setup initial opts values
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/wedge/config.rb', line 16 def initialize(opts = {}) opts = { cache_assets: false, assets_key: false, tmpl: IndifferentHash.new, scope: false, loaded: false, requires: [], on: [], on_server_methods: [], object_events: {}, is_plugin: false, assets_url: '/assets/wedge', plugins: [] }.merge opts @opts = OpenStruct.new(opts) end |
Instance Attribute Details
#opts ⇒ OpenStruct
Stores the options for the config
11 12 13 |
# File 'lib/wedge/config.rb', line 11 def opts @opts end |
Instance Method Details
#dom ⇒ Object
Used to set and update the dom
58 59 60 61 62 |
# File 'lib/wedge/config.rb', line 58 def dom if server? yield end end |
#get_requires(requires = false, previous_requires = []) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/wedge/config.rb', line 100 def get_requires(requires = false, previous_requires = []) list = [] unless requires requires ||= opts.requires.dup previous_requires << opts.name.to_sym end previous_requires.each { |p| requires.delete(p) } requires.each do |r| klass = Wedge.components[r.to_sym].klass o = klass.client_wedge_opts.select do |k, v| %w(path_name name requires).include? k.to_s end # We don't want to get a stack limit error so we stop something # requiring itself pr = previous_requires.dup << o[:name].to_sym o[:requires] = get_requires o[:requires].dup, pr if o[:requires].present? list << o end list end |
#html(html) ⇒ Object
Set the raw html
66 67 68 69 70 71 72 73 74 |
# File 'lib/wedge/config.rb', line 66 def html(html) unless RUBY_ENGINE == 'opal' opts.html = begin File.read html rescue html end.strip end end |
#is_plugin? ⇒ Boolean
47 48 49 |
# File 'lib/wedge/config.rb', line 47 def is_plugin? opts.is_plugin end |
#name(*names) ⇒ Object
Set the unique name of the component
38 39 40 41 42 43 44 45 |
# File 'lib/wedge/config.rb', line 38 def name(*names) names.each do |name| opts.name = name.to_sym opts.is_plugin = true if name.to_s =~ /_plugin$/ Wedge.components ||= {} Wedge.components[opts.name] = opts end end |
#opts_dup ⇒ Object
87 88 89 |
# File 'lib/wedge/config.rb', line 87 def opts_dup opts.to_h.inject({}) {|copy, (key, value)| copy[key] = value.dup rescue value; copy} end |
#plugin(name) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/wedge/config.rb', line 91 def plugin(name) unless RUBY_ENGINE == 'opal' require "wedge/plugins/#{name}" klass = Wedge.components[:"#{name}_plugin"].klass Wedge::Component.include(klass::InstanceMethods) if defined?(klass::InstanceMethods) Wedge::Component.extend(klass::ClassMethods) if defined?(klass::ClassMethods) end end |
#requires(*args) ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/wedge/config.rb', line 76 def requires(*args) unless RUBY_ENGINE == 'opal' args.each do |a| if a.to_s[/_plugin$/] require "wedge/plugins/#{a.to_s.gsub(/_plugin$/, '')}" end opts.requires << a end end end |