class Maglove::Engine::Scope

Public Class Methods

new(variables = {}) click to toggle source
# File lib/maglove/engine/scope.rb, line 4
def initialize(variables = {})
  @variables = variables
end

Public Instance Methods

asset(url) click to toggle source
# File lib/maglove/engine/scope.rb, line 16
def asset(url)
  "#{asset_uri}/themes/#{theme}/#{url}"
end
asset_uri() click to toggle source
# File lib/maglove/engine/scope.rb, line 12
def asset_uri
  var(:asset_uri, Maglove::Engine.config.asset_uri)
end
block(identifier, variables = {}) click to toggle source
# File lib/maglove/engine/scope.rb, line 32
def block(identifier, variables = {})
  variables = @variables.merge(variables)
  haml = Maglove::Engine.config.block_resolver.call(identifier, variables)
  Maglove::Engine.render(haml, variables)
end
drop_container() click to toggle source
# File lib/maglove/engine/scope.rb, line 65
def drop_container
  haml_tag :div, class: '_typeloft_widget_drop_container'
end
font(font_face) { || ... } click to toggle source
# File lib/maglove/engine/scope.rb, line 87
def font(font_face, &block)
  haml_tag :font, face: font_face do
    yield if block_given?
  end
end
method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/maglove/engine/scope.rb, line 50
def method_missing(name, *args, &block)
  if name.to_s.end_with?("_widget") and args.length <= 1
    identifier = "legacy_#{name[0..-8]}".to_sym
    widget(identifier, args.first || {}, &block)
  elsif args.length == 0 and @variables.key?(name.to_sym)
    @variables[name.to_sym]
  else
    super
  end
end
respond_to_missing?(name, include_private = false) click to toggle source
Calls superclass method
# File lib/maglove/engine/scope.rb, line 61
def respond_to_missing?(name, include_private = false)
  name.to_s.end_with?("_widget") || super
end
root_asset(url) click to toggle source
# File lib/maglove/engine/scope.rb, line 20
def root_asset(url)
  "#{asset_uri}/#{url}"
end
style(*args) { || ... } click to toggle source
# File lib/maglove/engine/scope.rb, line 69
def style(*args, &block)
  style = nil
  if args[-1].class.name == 'Hash'
    style_options = args.pop
    style = style_string(style_options, *style_options.keys)
  end
  classes = args.map { |a| "__#{a}" }
  haml_tag :span, class: classes.join(' '), style: style do
    yield if block_given?
  end
end
style_string(options, *args, &block) click to toggle source
# File lib/maglove/engine/scope.rb, line 46
def style_string(options, *args, &block)
  StyleBuilder.new(options, args).process(&block)
end
theme() click to toggle source
# File lib/maglove/engine/scope.rb, line 8
def theme
  @variables[:theme]
end
var(key, default = nil) click to toggle source
# File lib/maglove/engine/scope.rb, line 38
def var(key, default = nil)
  @variables[key.to_sym] || default
end
variable(key, default = nil) click to toggle source
# File lib/maglove/engine/scope.rb, line 42
def variable(key, default = nil)
  var(key, default)
end
widget(identifier, options = {}, &block) click to toggle source
# File lib/maglove/engine/scope.rb, line 24
def widget(identifier, options = {}, &block)
  unless Maglove::Engine::Registry.instance.widgets.keys.include?(identifier.to_sym)
    raise "Widget not found: #{identifier}"
  end
  widget = Maglove::Engine.widget(identifier, options, self)
  widget.render(&block)
end