dyndoc-ruby 0.9.2 → 0.9.3

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
  SHA1:
3
- metadata.gz: 2b104002585f67910c6674bd6d9937221cffe185
4
- data.tar.gz: 5014c79451e427798d0b2dac7307d0c55c83ccd9
3
+ metadata.gz: b9963c5d464efaa1e487405f7281a8fc0524bfb4
4
+ data.tar.gz: 381c9fdc302fc46caf90ff3add7ef0fa4509cd25
5
5
  SHA512:
6
- metadata.gz: 0ca0e8ddfd72441ad99174c31615946580bb135ddafbb4c8719faafd61f629060d93560440cdf5874c69dfef44921a064c2f037b6b446afb324dee56f47b8a8f
7
- data.tar.gz: 2d2d3e9eced1d1d0ce9ff6ed8e69134ed4c014f3a6e80cafb2a7ecde337e52973e3bbcd8c1cf64c7f95953852e4539bad62029a4f19cee7416532dcfd11b15bd
6
+ metadata.gz: 0f4be1e799a156cdc63609e0db7a5c18da45783fd8a56b390272b9a3cb2b96200e132d33f05e5c6a8220a32172a78bc895298f2ae14621de6605737ee68d1b25
7
+ data.tar.gz: 064ba3d1dc341f4b06f997d60bd12d0387ae126ddf072f43d7ab6bf80df766f5e42f40d67d2e1f5c1f35c6e469725d0c9fd7a8016d3f907ea749d001279d8a90
data/bin/dyn CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+
2
3
  require 'dyndoc/document'
3
4
 
4
5
  ## p Dyndoc.cfg_dir
data/bin/dyn-forever CHANGED
@@ -5,9 +5,7 @@ require "dyndoc/srv/interactive-server"
5
5
 
6
6
  Forever.run do
7
7
  on_error do |e|
8
-
9
8
  puts "%s\n %s\n" % [e.message, e.backtrace.join("\n ")]
10
-
11
9
  end
12
10
  before :all do
13
11
  Dyndoc::InteractiveServer.new.run
data/bin/dyn-html CHANGED
@@ -2,6 +2,8 @@
2
2
  require 'dyndoc-convert'
3
3
  require 'dyndoc-edit'
4
4
  require 'dyndoc/init/home'
5
+ require 'pathname'
6
+
5
7
  dyndoc_home = Dyndoc.home
6
8
  #p Dyndoc.home
7
9
 
@@ -14,72 +16,49 @@ cfg=YAML::load_file(cfg_yml) if File.exist? cfg_yml
14
16
 
15
17
  ## To put inside yaml config file!
16
18
  root = cfg["root"] || File.join(ENV["HOME"],"RCqls","RodaServer")
17
- edit_root = File.join(root ,"edit")
18
- pages_root = File.join(root ,"public","pages")
19
+ edit_root = cfg["edit_root"] || File.join(root ,"edit")
20
+ public_root = cfg["public_root"] || File.join(root ,"public")
21
+ pages_root = File.join(public_root ,"pages")
19
22
  current_email = cfg["email"] || "rdrouilh@gmail.com" #default email user can be overriden by -u option
23
+ base_url=cfg["base_url"] || "http://localhost:9292"
20
24
 
21
25
  args=ARGV
22
- args=["-h"] if args.empty?
23
26
 
24
27
  require 'optparse'
25
28
 
26
29
  $VERBOSE = nil
27
30
 
28
- ## Examples:
29
- ## 1) global mode:
30
- ## dyn-html /dev/R/test.dyn
31
- ## 2) user mode: relative path used instead of ~ since ~ is interpreted in bash mode!
32
- ## dyn-html cfies2017/index.dyn:index # -u <default_user_email>
33
- ## dyn-html -u remy.drouilhet@upmf-grenoble.fr cfies2017/index.dyn:index
34
- ## dyn-html -u remy.drouilhet@upmf-grenoble.fr cfies2017/index.dyn:all
35
-
36
- options={watching: nil, refresh: :auto, first: true}
31
+ options={first: true}
37
32
 
38
33
  OptionParser.new do |opts|
39
- opts.banner = "Usage: dyn-html [-u email_user] [-w] [-r <url-to-refresh-when-watched>] [/]<relative_path>/<file>.dyn"
40
-
41
- opts.on( '-u', '--user EMAIL', 'user email' ) do |email|
42
- current_email=email
43
- end
44
-
45
- opts.on( '-w', '--watch', 'watch file') do
46
- options[:watching]=true
47
- end
48
-
49
- opts.on( '-r', '--refresh HTML', 'page to refresh (only for MacOsX)' ) do |html|
50
- options[:refresh]=html
51
- end
52
-
53
- opts.on('--no-refresh', 'no refresh page' ) do
54
- options[:refresh]=nil
55
- end
56
-
34
+ opts.banner = "Usage: dyn-html"
57
35
  end.parse!(args)
58
36
 
59
37
  ## Mandatory input
60
- dyn_file,doc_tag=args[0].split(":")
61
- doc_tag="" unless doc_tag
62
- doc_tag="__ALL_DOC_TAG__" if doc_tag.downcase == "all"
38
+ # dyn_file=args[0]
39
+ # doc_tag="" unless doc_tag
40
+ # doc_tag="__ALL_DOC_TAG__" if doc_tag.downcase == "all"
63
41
 
64
42
  ## Detect docs_tags_info
65
- dyn_file=File.join(["","users",current_email],dyn_file) unless dyn_file[0,1]=="/"
66
- filename=File.join(edit_root,dyn_file)
67
- doc_tags_info=Dyndoc::Edit.get_doc_tags_info(File.read(filename))
43
+ # dyn_file=File.join(["","users",current_email],dyn_file) unless dyn_file[0,1]=="/"
44
+ # filename=File.join(edit_root,dyn_file)
68
45
 
69
- if dyn_file and (dyn_file=~/(.*)(?:\.dyn|_html.dyn)$/)
46
+ ### doc_tags_info=Dyndoc::Edit.get_doc_tags_info(File.read(filename))
47
+
48
+ ### if dyn_file and (dyn_file=~/(.*)(?:\.dyn|_html.dyn)$/)
70
49
  #p [:dyn_file,dyn_file,$1]
71
- html_files=Dyndoc::Edit.html_files({doc_tags_info: doc_tags_info , dyn_file: dyn_file },current_email)
72
- ##p [:html_files,html_files]
73
- html_file=html_files[doc_tag] || html_files[""]
50
+ ### html_files=Dyndoc::Edit.html_files({doc_tags_info: doc_tags_info , dyn_file: dyn_file },current_email)
51
+ ### ##p [:html_files,html_files]
52
+ ### html_file=html_files[doc_tag] || html_files[""]
74
53
 
75
- if options[:refresh] and options[:refresh] == :auto
76
- options[:refresh] = File.join(cfg["localhost_url"] || "http://localhost:9292",File.dirname(dyn_file),File.basename(dyn_file,".*"))
77
- end
54
+ ### if options[:refresh] and options[:refresh] == :auto
55
+ ### options[:refresh] = File.join(cfg["localhost_url"] || "http://localhost:9292",File.dirname(dyn_file),File.basename(dyn_file,".*"))
56
+ ### end
78
57
 
79
- output=""
80
- output << "Watching "+dyn_file if options[:watching]
81
- output << (options[:watching] ? " and refreshing " : "Refreshing ")+options[:refresh] if options[:refresh]
82
- puts output unless output.empty?
58
+ ### output=""
59
+ ### output << "Watching "+dyn_file if options[:watching]
60
+ ### output << (options[:watching] ? " and refreshing " : "Refreshing ")+options[:refresh] if options[:refresh]
61
+ ### puts output unless output.empty?
83
62
 
84
63
  # Ex for opts:
85
64
  # rdrouilh : [:dyn_opts, {:dyn_root=>"/Users/remy/RCqls/RodaServer/edit", :html_root=>"/Users/remy/RCqls/RodaServer/public/pages", :user=>"rdrouilh@gmail.com", :doc_tag=>"bio", :html_files=>{""=>"/dev/R/test.html", "ssd"=>"/dev/R/ssd.html", "bio"=>"/dev/R/bio.html", "tmp"=>"/dev/R/tmp.html", "cours"=>"/dev/R/cours.html"}}]
@@ -87,37 +66,42 @@ if dyn_file and (dyn_file=~/(.*)(?:\.dyn|_html.dyn)$/)
87
66
  opts = {
88
67
  dyn_root: edit_root,
89
68
  html_root: pages_root,
90
- user: current_email,
91
- doc_tag: doc_tag,
92
- html_files: html_files
69
+ user: current_email
93
70
  }
94
71
  ##p opts
95
- file_to_process=File.join(opts[:dyn_root],dyn_file)
72
+ ### file_to_process=File.join(opts[:dyn_root],dyn_file)
96
73
  cmd_to_open=nil
97
- if options[:refresh] and RUBY_PLATFORM =~ /darwin/
98
- cmd_to_open='tell application "Safari" to set URL of current tab of front window to "'+options[:refresh]+'"'
99
- cmd_to_refresh='tell application "System Events"' + "\n" + 'tell process "Safari"' + "\n" + 'keystroke "r" using {command down}' + "\n" + 'delay 60' + "\n" + 'end tell' + "\n" + 'end tell'
74
+ if RUBY_PLATFORM =~ /darwin/
75
+
100
76
  end
101
- unless options[:watching]
102
- ## dyn_file[1..-1] to have a relative path...
103
- if Dyndoc::Linter.check_file(file_to_process).empty?
104
- Dyndoc.cli_convert_from_file(dyn_file[1..-1],html_file, opts)
105
- else
106
- puts dyn_file[1..-1]+" not well-formed!"
107
- end
108
- else
109
- require 'filewatcher'
110
- require 'dyndoc-linter'
111
- FileWatcher.new([file_to_process]).watch() do |filename, event|
112
- if event == :changed
113
- if Dyndoc::Linter.check_file(file_to_process).empty?
114
- Dyndoc.cli_convert_from_file(dyn_file[1..-1],html_file, opts)
115
- puts dyn_file[1..-1]+" processed!"
116
- if options[:refresh] and RUBY_PLATFORM =~ /darwin/
117
- if options[:first]
118
- `osascript -e '#{cmd_to_open}'`
119
- options[:first]=nil
120
- else
77
+
78
+ require 'filewatcher'
79
+ require 'dyndoc-linter'
80
+ puts "watching "+File.join(edit_root)
81
+ old_html_file=""
82
+ FileWatcher.new(edit_root).watch() do |filename, event|
83
+ ##p [:filename,filename]
84
+ if [:changed,:new].include? event and File.extname(filename) == ".dyn"
85
+ ##p [:filename_event,event,filename]
86
+ if Dyndoc::Linter.check_file(filename).empty?
87
+ ## find dyn_file (relative path from root)
88
+ dyn_file="/"+Pathname(filename).relative_path_from(Pathname(edit_root)).to_s
89
+ opts_doc=Dyndoc::FileWatcher.get_dyn_html_info(filename,dyn_file,opts[:user])
90
+ opts.merge! opts_doc
91
+ ##p [:html_files,html_files]
92
+
93
+ html_file=opts[:html_files][opts[:current_doc_tag]] # No more default # || html_files[""]
94
+ ##p [:opts,opts,:current_doc_tag,opts[:current_doc_tag]]
95
+ Dyndoc.cli_convert_from_file(dyn_file[1..-1],html_file, opts)
96
+ puts dyn_file[1..-1]+" processed!"
97
+ if RUBY_PLATFORM =~ /darwin/
98
+ options[:first] = html_file != old_html_file
99
+ if html_file != old_html_file
100
+ old_html_file = html_file
101
+ url=File.join(base_url,html_file)
102
+ cmd_to_open='tell application "Safari" to set URL of current tab of front window to "'+url+'"'
103
+ `osascript -e '#{cmd_to_open}'`
104
+ else
121
105
  %x{osascript<<ENDREFRESH
122
106
  tell app "Safari" to activate
123
107
  tell application "System Events"
@@ -125,12 +109,12 @@ tell application "System Events"
125
109
  end tell
126
110
  ENDREFRESH
127
111
  }
128
- end
129
112
  end
130
- else
131
- puts dyn_file[1..-1]+" not well-formed!"
132
113
  end
114
+ else
115
+ puts dyn_file[1..-1]+" not well-formed!"
133
116
  end
134
117
  end
135
118
  end
136
- end
119
+
120
+ ### end
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env ruby
2
+ require 'dyndoc-convert'
3
+ require 'dyndoc-edit'
4
+ require 'dyndoc/init/home'
5
+ dyndoc_home = Dyndoc.home
6
+ #p Dyndoc.home
7
+
8
+ ###############################################
9
+ ## INFO: this file watch only one file and #
10
+ ## it is now replaced with dyn-html watching #
11
+ ## an entire directory! #
12
+ ###############################################
13
+ cfg_yml = File.join(dyndoc_home,"etc","dyn-html.yml")
14
+
15
+ cfg={}
16
+
17
+ cfg=YAML::load_file(cfg_yml) if File.exist? cfg_yml
18
+
19
+
20
+ ## To put inside yaml config file!
21
+ root = cfg["root"] || File.join(ENV["HOME"],"RCqls","RodaServer")
22
+ edit_root = cfg["edit_root"] || File.join(root ,"edit")
23
+ public_root = cfg["public_root"] || File.join(root ,"public")
24
+ pages_root = File.join(public_root ,"pages")
25
+ current_email = cfg["email"] || "rdrouilh@gmail.com" #default email user can be overriden by -u option
26
+
27
+ args=ARGV
28
+ args=["-h"] if args.empty?
29
+
30
+ require 'optparse'
31
+
32
+ $VERBOSE = nil
33
+
34
+ ## Examples:
35
+ ## 1) global mode:
36
+ ## dyn-html /dev/R/test.dyn
37
+ ## 2) user mode: relative path used instead of ~ since ~ is interpreted in bash mode!
38
+ ## dyn-html cfies2017/index.dyn:index # -u <default_user_email>
39
+ ## dyn-html -u remy.drouilhet@upmf-grenoble.fr cfies2017/index.dyn:index
40
+ ## dyn-html -u remy.drouilhet@upmf-grenoble.fr cfies2017/index.dyn:all
41
+
42
+ options={watching: nil, refresh: :auto, first: true}
43
+
44
+ OptionParser.new do |opts|
45
+ opts.banner = "Usage: dyn-html [-u email_user] [-w] [-r <url-to-refresh-when-watched>] [/]<relative_path>/<file>.dyn"
46
+
47
+ opts.on( '-u', '--user EMAIL', 'user email' ) do |email|
48
+ current_email=email
49
+ end
50
+
51
+ opts.on( '-w', '--watch', 'watch file') do
52
+ options[:watching]=true
53
+ end
54
+
55
+ opts.on( '-r', '--refresh HTML', 'page to refresh (only for MacOsX)' ) do |html|
56
+ options[:refresh]=html
57
+ end
58
+
59
+ opts.on('--no-refresh', 'no refresh page' ) do
60
+ options[:refresh]=nil
61
+ end
62
+
63
+ end.parse!(args)
64
+
65
+ ## Mandatory input
66
+ dyn_file,doc_tag=args[0].split(":")
67
+ doc_tag="" unless doc_tag
68
+ doc_tag="__ALL_DOC_TAG__" if doc_tag.downcase == "all"
69
+
70
+ ## Detect docs_tags_info
71
+ dyn_file=File.join(["","users",current_email],dyn_file) unless dyn_file[0,1]=="/"
72
+ filename=File.join(edit_root,dyn_file)
73
+
74
+ doc_tags_info=Dyndoc::Edit.get_doc_tags_info(File.read(filename))
75
+
76
+ if dyn_file and (dyn_file=~/(.*)(?:\.dyn|_html.dyn)$/)
77
+ #p [:dyn_file,dyn_file,$1]
78
+ html_files=Dyndoc::Edit.html_files({doc_tags_info: doc_tags_info , dyn_file: dyn_file },current_email)
79
+ ##p [:html_files,html_files]
80
+ html_file=html_files[doc_tag] || html_files[""]
81
+
82
+ if options[:refresh] and options[:refresh] == :auto
83
+ options[:refresh] = File.join(cfg["localhost_url"] || "http://localhost:9292",File.dirname(dyn_file),File.basename(dyn_file,".*"))
84
+ end
85
+
86
+ output=""
87
+ output << "Watching "+dyn_file if options[:watching]
88
+ output << (options[:watching] ? " and refreshing " : "Refreshing ")+options[:refresh] if options[:refresh]
89
+ puts output unless output.empty?
90
+
91
+ # Ex for opts:
92
+ # rdrouilh : [:dyn_opts, {:dyn_root=>"/Users/remy/RCqls/RodaServer/edit", :html_root=>"/Users/remy/RCqls/RodaServer/public/pages", :user=>"rdrouilh@gmail.com", :doc_tag=>"bio", :html_files=>{""=>"/dev/R/test.html", "ssd"=>"/dev/R/ssd.html", "bio"=>"/dev/R/bio.html", "tmp"=>"/dev/R/tmp.html", "cours"=>"/dev/R/cours.html"}}]
93
+ # remy.drouilhet : [:dyn_opts, {:dyn_root=>"/Users/remy/RCqls/RodaServer/edit", :html_root=>"/Users/remy/RCqls/RodaServer/public/pages", :user=>"remy.drouilhet@upmf-grenoble.fr", :doc_tag=>"index", :html_files=>{""=>"/users/remy.drouilhet@upmf-grenoble.fr/cfies2017/index.html", "index"=>"/users/remy.drouilhet@upmf-grenoble.fr/cfies2017/index.html", "dates"=>"/users/remy.drouilhet@upmf-grenoble.fr/cfies2017/dates.html", "sc"=>"/users/remy.drouilhet@upmf-grenoble.fr/cfies2017/sc.html", "orga"=>"/users/remy.drouilhet@upmf-grenoble.fr/cfies2017/orga.html"}}]
94
+ opts = {
95
+ dyn_root: edit_root,
96
+ html_root: pages_root,
97
+ user: current_email,
98
+ doc_tag: doc_tag,
99
+ html_files: html_files
100
+ }
101
+ ##p opts
102
+ file_to_process=File.join(opts[:dyn_root],dyn_file)
103
+ cmd_to_open=nil
104
+ if options[:refresh] and RUBY_PLATFORM =~ /darwin/
105
+ cmd_to_open='tell application "Safari" to set URL of current tab of front window to "'+options[:refresh]+'"'
106
+ cmd_to_refresh='tell application "System Events"' + "\n" + 'tell process "Safari"' + "\n" + 'keystroke "r" using {command down}' + "\n" + 'delay 60' + "\n" + 'end tell' + "\n" + 'end tell'
107
+ end
108
+ unless options[:watching]
109
+ ## dyn_file[1..-1] to have a relative path...
110
+ if Dyndoc::Linter.check_file(file_to_process).empty?
111
+ Dyndoc.cli_convert_from_file(dyn_file[1..-1],html_file, opts)
112
+ else
113
+ puts dyn_file[1..-1]+" not well-formed!"
114
+ end
115
+ else
116
+ require 'filewatcher'
117
+ require 'dyndoc-linter'
118
+ FileWatcher.new([file_to_process]).watch() do |filename, event|
119
+ if event == :changed
120
+ if Dyndoc::Linter.check_file(file_to_process).empty?
121
+ Dyndoc.cli_convert_from_file(dyn_file[1..-1],html_file, opts)
122
+ puts dyn_file[1..-1]+" processed!"
123
+ if options[:refresh] and RUBY_PLATFORM =~ /darwin/
124
+ if options[:first]
125
+ `osascript -e '#{cmd_to_open}'`
126
+ options[:first]=nil
127
+ else
128
+ %x{osascript<<ENDREFRESH
129
+ tell app "Safari" to activate
130
+ tell application "System Events"
131
+ keystroke "r" using {command down}
132
+ end tell
133
+ ENDREFRESH
134
+ }
135
+ end
136
+ end
137
+ else
138
+ puts dyn_file[1..-1]+" not well-formed!"
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
data/bin/dyn-html-srv ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dyndoc/init/home'
4
+ dyndoc_home = Dyndoc.home
5
+ ## read config file
6
+ cfg_yml = File.join(dyndoc_home,"etc","dyn-html.yml")
7
+ cfg={}
8
+ cfg.merge! YAML::load_file(cfg_yml) if File.exist? cfg_yml
9
+
10
+ require 'thin'
11
+ arg=["-R",File.join(dyndoc_home,"html-srv","dyn-html-srv.ru")]
12
+ if cfg["html-srv-port"]
13
+ arg += ["-p",cfg["html-srv-port"].to_s]
14
+ elsif (i=ARGV.index("-p"))
15
+ arg += ["-p",ARGV[i+1]]
16
+ end
17
+ arg << "start"
18
+ p [:arg,arg]
19
+ Thin::Runner.new(arg).run!
data/bin/dyn-init CHANGED
@@ -1,28 +1,67 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'fileutils'
3
+ require 'dyndoc/init/home'
3
4
 
4
5
  arg=ARGV[0]
5
6
  arg="path" if !arg or arg.empty?
6
7
 
8
+ share_path=File.expand_path("../../share", __FILE__)
9
+
7
10
  case arg
8
11
  when "help"
9
12
  puts <<-DOC
10
13
  Usage:
11
- ## create ~/dyndoc folder and initialize some sharing
12
- dyn-init path
13
- ## add room folder
14
- dyn-init sync <room_id>:<room_folder_full_path>@<room_remote_wordir>
14
+ ## get dyndoc home (i.e, ~/dyndoc or read config file ~/.dyndoc_home)
15
+ dyn-init home
16
+ ## set dyndoc home (update ~/.dyndoc_home)
17
+ dyn-init home <other dyndoc home path>
18
+ dyn-init home <other dyndoc home path> --init #with init path
19
+ ## create dyndoc home folder and initialize some sharing
20
+ dyn-init [path]
21
+ dyn-init --reset #reset dyndoc home folder
22
+ ## without creating dyndoc home folder, initialize some sharing
23
+ dyn-init install [all|etc|demo|html-srv|dyndoc.yml]
15
24
  DOC
16
- when "path"
17
- share_path=File.expand_path("../../share", __FILE__)
18
- dyndoc_path=File.join(ENV["HOME"],"dyndoc")
25
+ ## REMOVED from DOC above since maybe it is OBSOLETE
26
+ #### ## add room folder
27
+ #### dyn-init sync <room_id>:<room_folder_full_path>@<room_remote_wordir>
28
+ when "home"
29
+ if ARGV.length == 2 or (ARGV.length==3 and ["--init"].include? ARGV[2])
30
+ Dyndoc.home=ARGV[1]
31
+ FileUtils.mkdir_p Dyndoc.home
32
+ FileUtils.cp_r File.join(share_path,"."),Dyndoc.home if ARGV[2]=="--init"
33
+ end
34
+ unless File.directory? Dyndoc.home
35
+ puts "Folder #{Dyndoc.home} does not exist. \nDo you want to initialize (YES|no)?"
36
+ if STDIN.gets.chomp == "YES"
37
+ FileUtils.cp_r File.join(share_path,"."),Dyndoc.home
38
+ end
39
+ end
40
+ puts "dyndoc home set to #{Dyndoc.home}"+((ARGV.length==3 and ARGV[2]=="--init") ? " with paths initialization" : "" )
41
+ when "path","--reset"
42
+ dyndoc_path=Dyndoc.home
43
+ if arg=="--reset"
44
+ puts "Do you really want to reset the dyndoc home (YES|no)?"
45
+ if STDIN.gets.chomp=="YES" and File.directory? dyndoc_path
46
+ FileUtils.rm_rf dyndoc_path
47
+ end
48
+ end
19
49
  unless File.exist? dyndoc_path
20
50
  FileUtils.mkdir_p dyndoc_path
21
51
  FileUtils.cp_r File.join(share_path,"."),dyndoc_path
52
+ puts "Your dyndoc home now contains at least the default settings!"
22
53
  else
23
54
  puts "Warning: #{dyndoc_path} folder already exists!"
55
+ puts "Try: dyn-init install [all|etc|demo|html-srv|dyndoc.yml]"
56
+ end
57
+ when "install"
58
+ case ARGV[1].strip
59
+ when "all"
60
+ FileUtils.cp_r File.join(share_path,"."),Dyndoc.home
61
+ when "etc","demo","html-srv","dyndoc.yml"
62
+ FileUtils.cp_r File.join(share_path,ARGV[1].strip),Dyndoc.home
24
63
  end
25
- when "sync"
64
+ when "sync" ## MAYBE OBSOLETE!
26
65
  require 'fileutils'
27
66
  FileUtils.mkdir_p (etc=File.join(ENV["HOME"],"dyndoc","etc"))
28
67
  room_sync=File.join(etc,".room_sync")
@@ -56,6 +56,12 @@ module Dyndoc
56
56
  end
57
57
 
58
58
  ## TODO: a config.yml file for the site
59
+ ## NOTE: Mode multipage works as follows:
60
+ ## 1) "only:" can have a list of tags from "docs:" which is put inside opts[:doc_tag]
61
+ ## 2) In order to process files properly for this list of tags inside opts[:doc_tag]
62
+ ## cfg[:tag] and dyn_tags are replace with "__ALL_DOC_TAG__" instead of opts[:doc_tag]
63
+ ## Since are __ALL_DOC_TAG__ is replaced by the current tag for each file to be processed, everything goes well!
64
+
59
65
  def Dyndoc.cli_convert_from_file(dyn_file,html_file,opts={}) #ex: opts={dyn_root: , html_root:, user: , doc_tag: }
60
66
  addr="127.0.0.1"
61
67
 
@@ -80,7 +86,7 @@ module Dyndoc
80
86
  basename: File.basename(dyn_file,".*"),
81
87
  long_url: html_file,
82
88
  url: File.basename(html_file,".*"),
83
- tag: opts[:doc_tag],
89
+ tag: opts[:doc_tag],
84
90
  urls: html_files
85
91
  }
86
92
 
@@ -186,6 +192,7 @@ module Dyndoc
186
192
 
187
193
  ## mode multi-documents
188
194
  docs_tags=[]
195
+ ## since opts[:doc_tag] can have more than one tag it is replaced with __ALL_DOC_TAG__ that is replaced before processing with the proper tag
189
196
  docs_tags << opts[:doc_tag] if opts[:doc_tag]
190
197
  ## complete docs_tags with cfg["tags"]
191
198
  docs_tags += (cfg["tags"]||"").split(",").map{|e| e.strip}
@@ -201,7 +208,8 @@ module Dyndoc
201
208
  end
202
209
  code += "\n" + dyn_post_code if dyn_post_code
203
210
  ## TO TEST!!!
204
- ##Dyndoc.warn :cfg,cfg
211
+ ##
212
+ Dyndoc.warn :cfg,cfg
205
213
  ##Dyndoc.warn :page,page
206
214
  code = "[#rb<]require 'ostruct';cfg = OpenStruct.new(" + cfg.inspect + ");page = OpenStruct.new(" + page.inspect + ")[#>]" +code
207
215
  code = dyn_tags + code if dyn_tags
@@ -220,9 +228,9 @@ module Dyndoc
220
228
  unless opts[:doc_tag] == "__ALL_DOC_TAG__"
221
229
  Dyndoc.process_html_file_from_dyn_file(code,html_file,dyn_file,dyn_layout,addr,dyndoc_start)
222
230
  else
223
- html_files.keys[1..-1].each do |doc_tag|
231
+ (opts[:current_tags] || html_files.keys[1..-1]).each do |doc_tag|
224
232
  html_file=File.join(html_root,["users",opts[:user]] || [],cfg_files[:urls][doc_tag])
225
- p [:html_multi,doc_tag,html_file]
233
+ p [:html_multi,doc_tag,html_file] #,code.gsub(/__ALL_DOC_TAG__/,doc_tag)]
226
234
  Dyndoc.process_html_file_from_dyn_file(code.gsub(/__ALL_DOC_TAG__/,doc_tag),html_file,dyn_file,dyn_layout,addr,dyndoc_start)
227
235
  end
228
236
  end
data/lib/dyndoc-edit.rb CHANGED
@@ -1,4 +1,25 @@
1
1
  module Dyndoc
2
+ module FileWatcher ## USED by dyn-html
3
+
4
+ def FileWatcher.get_dyn_html_info(filename,dyn_file,user)
5
+ content=File.read(filename)
6
+ current_tags=[] #select current tags from doc_tags_info
7
+ doc_tags_info=Dyndoc::Edit.get_doc_tags_info(content,current_tags)
8
+ ##p [:fw_current_tags, current_tags]
9
+ doc_tag=(doc_tags_info.empty? ? "" : "__ALL_DOC_TAG__")
10
+ #p [:dyn_file,dyn_file,$1]
11
+ tmp=dyn_file.split("/")
12
+ user=tmp[2] if tmp[1]=="users"
13
+ ##p [:fw_user,user]
14
+ html_files=Dyndoc::Edit.html_files({doc_tags_info: doc_tags_info , dyn_file: dyn_file },user)
15
+
16
+ current_tags=html_files.keys[1..-1] if doc_tag=="__ALL_DOC_TAG__" and current_tags.empty?
17
+ current_doc_tag=(current_tags.empty? ? doc_tag : current_tags[0])
18
+ {html_files: html_files, doc_tag: doc_tag, user: user, current_doc_tag: current_doc_tag, current_tags: current_tags}
19
+ end
20
+
21
+ end
22
+
2
23
  module Edit
3
24
 
4
25
  def Edit.docs_from_doc_tags_info(doc_tags_info)
@@ -13,15 +34,28 @@ module Edit
13
34
  return docs
14
35
  end
15
36
 
16
- def Edit.get_doc_tags_info(content)
37
+ ## if selected_tag is an Array, allow to get current tags to proces
38
+ def Edit.get_doc_tags_info(content,current_tags=nil)
17
39
  doc_tags_info=""
18
40
  if content =~ /^\-{3}/
19
- b=content.split(/^(\-{3,})/,-1)
20
- if b[0].empty? and b.length>4
21
- tmp=b[2].strip.split("\n").select{|e2| e2.strip =~/^docs\:/}
22
- doc_tags_info=tmp[0] || ""
23
- doc_tags_info=$1.strip if doc_tags_info =~ /^docs\:(.*)/
41
+ b=content.split(/^(\-{3,})/,-1)
42
+ if b[0].empty? and b.length>4
43
+ tmp=b[2].strip.split("\n").select{|e2| e2.strip =~/^docs\:/}
44
+ doc_tags_info=tmp[0] || ""
45
+ doc_tags_info=$1.strip if doc_tags_info =~ /^docs\:(.*)/
46
+
47
+ tmp=b[2].strip.split("\n").select{|e2| e2.strip =~/^only\:/}
48
+ current_tag_info=tmp[0] || ""
49
+ current_tag_info=$1.strip if current_tag_info =~ /^only\:(.*)/
50
+ p [:only_tag,current_tag_info]
51
+ ## added possibility select current tags only when current_tags is provided as an Array
52
+ if tmp[0] and current_tags and current_tags.is_a? Array
53
+ doc_tags=Edit.get_doc_tags(doc_tags_info)
54
+ current_tag_info.split(",").map{|e| e.strip}.each{|e| current_tags << e if doc_tags.include? e}
55
+ ##p [:only_current_tags,current_tags]
24
56
  end
57
+
58
+ end
25
59
  end
26
60
  return doc_tags_info
27
61
  end
@@ -0,0 +1,165 @@
1
+ require "roda"
2
+ require "pathname"
3
+
4
+ ## read config file
5
+ require 'dyndoc/init/home'
6
+ dyndoc_home = Dyndoc.home
7
+ cfg_yml = File.join(dyndoc_home,"etc","dyn-html.yml")
8
+ cfg={}
9
+ cfg.merge! YAML::load_file(cfg_yml) if File.exist? cfg_yml
10
+ root = cfg["root"] || File.join(ENV["HOME"],"RCqls","RodaServer")
11
+ $public_root = cfg["public_root"] || File.join(root ,"public")
12
+ ##p [:public_root,$public_root]
13
+
14
+ class App < Roda
15
+ use Rack::Session::Cookie, :secret => (secret="Thanks like!")
16
+ plugin :static, ["/pages","/private","/tools"], :root => $public_root
17
+ #opts[:root]=File.expand_path("..",__FILE__),
18
+ #plugin :static, ["/pages","/private"]
19
+ plugin :multi_route
20
+ ###Dir[File.expand_path("../routes/*.rb",__FILE__)].each{|f| require f}
21
+ plugin :header_matchers
22
+ plugin :render,
23
+ :views => File.expand_path("../views",__FILE__),
24
+ :escape=>true,
25
+ :check_paths=>true,
26
+ :allowed_paths=>[File.expand_path("../views",__FILE__),$public_root]
27
+ # plugin :csrf,
28
+ # :skip => [
29
+ # "POST:/edit/dyn",
30
+ # "POST:/edit/save",
31
+ # "POST:/edit/change-all-dyn-files",
32
+ # "POST:/edit/add_delete_dyn_file",
33
+ # "POST:/edit/add_delete_user",
34
+ # "POST:/edit/add_user_dyn_file",
35
+ # "POST:/edit/delete_user_dyn_file",
36
+ # "POST:/edit/update_doc_tags_info"
37
+ # ],
38
+ # :skip_if => lambda{|req| req.env['CONTENT_TYPE'] =~ /application\/json/}
39
+
40
+ # plugin :rodauth, :name=>:editor, :json=>true do
41
+ # db DB
42
+ # enable :login, :logout
43
+ # account_password_hash_column :ph
44
+ # session_key :user_id
45
+ # login_label 'Email'
46
+ # password_label 'Mot de passe'
47
+ # login_redirect "/editor"
48
+ # end
49
+
50
+ # plugin :rodauth, :name=>:compte, :json=>true do
51
+ # db DB
52
+ # enable :change_login, :change_password, :close_account, :create_account,
53
+ # :lockout, :login, :logout #, :remember, :reset_password,
54
+ # #:verify_account,
55
+ # #:otp, :recovery_codes, :sms_codes,
56
+ # :password_complexity #,
57
+ # #:disallow_password_reuse, :password_expiration, :password_grace_period,
58
+ # #:account_expiration,
59
+ # #:single_session,
60
+ # #:jwt, :session_expiration,
61
+ # #:verify_account_grace_period, :verify_change_login
62
+ # create_account_link do
63
+ # "<p><a href=\"/compte/create-account\">Créer un nouveau compte</a></p>"
64
+ # end
65
+ # login_redirect "/editor"
66
+ # after_login do
67
+ # puts session[:user_id]
68
+ # end
69
+ # logout_redirect "/editor"
70
+ # create_account_redirect "/compte"
71
+ # session_key :user_id
72
+ # login_label "Email"
73
+ # password_label "Mot de passe"
74
+ # login_confirm_label "Confirme Email"
75
+ # password_confirm_label "Confirme Mot de passe"
76
+ # create_account_button "Création compte"
77
+ # max_invalid_logins 2
78
+ # #allow_password_change_after 60
79
+ # #verify_account_grace_period 300
80
+ # account_password_hash_column :ph
81
+ # title_instance_variable :@page_title
82
+ # delete_account_on_close? true
83
+ # #only_json? false
84
+ # #jwt_secret secret
85
+ # # sms_send do |phone_number, message|
86
+ # # MUTEX.synchronize{SMS[session_value] = "Would have sent the following SMS to #{phone_number}: #{message}"}
87
+ # # end
88
+ # end
89
+
90
+
91
+
92
+ route do |r|
93
+
94
+ # GET / request
95
+ r.root do
96
+ r.redirect "/hello"
97
+ end
98
+
99
+ #r.multi_route
100
+
101
+ # /hello branch
102
+ r.on "hello" do
103
+ # Set variable for all routes in /hello branch
104
+ @greeting = 'Hello'
105
+
106
+ # GET /hello/world request
107
+ r.get "world" do
108
+ "#{@greeting} world!"
109
+ end
110
+
111
+ # /hello request
112
+ r.is do
113
+ # GET /hello request
114
+ r.get do
115
+ "#{@greeting}!"
116
+ end
117
+
118
+ # POST /hello request
119
+ r.post do
120
+ puts "Someone said #{@greeting}!"
121
+ r.redirect
122
+ end
123
+ end
124
+ end
125
+
126
+ r.on "get" do
127
+ rsrc=r.remaining_path
128
+ #p [:get,rsrc]
129
+ static_root=File.join($public_root,"tools")
130
+ if (rsrc=~/[^\.]*\.(?:css|js|rb|red|r|R|RData|rdata|rds|csv|txt|xls|xlsx|jpeg|jpg|png|gif)/)
131
+ rsrc_files=Dir[File.join(static_root,"**",rsrc)]
132
+ ##p rsrc_files
133
+ unless rsrc_files.empty?
134
+ rsrc_file="/tools/"+Pathname(rsrc_files[0]).relative_path_from(Pathname(static_root)).to_s
135
+ r.redirect rsrc_file
136
+ end
137
+ end
138
+ "No resource #{rsrc} to serve!"
139
+ end
140
+
141
+ r.get do
142
+ page=r.remaining_path
143
+ static_root=File.join($public_root,"pages")
144
+ ##p [:page,File.join(static_root,"**",page+".html")]
145
+ pattern=(page=~/[^\.]*\.(?:R|Rmd|css|js|html|html|rb|red|r|jpeg|jpg|png|gif)/) ? page : page+".html"
146
+ html_files=Dir[File.join(static_root,"**",pattern)]
147
+ ##p html_files
148
+ unless html_files.empty?
149
+ html_file="pages/"+Pathname(html_files[0]).relative_path_from(Pathname(static_root)).to_s
150
+ if File.extname(html_file) == ".html"
151
+ html_file=File.join(File.dirname(html_file),File.basename(html_file,".html"))
152
+ p html_file
153
+ render html_file, :engine=>'html', :views=>$public_root
154
+ else
155
+ r.redirect html_file
156
+ end
157
+ else
158
+ "no #{page} to serve!"
159
+ end
160
+ end
161
+
162
+ end
163
+ end
164
+
165
+ run App.freeze.app
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: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - CQLS
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-20 00:00:00.000000000 Z
11
+ date: 2016-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: R4rb
@@ -103,6 +103,7 @@ executables:
103
103
  - dyn-srv
104
104
  - dpm
105
105
  - dyn-html
106
+ - dyn-html-srv
106
107
  - dyn-init
107
108
  - dyn-scan
108
109
  - dyn-lint
@@ -115,6 +116,8 @@ files:
115
116
  - bin/dyn-env
116
117
  - bin/dyn-forever
117
118
  - bin/dyn-html
119
+ - bin/dyn-html-onefile
120
+ - bin/dyn-html-srv
118
121
  - bin/dyn-init
119
122
  - bin/dyn-lint
120
123
  - bin/dyn-scan
@@ -383,6 +386,7 @@ files:
383
386
  - share/etc/uv/syntax/text.xml.syntax
384
387
  - share/etc/uv/syntax/text.xml.xsl.syntax
385
388
  - share/etc/uv/uv.rb
389
+ - share/html-srv/dyn-html-srv.ru
386
390
  - install/README.md
387
391
  - install/dyn-upstart.sh
388
392
  - install/dyndoc_install_ubuntu.sh