<commit_before>var _ = require("underscore")
  , moment = require("moment")
  , cache = require("/templates/cache")

// Constructs a new live view from a template (css selector, html, or template url)
// and, optional data.
var LiveView = function(template, data, callback) {
  var that = this
  if(typeof template === "string" && template.match(/.*\.html/)) {
    if(cache[template]) {
      template = cache[template]
      that.initialize(template, data, callback)
    } else {
      $.get(template, function(template) {
        that.initialize(template, data, callback)
      })
    }
  } else {
    that.initialize(template, data, callback)
  }
}

LiveView.prototype.initialize = function(template, data, callback) {
  callback = callback || function() {}
  var that = this
  this.template = $(template).clone(true)
  this.context = $(template)
  this.collections = {}
  this.subViews = {}
  this.data = data = data || {}
  this.id = data.id

  //shorthand for an array of strings
  if(typeof data === "string") {
    data = {value: data}
  }

  this.substitutePartials(function() {
    that.getAttributesWithVariables()

    that.set(data)
    callback(that)
  })
}

LiveView.prototype.addCollection = function(key, value) {
  var element = this.getElementFromName(key, this.context)
  if(!this.collections[key]) {
    this.collections[key] = new LiveViewCollection(element, value, key)
  } else {
    this.collections[key].removeAll()
    this.collections[key].append(value)
  }
}

LiveView.prototype.col = LiveView.prototype.collection = function(key, value) {
  if(typeof value == "undefined" || value === null) {
    return this.collections[key]
  } else {
    this.addCollection(key, value)
  }
}

LiveView.prototype.substitutePartials = function(callback) {
  var partials = $("[data-partial]")
    , length = partials.length
    , completed = 0
  if(length == 0) {
    callback()
  } else {
    partials.each(function(index, element) {
      template = $(element).attr("data-partial")
      $.get(template, function(r) {
        $(element).html(r.responseText)
        if((++completed) == length) {
          callback()
        }
      })
    })
  }
}

LiveView.prototype.getAttributesWithVariables = function() {
  var orig = []
  $("*", this.context).each(function(i, el) {
    var attrs = []
    orig.push({attrs: attrs, element: el})
    for(var i = 0; i < el.attributes.length; i++) {
      var attrib = el.attributes[i]
      if(attrib.specified == true) {
        var memo = { name: attrib.name
                   , value: attrib.value }
      }
      attrs.push(memo)
    }
  })

  this.setAttributeOfElement = function(name, value) {
    _(orig).each(function(obj) {
      var element = $(obj.element)
      _(obj.attrs).each(function(memo) {
        regex = new RegExp("#{" + name + "}","g")
        if(memo.value.match(regex)) {
          element.attr(memo.name, memo.value.replace(regex, value.content))
        }
      })
    })
  }
}

// Given the name of the data a user passed in, return an element
// to populate with that data
LiveView.prototype.getElementFromName = function(name, context) {
  if($(context).is("." + name)) {
    return context
  }
  return $("." + name, context)
}

LiveView.prototype.setVisible = function(name, value) {
  var element = this.getElementFromName(name, this.context)
    , value
  //anything but strict false
  if (value === false) {
    $(element).hide()
  } else {
    $(element).show()
  }
}

// Sets the values of named element to value, also
// can take an object of name value pairs to bulk set
LiveView.prototype.set = function(name, value) {
  var that = this
    , obj
  if(value == null) {
    value = ""
  }
  if(arguments.length !== 2) {
    obj = name
    if(typeof obj.get === "function" && typeof obj.keys === "function") {
      obj.load(function() {
        _(obj.keys()).each(function(key) {
          that.set(key, obj.get(key))
        })
        _(obj.oneAssocs()).each(function(assoc) {
          var assocContainer = that.getElementFromName(assoc, that.context)
          if(assocContainer.length) {
            obj.assoc(assoc, function(associated) {
              that.subViews[assoc] = new LiveView(assocContainer, associated)
            })
          }
        })
        _(obj.manyAssocs()).each(function(assoc) {
          var assocContainer = that.getElementFromName(assoc, that.context)
          obj.assoc(assoc, function(associated) {
            that.set(assoc + "Count", associated.length)
            if(assocContainer.length) {
              that.subViews[assoc] = new LiveViewCollection(assocContainer, associated, assoc)
            }
          })
        })
      })
    }
    _.each(name, function(value, key) {
      that.set(key, value)
    })
  } else {
    if(_.isArray(value)) {
      this.addCollection(name, value)
      return
    }

    if(typeof value == "boolean") {
      value = {visible: value}
    } else if(typeof value !== "object") {
      value = {content: value}
    }

    this.setAttributeOfElement(name, value)

    var element = this.getElementFromName(name, this.context)

    element.each(function(index, element) {
      var el = $(element)
        , format = el.attr("data-date-format")
      tagName = element.tagName
      _.each(value, function(value, key) {
        if(key === "content") {
          if(tagName.toLowerCase() == "input" || tagName.toLowerCase() == "select") {
            if(el.attr("type") && el.attr("type").toLowerCase() == "file") {
              el.attr("data-value", value)
            } else {
              el.val(value)
            }
          } else {
            if (format) {
              var momentFormat = moment(value)
              value = momentFormat.format(format)
            }
            el.html(value)
          }
        } else if(key === "visible") {
          that.setVisible(name, value)
        } else if(key === "class") {
          el.attr("class", name + " " + value)
        } else {
          el.attr(key, value)
        }
      })
    })
  }
}

LiveView.prototype.remove = function() {
  this.context.remove()
}

LiveView.prototype.detach = function() {
  this.context.detach()
}

LiveView.prototype.attach = function(element) {
  this.context.appendTo(element)
}

LiveView.prototype.attach = function(container) {
  container.append(this.context)
}

var LiveViewCollection = function(container, data, name) {
  this.container = container
  this.collection = []
  this.views = {}
  this.events = {}

  this.name = name

  this.empty = container.find("."+name + "Empty").remove()
  this.templates = container.children().remove()

  this.container.html("")
  this.append(data)

  if (this.collection.length === 0) {
    this.container.append(this.empty)
  }
}

LiveViewCollection.prototype.getTemplate = function(type) {
  if(!type) {
    return $(this.templates[0])
  }
  var template = $(this.templates.filter("." + type)[0])
  if(template.length === 0) {
    return $(this.templates[0])
  } else {
    return template
  }
}

// If one argument, returns view at that index
// if two, returns first element with data
// where key arg1 === arg2
LiveViewCollection.prototype.get = function(id) {
    return this.views[id]
}

// number of live views in this collection
LiveViewCollection.prototype.length = function() {
  return this.collection.moment.jslength
}

LiveViewCollection.prototype.remove = function(id) {
  this.collection.splice(this.collection.indexOf(id), 1)
  var view = this.views[id]
  delete this.views[id]
  if(this.collection.length === 0) {
    this.container.append(this.empty)
  }
  return view.remove()
}

LiveViewCollection.prototype.removeAll = function() {
  _.each(this.views, function(view) {
    view.remove()
  })
  this.collection = []
  this.container.html("")
  this.views = {}
  this.container.append(this.empty)
}

// add it at the end
// return a the new liveView when completed
LiveViewCollection.prototype.insert = function(document, index) {
  var view
    , id
    , type
    , element
    , that = this

  if(!_.isArray(document)) {
    this.empty.remove()
    document = document || {}

    if(typeof document.get === "function") {
      type = document.get("type") || ""
    } else {
      type = document.type || ""
    }

    id = document.id
    element = this.getTemplate(type).clone(true)
    view = new LiveView(element, document)

    if(index === undefined) {
      this.appendView(view, id)
    } else {
      this.insertView(view, index, id)
    }
    return view
  } else {
    if(typeof document.each === "function") {
      document.each(function(item) { that.insert(item, index) })
    } else {
    _.each(document, function(item) { this.insert(item, index) }, this)
    }
  }
}

LiveViewCollection.prototype.append = function(data) {
  if(!_.isArray(data)) {
    return this.insert(data)
  } else {
    _.each(data, function(item) { this.append(item) }, this)
  }
}

LiveViewCollection.prototype.appendView = function(view, id) {
  this.container.append(view.context.detach())
  this.collection.push(id)
  this.views[id] = view
}

LiveViewCollection.prototype.insertView = function(view, index, id) {
  view.context.detach().insertBefore(this.container.children()[index])
  this.collection.splice(index, 0, index)
  this.views[id] = view
}

module.exports = LiveView
<commit_msg>itemType or type now, for now<commit_after>var _ = require("underscore")
  , moment = require("moment")
  , cache = require("/templates/cache")

// Constructs a new live view from a template (css selector, html, or template url)
// and, optional data.
var LiveView = function(template, data, callback) {
  var that = this
  if(typeof template === "string" && template.match(/.*\.html/)) {
    if(cache[template]) {
      template = cache[template]
      that.initialize(template, data, callback)
    } else {
      $.get(template, function(template) {
        that.initialize(template, data, callback)
      })
    }
  } else {
    that.initialize(template, data, callback)
  }
}

LiveView.prototype.initialize = function(template, data, callback) {
  callback = callback || function() {}
  var that = this
  this.template = $(template).clone(true)
  this.context = $(template)
  this.collections = {}
  this.subViews = {}
  this.data = data = data || {}
  this.id = data.id

  //shorthand for an array of strings
  if(typeof data === "string") {
    data = {value: data}
  }

  this.substitutePartials(function() {
    that.getAttributesWithVariables()

    that.set(data)
    callback(that)
  })
}

LiveView.prototype.addCollection = function(key, value) {
  var element = this.getElementFromName(key, this.context)
  if(!this.collections[key]) {
    this.collections[key] = new LiveViewCollection(element, value, key)
  } else {
    this.collections[key].removeAll()
    this.collections[key].append(value)
  }
}

LiveView.prototype.col = LiveView.prototype.collection = function(key, value) {
  if(typeof value == "undefined" || value === null) {
    return this.collections[key]
  } else {
    this.addCollection(key, value)
  }
}

LiveView.prototype.substitutePartials = function(callback) {
  var partials = $("[data-partial]")
    , length = partials.length
    , completed = 0
  if(length == 0) {
    callback()
  } else {
    partials.each(function(index, element) {
      template = $(element).attr("data-partial")
      $.get(template, function(r) {
        $(element).html(r.responseText)
        if((++completed) == length) {
          callback()
        }
      })
    })
  }
}

LiveView.prototype.getAttributesWithVariables = function() {
  var orig = []
  $("*", this.context).each(function(i, el) {
    var attrs = []
    orig.push({attrs: attrs, element: el})
    for(var i = 0; i < el.attributes.length; i++) {
      var attrib = el.attributes[i]
      if(attrib.specified == true) {
        var memo = { name: attrib.name
                   , value: attrib.value }
      }
      attrs.push(memo)
    }
  })

  this.setAttributeOfElement = function(name, value) {
    _(orig).each(function(obj) {
      var element = $(obj.element)
      _(obj.attrs).each(function(memo) {
        regex = new RegExp("#{" + name + "}","g")
        if(memo.value.match(regex)) {
          element.attr(memo.name, memo.value.replace(regex, value.content))
        }
      })
    })
  }
}

// Given the name of the data a user passed in, return an element
// to populate with that data
LiveView.prototype.getElementFromName = function(name, context) {
  if($(context).is("." + name)) {
    return context
  }
  return $("." + name, context)
}

LiveView.prototype.setVisible = function(name, value) {
  var element = this.getElementFromName(name, this.context)
    , value
  //anything but strict false
  if (value === false) {
    $(element).hide()
  } else {
    $(element).show()
  }
}

// Sets the values of named element to value, also
// can take an object of name value pairs to bulk set
LiveView.prototype.set = function(name, value) {
  var that = this
    , obj
  if(value == null) {
    value = ""
  }
  if(arguments.length !== 2) {
    obj = name
    if(typeof obj.get === "function" && typeof obj.keys === "function") {
      obj.load(function() {
        _(obj.keys()).each(function(key) {
          that.set(key, obj.get(key))
        })
        _(obj.oneAssocs()).each(function(assoc) {
          var assocContainer = that.getElementFromName(assoc, that.context)
          if(assocContainer.length) {
            obj.assoc(assoc, function(associated) {
              that.subViews[assoc] = new LiveView(assocContainer, associated)
            })
          }
        })
        _(obj.manyAssocs()).each(function(assoc) {
          var assocContainer = that.getElementFromName(assoc, that.context)
          obj.assoc(assoc, function(associated) {
            that.set(assoc + "Count", associated.length)
            if(assocContainer.length) {
              that.subViews[assoc] = new LiveViewCollection(assocContainer, associated, assoc)
            }
          })
        })
      })
    }
    _.each(name, function(value, key) {
      that.set(key, value)
    })
  } else {
    if(_.isArray(value)) {
      this.addCollection(name, value)
      return
    }

    if(typeof value == "boolean") {
      value = {visible: value}
    } else if(typeof value !== "object") {
      value = {content: value}
    }

    this.setAttributeOfElement(name, value)

    var element = this.getElementFromName(name, this.context)

    element.each(function(index, element) {
      var el = $(element)
        , format = el.attr("data-date-format")
      tagName = element.tagName
      _.each(value, function(value, key) {
        if(key === "content") {
          if(tagName.toLowerCase() == "input" || tagName.toLowerCase() == "select") {
            if(el.attr("type") && el.attr("type").toLowerCase() == "file") {
              el.attr("data-value", value)
            } else {
              el.val(value)
            }
          } else {
            if (format) {
              var momentFormat = moment(value)
              value = momentFormat.format(format)
            }
            el.html(value)
          }
        } else if(key === "visible") {
          that.setVisible(name, value)
        } else if(key === "class") {
          el.attr("class", name + " " + value)
        } else {
          el.attr(key, value)
        }
      })
    })
  }
}

LiveView.prototype.remove = function() {
  this.context.remove()
}

LiveView.prototype.detach = function() {
  this.context.detach()
}

LiveView.prototype.attach = function(element) {
  this.context.appendTo(element)
}

LiveView.prototype.attach = function(container) {
  container.append(this.context)
}

var LiveViewCollection = function(container, data, name) {
  this.container = container
  this.collection = []
  this.views = {}
  this.events = {}

  this.name = name

  this.empty = container.find("."+name + "Empty").remove()
  this.templates = container.children().remove()

  this.container.html("")
  this.append(data)

  if (this.collection.length === 0) {
    this.container.append(this.empty)
  }
}

LiveViewCollection.prototype.getTemplate = function(type) {
  if(!type) {
    return $(this.templates[0])
  }
  var template = $(this.templates.filter("." + type)[0])
  if(template.length === 0) {
    return $(this.templates[0])
  } else {
    return template
  }
}

// If one argument, returns view at that index
// if two, returns first element with data
// where key arg1 === arg2
LiveViewCollection.prototype.get = function(id) {
    return this.views[id]
}

// number of live views in this collection
LiveViewCollection.prototype.length = function() {
  return this.collection.moment.jslength
}

LiveViewCollection.prototype.remove = function(id) {
  this.collection.splice(this.collection.indexOf(id), 1)
  var view = this.views[id]
  delete this.views[id]
  if(this.collection.length === 0) {
    this.container.append(this.empty)
  }
  return view.remove()
}

LiveViewCollection.prototype.removeAll = function() {
  _.each(this.views, function(view) {
    view.remove()
  })
  this.collection = []
  this.container.html("")
  this.views = {}
  this.container.append(this.empty)
}

// add it at the end
// return a the new liveView when completed
LiveViewCollection.prototype.insert = function(document, index) {
  var view
    , id
    , type
    , element
    , that = this

  if(!_.isArray(document)) {
    this.empty.remove()
    document = document || {}

    if(typeof document.get === "function") {
      type = document.get("type") || document.get("itemType") || ""
    } else {
      type = document.type || ""
    }

    id = document.id
    element = this.getTemplate(type).clone(true)
    view = new LiveView(element, document)

    if(index === undefined) {
      this.appendView(view, id)
    } else {
      this.insertView(view, index, id)
    }
    return view
  } else {
    if(typeof document.each === "function") {
      document.each(function(item) { that.insert(item, index) })
    } else {
    _.each(document, function(item) { this.insert(item, index) }, this)
    }
  }
}

LiveViewCollection.prototype.append = function(data) {
  if(!_.isArray(data)) {
    return this.insert(data)
  } else {
    _.each(data, function(item) { this.append(item) }, this)
  }
}

LiveViewCollection.prototype.appendView = function(view, id) {
  this.container.append(view.context.detach())
  this.collection.push(id)
  this.views[id] = view
}

LiveViewCollection.prototype.insertView = function(view, index, id) {
  view.context.detach().insertBefore(this.container.children()[index])
  this.collection.splice(index, 0, index)
  this.views[id] = view
}

module.exports = LiveView
<|endoftext|>


<commit_before>Package.describe({
    summary: "Accounts Templates styled for Zurb Foundation.",
    version: "0.9.0",
    name: "splendido:accounts-templates-foundation",
    git: "https://github.com/splendido/accounts-templates-foundation.git",
});

Package.on_use(function(api, where) {
    api.use([
        'accounts-templates-core',
        'templating',
        'less'
    ], 'client');
    api.use([
        'accounts-templates-core',
    ], 'server');

    api.imply([
        'accounts-templates-core',
    ], ['client', 'server']);

    api.add_files([
        'lib/at_error.html',
        'lib/at_error.js',
        'lib/at_form.html',
        'lib/at_form.js',
        'lib/at_input.html',
        'lib/at_input.js',
        'lib/at_oauth.html',
        'lib/at_oauth.js',
        'lib/at_pwd_form.html',
        'lib/at_pwd_form.js',
        'lib/at_pwd_form_btn.html',
        'lib/at_pwd_form_btn.js',
        'lib/at_pwd_link.html',
        'lib/at_pwd_link.js',
        'lib/at_result.html',
        'lib/at_result.js',
        'lib/at_sep.html',
        'lib/at_sep.js',
        'lib/at_signin_link.html',
        'lib/at_signin_link.js',
        'lib/at_signup_link.html',
        'lib/at_signup_link.js',
        'lib/at_social.html',
        'lib/at_social.js',
        'lib/at_terms_link.html',
        'lib/at_terms_link.js',
        'lib/at_title.html',
        'lib/at_title.js',
        'lib/full_page_at_form.html',
        'lib/at_foundation.less'
    ], ['client']);
});

Package.on_test(function(api) {
    api.use([
        'accounts-templates-foundation',
        'accounts-templates-core',
    ]);
    api.use(['tinytest', 'test-helpers'], ['client', 'server']);
    api.add_files('tests/accounts-templates-foundation_tests.js', ['client', 'server']);
});<commit_msg>Bump to version 0.9.0<commit_after>Package.describe({
    summary: "Accounts Templates styled for Zurb Foundation.",
    version: "0.9.0",
    name: "splendido:accounts-templates-foundation",
    git: "https://github.com/splendido/accounts-templates-foundation.git",
});

Package.on_use(function(api, where) {
    api.use([
        'splendido:accounts-templates-core@0.9.0',
        'templating@1.0.6',
        'less@1.0.8'
    ], 'client');
    api.use([
        'splendido:accounts-templates-core@0.9.0',
    ], 'server');

    api.imply([
        'splendido:accounts-templates-core@0.9.0',
    ], ['client', 'server']);

    api.add_files([
        'lib/at_error.html',
        'lib/at_error.js',
        'lib/at_form.html',
        'lib/at_form.js',
        'lib/at_input.html',
        'lib/at_input.js',
        'lib/at_oauth.html',
        'lib/at_oauth.js',
        'lib/at_pwd_form.html',
        'lib/at_pwd_form.js',
        'lib/at_pwd_form_btn.html',
        'lib/at_pwd_form_btn.js',
        'lib/at_pwd_link.html',
        'lib/at_pwd_link.js',
        'lib/at_result.html',
        'lib/at_result.js',
        'lib/at_sep.html',
        'lib/at_sep.js',
        'lib/at_signin_link.html',
        'lib/at_signin_link.js',
        'lib/at_signup_link.html',
        'lib/at_signup_link.js',
        'lib/at_social.html',
        'lib/at_social.js',
        'lib/at_terms_link.html',
        'lib/at_terms_link.js',
        'lib/at_title.html',
        'lib/at_title.js',
        'lib/full_page_at_form.html',
        'lib/at_foundation.less'
    ], ['client']);
});

Package.on_test(function(api) {
    api.use([
        'splendido:accounts-templates-foundation',
        'splendido:accounts-templates-core@0.9.0',
    ]);

    api.use([
        'accounts-password',
        'tinytest',
        'test-helpers'
    ], ['client', 'server']);

    api.add_files([
        'tests/accounts-templates-foundation_tests.js'
    ], ['client', 'server']);
});
<|endoftext|>


<commit_before>var _ = require("underscore")
  , moment = require("moment")
  , cache = require("/templates/cache")

// Constructs a new live view from a template (css selector, html, or template url)
// and, optional data.
var LiveView = function(template, data, callback) {
  var that = this
  if(typeof template === "string" && template.match(/.*\.html/)) {
    if(cache[template]) {
      template = cache[template]
      that.initialize(template, data, callback)
    } else {
      $.get(template, function(template) {
        that.initialize(template, data, callback)
      })
    }
  } else {
    that.initialize(template, data, callback)
  }
}

LiveView.prototype.initialize = function(template, data, callback) {
  callback = callback || function() {}
  var that = this
  this.template = $(template).clone(true)
  this.context = $(template)
  this.collections = {}
  this.subViews = {}
  this.data = data = data || {}
  this.id = data.id

  //shorthand for an array of strings
  if(typeof data === "string") {
    data = {value: data}
  }

  this.substitutePartials(function() {
    that.getAttributesWithVariables()

    that.set(data)
    callback(that)
  })
}

LiveView.prototype.addCollection = function(key, value) {
  var element = this.getElementFromName(key, this.context)
  if(!this.collections[key]) {
    this.collections[key] = new LiveViewCollection(element, value, key)
  } else {
    this.collections[key].removeAll()
    this.collections[key].append(value)
  }
}

LiveView.prototype.col = LiveView.prototype.collection = function(key, value) {
  if(typeof value == "undefined" || value === null) {
    return this.collections[key]
  } else {
    this.addCollection(key, value)
  }
}

LiveView.prototype.substitutePartials = function(callback) {
  var partials = $("[data-partial]")
    , length = partials.length
    , completed = 0
  if(length == 0) {
    callback()
  } else {
    partials.each(function(index, element) {
      template = $(element).attr("data-partial")
      $.get(template, function(r) {
        $(element).html(r.responseText)
        if((++completed) == length) {
          callback()
        }
      })
    })
  }
}

LiveView.prototype.getAttributesWithVariables = function() {
  var orig = []
  $("*", this.context).each(function(i, el) {
    var attrs = []
    orig.push({attrs: attrs, element: el})
    for(var i = 0; i < el.attributes.length; i++) {
      var attrib = el.attributes[i]
      if(attrib.specified == true) {
        var memo = { name: attrib.name
                   , value: attrib.value }
      }
      attrs.push(memo)
    }
  })

  this.setAttributeOfElement = function(name, value) {
    _(orig).each(function(obj) {
      var element = $(obj.element)
      _(obj.attrs).each(function(memo) {
        regex = new RegExp("#{" + name + "}","g")
        if(memo.value.match(regex)) {
          element.attr(memo.name, memo.value.replace(regex, value.content))
        }
      })
    })
  }
}

// Given the name of the data a user passed in, return an element
// to populate with that data
LiveView.prototype.getElementFromName = function(name, context) {
  if($(context).is("." + name)) {
    return context
  }
  return $("." + name, context)
}

LiveView.prototype.setVisible = function(name, value) {
  var element = this.getElementFromName(name, this.context)
    , value
  //anything but strict false
  if (value === false) {
    $(element).hide()
  } else {
    $(element).show()
  }
}

// Sets the values of named element to value, also
// can take an object of name value pairs to bulk set
LiveView.prototype.set = function(name, value) {
  var that = this
    , obj
  if(value == null) {
    value = ""
  }
  if(arguments.length !== 2) {
    obj = name
    if(typeof obj.get === "function" && typeof obj.keys === "function") {
      _(obj.keys()).each(function(key) {
        that.set(key, obj.get(key))
      })
      _(obj.oneAssocs()).each(function(assoc) {
        var assocContainer = that.getElementFromName(assoc, that.context)
        if(assocContainer.length) {
          obj.assoc(assoc, function(associated) {
            that.subViews[assoc] = new LiveView(assocContainer, associated)
          })
        }
      })
      _(obj.manyAssocs()).each(function(assoc) {
        var assocContainer = that.getElementFromName(assoc, that.context)
        obj.assoc(assoc, function(associated) {
          that.set(assoc + "Count", associated.length)
          if(assocContainer.length) {
            that.subViews[assoc] = new LiveViewCollection(assocContainer, associated, assoc)
          }
        })
      })
    }
    _.each(name, function(value, key) {
      that.set(key, value)
    })
  } else {
    if(_.isArray(value)) {
      this.addCollection(name, value)
      return
    }

    if(typeof value == "boolean") {
      value = {visible: value}
    } else if(typeof value !== "object") {
      value = {content: value}
    }

    this.setAttributeOfElement(name, value)

    var element = this.getElementFromName(name, this.context)

    element.each(function(index, element) {
      var el = $(element)
        , format = el.attr("data-date-format")
      tagName = element.tagName
      _.each(value, function(value, key) {
        if(key === "content") {
          if(tagName.toLowerCase() == "input" || tagName.toLowerCase() == "select") {
            if(el.attr("type") && el.attr("type").toLowerCase() == "file") {
              el.attr("data-value", value)
            } else {
              el.val(value)
            }
          } else {
            if (format) {
              var momentFormat = moment(value)
              value = momentFormat.format(format)
            }
            el.html(value)
          }
        } else if(key === "visible") {
          that.setVisible(name, value)
        } else if(key === "class") {
          el.attr("class", name + " " + value)
        } else {
          el.attr(key, value)
        }
      })
    })
  }
}

LiveView.prototype.remove = function() {
  this.context.remove()
}

LiveView.prototype.detach = function() {
  this.context.detach()
}

LiveView.prototype.attach = function(element) {
  this.context.appendTo(element)
}

LiveView.prototype.attach = function(container) {
  container.append(this.context)
}

var LiveViewCollection = function(container, data, name) {
  this.container = container
  this.collection = []
  this.views = {}
  this.events = {}

  this.name = name

  this.empty = container.find("."+name + "Empty").remove()
  this.templates = container.children().remove()

  this.container.html("")
  this.append(data)

  if (this.collection.length === 0) {
    this.container.append(this.empty)
  }
}

LiveViewCollection.prototype.getTemplate = function(type) {
  if(!type) {
    return $(this.templates[0])
  }
  var template = $(this.templates.filter("." + type)[0])
  if(template.length === 0) {
    return $(this.templates[0])
  } else {
    return template
  }
}

// If one argument, returns view at that index
// if two, returns first element with data
// where key arg1 === arg2
LiveViewCollection.prototype.get = function(id) {
    return this.views[id]
}

// number of live views in this collection
LiveViewCollection.prototype.length = function() {
  return this.collection.moment.jslength
}

LiveViewCollection.prototype.remove = function(id) {
  this.collection.splice(this.collection.indexOf(id), 1)
  var view = this.views[id]
  delete this.views[id]
  if(this.collection.length === 0) {
    this.container.append(this.empty)
  }
  return view.remove()
}

LiveViewCollection.prototype.removeAll = function() {
  _.each(this.views, function(view) {
    view.remove()
  })
  this.collection = []
  this.container.html("")
  this.views = {}
  this.container.append(this.empty)
}

// add it at the end
// return a the new liveView when completed
LiveViewCollection.prototype.insert = function(document, index) {
  var view
    , id
    , type
    , element
    , that = this

  if(!_.isArray(document)) {
    this.empty.remove()
    document = document || {}

    if(typeof document.get === "function") {
      type = document.get("type") || ""
    } else {
      type = document.type || ""
    }

    id = document.id
    element = this.getTemplate(type).clone(true)
    view = new LiveView(element, document)

    if(index === undefined) {
      this.appendView(view, id)
    } else {
      this.insertView(view, index, id)
    }
    return view
  } else {
    if(typeof document.each === "function") {
      document.each(function(item) { that.insert(item, index) })
    } else {
    _.each(document, function(item) { this.insert(item, index) }, this)
    }
  }
}

LiveViewCollection.prototype.append = function(data) {
  if(!_.isArray(data)) {
    return this.insert(data)
  } else {
    _.each(data, function(item) { this.append(item) }, this)
  }
}

LiveViewCollection.prototype.appendView = function(view, id) {
  this.container.append(view.context.detach())
  this.collection.push(id)
  this.views[id] = view
}

LiveViewCollection.prototype.insertView = function(view, index, id) {
  view.context.detach().insertBefore(this.container.children()[index])
  this.collection.splice(index, 0, index)
  this.views[id] = view
}

module.exports = LiveView
<commit_msg>wait until the document is loaded to set the values<commit_after>var _ = require("underscore")
  , moment = require("moment")
  , cache = require("/templates/cache")

// Constructs a new live view from a template (css selector, html, or template url)
// and, optional data.
var LiveView = function(template, data, callback) {
  var that = this
  if(typeof template === "string" && template.match(/.*\.html/)) {
    if(cache[template]) {
      template = cache[template]
      that.initialize(template, data, callback)
    } else {
      $.get(template, function(template) {
        that.initialize(template, data, callback)
      })
    }
  } else {
    that.initialize(template, data, callback)
  }
}

LiveView.prototype.initialize = function(template, data, callback) {
  callback = callback || function() {}
  var that = this
  this.template = $(template).clone(true)
  this.context = $(template)
  this.collections = {}
  this.subViews = {}
  this.data = data = data || {}
  this.id = data.id

  //shorthand for an array of strings
  if(typeof data === "string") {
    data = {value: data}
  }

  this.substitutePartials(function() {
    that.getAttributesWithVariables()

    that.set(data)
    callback(that)
  })
}

LiveView.prototype.addCollection = function(key, value) {
  var element = this.getElementFromName(key, this.context)
  if(!this.collections[key]) {
    this.collections[key] = new LiveViewCollection(element, value, key)
  } else {
    this.collections[key].removeAll()
    this.collections[key].append(value)
  }
}

LiveView.prototype.col = LiveView.prototype.collection = function(key, value) {
  if(typeof value == "undefined" || value === null) {
    return this.collections[key]
  } else {
    this.addCollection(key, value)
  }
}

LiveView.prototype.substitutePartials = function(callback) {
  var partials = $("[data-partial]")
    , length = partials.length
    , completed = 0
  if(length == 0) {
    callback()
  } else {
    partials.each(function(index, element) {
      template = $(element).attr("data-partial")
      $.get(template, function(r) {
        $(element).html(r.responseText)
        if((++completed) == length) {
          callback()
        }
      })
    })
  }
}

LiveView.prototype.getAttributesWithVariables = function() {
  var orig = []
  $("*", this.context).each(function(i, el) {
    var attrs = []
    orig.push({attrs: attrs, element: el})
    for(var i = 0; i < el.attributes.length; i++) {
      var attrib = el.attributes[i]
      if(attrib.specified == true) {
        var memo = { name: attrib.name
                   , value: attrib.value }
      }
      attrs.push(memo)
    }
  })

  this.setAttributeOfElement = function(name, value) {
    _(orig).each(function(obj) {
      var element = $(obj.element)
      _(obj.attrs).each(function(memo) {
        regex = new RegExp("#{" + name + "}","g")
        if(memo.value.match(regex)) {
          element.attr(memo.name, memo.value.replace(regex, value.content))
        }
      })
    })
  }
}

// Given the name of the data a user passed in, return an element
// to populate with that data
LiveView.prototype.getElementFromName = function(name, context) {
  if($(context).is("." + name)) {
    return context
  }
  return $("." + name, context)
}

LiveView.prototype.setVisible = function(name, value) {
  var element = this.getElementFromName(name, this.context)
    , value
  //anything but strict false
  if (value === false) {
    $(element).hide()
  } else {
    $(element).show()
  }
}

// Sets the values of named element to value, also
// can take an object of name value pairs to bulk set
LiveView.prototype.set = function(name, value) {
  var that = this
    , obj
  if(value == null) {
    value = ""
  }
  if(arguments.length !== 2) {
    obj = name
    if(typeof obj.get === "function" && typeof obj.keys === "function") {
      obj.load(function() {
        _(obj.keys()).each(function(key) {
          that.set(key, obj.get(key))
        })
        _(obj.oneAssocs()).each(function(assoc) {
          var assocContainer = that.getElementFromName(assoc, that.context)
          if(assocContainer.length) {
            obj.assoc(assoc, function(associated) {
              that.subViews[assoc] = new LiveView(assocContainer, associated)
            })
          }
        })
        _(obj.manyAssocs()).each(function(assoc) {
          var assocContainer = that.getElementFromName(assoc, that.context)
          obj.assoc(assoc, function(associated) {
            that.set(assoc + "Count", associated.length)
            if(assocContainer.length) {
              that.subViews[assoc] = new LiveViewCollection(assocContainer, associated, assoc)
            }
          })
        })
      })
    }
    _.each(name, function(value, key) {
      that.set(key, value)
    })
  } else {
    if(_.isArray(value)) {
      this.addCollection(name, value)
      return
    }

    if(typeof value == "boolean") {
      value = {visible: value}
    } else if(typeof value !== "object") {
      value = {content: value}
    }

    this.setAttributeOfElement(name, value)

    var element = this.getElementFromName(name, this.context)

    element.each(function(index, element) {
      var el = $(element)
        , format = el.attr("data-date-format")
      tagName = element.tagName
      _.each(value, function(value, key) {
        if(key === "content") {
          if(tagName.toLowerCase() == "input" || tagName.toLowerCase() == "select") {
            if(el.attr("type") && el.attr("type").toLowerCase() == "file") {
              el.attr("data-value", value)
            } else {
              el.val(value)
            }
          } else {
            if (format) {
              var momentFormat = moment(value)
              value = momentFormat.format(format)
            }
            el.html(value)
          }
        } else if(key === "visible") {
          that.setVisible(name, value)
        } else if(key === "class") {
          el.attr("class", name + " " + value)
        } else {
          el.attr(key, value)
        }
      })
    })
  }
}

LiveView.prototype.remove = function() {
  this.context.remove()
}

LiveView.prototype.detach = function() {
  this.context.detach()
}

LiveView.prototype.attach = function(element) {
  this.context.appendTo(element)
}

LiveView.prototype.attach = function(container) {
  container.append(this.context)
}

var LiveViewCollection = function(container, data, name) {
  this.container = container
  this.collection = []
  this.views = {}
  this.events = {}

  this.name = name

  this.empty = container.find("."+name + "Empty").remove()
  this.templates = container.children().remove()

  this.container.html("")
  this.append(data)

  if (this.collection.length === 0) {
    this.container.append(this.empty)
  }
}

LiveViewCollection.prototype.getTemplate = function(type) {
  if(!type) {
    return $(this.templates[0])
  }
  var template = $(this.templates.filter("." + type)[0])
  if(template.length === 0) {
    return $(this.templates[0])
  } else {
    return template
  }
}

// If one argument, returns view at that index
// if two, returns first element with data
// where key arg1 === arg2
LiveViewCollection.prototype.get = function(id) {
    return this.views[id]
}

// number of live views in this collection
LiveViewCollection.prototype.length = function() {
  return this.collection.moment.jslength
}

LiveViewCollection.prototype.remove = function(id) {
  this.collection.splice(this.collection.indexOf(id), 1)
  var view = this.views[id]
  delete this.views[id]
  if(this.collection.length === 0) {
    this.container.append(this.empty)
  }
  return view.remove()
}

LiveViewCollection.prototype.removeAll = function() {
  _.each(this.views, function(view) {
    view.remove()
  })
  this.collection = []
  this.container.html("")
  this.views = {}
  this.container.append(this.empty)
}

// add it at the end
// return a the new liveView when completed
LiveViewCollection.prototype.insert = function(document, index) {
  var view
    , id
    , type
    , element
    , that = this

  if(!_.isArray(document)) {
    this.empty.remove()
    document = document || {}

    if(typeof document.get === "function") {
      type = document.get("type") || ""
    } else {
      type = document.type || ""
    }

    id = document.id
    element = this.getTemplate(type).clone(true)
    view = new LiveView(element, document)

    if(index === undefined) {
      this.appendView(view, id)
    } else {
      this.insertView(view, index, id)
    }
    return view
  } else {
    if(typeof document.each === "function") {
      document.each(function(item) { that.insert(item, index) })
    } else {
    _.each(document, function(item) { this.insert(item, index) }, this)
    }
  }
}

LiveViewCollection.prototype.append = function(data) {
  if(!_.isArray(data)) {
    return this.insert(data)
  } else {
    _.each(data, function(item) { this.append(item) }, this)
  }
}

LiveViewCollection.prototype.appendView = function(view, id) {
  this.container.append(view.context.detach())
  this.collection.push(id)
  this.views[id] = view
}

LiveViewCollection.prototype.insertView = function(view, index, id) {
  view.context.detach().insertBefore(this.container.children()[index])
  this.collection.splice(index, 0, index)
  this.views[id] = view
}

module.exports = LiveView
<|endoftext|>


<commit_before>Package.describe({
  summary: 'Relations for Meteor Astronomy',
  version: '0.1.1',
  name: 'jagi:astronomy-relations',
  git: 'https://github.com/jagi/meteor-astronomy-relations.git'
});

Package.onUse(function(api) {
  api.versionsFrom('1.1.0.2');

  api.use('jagi:astronomy@0.10.5');
  api.use('underscore');

  api.imply('jagi:astronomy');

  // Module.
  api.addFiles('lib/module/init_module.js', ['client', 'server']);
  api.addFiles('lib/module/init_class.js', ['client', 'server']);
  api.addFiles('lib/module/init_instance.js', ['client', 'server']);
  api.addFiles('lib/module/module.js', ['client', 'server']);
});
<commit_msg>Add tracker package to package.js<commit_after>Package.describe({
  summary: 'Relations for Meteor Astronomy',
  version: '0.1.2',
  name: 'jagi:astronomy-relations',
  git: 'https://github.com/jagi/meteor-astronomy-relations.git'
});

Package.onUse(function(api) {
  api.versionsFrom('1.1.0.2');

  api.use('jagi:astronomy@0.10.5');
  api.use('underscore');
  api.use('tracker');

  api.imply('jagi:astronomy');

  // Module.
  api.addFiles('lib/module/init_module.js', ['client', 'server']);
  api.addFiles('lib/module/init_class.js', ['client', 'server']);
  api.addFiles('lib/module/init_instance.js', ['client', 'server']);
  api.addFiles('lib/module/module.js', ['client', 'server']);
});
<|endoftext|>


<commit_before>StompLogging = exports.StompLogging = function(should_debug) {
    this.should_debug = should_debug;
};

StompLogging.prototype.debug = function(message) {
    if (this.should_debug)
        console.log("debug: " + message);
};

/**
 * Queueing implementation, blatantly ripped off from:
 * http://safalra.com/web-design/javascript/queues/Queue.js
 * only really semantics have been changed.
 */
StompQueue = exports.StompQueue = function() {
    this.queue = [];
    this.queue_space = 0;
};

StompQueue.prototype.get_size = function() {
    return this.queue.length - this.queue_space;
}

StompQueue.prototype.is_empty = function() {
    return (this.queue.length == 0);
}

StompQueue.prototype.put = function(item) {
    this.queue.push(item);
}

StompQueue.prototype.get = function() {
    var item = undefined;

    if (this.queue.length) {
        item = this.queue[this.queue_space];

        if (++this.queue_space * 2 >= this.queue.length) {
            this.queue = this.queue.slice(this.queue_space);
            this.queue_space = 0;
        }
    }
    return item;
};

StompQueue.prototype.get_oldest_item = function() {
    var item = undefined;

    if (this.queue.length)
        item = this.queue[this.queue_space];

    return item;
};
<commit_msg>Consistent code is consistent.<commit_after>StompLogging = exports.StompLogging = function(should_debug) {
    this.should_debug = should_debug;
};

StompLogging.prototype.debug = function(message) {
    if (this.should_debug)
        console.log("debug: " + message);
};

/**
 * Queueing implementation, blatantly ripped off from:
 * http://safalra.com/web-design/javascript/queues/Queue.js
 * only really semantics have been changed.
 */
StompQueue = exports.StompQueue = function() {
    this.queue = [];
    this.queue_space = 0;
};

StompQueue.prototype.get_size = function() {
    return this.queue.length - this.queue_space;
};

StompQueue.prototype.is_empty = function() {
    return (this.queue.length == 0);
};

StompQueue.prototype.put = function(item) {
    this.queue.push(item);
};

StompQueue.prototype.get = function() {
    var item = undefined;

    if (this.queue.length) {
        item = this.queue[this.queue_space];

        if (++this.queue_space * 2 >= this.queue.length) {
            this.queue = this.queue.slice(this.queue_space);
            this.queue_space = 0;
        }
    }
    return item;
};

StompQueue.prototype.get_oldest_item = function() {
    var item = undefined;

    if (this.queue.length)
        item = this.queue[this.queue_space];

    return item;
};
<|endoftext|>


<commit_before>module.exports = LRUCache

// This will be a proper iterable 'Map' in engines that support it,
// or a fakey-fake PseudoMap in older versions.
var Map = require('pseudomap')
var util = require('util')

// A linked list to keep track of recently-used-ness
var Yallist = require('yallist')

// use symbols if possible, otherwise just _props
var symbols = {}
var hasSymbol = typeof Symbol === 'function'
var makeSymbol
if (hasSymbol) {
  makeSymbol = function (key) {
    return Symbol.for(key)
  }
} else {
  makeSymbol = function (key) {
    return '_' + key
  }
}

function priv (obj, key, val) {
  var sym
  if (symbols[key]) {
    sym = symbols[key]
  } else {
    sym = makeSymbol(key)
    symbols[key] = sym
  }
  if (arguments.length === 2) {
    return obj[sym]
  } else {
    obj[sym] = val
    return val
  }
}

function naiveLength () { return 1 }

// lruList is a yallist where the head is the youngest
// item, and the tail is the oldest.  the list contains the Hit
// objects as the entries.
// Each Hit object has a reference to its Yallist.Node.  This
// never changes.
//
// cache is a Map (or PseudoMap) that matches the keys to
// the Yallist.Node object.
function LRUCache (options) {
  if (!(this instanceof LRUCache)) {
    return new LRUCache(options)
  }

  if (typeof options === 'number') {
    options = { max: options }
  }

  if (!options) {
    options = {}
  }

  var max = priv(this, 'max', options.max)
  // Kind of weird to have a default max of Infinity, but oh well.
  if (!max ||
      !(typeof max === 'number') ||
      max <= 0) {
    priv(this, 'max', Infinity)
  }

  var lc = options.length || naiveLength
  if (typeof lc !== 'function') {
    lc = naiveLength
  }
  priv(this, 'lengthCalculator', lc)

  priv(this, 'allowStale', options.stale || false)
  priv(this, 'maxAge', options.maxAge || 0)
  priv(this, 'dispose', options.dispose)
  this.reset()
}

// resize the cache when the max changes.
Object.defineProperty(LRUCache.prototype, 'max', {
  set: function (mL) {
    if (!mL || !(typeof mL === 'number') || mL <= 0) {
      mL = Infinity
    }
    priv(this, 'max', mL)
    trim(this)
  },
  get: function () {
    return priv(this, 'max')
  },
  enumerable: true
})

Object.defineProperty(LRUCache.prototype, 'allowStale', {
  set: function (allowStale) {
    priv(this, 'allowStale', !!allowStale)
  },
  get: function () {
    return priv(this, 'allowStale')
  },
  enumerable: true
})

Object.defineProperty(LRUCache.prototype, 'maxAge', {
  set: function (mA) {
    if (!mA || !(typeof mA === 'number') || mA < 0) {
      mA = 0
    }
    priv(this, 'maxAge', mA)
    trim(this)
  },
  get: function () {
    return priv(this, 'maxAge')
  },
  enumerable: true
})

// resize the cache when the lengthCalculator changes.
Object.defineProperty(LRUCache.prototype, 'lengthCalculator', {
  set: function (lC) {
    if (typeof lC !== 'function') {
      lC = naiveLength
    }
    if (lC !== priv(this, 'lengthCalculator')) {
      priv(this, 'lengthCalculator', lC)
      priv(this, 'length', 0)
      priv(this, 'lruList').forEach(function (hit) {
        hit.length = priv(this, 'lengthCalculator').call(this, hit.value, hit.key)
        priv(this, 'length', priv(this, 'length') + hit.length)
      }, this)
    }
    trim(this)
  },
  get: function () { return priv(this, 'lengthCalculator') },
  enumerable: true
})

Object.defineProperty(LRUCache.prototype, 'length', {
  get: function () { return priv(this, 'length') },
  enumerable: true
})

Object.defineProperty(LRUCache.prototype, 'itemCount', {
  get: function () { return priv(this, 'lruList').length },
  enumerable: true
})

LRUCache.prototype.rforEach = function (fn, thisp) {
  thisp = thisp || this
  for (var walker = priv(this, 'lruList').tail; walker !== null;) {
    var prev = walker.prev
    forEachStep(this, fn, walker, thisp)
    walker = prev
  }
}

function forEachStep (self, fn, node, thisp) {
  var hit = node.value
  if (isStale(self, hit)) {
    del(self, node)
    if (!priv(self, 'allowStale')) {
      hit = undefined
    }
  }
  if (hit) {
    fn.call(thisp, hit.value, hit.key, self)
  }
}

LRUCache.prototype.forEach = function (fn, thisp) {
  thisp = thisp || this
  for (var walker = priv(this, 'lruList').head; walker !== null;) {
    var next = walker.next
    forEachStep(this, fn, walker, thisp)
    walker = next
  }
}

LRUCache.prototype.keys = function () {
  return priv(this, 'lruList').toArray().map(function (k) {
    return k.key
  }, this)
}

LRUCache.prototype.values = function () {
  return priv(this, 'lruList').toArray().map(function (k) {
    return k.value
  }, this)
}

LRUCache.prototype.reset = function () {
  if (priv(this, 'dispose') &&
      priv(this, 'lruList') &&
      priv(this, 'lruList').length) {
    priv(this, 'lruList').forEach(function (hit) {
      priv(this, 'dispose').call(this, hit.key, hit.value)
    }, this)
  }

  priv(this, 'cache', new Map()) // hash of items by key
  priv(this, 'lruList', new Yallist()) // list of items in order of use recency
  priv(this, 'length', 0) // length of items in the list
}

LRUCache.prototype.dump = function () {
  return priv(this, 'lruList').map(function (hit) {
    if (!isStale(this, hit)) {
      return {
        k: hit.key,
        v: hit.value,
        e: hit.now + (hit.maxAge || 0)
      }
    }
  }, this).toArray().filter(function (h) {
    return h
  })
}

LRUCache.prototype.dumpLru = function () {
  return priv(this, 'lruList')
}

LRUCache.prototype.inspect = function (n, opts) {
  var str = 'LRUCache {'
  var extras = false

  var as = priv(this, 'allowStale')
  if (as) {
    str += '\n  allowStale: true'
    extras = true
  }

  var max = priv(this, 'max')
  if (max && max !== Infinity) {
    if (extras) {
      str += ','
    }
    str += '\n  max: ' + util.inspect(max, opts)
    extras = true
  }

  var maxAge = priv(this, 'maxAge')
  if (maxAge) {
    if (extras) {
      str += ','
    }
    str += '\n  maxAge: ' + util.inspect(maxAge, opts)
    extras = true
  }

  var lc = priv(this, 'lengthCalculator')
  if (lc && lc !== naiveLength) {
    if (extras) {
      str += ','
    }
    str += '\n  length: ' + util.inspect(priv(this, 'length'), opts)
    extras = true
  }

  var didFirst = false
  priv(this, 'lruList').forEach(function (item) {
    if (didFirst) {
      str += ',\n  '
    } else {
      if (extras) {
        str += ',\n'
      }
      didFirst = true
      str += '\n  '
    }
    var key = util.inspect(item.key).split('\n').join('\n  ')
    var val = { value: item.value }
    if (item.maxAge !== maxAge) {
      val.maxAge = item.maxAge
    }
    if (lc !== naiveLength) {
      val.length = item.length
    }
    if (isStale(this, item)) {
      val.stale = true
    }

    val = util.inspect(val, opts).split('\n').join('\n  ')
    str += key + ' => ' + val
  })

  if (didFirst || extras) {
    str += '\n'
  }
  str += '}'

  return str
}

LRUCache.prototype.set = function (key, value, maxAge) {
  maxAge = maxAge || priv(this, 'maxAge')

  var now = maxAge ? Date.now() : 0
  var len = priv(this, 'lengthCalculator').call(this, value, key)

  if (priv(this, 'cache').has(key)) {
    if (len > priv(this, 'max')) {
      del(this, priv(this, 'cache').get(key))
      return false
    }

    var node = priv(this, 'cache').get(key)
    var item = node.value

    // dispose of the old one before overwriting
    if (priv(this, 'dispose')) {
      priv(this, 'dispose').call(this, key, item.value)
    }

    item.now = now
    item.maxAge = maxAge
    item.value = value
    priv(this, 'length', priv(this, 'length') + (len - item.length))
    item.length = len
    this.get(key)
    trim(this)
    return true
  }

  var hit = new Entry(key, value, len, now, maxAge)

  // oversized objects fall out of cache automatically.
  if (hit.length > priv(this, 'max')) {
    if (priv(this, 'dispose')) {
      priv(this, 'dispose').call(this, key, value)
    }
    return false
  }

  priv(this, 'length', priv(this, 'length') + hit.length)
  priv(this, 'lruList').unshift(hit)
  priv(this, 'cache').set(key, priv(this, 'lruList').head)
  trim(this)
  return true
}

LRUCache.prototype.has = function (key) {
  if (!priv(this, 'cache').has(key)) return false
  var hit = priv(this, 'cache').get(key).value
  if (isStale(this, hit)) {
    return false
  }
  return true
}

LRUCache.prototype.get = function (key) {
  return get(this, key, true)
}

LRUCache.prototype.peek = function (key) {
  return get(this, key, false)
}

LRUCache.prototype.pop = function () {
  var node = priv(this, 'lruList').tail
  if (!node) return null
  del(this, node)
  return node.value
}

LRUCache.prototype.del = function (key) {
  del(this, priv(this, 'cache').get(key))
}

LRUCache.prototype.load = function (arr) {
  // reset the cache
  this.reset()

  var now = Date.now()
  // A previous serialized cache has the most recent items first
  for (var l = arr.length - 1; l >= 0; l--) {
    var hit = arr[l]
    var expiresAt = hit.e || 0
    if (expiresAt === 0) {
      // the item was created without expiration in a non aged cache
      this.set(hit.k, hit.v)
    } else {
      var maxAge = expiresAt - now
      // dont add already expired items
      if (maxAge > 0) {
        this.set(hit.k, hit.v, maxAge)
      }
    }
  }
}

LRUCache.prototype.prune = function () {
  var self = this
  priv(this, 'cache').forEach(function (value, key) {
    get(self, key, false)
  })
}

function get (self, key, doUse) {
  var node = priv(self, 'cache').get(key)
  if (node) {
    var hit = node.value
    if (isStale(self, hit)) {
      del(self, node)
      if (!priv(self, 'allowStale')) hit = undefined
    } else {
      if (doUse) {
        priv(self, 'lruList').unshiftNode(node)
      }
    }
    if (hit) hit = hit.value
  }
  return hit
}

function isStale (self, hit) {
  if (!hit || (!hit.maxAge && !priv(self, 'maxAge'))) {
    return false
  }
  var stale = false
  var diff = Date.now() - hit.now
  if (hit.maxAge) {
    stale = diff > hit.maxAge
  } else {
    stale = priv(self, 'maxAge') && (diff > priv(self, 'maxAge'))
  }
  return stale
}

function trim (self) {
  if (priv(self, 'length') > priv(self, 'max')) {
    for (var walker = priv(self, 'lruList').tail;
         priv(self, 'length') > priv(self, 'max') && walker !== null;) {
      // We know that we're about to delete this one, and also
      // what the next least recently used key will be, so just
      // go ahead and set it now.
      var prev = walker.prev
      del(self, walker)
      walker = prev
    }
  }
}

function del (self, node) {
  if (node) {
    var hit = node.value
    if (priv(self, 'dispose')) {
      priv(self, 'dispose').call(this, hit.key, hit.value)
    }
    priv(self, 'length', priv(self, 'length') - hit.length)
    priv(self, 'cache').delete(hit.key)
    priv(self, 'lruList').removeNode(node)
  }
}

// classy, since V8 prefers predictable objects.
function Entry (key, value, length, now, maxAge) {
  this.key = key
  this.value = value
  this.length = length
  this.now = now
  this.maxAge = maxAge || 0
}
<commit_msg>ignore test coverage around Symbol capability test<commit_after>module.exports = LRUCache

// This will be a proper iterable 'Map' in engines that support it,
// or a fakey-fake PseudoMap in older versions.
var Map = require('pseudomap')
var util = require('util')

// A linked list to keep track of recently-used-ness
var Yallist = require('yallist')

// use symbols if possible, otherwise just _props
var symbols = {}
var hasSymbol = typeof Symbol === 'function'
var makeSymbol
/* istanbul ignore if */
if (hasSymbol) {
  makeSymbol = function (key) {
    return Symbol.for(key)
  }
} else {
  makeSymbol = function (key) {
    return '_' + key
  }
}

function priv (obj, key, val) {
  var sym
  if (symbols[key]) {
    sym = symbols[key]
  } else {
    sym = makeSymbol(key)
    symbols[key] = sym
  }
  if (arguments.length === 2) {
    return obj[sym]
  } else {
    obj[sym] = val
    return val
  }
}

function naiveLength () { return 1 }

// lruList is a yallist where the head is the youngest
// item, and the tail is the oldest.  the list contains the Hit
// objects as the entries.
// Each Hit object has a reference to its Yallist.Node.  This
// never changes.
//
// cache is a Map (or PseudoMap) that matches the keys to
// the Yallist.Node object.
function LRUCache (options) {
  if (!(this instanceof LRUCache)) {
    return new LRUCache(options)
  }

  if (typeof options === 'number') {
    options = { max: options }
  }

  if (!options) {
    options = {}
  }

  var max = priv(this, 'max', options.max)
  // Kind of weird to have a default max of Infinity, but oh well.
  if (!max ||
      !(typeof max === 'number') ||
      max <= 0) {
    priv(this, 'max', Infinity)
  }

  var lc = options.length || naiveLength
  if (typeof lc !== 'function') {
    lc = naiveLength
  }
  priv(this, 'lengthCalculator', lc)

  priv(this, 'allowStale', options.stale || false)
  priv(this, 'maxAge', options.maxAge || 0)
  priv(this, 'dispose', options.dispose)
  this.reset()
}

// resize the cache when the max changes.
Object.defineProperty(LRUCache.prototype, 'max', {
  set: function (mL) {
    if (!mL || !(typeof mL === 'number') || mL <= 0) {
      mL = Infinity
    }
    priv(this, 'max', mL)
    trim(this)
  },
  get: function () {
    return priv(this, 'max')
  },
  enumerable: true
})

Object.defineProperty(LRUCache.prototype, 'allowStale', {
  set: function (allowStale) {
    priv(this, 'allowStale', !!allowStale)
  },
  get: function () {
    return priv(this, 'allowStale')
  },
  enumerable: true
})

Object.defineProperty(LRUCache.prototype, 'maxAge', {
  set: function (mA) {
    if (!mA || !(typeof mA === 'number') || mA < 0) {
      mA = 0
    }
    priv(this, 'maxAge', mA)
    trim(this)
  },
  get: function () {
    return priv(this, 'maxAge')
  },
  enumerable: true
})

// resize the cache when the lengthCalculator changes.
Object.defineProperty(LRUCache.prototype, 'lengthCalculator', {
  set: function (lC) {
    if (typeof lC !== 'function') {
      lC = naiveLength
    }
    if (lC !== priv(this, 'lengthCalculator')) {
      priv(this, 'lengthCalculator', lC)
      priv(this, 'length', 0)
      priv(this, 'lruList').forEach(function (hit) {
        hit.length = priv(this, 'lengthCalculator').call(this, hit.value, hit.key)
        priv(this, 'length', priv(this, 'length') + hit.length)
      }, this)
    }
    trim(this)
  },
  get: function () { return priv(this, 'lengthCalculator') },
  enumerable: true
})

Object.defineProperty(LRUCache.prototype, 'length', {
  get: function () { return priv(this, 'length') },
  enumerable: true
})

Object.defineProperty(LRUCache.prototype, 'itemCount', {
  get: function () { return priv(this, 'lruList').length },
  enumerable: true
})

LRUCache.prototype.rforEach = function (fn, thisp) {
  thisp = thisp || this
  for (var walker = priv(this, 'lruList').tail; walker !== null;) {
    var prev = walker.prev
    forEachStep(this, fn, walker, thisp)
    walker = prev
  }
}

function forEachStep (self, fn, node, thisp) {
  var hit = node.value
  if (isStale(self, hit)) {
    del(self, node)
    if (!priv(self, 'allowStale')) {
      hit = undefined
    }
  }
  if (hit) {
    fn.call(thisp, hit.value, hit.key, self)
  }
}

LRUCache.prototype.forEach = function (fn, thisp) {
  thisp = thisp || this
  for (var walker = priv(this, 'lruList').head; walker !== null;) {
    var next = walker.next
    forEachStep(this, fn, walker, thisp)
    walker = next
  }
}

LRUCache.prototype.keys = function () {
  return priv(this, 'lruList').toArray().map(function (k) {
    return k.key
  }, this)
}

LRUCache.prototype.values = function () {
  return priv(this, 'lruList').toArray().map(function (k) {
    return k.value
  }, this)
}

LRUCache.prototype.reset = function () {
  if (priv(this, 'dispose') &&
      priv(this, 'lruList') &&
      priv(this, 'lruList').length) {
    priv(this, 'lruList').forEach(function (hit) {
      priv(this, 'dispose').call(this, hit.key, hit.value)
    }, this)
  }

  priv(this, 'cache', new Map()) // hash of items by key
  priv(this, 'lruList', new Yallist()) // list of items in order of use recency
  priv(this, 'length', 0) // length of items in the list
}

LRUCache.prototype.dump = function () {
  return priv(this, 'lruList').map(function (hit) {
    if (!isStale(this, hit)) {
      return {
        k: hit.key,
        v: hit.value,
        e: hit.now + (hit.maxAge || 0)
      }
    }
  }, this).toArray().filter(function (h) {
    return h
  })
}

LRUCache.prototype.dumpLru = function () {
  return priv(this, 'lruList')
}

LRUCache.prototype.inspect = function (n, opts) {
  var str = 'LRUCache {'
  var extras = false

  var as = priv(this, 'allowStale')
  if (as) {
    str += '\n  allowStale: true'
    extras = true
  }

  var max = priv(this, 'max')
  if (max && max !== Infinity) {
    if (extras) {
      str += ','
    }
    str += '\n  max: ' + util.inspect(max, opts)
    extras = true
  }

  var maxAge = priv(this, 'maxAge')
  if (maxAge) {
    if (extras) {
      str += ','
    }
    str += '\n  maxAge: ' + util.inspect(maxAge, opts)
    extras = true
  }

  var lc = priv(this, 'lengthCalculator')
  if (lc && lc !== naiveLength) {
    if (extras) {
      str += ','
    }
    str += '\n  length: ' + util.inspect(priv(this, 'length'), opts)
    extras = true
  }

  var didFirst = false
  priv(this, 'lruList').forEach(function (item) {
    if (didFirst) {
      str += ',\n  '
    } else {
      if (extras) {
        str += ',\n'
      }
      didFirst = true
      str += '\n  '
    }
    var key = util.inspect(item.key).split('\n').join('\n  ')
    var val = { value: item.value }
    if (item.maxAge !== maxAge) {
      val.maxAge = item.maxAge
    }
    if (lc !== naiveLength) {
      val.length = item.length
    }
    if (isStale(this, item)) {
      val.stale = true
    }

    val = util.inspect(val, opts).split('\n').join('\n  ')
    str += key + ' => ' + val
  })

  if (didFirst || extras) {
    str += '\n'
  }
  str += '}'

  return str
}

LRUCache.prototype.set = function (key, value, maxAge) {
  maxAge = maxAge || priv(this, 'maxAge')

  var now = maxAge ? Date.now() : 0
  var len = priv(this, 'lengthCalculator').call(this, value, key)

  if (priv(this, 'cache').has(key)) {
    if (len > priv(this, 'max')) {
      del(this, priv(this, 'cache').get(key))
      return false
    }

    var node = priv(this, 'cache').get(key)
    var item = node.value

    // dispose of the old one before overwriting
    if (priv(this, 'dispose')) {
      priv(this, 'dispose').call(this, key, item.value)
    }

    item.now = now
    item.maxAge = maxAge
    item.value = value
    priv(this, 'length', priv(this, 'length') + (len - item.length))
    item.length = len
    this.get(key)
    trim(this)
    return true
  }

  var hit = new Entry(key, value, len, now, maxAge)

  // oversized objects fall out of cache automatically.
  if (hit.length > priv(this, 'max')) {
    if (priv(this, 'dispose')) {
      priv(this, 'dispose').call(this, key, value)
    }
    return false
  }

  priv(this, 'length', priv(this, 'length') + hit.length)
  priv(this, 'lruList').unshift(hit)
  priv(this, 'cache').set(key, priv(this, 'lruList').head)
  trim(this)
  return true
}

LRUCache.prototype.has = function (key) {
  if (!priv(this, 'cache').has(key)) return false
  var hit = priv(this, 'cache').get(key).value
  if (isStale(this, hit)) {
    return false
  }
  return true
}

LRUCache.prototype.get = function (key) {
  return get(this, key, true)
}

LRUCache.prototype.peek = function (key) {
  return get(this, key, false)
}

LRUCache.prototype.pop = function () {
  var node = priv(this, 'lruList').tail
  if (!node) return null
  del(this, node)
  return node.value
}

LRUCache.prototype.del = function (key) {
  del(this, priv(this, 'cache').get(key))
}

LRUCache.prototype.load = function (arr) {
  // reset the cache
  this.reset()

  var now = Date.now()
  // A previous serialized cache has the most recent items first
  for (var l = arr.length - 1; l >= 0; l--) {
    var hit = arr[l]
    var expiresAt = hit.e || 0
    if (expiresAt === 0) {
      // the item was created without expiration in a non aged cache
      this.set(hit.k, hit.v)
    } else {
      var maxAge = expiresAt - now
      // dont add already expired items
      if (maxAge > 0) {
        this.set(hit.k, hit.v, maxAge)
      }
    }
  }
}

LRUCache.prototype.prune = function () {
  var self = this
  priv(this, 'cache').forEach(function (value, key) {
    get(self, key, false)
  })
}

function get (self, key, doUse) {
  var node = priv(self, 'cache').get(key)
  if (node) {
    var hit = node.value
    if (isStale(self, hit)) {
      del(self, node)
      if (!priv(self, 'allowStale')) hit = undefined
    } else {
      if (doUse) {
        priv(self, 'lruList').unshiftNode(node)
      }
    }
    if (hit) hit = hit.value
  }
  return hit
}

function isStale (self, hit) {
  if (!hit || (!hit.maxAge && !priv(self, 'maxAge'))) {
    return false
  }
  var stale = false
  var diff = Date.now() - hit.now
  if (hit.maxAge) {
    stale = diff > hit.maxAge
  } else {
    stale = priv(self, 'maxAge') && (diff > priv(self, 'maxAge'))
  }
  return stale
}

function trim (self) {
  if (priv(self, 'length') > priv(self, 'max')) {
    for (var walker = priv(self, 'lruList').tail;
         priv(self, 'length') > priv(self, 'max') && walker !== null;) {
      // We know that we're about to delete this one, and also
      // what the next least recently used key will be, so just
      // go ahead and set it now.
      var prev = walker.prev
      del(self, walker)
      walker = prev
    }
  }
}

function del (self, node) {
  if (node) {
    var hit = node.value
    if (priv(self, 'dispose')) {
      priv(self, 'dispose').call(this, hit.key, hit.value)
    }
    priv(self, 'length', priv(self, 'length') - hit.length)
    priv(self, 'cache').delete(hit.key)
    priv(self, 'lruList').removeNode(node)
  }
}

// classy, since V8 prefers predictable objects.
function Entry (key, value, length, now, maxAge) {
  this.key = key
  this.value = value
  this.length = length
  this.now = now
  this.maxAge = maxAge || 0
}
<|endoftext|>


<commit_before>Package.describe({
  summary: "Expressive, dynamic, robust CSS",
  name: "mquandalle:stylus",
  version: "1.0.5",
  git: "https://github.com/mquandalle/meteor-stylus.git"
});

Package._transitional_registerBuildPlugin({
  name: "compileStylus",
  use: [],
  sources: [
    'plugin/compile-stylus.js'
  ],
  npmDependencies: {
    stylus: "0.48.1",
    nib: "1.0.3",
    jeet: "5.3.0",
    rupture: "0.4.0"
  }
});

Package.on_test(function (api) {
  api.use(['tinytest', 'mquandalle:stylus', 'test-helpers']);
  api.add_files([
    'tests/presence.styl',
    'tests/importer.styl',
    'tests/relative.import.styl',
    'tests/absolute.import.styl',
    'tests/nib_.styl',
    'tests/jeet_.styl',
    'tests/rupture_.styl',
    'tests/tinytest.js'
  ],'client');
});
<commit_msg>Bump version to 1.0.6<commit_after>Package.describe({
  summary: "Expressive, dynamic, robust CSS",
  name: "mquandalle:stylus",
  version: "1.0.6",
  git: "https://github.com/mquandalle/meteor-stylus.git"
});

Package._transitional_registerBuildPlugin({
  name: "compileStylus",
  use: [],
  sources: [
    'plugin/compile-stylus.js'
  ],
  npmDependencies: {
    stylus: "0.48.1",
    nib: "1.0.3",
    jeet: "5.3.0",
    rupture: "0.4.0"
  }
});

Package.on_test(function (api) {
  api.use(['tinytest', 'mquandalle:stylus', 'test-helpers']);
  api.add_files([
    'tests/presence.styl',
    'tests/importer.styl',
    'tests/relative.import.styl',
    'tests/absolute.import.styl',
    'tests/nib_.styl',
    'tests/jeet_.styl',
    'tests/rupture_.styl',
    'tests/tinytest.js'
  ],'client');
});
<|endoftext|>


<commit_before>Package.describe({
    summary: "Translations for the meteor account's error messages.",
    version: "0.0.20",
    name: "softwarerero:accounts-t9n",
    git: "https://github.com/softwarerero/meteor-accounts-t9n.git",
});

Package.on_use(function (api, where) {
    if (api.versionsFrom)
        api.versionsFrom("METEOR@0.9.0");

    api.add_files([
        't9n.coffee',
        't9n/ar.coffee',
        't9n/zh-cn.coffee',
        't9n/cs.coffee',
        't9n/da.coffee',
        't9n/de.coffee',
        't9n/en.coffee',
        't9n/es.coffee',
        't9n/es_ES.coffee',
        't9n/fr.coffee',
        't9n/he.coffee',
        't9n/it.coffee',
        't9n/pl.coffee',
        't9n/pt.coffee',
        't9n/ru.coffee',
        't9n/sl.coffee',
        't9n/sv.coffee',
        't9n/uk.coffee',
        't9n/vi.coffee',
        't9n/no_NO.coffee',
    ], ['client', 'server']);

    api.use(['coffeescript', 'deps'], ['client', 'server']);
    api.export('T9n', ['client', 'server']);
});

Package.on_test(function (api) {
    api.add_files([
        't9n.coffee',
        't9n/ar.coffee',
        't9n/zh-cn.coffee',
        't9n/cs.coffee',
        't9n/da.coffee',
        't9n/de.coffee',
        't9n/en.coffee',
        't9n/es.coffee',
        't9n/es_ES.coffee',
        't9n/fr.coffee',
        't9n/he.coffee',
        't9n/it.coffee',
        't9n/pl.coffee',
        't9n/pt.coffee',
        't9n/ru.coffee',
        't9n/sl.coffee',
        't9n/sv.coffee',
        't9n/uk.coffee',
        't9n/no_NO.coffee',
    ], ['client', 'server']);

    api.use(['coffeescript', 'deps'], ['client', 'server']);
});
<commit_msg>fixed erroneous removal of add_files line<commit_after>Package.describe({
    summary: "Translations for the meteor account's error messages.",
    version: "0.0.20",
    name: "softwarerero:accounts-t9n",
    git: "https://github.com/softwarerero/meteor-accounts-t9n.git",
});

Package.on_use(function (api, where) {
    if (api.versionsFrom)
        api.versionsFrom("METEOR@0.9.0");

    api.add_files([
        't9n.coffee',
        't9n/ar.coffee',
        't9n/zh-cn.coffee',
        't9n/cs.coffee',
        't9n/da.coffee',
        't9n/de.coffee',
        't9n/en.coffee',
        't9n/es.coffee',
        't9n/es_ES.coffee',
        't9n/fr.coffee',
        't9n/he.coffee',
        't9n/it.coffee',
        't9n/pl.coffee',
        't9n/pt.coffee',
        't9n/ru.coffee',
        't9n/sl.coffee',
        't9n/sv.coffee',
        't9n/uk.coffee',
        't9n/vi.coffee',
        't9n/no_NO.coffee',
    ], ['client', 'server']);

    api.use(['coffeescript', 'deps'], ['client', 'server']);
    api.export('T9n', ['client', 'server']);
});

Package.on_test(function (api) {
    api.add_files([
        't9n.coffee',
        't9n/ar.coffee',
        't9n/zh-cn.coffee',
        't9n/cs.coffee',
        't9n/da.coffee',
        't9n/de.coffee',
        't9n/en.coffee',
        't9n/es.coffee',
        't9n/es_ES.coffee',
        't9n/fr.coffee',
        't9n/he.coffee',
        't9n/it.coffee',
        't9n/pl.coffee',
        't9n/pt.coffee',
        't9n/ru.coffee',
        't9n/sl.coffee',
        't9n/sv.coffee',
        't9n/uk.coffee',
        't9n/vi.coffee',
        't9n/no_NO.coffee',
    ], ['client', 'server']);

    api.use(['coffeescript', 'deps'], ['client', 'server']);
});
<|endoftext|>


<commit_before>/* maniUtils
 * This Object holds all functions to parse manifests to HTML
 */

var fs = Npm.require('fs')
var path = Npm.require('path')

// This holds all variables that will be exported from this file
// It's just an experiment to make the meteor scoping system inside packages hurt less...
var maniUtils = {}

maniUtils.getIncludes = function getIncludes (manifest) {
  var filteredIncludes = maniUtils.filterIncludes(manifest)
  filteredIncludes['js'] = filteredIncludes['js'].concat(maniUtils.parseStaticJS(WebAppInternals.additionalStaticJs))
  return filteredIncludes
}

/* maniUtils.filterIncludes(manifest)
 * `manifest` - the manifest to loop through
 * loops through a manifest and calls the `maniUtils.transform` function named the same as the items `type`
 */
maniUtils.filterIncludes = function filterIncludes (manifest) {
  var returnObj = {
    js: [],
    css: [],
    head: [],
    body: []
  }
  _.each(manifest, function (include) {
    var type = include.type
    if(maniUtils.transform[type])
      returnObj[type].push(maniUtils.transform[type](include))
  })
  return returnObj
}

maniUtils.transform = {}

/* maniUtils.transform.js(include)
 * `include` an object structured like a manifest item
 * returns a URL a script
 */
maniUtils.transform.js = function transformJs (include) {
  return include.where === 'client' ? include.path : false
}

/* maniUtils.transform.css(include)
 * `include` an object structured like a manifest item
 * returns the url to a css file
 */
maniUtils.transform.css = function transformCss (include) {
  return include.url
}

/* maniUtils.transform.head(include)
 * `include` an object structured like a manifest item
 * returns a piece of HTML that should be included in the `head`
 */
maniUtils.transform.head = function transformHead (include) {
  return maniUtils.getResource(include.path)
}

/* maniUtils.transform.body(include)
 * `include` an object structured like a manifest item
 * returns a piece of HTML that should be included in the `body`
 */
maniUtils.transform.body = function transformHead (include) {
  return maniUtils.getResource(include.path)
}

maniUtils.parseStaticJS = function parseStaticJS (staticJsObj) {
  var returnArr = []
  _.each(staticJsObj, function (js, key) {
    returnArr.push({
      type: 'js',
      url: key
    })
  })
  return returnArr
}

/* maniUtils.getResource(path)
 * `path` - A path to the resource relative to the resources directory
 * returns the file as a string
 */
 maniUtils.getResource = function getResource (path) {
  return fs.readFileSync(maniUtils.pathMapper(path), {encoding: 'utf8'})
 }

/* maniUtils.pathMapper(path)
 * `path` - A path to the resource relative to the resources directory
 * Returns a path relative to $PWD
 * Taken from the WebApp package
 * https://github.com/meteor/meteor/blob/devel/packages/webapp/webapp_server.js#L287
 */
maniUtils.pathMapper = function pathMapper (itemPath) {
  return path.join(maniUtils.getResourcesPath(), itemPath)
}

/* maniUtils.getResourcesPath()
 * Returns a Path to the resources
 * This is sort of a necessary evil
 * It's super ugly, but meteor doesn't provide me with anything better
 * https://github.com/meteor/meteor/blob/devel/packages/webapp/webapp_server.js#L509
 */
maniUtils.getResourcesPath = (function getResourcesPath () {
  var cachedResourcesPath
  return function getResourcesPathGetter () {
    return cachedResourcesPath || (
      cachedResourcesPath = path.dirname(__meteor_bootstrap__.configJson.clientPaths[CURRENT_ARCH])
    )
  }
})()

/* maniUtils.getScripts(jsPaths)
 * `jsPaths` - A ressource path to a script
 * returns all scripts inside the array concatenated in a string
 */
maniUtils.getScripts = function getScripts (jsPaths) {
  return _.map(jsPaths, maniUtils.getResource).join('\n')
}

_altboilerScope = _altboilerScope || {}
_altboilerScope.maniUtils = maniUtils<commit_msg>Fix the maniUtils.transforms to handle CSS<commit_after>/* maniUtils
 * This Object holds all functions to parse manifests to HTML
 */

var fs = Npm.require('fs')
var path = Npm.require('path')

// This holds all variables that will be exported from this file
// It's just an experiment to make the meteor scoping system inside packages hurt less...
var maniUtils = {}

maniUtils.getIncludes = function getIncludes (manifest) {
  var filteredIncludes = maniUtils.filterIncludes(manifest)
  filteredIncludes['js'] = filteredIncludes['js'].concat(maniUtils.parseStaticJS(WebAppInternals.additionalStaticJs))
  return filteredIncludes
}

/* maniUtils.filterIncludes(manifest)
 * `manifest` - the manifest to loop through
 * loops through a manifest and calls the `maniUtils.transform` function named the same as the items `type`
 */
maniUtils.filterIncludes = function filterIncludes (manifest) {
  var returnObj = {
    js: [],
    css: [],
    head: [],
    body: []
  }
  _.each(manifest, function (include) {
    var type = include.type
    if(maniUtils.transform[type])
      maniUtils.transform[type](include, returnObj)
  })
  return returnObj
}

maniUtils.transform = {}

/* maniUtils.transform.js(include)
 * `include` an object structured like a manifest item
 * returns a URL a script
 */
maniUtils.transform.js = function transformJs (include, includesObject) {
  includesObject['js'].push(include.where === 'client' ? include.path : false)
}

/* maniUtils.transform.css(include, includesObject)
 * `include` - an object structured like a manifest item
 * `includesObject` - The returnObj to modifiy
 * returns the url to a css file
 */
maniUtils.transform.css = function transformCss (include, includesObject) {
  includesObject['head'].push(['<link type="text/css" rel="stylesheet" href="', '">'].join(include.url))
}

/* maniUtils.transform.head(include, includesObject)
 * `include` - an object structured like a manifest item
 * `includesObject` - The returnObj to modifiy
 * returns a piece of HTML that should be included in the `head`
 */
maniUtils.transform.head = function transformHead (include, includesObject) {
  includesObject['head'].push(maniUtils.getResource(include.path))
}

/* maniUtils.transform.body(include, includesObject)
 * `include` - an object structured like a manifest item
 * `includesObject` - The returnObj to modifiy
 * returns a piece of HTML that should be included in the `body`
 */
maniUtils.transform.body = function transformBody (include, includesObject) {
  includesObject['body'].push(maniUtils.getResource(include.path))
}

maniUtils.parseStaticJS = function parseStaticJS (staticJsObj) {
  var returnArr = []
  _.each(staticJsObj, function (js, key) {
    returnArr.push({
      type: 'js',
      url: key
    })
  })
  return returnArr
}

/* maniUtils.getResource(path)
 * `path` - A path to the resource relative to the resources directory
 * returns the file as a string
 */
 maniUtils.getResource = function getResource (path) {
  return fs.readFileSync(maniUtils.pathMapper(path), {encoding: 'utf8'})
 }

/* maniUtils.pathMapper(path)
 * `path` - A path to the resource relative to the resources directory
 * Returns a path relative to $PWD
 * Taken from the WebApp package
 * https://github.com/meteor/meteor/blob/devel/packages/webapp/webapp_server.js#L287
 */
maniUtils.pathMapper = function pathMapper (itemPath) {
  return path.join(maniUtils.getResourcesPath(), itemPath)
}

/* maniUtils.getResourcesPath()
 * Returns a Path to the resources
 * This is sort of a necessary evil
 * It's super ugly, but meteor doesn't provide me with anything better
 * https://github.com/meteor/meteor/blob/devel/packages/webapp/webapp_server.js#L509
 */
maniUtils.getResourcesPath = (function getResourcesPath () {
  var cachedResourcesPath
  return function getResourcesPathGetter () {
    return cachedResourcesPath || (
      cachedResourcesPath = path.dirname(__meteor_bootstrap__.configJson.clientPaths[CURRENT_ARCH])
    )
  }
})()

/* maniUtils.getScripts(jsPaths)
 * `jsPaths` - A ressource path to a script
 * returns all scripts inside the array concatenated in a string
 */
maniUtils.getScripts = function getScripts (jsPaths) {
  return _.map(jsPaths, maniUtils.getResource).join('\n')
}

_altboilerScope = _altboilerScope || {}
_altboilerScope.maniUtils = maniUtils<|endoftext|>


<commit_before>Package.describe({
  "summary": "Performance Monitoring for Meteor",
  "version": "2.28.6",
  "git": "https://github.com/meteorhacks/kadira.git",
  "name": "meteorhacks:kadira"
});

var npmModules = {
  "debug": "0.7.4",
  "kadira-core": "1.3.1",
  "pidusage": "1.0.1",
  "evloop-monitor": "0.1.0",
  "pidusage": "0.1.1",
  "lru-cache": "4.0.0"
};

Npm.depends(npmModules);

Package.on_use(function(api) {
  configurePackage(api);
  api.export(['Kadira']);
});

Package.on_test(function(api) {
  configurePackage(api);
  api.use([
    'tinytest',
    'test-helpers'
  ], ['client', 'server']);

  // common before
  api.add_files([
    'tests/models/base_error.js'
  ], ['client', 'server']);

  // common server
  api.add_files([
    'tests/utils.js',
    'tests/ntp.js',
    'tests/jobs.js',
    'tests/_helpers/globals.js',
    'tests/_helpers/helpers.js',
    'tests/_helpers/init.js',
    'tests/ping.js',
    'tests/hijack/info.js',
    'tests/hijack/user.js',
    'tests/hijack/email.js',
    'tests/hijack/base.js',
    'tests/hijack/async.js',
    'tests/hijack/http.js',
    'tests/hijack/db.js',
    'tests/hijack/subscriptions.js',
    'tests/hijack/error.js',
    'tests/models/methods.js',
    'tests/models/pubsub.js',
    'tests/models/system.js',
    'tests/models/errors.js',
    'tests/tracer/tracer_store.js',
    'tests/tracer/tracer.js',
    'tests/tracer/default_filters.js',
    'tests/check_for_oplog.js',
    'tests/error_tracking.js',
    'tests/wait_time_builder.js',
    'tests/hijack/set_labels.js',
    'tests/environment_variables.js',
    'tests/docsize_cache.js',
  ], 'server');

  // common client
  api.add_files([
    'tests/client/utils.js',
    'tests/client/error_tracking.js',
    'tests/client/models/error.js',
    'tests/client/error_reporters/window_error.js',
    'tests/client/error_reporters/zone.js',
    'tests/client/error_reporters/meteor_debug.js',
  ], 'client');

  // common after
  api.add_files([
    'tests/common/default_error_filters.js',
    'tests/common/send.js'
  ], ['client', 'server']);
});

function configurePackage(api) {
  if(api.versionsFrom) {
    api.versionsFrom('METEOR@1.2');
    api.use('meteorhacks:meteorx@1.4.1', ['server']);
    api.use('meteorhacks:zones@1.2.1', {weak: true});
  }

  api.use([
    'minimongo', 'livedata', 'mongo-livedata', 'ejson', 'ddp-common',
    'underscore', 'http', 'email', 'random'
  ], ['server']);
  api.use(['underscore', 'random', 'jquery', 'localstorage'], ['client']);

  // common before
  api.add_files([
    'lib/common/unify.js',
    'lib/models/base_error.js'
  ], ['client', 'server']);

  // only server
  api.add_files([
    'lib/jobs.js',
    'lib/retry.js',
    'lib/utils.js',
    'lib/ntp.js',
    'lib/wait_time_builder.js',
    'lib/check_for_oplog.js',
    'lib/tracer/tracer.js',
    'lib/tracer/default_filters.js',
    'lib/tracer/tracer_store.js',
    'lib/models/0model.js',
    'lib/models/methods.js',
    'lib/models/pubsub.js',
    'lib/models/system.js',
    'lib/models/errors.js',
    'lib/docsize_cache.js',
    'lib/kadira.js',
    'lib/hijack/wrap_server.js',
    'lib/hijack/wrap_session.js',
    'lib/hijack/wrap_subscription.js',
    'lib/hijack/wrap_observers.js',
    'lib/hijack/wrap_ddp_stringify.js',
    'lib/hijack/instrument.js',
    'lib/hijack/db.js',
    'lib/hijack/http.js',
    'lib/hijack/email.js',
    'lib/hijack/async.js',
    'lib/hijack/error.js',
    'lib/hijack/set_labels.js',
    'lib/environment_variables.js',
    'lib/auto_connect.js',
  ], 'server');

  // only client
  api.add_files([
    'lib/retry.js',
    'lib/ntp.js',
    'lib/client/utils.js',
    'lib/client/models/error.js',
    'lib/client/error_reporters/zone.js',
    'lib/client/error_reporters/window_error.js',
    'lib/client/error_reporters/meteor_debug.js',
    'lib/client/kadira.js'
  ], 'client');

  api.add_files([
    // It's possible to remove this file after some since this just contains
    // a notice to the user.
    // Actual implementation is in the meteorhacks:kadira-profiler package
    'lib/profiler/client.js',
  ], 'client');

  // common after
  api.add_files([
    'lib/common/default_error_filters.js',
    'lib/common/send.js'
  ], ['client', 'server']);
}
<commit_msg>Update kadira-core to 1.3.2.<commit_after>Package.describe({
  "summary": "Performance Monitoring for Meteor",
  "version": "2.28.6",
  "git": "https://github.com/meteorhacks/kadira.git",
  "name": "meteorhacks:kadira"
});

var npmModules = {
  "debug": "0.7.4",
  "kadira-core": "1.3.2",
  "pidusage": "1.0.1",
  "evloop-monitor": "0.1.0",
  "pidusage": "0.1.1",
  "lru-cache": "4.0.0"
};

Npm.depends(npmModules);

Package.on_use(function(api) {
  configurePackage(api);
  api.export(['Kadira']);
});

Package.on_test(function(api) {
  configurePackage(api);
  api.use([
    'tinytest',
    'test-helpers'
  ], ['client', 'server']);

  // common before
  api.add_files([
    'tests/models/base_error.js'
  ], ['client', 'server']);

  // common server
  api.add_files([
    'tests/utils.js',
    'tests/ntp.js',
    'tests/jobs.js',
    'tests/_helpers/globals.js',
    'tests/_helpers/helpers.js',
    'tests/_helpers/init.js',
    'tests/ping.js',
    'tests/hijack/info.js',
    'tests/hijack/user.js',
    'tests/hijack/email.js',
    'tests/hijack/base.js',
    'tests/hijack/async.js',
    'tests/hijack/http.js',
    'tests/hijack/db.js',
    'tests/hijack/subscriptions.js',
    'tests/hijack/error.js',
    'tests/models/methods.js',
    'tests/models/pubsub.js',
    'tests/models/system.js',
    'tests/models/errors.js',
    'tests/tracer/tracer_store.js',
    'tests/tracer/tracer.js',
    'tests/tracer/default_filters.js',
    'tests/check_for_oplog.js',
    'tests/error_tracking.js',
    'tests/wait_time_builder.js',
    'tests/hijack/set_labels.js',
    'tests/environment_variables.js',
    'tests/docsize_cache.js',
  ], 'server');

  // common client
  api.add_files([
    'tests/client/utils.js',
    'tests/client/error_tracking.js',
    'tests/client/models/error.js',
    'tests/client/error_reporters/window_error.js',
    'tests/client/error_reporters/zone.js',
    'tests/client/error_reporters/meteor_debug.js',
  ], 'client');

  // common after
  api.add_files([
    'tests/common/default_error_filters.js',
    'tests/common/send.js'
  ], ['client', 'server']);
});

function configurePackage(api) {
  if(api.versionsFrom) {
    api.versionsFrom('METEOR@1.2');
    api.use('meteorhacks:meteorx@1.4.1', ['server']);
    api.use('meteorhacks:zones@1.2.1', {weak: true});
  }

  api.use([
    'minimongo', 'livedata', 'mongo-livedata', 'ejson', 'ddp-common',
    'underscore', 'http', 'email', 'random'
  ], ['server']);
  api.use(['underscore', 'random', 'jquery', 'localstorage'], ['client']);

  // common before
  api.add_files([
    'lib/common/unify.js',
    'lib/models/base_error.js'
  ], ['client', 'server']);

  // only server
  api.add_files([
    'lib/jobs.js',
    'lib/retry.js',
    'lib/utils.js',
    'lib/ntp.js',
    'lib/wait_time_builder.js',
    'lib/check_for_oplog.js',
    'lib/tracer/tracer.js',
    'lib/tracer/default_filters.js',
    'lib/tracer/tracer_store.js',
    'lib/models/0model.js',
    'lib/models/methods.js',
    'lib/models/pubsub.js',
    'lib/models/system.js',
    'lib/models/errors.js',
    'lib/docsize_cache.js',
    'lib/kadira.js',
    'lib/hijack/wrap_server.js',
    'lib/hijack/wrap_session.js',
    'lib/hijack/wrap_subscription.js',
    'lib/hijack/wrap_observers.js',
    'lib/hijack/wrap_ddp_stringify.js',
    'lib/hijack/instrument.js',
    'lib/hijack/db.js',
    'lib/hijack/http.js',
    'lib/hijack/email.js',
    'lib/hijack/async.js',
    'lib/hijack/error.js',
    'lib/hijack/set_labels.js',
    'lib/environment_variables.js',
    'lib/auto_connect.js',
  ], 'server');

  // only client
  api.add_files([
    'lib/retry.js',
    'lib/ntp.js',
    'lib/client/utils.js',
    'lib/client/models/error.js',
    'lib/client/error_reporters/zone.js',
    'lib/client/error_reporters/window_error.js',
    'lib/client/error_reporters/meteor_debug.js',
    'lib/client/kadira.js'
  ], 'client');

  api.add_files([
    // It's possible to remove this file after some since this just contains
    // a notice to the user.
    // Actual implementation is in the meteorhacks:kadira-profiler package
    'lib/profiler/client.js',
  ], 'client');

  // common after
  api.add_files([
    'lib/common/default_error_filters.js',
    'lib/common/send.js'
  ], ['client', 'server']);
}
<|endoftext|>


<commit_before>Package.describe({
  name: "chroma:autoform-file",
  summary: "File upload for AutoForm",
  description: "File upload for AutoForm",
  version: "0.2.8",
  git: "http://github.com/yogiben/autoform-file.git"
});

Package.onUse(function(api) {
  api.versionsFrom('METEOR@1.0');

  api.use([
    'coffeescript',
    'underscore',
    'reactive-var',
    'templating',
    'mquandalle:jade',
    'less@2.0.0',
    'aldeed:autoform@5.3.2',
    'fortawesome:fontawesome@4.3.0'
  ]);

  api.addFiles('lib/client/autoform-file.jade', 'client');
  api.addFiles('lib/client/autoform-file.less', 'client');
  api.addFiles('lib/client/autoform-file.coffee', 'client');
  api.addFiles('lib/server/publish.coffee', 'server');
});
<commit_msg>update autoform<commit_after>Package.describe({
  name: "chroma:autoform-file",
  summary: "File upload for AutoForm",
  description: "File upload for AutoForm",
  version: "0.2.8",
  git: "http://github.com/yogiben/autoform-file.git"
});

Package.onUse(function(api) {
  api.versionsFrom('METEOR@1.0');

  api.use([
    'coffeescript',
    'underscore',
    'reactive-var',
    'templating',
    'mquandalle:jade',
    'less@2.0.0',
    'aldeed:autoform@5.7.1',
    'fortawesome:fontawesome@4.3.0'
  ]);

  api.addFiles('lib/client/autoform-file.jade', 'client');
  api.addFiles('lib/client/autoform-file.less', 'client');
  api.addFiles('lib/client/autoform-file.coffee', 'client');
  api.addFiles('lib/server/publish.coffee', 'server');
});
<|endoftext|>


<commit_before>Package.describe({
  git: 'https://github.com/zimme/meteor-collection-behaviours',
  name: 'zimme:collection-behaviours',
  summary: 'Define and attach behaviours for collections',
  version: '0.1.2'
});

Package.onUse(function(api) {
  api.versionsFrom('0.9.1');

  api.use([
    'coffeescript',
    'mongo',
    'underscore'
  ]);

  api.use('matb33:collection-hooks@0.7.6');

  api.use([
    'aldeed:autoform@2.0.0',
    'aldeed:collection2@2.0.0',
    'aldeed:simple-schema@1.0.3'
  ], ['client', 'server'], {weak: true});

  api.addFiles([
    'collection-behaviour.coffee',
    'mongo.coffee'
  ]);

  api.addFiles([
    'behaviours/timestampable.coffee',
    'behaviours/softremovable.coffee'
  ]);

  api.export('CollectionBehaviours');
});
<commit_msg>Version bump<commit_after>Package.describe({
  git: 'https://github.com/zimme/meteor-collection-behaviours',
  name: 'zimme:collection-behaviours',
  summary: 'Define and attach behaviours for collections',
  version: '0.1.3'
});

Package.onUse(function(api) {
  api.versionsFrom('0.9.1');

  api.use([
    'coffeescript',
    'mongo',
    'underscore'
  ]);

  api.use('matb33:collection-hooks@0.7.6');

  api.use([
    'aldeed:autoform@2.0.0',
    'aldeed:collection2@2.0.0',
    'aldeed:simple-schema@1.0.3'
  ], ['client', 'server'], {weak: true});

  api.addFiles([
    'collection-behaviour.coffee',
    'mongo.coffee'
  ]);

  api.addFiles([
    'behaviours/timestampable.coffee',
    'behaviours/softremovable.coffee'
  ]);

  api.export('CollectionBehaviours');
});
<|endoftext|>


<commit_before>Package.describe({
  summary: "Meteor smart package for full authentication pages styled with Bootstrap 3"
});

Package.on_use(function (api, where) {

  // client
  api.use([
    'ui',
    'templating',
    'spacebars',
    'less'
    ], 'client');

  api.add_files([
    'client/views/account_button.html',
    'client/views/account_button.js',
    'client/views/sign_in.html',
    'client/views/sign_in.js',
    'client/views/sign_up.html',
    'client/views/sign_up.js',
    'client/views/forgot_password.html',
    'client/views/forgot_password.js',
    'client/views/reset_password.html',
    'client/views/reset_password.js',
    'client/views/error.html',
    'client/views/error.js',
    'client/views/account_settings.html',
    'client/views/account_settings.js',
    'client/views/user_profile.html',
    'client/views/user_profile.js',
    'client/views/accounts_pages_layout.html'
  ], 'client');

  // server
  api.add_files([
    'server/startup.js'
  ], 'server');

  // client and server
  api.export('AccountsPages', ['client', 'server']);

  api.use([
    'iron-router',
    'autoform',
    'simple-schema',
    'accounts-base',
    'accounts-password',
    'check',
    'moment'
  ], ['client', 'server']);

  api.add_files([
    'lib/startup.js',
    'lib/router.js',
    'lib/schema_user.js'
  ], ['client', 'server']);

});

Package.on_test(function (api) {

});
<commit_msg>Update package definition and used packages to new Meteor packaging system<commit_after>Package.describe({
  summary: "Meteor smart package for full authentication pages styled with Bootstrap 3",
  version: "0.1.0",
  git: "https://github.com/lgollut/meteor-accounts-pages.git"
});

Package.onUse(function (api) {

  api.use('blaze', 'client');
  api.use('templating', 'client');
  api.use('spacebars', 'client');
  api.use('less', 'client');

  api.use('iron:router', ['client', 'server']);
  api.use('aldeed:autoform', ['client', 'server']);
  api.use('aldeed:simple-schema', ['client', 'server']);
  api.use('mrt:moment', ['client', 'server']);
  api.use('accounts-base', ['client', 'server']);
  api.use('accounts-password', ['client', 'server']);
  api.use('check', ['client', 'server']);
  api.use('underscore', ['client', 'server']);

  api.addFiles('client/views/account_button.html', 'client');
  api.addFiles('client/views/account_button.js', 'client');
  api.addFiles('client/views/sign_in.html', 'client');
  api.addFiles('client/views/sign_in.js', 'client');
  api.addFiles('client/views/sign_up.html', 'client');
  api.addFiles('client/views/sign_up.js', 'client');
  api.addFiles('client/views/forgot_password.html', 'client');
  api.addFiles('client/views/forgot_password.js', 'client');
  api.addFiles('client/views/reset_password.html', 'client');
  api.addFiles('client/views/reset_password.js', 'client');
  api.addFiles('client/views/error.html', 'client');
  api.addFiles('client/views/error.js', 'client');

  api.addFiles('lib/startup.js', ['client', 'server']);
  api.addFiles('lib/router.js', ['client', 'server']);
  api.addFiles('schemas/accounts.js', ['client', 'server']);

  api.export('AccountsPages', ['client', 'server']);

});

Package.onTest(function (api) {

});
<|endoftext|>


<commit_before>// Package metadata for Meteor.js web platform (https://www.meteor.com/)
// This file is defined within the Meteor documentation at
//
//   http://docs.meteor.com/#/full/packagejs
//
// and it is needed to define a Meteor package
'use strict';

Package.describe({
  name: 'useraccounts:flow-routing',
  summary: 'UserAccounts package providing routes configuration capability via kadira:flow-router.',
  version: '1.14.3',
  git: 'https://github.com/meteor-useraccounts/flow-routing.git',
});

Package.onUse(function(api) {
  api.versionsFrom('METEOR@1.0.3');

  api.use([
    'check',
    'kadira:flow-router',
    'underscore',
    'useraccounts:core',
    'modules'
  ], ['client', 'server']);

  api.imply([
    'kadira:flow-router@2.10.1',
    'useraccounts:core@1.14.2',
  ], ['client', 'server']);

  api.use([
     'react@0.14.1_1',
     'kadira:blaze-layout@2.3.0',
     'kadira:react-layout@1.5.2',
     'gwendall:blaze-to-react@0.1.2'
  ], ['client', 'server'], { weak: true });

  api.addFiles([
    'lib/core.js',
  ], ['client', 'server']);

  api.addFiles([
    'lib/client/client.js',
    'lib/client/templates_helpers/at_input.js',
  ], ['client']);
});
<commit_msg>Undo version number update<commit_after>// Package metadata for Meteor.js web platform (https://www.meteor.com/)
// This file is defined within the Meteor documentation at
//
//   http://docs.meteor.com/#/full/packagejs
//
// and it is needed to define a Meteor package
'use strict';

Package.describe({
  name: 'useraccounts:flow-routing',
  summary: 'UserAccounts package providing routes configuration capability via kadira:flow-router.',
  version: '1.14.2',
  git: 'https://github.com/meteor-useraccounts/flow-routing.git',
});

Package.onUse(function(api) {
  api.versionsFrom('METEOR@1.0.3');

  api.use([
    'check',
    'kadira:flow-router',
    'underscore',
    'useraccounts:core',
    'modules'
  ], ['client', 'server']);

  api.imply([
    'kadira:flow-router@2.10.1',
    'useraccounts:core@1.14.2',
  ], ['client', 'server']);

  api.use([
     'react@0.14.1_1',
     'kadira:blaze-layout@2.3.0',
     'kadira:react-layout@1.5.2',
     'gwendall:blaze-to-react@0.1.2'
  ], ['client', 'server'], { weak: true });

  api.addFiles([
    'lib/core.js',
  ], ['client', 'server']);

  api.addFiles([
    'lib/client/client.js',
    'lib/client/templates_helpers/at_input.js',
  ], ['client']);
});
<|endoftext|>