mirror of
https://github.com/atom/atom.git
synced 2026-01-24 22:38:20 -05:00
Settings grab data from ~/.atomocity/settings.coffee
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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/, ''
|
||||
|
||||
Reference in New Issue
Block a user