Add view creation support.
This commit is contained in:
parent
cdcec384f0
commit
f200005e92
5 changed files with 37 additions and 37 deletions
|
@ -63,8 +63,16 @@ module Kook
|
|||
|
||||
raise MissingProject if not @projects.has_key? project_name
|
||||
|
||||
view = View.new view_name
|
||||
@projects[project_name].add_view view
|
||||
project_path = @projects[project_name].path
|
||||
|
||||
# simplify if current dir is a subdir of project base
|
||||
if view_path == project_path then
|
||||
view_path = '.'
|
||||
else
|
||||
view_path.gsub!(/^#{project_path}\//,'')
|
||||
end
|
||||
|
||||
@projects[project_name].create_view view_name, view_path
|
||||
save
|
||||
end
|
||||
|
||||
|
|
|
@ -125,22 +125,6 @@ module Kook
|
|||
|
||||
@app.add_view project_name, view_name, view_path
|
||||
|
||||
project_rootdir = config['projects'][project]
|
||||
# simplify if current dir is a subdir of project base
|
||||
if path == project_rootdir then
|
||||
path = '.'
|
||||
else
|
||||
path.gsub!(/^#{project_rootdir}\//,'')
|
||||
end
|
||||
|
||||
if not config['views'].has_key? project then
|
||||
config['views'][project] = {}
|
||||
elsif config['views'][project].nil? then
|
||||
config['views'][project] = {}
|
||||
end
|
||||
#binding.pry
|
||||
config['views'][project][view] = path
|
||||
config.save_main
|
||||
end
|
||||
|
||||
desc "rm PROJECT VIEW", "Unregister existing view on project"
|
||||
|
|
|
@ -31,9 +31,17 @@ module Kook
|
|||
@path = path
|
||||
end
|
||||
|
||||
def add_view view
|
||||
raise "ExistingView #{view.name}" if @views.has_key? view.name
|
||||
@views[view.name] = view
|
||||
def create_view view_name, view_path
|
||||
raise ExistingView, view_name if @views.has_key? view_name
|
||||
View.validate_name view_name
|
||||
|
||||
@views[view_name] = View.new view_name, view_path
|
||||
end
|
||||
|
||||
def add_view view_data
|
||||
raise ExistingView, view_data.name if @views.has_key? view_data.name
|
||||
|
||||
@views[view_data.name] = view_data
|
||||
end
|
||||
|
||||
def remove_view view_name
|
||||
|
@ -42,6 +50,7 @@ module Kook
|
|||
end
|
||||
|
||||
def each_view
|
||||
pp @views
|
||||
@views.each do |view_name, view_data|
|
||||
yield view_name, view_data
|
||||
end
|
||||
|
@ -61,12 +70,11 @@ module Kook
|
|||
p.description = project_hash['description']
|
||||
p.path = project_path
|
||||
|
||||
#project_hash[:views].each do |hash_view|
|
||||
# view = View.new do |v|
|
||||
# v.from_hash hash_view
|
||||
# end
|
||||
# p.add_view view
|
||||
#end
|
||||
#pp project_hash['views']
|
||||
project_hash['views'].each do |view_hash|
|
||||
view_data = View.from_hash view_hash
|
||||
p.add_view view_data
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,10 +6,10 @@ module Kook
|
|||
VIEW_NAME_MIN_SIZE = 4
|
||||
VIEW_NAME_MAX_SIZE = 12
|
||||
|
||||
def initialize name
|
||||
def initialize name, path=nil
|
||||
self.class.validate_name name
|
||||
@name = name
|
||||
@path = nil
|
||||
@path = path
|
||||
@commands = {}
|
||||
end
|
||||
|
||||
|
@ -24,16 +24,16 @@ module Kook
|
|||
|
||||
def to_hash
|
||||
return {
|
||||
view: @name,
|
||||
path: @path,
|
||||
commands: @commands.values
|
||||
'view' => @name,
|
||||
'path' => @path,
|
||||
'commands' => @commands.values
|
||||
}
|
||||
end
|
||||
|
||||
def from_hash view_hash
|
||||
@name = view_hash[:view]
|
||||
@path = view_hash[:path]
|
||||
@commands = view_hash[:commands]
|
||||
def self.from_hash view_hash
|
||||
view = View.new view_hash['view'], view_hash['path']
|
||||
# @commands = view_hash['commands']
|
||||
view
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
2
test.sh
2
test.sh
|
@ -67,4 +67,4 @@ kook project add kook-project $KOOK_OPTS || fail
|
|||
kook view add root $KOOK_OPTS --project kook-project || fail
|
||||
kook view list $KOOK_OPTS --project kook-project || fail
|
||||
|
||||
test_cleanup
|
||||
#test_cleanup
|
||||
|
|
Loading…
Reference in a new issue