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
|
raise MissingProject if not @projects.has_key? project_name
|
||||||
|
|
||||||
view = View.new view_name
|
project_path = @projects[project_name].path
|
||||||
@projects[project_name].add_view view
|
|
||||||
|
# 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
|
save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -125,22 +125,6 @@ module Kook
|
||||||
|
|
||||||
@app.add_view project_name, view_name, view_path
|
@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
|
end
|
||||||
|
|
||||||
desc "rm PROJECT VIEW", "Unregister existing view on project"
|
desc "rm PROJECT VIEW", "Unregister existing view on project"
|
||||||
|
|
|
@ -31,9 +31,17 @@ module Kook
|
||||||
@path = path
|
@path = path
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_view view
|
def create_view view_name, view_path
|
||||||
raise "ExistingView #{view.name}" if @views.has_key? view.name
|
raise ExistingView, view_name if @views.has_key? view_name
|
||||||
@views[view.name] = view
|
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
|
end
|
||||||
|
|
||||||
def remove_view view_name
|
def remove_view view_name
|
||||||
|
@ -42,6 +50,7 @@ module Kook
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_view
|
def each_view
|
||||||
|
pp @views
|
||||||
@views.each do |view_name, view_data|
|
@views.each do |view_name, view_data|
|
||||||
yield view_name, view_data
|
yield view_name, view_data
|
||||||
end
|
end
|
||||||
|
@ -61,12 +70,11 @@ module Kook
|
||||||
p.description = project_hash['description']
|
p.description = project_hash['description']
|
||||||
p.path = project_path
|
p.path = project_path
|
||||||
|
|
||||||
#project_hash[:views].each do |hash_view|
|
#pp project_hash['views']
|
||||||
# view = View.new do |v|
|
project_hash['views'].each do |view_hash|
|
||||||
# v.from_hash hash_view
|
view_data = View.from_hash view_hash
|
||||||
# end
|
p.add_view view_data
|
||||||
# p.add_view view
|
end
|
||||||
#end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,10 @@ module Kook
|
||||||
VIEW_NAME_MIN_SIZE = 4
|
VIEW_NAME_MIN_SIZE = 4
|
||||||
VIEW_NAME_MAX_SIZE = 12
|
VIEW_NAME_MAX_SIZE = 12
|
||||||
|
|
||||||
def initialize name
|
def initialize name, path=nil
|
||||||
self.class.validate_name name
|
self.class.validate_name name
|
||||||
@name = name
|
@name = name
|
||||||
@path = nil
|
@path = path
|
||||||
@commands = {}
|
@commands = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -24,16 +24,16 @@ module Kook
|
||||||
|
|
||||||
def to_hash
|
def to_hash
|
||||||
return {
|
return {
|
||||||
view: @name,
|
'view' => @name,
|
||||||
path: @path,
|
'path' => @path,
|
||||||
commands: @commands.values
|
'commands' => @commands.values
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def from_hash view_hash
|
def self.from_hash view_hash
|
||||||
@name = view_hash[:view]
|
view = View.new view_hash['view'], view_hash['path']
|
||||||
@path = view_hash[:path]
|
# @commands = view_hash['commands']
|
||||||
@commands = view_hash[:commands]
|
view
|
||||||
end
|
end
|
||||||
end
|
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 add root $KOOK_OPTS --project kook-project || fail
|
||||||
kook view list $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