class Wedge::Config

Attributes

opts[RW]

Stores the options for the config

@return [OpenStruct]

Public Class Methods

new(opts = {}) click to toggle source

Setup initial opts values

@param opts [Hash] The initial params for opts.

# 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

Public Instance Methods

dom() { || ... } click to toggle source

Used to set and update the dom

# File lib/wedge/config.rb, line 58
def dom
  if server?
    yield
  end
end
get_requires(requires = false, previous_requires = []) click to toggle source
# 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) click to toggle source

Set the raw html @param html [String]

# 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?() click to toggle source
# File lib/wedge/config.rb, line 47
def is_plugin?
  opts.is_plugin
end
name(*names) click to toggle source

Set the unique name of the component

@param name [<String, Symbol>, to_sym]

# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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