dyndoc-ruby 1.3.6 → 1.3.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1429abd256e9d0441df24744231a62ae8129a5274c3e8de413e700a81dfdc917
4
- data.tar.gz: 21e08fa73d544abf8618461df13e40cdfc333a542e4c71185ae301ad12784ea7
3
+ metadata.gz: 8e134057e655c0154df49f4518d6964d373efd163adde55ac057f734649c677b
4
+ data.tar.gz: 6f92db285fbbb590d952480e9ba1b8a1fc099c6924861b87a548e097b1188e55
5
5
  SHA512:
6
- metadata.gz: 1a02a9276665a3302bea5445e7d7b1f2b1129ae62ca5409464afc25180254ebf053046298cac9f46130a8e4b1d8ac282f5ddf01dd93066d29905942d8f1d534a
7
- data.tar.gz: 3953bd8ce467a7e6dc5306085e0062152571af478634e3404eb057da0211d8d726091e88bf57e15ae0c3e854deeecef445c0d7c38df34f9f0fa5640f961e21b1
6
+ metadata.gz: 673b82c1efc5b4e1f6a16e9f394ff35cba499353050043351c13037ef49e6ee24be0a75acb1d1ef378ad6decf741859aa9b15920eee2f5936b78d6ab17e46417
7
+ data.tar.gz: d1b541c745c7dab4ee9c8372f71d9f7524c6b438ad8c0d101e5adf6de0a6581b4674f735dbf601daaf0af124cb0466abdb631440d0a708c84a36c298dbe22f60
@@ -1,11 +1,75 @@
1
+ require 'yaml'
2
+
1
3
  module DyndocWorld
2
4
 
3
- def DyndocWorld.yml?(prj,yml)
4
- true
5
+ @@root=nil
6
+ @@public=nil
7
+
8
+ def DyndocWorld.root(root=nil)
9
+ @@root=root if root
10
+ return @@root
11
+ end
12
+
13
+ def DyndocWorld.public_root(public_root=nil)
14
+ @@public=public_root if public_root
15
+ return @@public
5
16
  end
6
17
 
7
- def DyndocWorld.prj_dir(prj,yml)
8
- prj
18
+ def DyndocWorld.cfg(admin=nil)
19
+ cfg={}
20
+ secret = File.join(DyndocWorld.root,admin ? ".admin.yml" : ".secret.yml")
21
+ cfg = YAML::load_file(secret) if DyndocWorld.root and File.exists? secret
22
+ return cfg
9
23
  end
10
24
 
25
+ ## access ##
26
+ ## prj is to give access for a user or a group of users
27
+ ## if prj or prj/secret is undefined it is accessible
28
+ def DyndocWorld.yml?(prj,yml)
29
+ admin=(prj=="admin")
30
+ cfg=DyndocWorld.cfg(admin)
31
+ cfg=cfg[prj] unless admin
32
+ return true unless cfg
33
+ ##DEBUG: p [:"yml?", cfg, yml, (cfg and yml and ((cfg["secret"] || "none") == (yml["secret"] || "none")) and yml["file"] and !(yml["file"].include? "../"))]
34
+ return (cfg and yml and ((cfg["secret"] || "none") == (yml["secret"] || "none")) and yml["file"] and !(yml["file"].include? "../"))
35
+ end
36
+
37
+ ## file ##
38
+ ## from yml
39
+ ## ex: public/<user>/<pathname>
40
+ ## edit/<user>/<pathname>
41
+ ## dynworld/<user>/<pathname>
42
+ def DyndocWorld.prj_file(yml,content)
43
+ success,prj_file=false,""
44
+ parts=yml["file"].split("/")
45
+ p [:parts,parts]
46
+ root=parts.shift
47
+ p [:root,root]
48
+ if ["public","edit","dynworld"].include? root
49
+ user=parts.shift
50
+ case root
51
+ when "public"
52
+ prj_file=File.join(DyndocWorld.public_root,"users",user)
53
+ prj_file=(Dir.exists? prj_file) ? File.join(prj_file,parts) : ""
54
+ when "edit"
55
+ prj_file=File.join(DyndocWorld.public_root,"users",user,".edit")
56
+ prj_file=(Dir.exists? prj_file) ? File.join(prj_file,parts) : ""
57
+ when "dynworld"
58
+ prj_file=File.join(DyndocWorld.root,user,parts)
59
+ end
60
+ end
61
+ p [:prj_file,prj_file]
62
+ unless prj_file.empty?
63
+ FileUtils.mkdir_p File.dirname prj_file
64
+ File.open(prj_file,"w") {|f|
65
+ if root == "edit"
66
+ f << yml.to_yaml
67
+ f << "---\n"
68
+ end
69
+ f << content.strip
70
+ }
71
+ success=true
72
+ end
73
+ return success
74
+ end
11
75
  end
@@ -10,9 +10,10 @@ cfg.merge! YAML::load_file(cfg_yml) if File.exist? cfg_yml
10
10
  root = cfg["root"] || File.join(ENV["HOME"],"RCqls","RodaServer")
11
11
  $public_root = cfg["public_root"] || File.join(root ,"public")
12
12
  ##p [:public_root,$public_root]
13
- $dynworld_root=cfg["dynworld_root"] || File.join(ENV["HOME"],".dyndoc-world")
14
13
 
15
14
  require 'dyndoc-world'
15
+ DyndocWorld.root(cfg["dynworld_root"] || File.join(ENV["HOME"],".dyndoc-world"))
16
+ DyndocWorld.public_root($public_root)
16
17
 
17
18
  class App < Roda
18
19
  use Rack::Session::Cookie, :secret => (secret="Thanks like!")
@@ -42,24 +43,19 @@ class App < Roda
42
43
 
43
44
  r.post "file-save" do
44
45
  puts "file-save"
45
- prj,yml,@file,@content=r['prj'].strip,r['yml'].strip,r['file'].strip,r['content']
46
- p [prj,yml,@file,@content]
46
+ prj,yml,@content=r['prj'].strip,r['yml'].strip,r['content']
47
+ p [prj,yml,@content]
47
48
  success=false
48
49
  unless yml.empty?
49
50
  yml="---\n" + yml unless yml[0,4] == "---\n"
50
51
  yml=YAML::load(yml)
51
52
  p [:yml, yml]
52
53
  require 'fileutils'
53
- if @file and !(@file.include? "../") and (DyndocWorld.yml?(prj,yml))
54
- if Dir.exists? $dynworld_root
55
- prj_dir=DyndocWorld.prj_dir(prj,yml)
56
- dynworld_file=File.join($dynworld_root,prj_dir,@file)
57
- FileUtils.mkdir_p File.dirname dynworld_file
58
- File.open(dynworld_file,"w") {|f| f << @content.strip}
59
- success=true
60
- end
54
+ if DyndocWorld.yml?(prj,yml)
55
+ success=DyndocWorld.prj_file(yml,@content)
61
56
  end
62
57
  end
58
+ p [:success, "{success: " + success.to_s + "}"]
63
59
  "{success: " + success.to_s + "}"
64
60
  end
65
61
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dyndoc-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.6
4
+ version: 1.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - RCqls
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-24 00:00:00.000000000 Z
11
+ date: 2019-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: R4rb