module Xmvc module Settings class << self def dispatch(action, *params) end def load @settings = YAML.load_file('config/environment.yml') end ## # write a newly generated controller, model or view to environment.json # Unfortunately, we cannot JSON.parse the entire config/environment.json, since it contains comments # and such. Have to RegExp, pick-out the requested key, and JSON.parse the returned chunk. # Is this Regexp satisfactory?? Could probably be made better. # def add (key, item) key = key.to_s @settings[key] = [] unless @settings[key] && @settings[key].kind_of?(Array) unless key == "views" @settings[key] << item else if controller = @settings[key].find {|i| i[item[:package]]} controller[item[:package]] << item[:filename] else @settings[key] << { item[:package] => [ item[:filename] ] } end end save end private def save File.open('config/environment.yml', "w") {|file| file << @settings.to_yaml } File.open('public/config/environment.json', "w") {|file| file << @settings.to_json } end end end end ## # # ORIGINAL CODE # # module ExtJS module MVC # extracts settings from the config/settings.yml file def self.settings @config ||= YAML.load_file('config/settings.yml') end # returns environment settings def self.environment settings['environment'] end def self.namespace environment["namespace"] end def self.show_settings puts environment.inspect end def self.application_files_for(environment) files = [] [ environment["plugins"].collect {|o| "vendor/plugins/#{o}/#{o}-all.js"}, environment["overrides"].collect {|o| "config/overrides/#{o}.js"}, environment["config"].collect {|o| "#{o}.js"}, environment["models"].collect {|o| "app/models/#{o}.js"}, environment["controllers"].collect {|o| "app/controllers/#{o}Controller.js"}, environment["views"].collect {|o| o.collect {|dir, fileList| fileList.collect {|fileName| "app/views/#{dir}/#{fileName}.js"}.flatten}}.flatten ].each {|f| files.concat(f)} files end def self.css_files_for(environment) environment['stylesheets'].collect {|s| "public/stylesheets/#{s}.css"} end def self.mvc_development_environment environment = {} default = JSON::Parser.new(File.read('public/config/environment.json')).parse() development = JSON::Parser.new(File.read('public/config/environments/development.json')).parse() environment.merge!(default) environment.merge!(development) environment end def self.mvc_production_environment environment = { 'pluginsDir' => '../vendor/plugins', 'libDir' => '../lib', 'configDir' => '../config', 'overridesDir' => '../config/overrides', 'appDir' => '../app', 'vendor' => ['mvc'], 'mvcFilename' => 'ext-mvc-all-min', 'config' => ['app/App', 'config/routes'], 'stylesheets' => ['ext-all'] } default = JSON::Parser.new(File.read('public/config/environment.json')).parse() production = JSON::Parser.new(File.read('public/config/environments/production.json')).parse() environment.merge!(default) environment.merge!(production) environment end end end