class Dasht::Board

Attributes

background[RW]
default_height[RW]
default_refresh[RW]
default_resolution[RW]
default_width[RW]
name[RW]
parent[RW]
tiles[RW]

Public Class Methods

new(parent, name) click to toggle source
# File lib/dasht/board.rb, line 12
def initialize(parent, name)
  @parent = parent
  @name  = name
  @tiles = []
end

Public Instance Methods

emit_plugin_css() click to toggle source
# File lib/dasht/board.rb, line 25
def emit_plugin_css
  _emit_css(parent.system_plugins_path)
end
emit_plugin_html() click to toggle source
# File lib/dasht/board.rb, line 29
def emit_plugin_html
  _emit_html(parent.system_plugins_path)
end
emit_plugin_js() click to toggle source
# File lib/dasht/board.rb, line 33
def emit_plugin_js
  _emit_js(parent.system_plugins_path)
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/dasht/board.rb, line 37
def method_missing(method, *args, &block)
  begin
    metric = args.shift
    options = args.pop || {}
    @tiles << {
      :type       => method,
      :metric     => metric,
      :resolution => self.default_resolution || parent.default_resolution || 60,
      :refresh    => self.default_refresh    || parent.default_refresh    || 5,
      :width      => self.default_width      || parent.default_width      || 3,
      :height     => self.default_height     || parent.default_height     || 3,
      :extra_args => args
    }.merge(options)
  rescue => e
    super(method, *args, &block)
  end
end
to_html() click to toggle source
# File lib/dasht/board.rb, line 18
def to_html
  # Load the erb.
  path = File.join(parent.views_path, "dashboard.erb")
  @erb = ERB.new(IO.read(path))
  @erb.result(binding)
end

Private Instance Methods

_emit_css(plugin_path) click to toggle source
# File lib/dasht/board.rb, line 77
def _emit_css(plugin_path)
  s = ""
  Dir[File.join(plugin_path, "*.css")].each do |path|
    name = File.basename(path)
    s += "<link rel='stylesheet' type='text/css' href='/assets/plugins/#{name}'>\n"
  end
  return s
end
_emit_html(plugin_path) click to toggle source
# File lib/dasht/board.rb, line 86
def _emit_html(plugin_path)
  s = ""
  Dir[File.join(plugin_path, "*.html")].each do |path|
    name = File.basename(path).gsub(".html", "")
    s += "<script id='#{name}-template' type='x-tmpl-mustache'>\n"
    s += "<div class='tile #{name}-tile width-{{width}} height-{{height}}'>\n"
    s += IO.read(path)
    s += "</div>\n"
    s += "</script>\n"
  end
  return s
end
_emit_js(plugin_path) click to toggle source
# File lib/dasht/board.rb, line 99
def _emit_js(plugin_path)
  s = ""
  Dir[File.join(plugin_path, "*.js")].each do |path|
    name = File.basename(path)
    s += "<script src='/assets/plugins/#{name}'></script>\n"
  end
  s
end
emit_board_js() click to toggle source
# File lib/dasht/board.rb, line 68
def emit_board_js
  s = "<script>"
  if background = self.background || parent.background
    s += "$('body').css('background', #{background.to_json});\n"
  end
  s += "</script>\n"
  s
end
emit_tile_js() click to toggle source
# File lib/dasht/board.rb, line 57
def emit_tile_js
  s = "<script>\n"
  s += "$(function() {\n";
  @tiles.map do |options|
    s += "Dasht.add_tile(#{options.to_json});\n"
  end
  s += "});"
  s += "</script>\n"
  s
end