lib/ninjs/configuration.rb in ninjs-0.13.1 vs lib/ninjs/configuration.rb in ninjs-0.13.2
- old
+ new
@@ -1,30 +1,26 @@
module Ninjs
class Configuration
attr_reader :name,
- :app_filename,
- :directory,
- :output,
:dependencies,
:autoload,
- :config_path,
- :asset_root,
- :base_url,
- :test_path
+ :asset_root
+ attr_accessor :output
+
def initialize(project_path, name = '')
@project_path = project_path
+
@defaults = {
:name => name,
- :app_filename => name.gsub(/\s|\-|\./, '').downcase,
:output => 'expanded',
- :dependencies => ['<jquery/latest>'],
- :autoload => ['<ninjs/utilities/all>'],
- :base_url => 'http://www.example.com/',
- :test_path => 'tests/'
+ :dependencies => ['"<jquery/latest>"'],
+ :autoload => ['"../lib/utilities"']
}
+
+ @asset_root = @project_path
@defaults.each do |label, setting|
instance_variable_set("@#{label}", setting)
end
@@ -32,20 +28,18 @@
read
end
end
def create
- options = @defaults
- options.delete :app_filename
- default_content = conf_content options
- create_conf_file default_content
+ create_conf_file conf_content(@defaults)
end
def conf_content(options)
content = String.new
options.each do |option, value|
- content << "#{option}: #{value}\n"
+ content << "#{option}: #{value}\n" if value.kind_of? String
+ content << "#{option}: [#{value.join(', ')}]\n" if value.kind_of? Array
end
content
end
def create_conf_file(content)
@@ -53,36 +47,20 @@
conf_file << conf_content(@defaults)
end
Ninjs::Notification.notify "ninjs.conf created", :added
end
-
- def update
- options = {
- :name => @name,
- :asset_root => @asset_root,
- :output => @output,
- :dependencies => @dependencies,
- :autoload => @autoload,
- :base_url => @base_url,
- :test_path => @test_path
- }
- options.reject! { |option| option.nil? }
-
- content = conf_content options
- create_conf_file content
- end
-
+
def read
config = YAML.load_file("#{@project_path}ninjs.conf")
- @asset_root = config['asset_root'] unless config['asset_root'].nil?
+
@name = config['name']
- @app_filename = config['name'].downcase
@output = config['output']
+
@dependencies = config['dependencies'] || Array.new
@autoload = config['autoload'] || Array.new
- @base_url = config['base_url'] || 'http://www.example.com/'
- @test_path = config['test_path'] || 'tests/'
+
+ @asset_root = config['asset_root'] unless config['ass'].nil?
end
end
end
\ No newline at end of file