Settings grab data from ~/.atomocity/settings.coffee

This commit is contained in:
Corey Johnson
2011-11-23 14:42:38 -05:00
parent c76119020a
commit 90995ba0b2
2 changed files with 46 additions and 3 deletions

View File

@@ -6,9 +6,13 @@ Pane = require 'pane'
module.exports =
class Resource extends Pane
position: "main"
settings: {}
url: null
# Can be used to delegate key events to another object, such as a pane.
constructor: ->
atom.settings.applyTo this
responder: ->
this

View File

@@ -1,8 +1,47 @@
fs = require 'fs'
{CoffeeScript} = require 'coffee-script'
module.exports =
class Settings
settings: {}
constructor: ->
atom.on 'window:load', ->
if fs.isFile "~/.atomicity/settings.coffee"
require "~/.atomicity/settings.coffee"
@load "~/.atomicity/settings.coffee"
console.log @settings
load: (path) ->
path = require.resolve path
if not fs.isFile path
console.warn "Could not find settings file '#{path}'"
return
try
json = CoffeeScript.eval "return " + (fs.read path)
for className, value of json
@settings[@simplifyClassName className] = value
catch error
console.error "Can't evaluate settings at `#{path}`."
console.error error
applyTo: (object) ->
if not object.settings
console.warning "#{object.constructor.name}: Does not have `settings` varible"
return
classHierarchy = []
# ICK: Using internal var __super to get the build heirarchy
walker = object
while walker
classHierarchy.unshift @simplifyClassName walker.constructor.name
walker = walker.constructor.__super__
for className in classHierarchy
for setting, value of @settings[className] ? {}
object.settings[setting] = value
# I don't care if you use camelCase, underscores or dashes. It should all
# point to the same place
simplifyClassName: (className) ->
className.toLowerCase().replace /\W/, ''