Merge branch 'master' into production

This commit is contained in:
Scott Erickson 2014-06-10 13:21:19 -07:00
commit b414886878
14 changed files with 48 additions and 28 deletions

View file

@ -19,8 +19,8 @@ module.exports = class LevelComponent extends CocoModel
@set 'js', @compile(@get 'code') unless @get 'js' @set 'js', @compile(@get 'code') unless @get 'js'
compile: (code) -> compile: (code) ->
if @get('language') and @get('language') isnt 'coffeescript' if @get('codeLanguage') and @get('codeLanguage') isnt 'coffeescript'
return console.error("Can't compile", @get('language'), "-- only CoffeeScript.", @) return console.error("Can't compile", @get('codeLanguage'), "-- only CoffeeScript.", @)
try try
js = CoffeeScript.compile(code, bare: true) js = CoffeeScript.compile(code, bare: true)
catch e catch e

View file

@ -21,8 +21,8 @@ module.exports = class LevelSystem extends CocoModel
SystemNameLoader.setName @ SystemNameLoader.setName @
compile: (code) -> compile: (code) ->
if @get('language') and @get('language') isnt 'coffeescript' if @get('codeLanguage') and @get('codeLanguage') isnt 'coffeescript'
return console.error("Can't compile", @get('language'), "-- only CoffeeScript.", @) return console.error("Can't compile", @get('codeLanguage'), "-- only CoffeeScript.", @)
try try
js = CoffeeScript.compile(code, bare: true) js = CoffeeScript.compile(code, bare: true)
catch e catch e

View file

@ -60,13 +60,13 @@ DependencySchema = c.object {
LevelComponentSchema = c.object { LevelComponentSchema = c.object {
title: "Component" title: "Component"
description: "A Component which can affect Thang behavior." description: "A Component which can affect Thang behavior."
required: ["system", "name", "description", "code", "dependencies", "propertyDocumentation", "language"] required: ["system", "name", "description", "code", "dependencies", "propertyDocumentation", "codeLanguage"]
"default": "default":
system: "ai" system: "ai"
name: "AttacksSelf" name: "AttacksSelf"
description: "This Component makes the Thang attack itself." description: "This Component makes the Thang attack itself."
code: attackSelfCode code: attackSelfCode
language: "coffeescript" codeLanguage: "coffeescript"
dependencies: [] # TODO: should depend on something by default dependencies: [] # TODO: should depend on something by default
propertyDocumentation: [] propertyDocumentation: []
} }
@ -85,7 +85,7 @@ _.extend LevelComponentSchema.properties,
type: "string" type: "string"
maxLength: 2000 maxLength: 2000
"default": "This Component makes the Thang attack itself." "default": "This Component makes the Thang attack itself."
language: codeLanguage:
type: "string" type: "string"
title: "Language" title: "Language"
description: "Which programming language this Component is written in." description: "Which programming language this Component is written in."

View file

@ -54,12 +54,12 @@ DependencySchema = c.object {
LevelSystemSchema = c.object { LevelSystemSchema = c.object {
title: "System" title: "System"
description: "A System which can affect Level behavior." description: "A System which can affect Level behavior."
required: ["name", "description", "code", "dependencies", "propertyDocumentation", "language"] required: ["name", "description", "code", "dependencies", "propertyDocumentation", "codeLanguage"]
"default": "default":
name: "JitterSystem" name: "JitterSystem"
description: "This System makes all idle, movable Thangs jitter around." description: "This System makes all idle, movable Thangs jitter around."
code: jitterSystemCode code: jitterSystemCode
language: "coffeescript" codeLanguage: "coffeescript"
dependencies: [] # TODO: should depend on something by default dependencies: [] # TODO: should depend on something by default
propertyDocumentation: [] propertyDocumentation: []
} }
@ -72,7 +72,7 @@ _.extend LevelSystemSchema.properties,
type: "string" type: "string"
maxLength: 2000 maxLength: 2000
"default": "This System doesn't do anything yet." "default": "This System doesn't do anything yet."
language: codeLanguage:
type: "string" type: "string"
title: "Language" title: "Language"
description: "Which programming language this System is written in." description: "Which programming language this System is written in."

View file

@ -8,7 +8,7 @@ SaveVersionModal = require 'views/modal/save_version_modal'
module.exports = class LevelComponentEditView extends View module.exports = class LevelComponentEditView extends View
id: "editor-level-component-edit-view" id: "editor-level-component-edit-view"
template: template template: template
editableSettings: ['name', 'description', 'system', 'language', 'dependencies', 'propertyDocumentation', 'i18n'] editableSettings: ['name', 'description', 'system', 'codeLanguage', 'dependencies', 'propertyDocumentation', 'i18n']
events: events:
'click #done-editing-component-button': 'endEditing' 'click #done-editing-component-button': 'endEditing'

View file

@ -8,7 +8,7 @@ SaveVersionModal = require 'views/modal/save_version_modal'
module.exports = class LevelSystemEditView extends View module.exports = class LevelSystemEditView extends View
id: "editor-level-system-edit-view" id: "editor-level-system-edit-view"
template: template template: template
editableSettings: ['name', 'description', 'language', 'dependencies', 'propertyDocumentation', 'i18n'] editableSettings: ['name', 'description', 'codeLanguage', 'dependencies', 'propertyDocumentation', 'i18n']
events: events:
'click #done-editing-system-button': 'endEditing' 'click #done-editing-system-button': 'endEditing'

View file

@ -12,6 +12,7 @@ LevelComponentSchema.plugin plugins.PermissionsPlugin
LevelComponentSchema.plugin plugins.VersionedPlugin LevelComponentSchema.plugin plugins.VersionedPlugin
LevelComponentSchema.plugin plugins.SearchablePlugin, {searchable: ['name', 'description', 'system']} LevelComponentSchema.plugin plugins.SearchablePlugin, {searchable: ['name', 'description', 'system']}
LevelComponentSchema.plugin plugins.PatchablePlugin LevelComponentSchema.plugin plugins.PatchablePlugin
LevelComponentSchema.plugin plugins.MigrationPlugin, {'language': 'codeLanguage'}
LevelComponentSchema.pre 'init', (next) -> LevelComponentSchema.pre 'init', (next) ->
return next() unless jsonschema.properties? return next() unless jsonschema.properties?

View file

@ -11,6 +11,7 @@ LevelSystemSchema.plugin(plugins.PermissionsPlugin)
LevelSystemSchema.plugin(plugins.VersionedPlugin) LevelSystemSchema.plugin(plugins.VersionedPlugin)
LevelSystemSchema.plugin(plugins.SearchablePlugin, {searchable: ['name', 'description']}) LevelSystemSchema.plugin(plugins.SearchablePlugin, {searchable: ['name', 'description']})
LevelSystemSchema.plugin(plugins.PatchablePlugin) LevelSystemSchema.plugin(plugins.PatchablePlugin)
LevelSystemSchema.plugin plugins.MigrationPlugin, {'language': 'codeLanguage'}
LevelSystemSchema.pre 'init', (next) -> LevelSystemSchema.pre 'init', (next) ->
return next() unless jsonschema.properties? return next() unless jsonschema.properties?

View file

@ -2,6 +2,24 @@ mongoose = require('mongoose')
User = require('../users/User') User = require('../users/User')
textSearch = require('mongoose-text-search') textSearch = require('mongoose-text-search')
module.exports.MigrationPlugin = (schema, migrations) ->
# Property name migrations made EZ
# This is for just when you want one property to be named differently
# 1. Change the schema and the client/server logic to use the new name
# 2. Add this plugin to the target models, passing in a dictionary of old/new names.
# 3. Check that tests still run, deploy to production.
# 4. Run db.<collection>.update({}, { $rename: {'<oldname>':'<newname>'} }) on the server
# 5. Remove the names you added to the migrations dictionaries for the next deploy
schema.post 'init', ->
for oldKey in _.keys migrations
val = @get oldKey
@set oldKey, undefined
continue if val is undefined
newKey = migrations[oldKey]
@set newKey, val
module.exports.PatchablePlugin = (schema) -> module.exports.PatchablePlugin = (schema) ->
schema.is_patchable = true schema.is_patchable = true
schema.index({'target.original':1, 'status':'1', 'created':-1}) schema.index({'target.original':1, 'status':'1', 'created':-1})

View file

@ -6,7 +6,7 @@ describe 'LevelComponent', ->
name:'BashesEverything' name:'BashesEverything'
description:'Makes the unit uncontrollably bash anything bashable, using the bash system.' description:'Makes the unit uncontrollably bash anything bashable, using the bash system.'
code: 'bash();' code: 'bash();'
language: 'coffeescript' codeLanguage: 'coffeescript'
permissions:simplePermissions permissions:simplePermissions
propertyDocumentation: [] propertyDocumentation: []
system: 'ai' system: 'ai'
@ -35,7 +35,7 @@ describe 'LevelComponent', ->
expect(body.name).toBe(component.name) expect(body.name).toBe(component.name)
expect(body.description).toBe(component.description) expect(body.description).toBe(component.description)
expect(body.code).toBe(component.code) expect(body.code).toBe(component.code)
expect(body.language).toBe(component.language) expect(body.codeLanguage).toBe(component.codeLanguage)
expect(body.__v).toBe(0) expect(body.__v).toBe(0)
expect(body.creator).toBeDefined() expect(body.creator).toBeDefined()
expect(body.original).toBeDefined() expect(body.original).toBeDefined()
@ -69,7 +69,7 @@ describe 'LevelComponent', ->
expect(body.slug).toBeDefined() expect(body.slug).toBeDefined()
expect(body.description).toBe(components[0].description) expect(body.description).toBe(components[0].description)
expect(body.code).toBe(components[0].code) expect(body.code).toBe(components[0].code)
expect(body.language).toBe(components[0].language) expect(body.codeLanguage).toBe(components[0].codeLanguage)
expect(body.__v).toBe(0) expect(body.__v).toBe(0)
expect(body.official).toBeDefined() expect(body.official).toBeDefined()
expect(body.creator).toBeDefined() expect(body.creator).toBeDefined()

View file

@ -9,7 +9,7 @@ describe 'LevelSystem', ->
constructor: (world) -> constructor: (world) ->
super world super world
""" """
language: 'coffeescript' codeLanguage: 'coffeescript'
permissions:simplePermissions permissions:simplePermissions
dependencies: [] dependencies: []
propertyDocumentation: [] propertyDocumentation: []
@ -37,7 +37,7 @@ describe 'LevelSystem', ->
expect(body.name).toBe(system.name) expect(body.name).toBe(system.name)
expect(body.description).toBe(system.description) expect(body.description).toBe(system.description)
expect(body.code).toBe(system.code) expect(body.code).toBe(system.code)
expect(body.language).toBe(system.language) expect(body.codeLanguage).toBe(system.codeLanguage)
expect(body.__v).toBe(0) expect(body.__v).toBe(0)
expect(body.creator).toBeDefined() expect(body.creator).toBeDefined()
expect(body.original).toBeDefined() expect(body.original).toBeDefined()
@ -71,7 +71,7 @@ describe 'LevelSystem', ->
expect(body.slug).toBeDefined() expect(body.slug).toBeDefined()
expect(body.description).toBe(systems[0].description) expect(body.description).toBe(systems[0].description)
expect(body.code).toBe(systems[0].code) expect(body.code).toBe(systems[0].code)
expect(body.language).toBe(systems[0].language) expect(body.codeLanguage).toBe(systems[0].codeLanguage)
expect(body.__v).toBe(0) expect(body.__v).toBe(0)
expect(body.official).toBeDefined() expect(body.official).toBeDefined()
expect(body.creator).toBeDefined() expect(body.creator).toBeDefined()

View file

@ -6,7 +6,7 @@ describe 'LevelComponent', ->
name:'Bashes Everything' name:'Bashes Everything'
description:'Makes the unit uncontrollably bash anything bashable, using the bash system.' description:'Makes the unit uncontrollably bash anything bashable, using the bash system.'
code: 'bash();' code: 'bash();'
language: 'javascript' codeLanguage: 'javascript'
official: true official: true
permissions:simplePermissions permissions:simplePermissions

View file

@ -9,7 +9,7 @@ describe 'LevelSystem', ->
constructor: (world) -> constructor: (world) ->
super world super world
""" """
language: 'coffeescript' codeLanguage: 'coffeescript'
official: true official: true
permissions:simplePermissions permissions:simplePermissions