dyndoc-ruby 0.9.3 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/dyn-forever +159 -7
- data/bin/dyn-html +16 -117
- data/bin/{dyn-html-onefile → dyn-html-fw-onefile} +1 -1
- data/bin/dyn-http +17 -0
- data/bin/dyn-srv +14 -1
- data/bin/{dyn-env → dyn-win-env} +0 -0
- data/lib/dyndoc-html-servers.rb +103 -0
- metadata +23 -8
- data/bin/dyn-html-srv +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79b4ca5f20589fb0b08d6fe79c421afe12426110
|
4
|
+
data.tar.gz: 4e78227c3d20949e46ffa04d65394d07024eee7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b5cd10ab3476e5bf25c11f52454a97a758251fd1d1ba0fa1aa5d1b1d4f6de5109384b9b304784d9e22c847b7052b42eafaeaf68dbacf77cc38ddb703de9664d
|
7
|
+
data.tar.gz: cd0fe4d247fa316ed6fb61ecf5e5e8ea26356ed38947013f5e4ade5858081448cea7a41acf15bd6eac4ff1f5e8017cef1d6877dc6658921e155e9746c42123d1
|
data/bin/dyn-forever
CHANGED
@@ -1,14 +1,166 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
-
|
4
|
-
require
|
3
|
+
## THIS IS AN ADAPTATION OF FOREVERB (https://github.com/DAddYE/foreverb) TO DYN
|
4
|
+
require 'rubygems' unless defined?(Gem)
|
5
|
+
require 'thor'
|
6
|
+
require 'yaml'
|
7
|
+
require 'fileutils'
|
8
|
+
require 'dyndoc/init/home'
|
5
9
|
|
6
|
-
|
7
|
-
|
8
|
-
|
10
|
+
DYN_FOREVER_PATH = ENV['DYN_FOREVER_PATH'] ||= File.expand_path(Dyndoc.home,"etc","dyn-foreverb.yml") unless defined?(DYN_FOREVER_PATH)
|
11
|
+
|
12
|
+
class CLI < Thor
|
13
|
+
|
14
|
+
desc "list", "List Forever running daemons"
|
15
|
+
method_option :monitor, :type => :boolean, :aliases => "-m", :default => false, :desc => "Show memory and cpu usage with ps"
|
16
|
+
def list
|
17
|
+
say "Your config is empty, so no deamons was found.", :red if config.empty? && !options.monitor
|
18
|
+
|
19
|
+
if options.monitor
|
20
|
+
print_table([%w(PID RSS CPU CMD), *ps])
|
21
|
+
else
|
22
|
+
config.each do |conf|
|
23
|
+
status = begin
|
24
|
+
pid = File.read(conf[:pid]).to_i
|
25
|
+
Process.kill(0, pid)
|
26
|
+
"RUNNING"
|
27
|
+
rescue Errno::ESRCH, Errno::ENOENT
|
28
|
+
"NOT RUNNING"
|
29
|
+
rescue Errno::EPERM
|
30
|
+
"RUNNING"
|
31
|
+
end
|
32
|
+
say_status status, conf[:file], status =~ /^RUNNING/ ? :green : :red
|
33
|
+
end
|
34
|
+
say "Reading config from: #{DYN_FOREVER_PATH}", :blue
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "stop [DAEMON] [--all] [--yes]", "Stop one or more matching daemons"
|
39
|
+
method_option :all, :type => :boolean, :aliases => "-a", :desc => "All matching daemons"
|
40
|
+
method_option :yes, :type => :boolean, :aliases => "-y", :desc => "Don't ask permission to kill daemon"
|
41
|
+
def stop(daemon=nil)
|
42
|
+
find(daemon, :multiple => options.all).each do |conf|
|
43
|
+
stop_daemon(conf) if options.yes || yes?("Do you want really stop \e[1m#{conf[:file]}\e[0m?")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "kill [DAEMON] [--all] [--yes]", "Kill one or more matching daemons"
|
48
|
+
method_option :all, :type => :boolean, :aliases => "-a", :desc => "All matching daemons"
|
49
|
+
method_option :yes, :type => :boolean, :aliases => "-y", :desc => "Don't ask permission to kill daemon"
|
50
|
+
def kill(daemon=nil)
|
51
|
+
find(daemon, :multiple => options.all).each do |conf|
|
52
|
+
if options.yes || yes?("Do you want really kill \e[1m#{conf[:file]}\e[0m?")
|
53
|
+
say_status "KILLING", conf[:file]
|
54
|
+
begin
|
55
|
+
pid = File.read(conf[:pid]).to_i
|
56
|
+
Process.kill(:INT, pid)
|
57
|
+
rescue Exception => e
|
58
|
+
say_status "ERROR", e.message, :red
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "start [DAEMON] [--all] [--yes]", "Start one or more matching daemons"
|
65
|
+
method_option :all, :type => :boolean, :aliases => "-a", :desc => "All matching daemons"
|
66
|
+
method_option :yes, :type => :boolean, :aliases => "-y", :desc => "Don't ask permission to start the daemon"
|
67
|
+
def start(daemon=nil)
|
68
|
+
find(daemon, :multiple => options.all).each do |conf|
|
69
|
+
system(conf[:file]) if options.yes || yes?("Do you want really start \e[1m#{conf[:file]}\e[0m?")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
desc "restart [DAEMON] [--all] [--yes]", "Restart one or more matching daemons"
|
74
|
+
method_option :all, :type => :boolean, :aliases => "-a", :desc => "All matching daemons"
|
75
|
+
method_option :yes, :type => :boolean, :aliases => "-y", :desc => "Don't ask permission to start the daemon"
|
76
|
+
def restart(daemon=nil)
|
77
|
+
invoke :start
|
9
78
|
end
|
10
|
-
|
11
|
-
|
79
|
+
|
80
|
+
desc "tail [DAEMON]", "Tail log of first matching daemon"
|
81
|
+
method_option :lines, :aliases => "-n", :default => 150, :desc => "How many lines show?"
|
82
|
+
def tail(daemon)
|
83
|
+
found = find(daemon)[0]
|
84
|
+
return unless found
|
85
|
+
system "tail -f -n #{options.lines} #{found[:log]}"
|
86
|
+
end
|
87
|
+
|
88
|
+
desc "update [DAEMON] [--all] [--yes]", "Update config from one or more matching daemons"
|
89
|
+
method_option :all, :type => :boolean, :aliases => "-a", :desc => "All matching daemons"
|
90
|
+
method_option :yes, :type => :boolean, :aliases => "-y", :desc => "Don't ask permission to start the daemon"
|
91
|
+
def update(daemon=nil)
|
92
|
+
match = find(daemon, :multiple => options.all)
|
93
|
+
return if match.empty?
|
94
|
+
FileUtils.rm_rf(DYN_FOREVER_PATH)
|
95
|
+
match.each do |conf|
|
96
|
+
system(conf[:file], 'update') if options.yes || yes?("Do you want really update config from \e[1m#{conf[:file]}\e[0m?")
|
97
|
+
end
|
12
98
|
end
|
13
99
|
|
100
|
+
desc "remove [DAEMON] [--all]", "Remove the config of a daemon from foreverb"
|
101
|
+
method_option :all, :type => :boolean, :aliases => "-a", :desc => "All matching daemons"
|
102
|
+
method_option :yes, :type => :boolean, :aliases => "-y", :desc => "Don't ask permission to remove the daemon"
|
103
|
+
def remove(daemon=nil)
|
104
|
+
say "You must provide a daemon name or provide --all option", :red and return if daemon.nil? && !options.all
|
105
|
+
new_config = config.delete_if do |conf|
|
106
|
+
if conf[:file] =~ /#{daemon}/
|
107
|
+
if options.yes || yes?("Do you really want to remove the daemon \e[1m#{conf[:file]}\e[0m?")
|
108
|
+
stop_daemon(conf)
|
109
|
+
say "\e[1m#{conf[:file]}\e[0m removed."
|
110
|
+
true
|
111
|
+
else
|
112
|
+
say "\e[1m#{conf[:file]}\e[0m remains on the list."
|
113
|
+
false
|
114
|
+
end
|
115
|
+
else
|
116
|
+
false
|
117
|
+
end
|
118
|
+
end
|
119
|
+
write_config! new_config
|
120
|
+
end
|
121
|
+
|
122
|
+
private
|
123
|
+
def find(daemon, options={})
|
124
|
+
multiple = options.delete(:multiple)
|
125
|
+
say "You must provide a daemon name or provide --all option", :red and return [] if daemon.nil? && !multiple
|
126
|
+
found = multiple ? config : config.find_all { |conf| conf[:file] =~ /#{daemon}/ }
|
127
|
+
say "Daemon(s) matching '#{daemon}' not found", :red if found.empty? && !daemon.nil?
|
128
|
+
say "Daemons not found", :red if found.empty? && nil && daemon.nil?
|
129
|
+
found
|
130
|
+
end
|
131
|
+
|
132
|
+
def find_all(daemon)
|
133
|
+
find(daemon, :multiple => true)
|
134
|
+
end
|
135
|
+
|
136
|
+
def config
|
137
|
+
File.exist?(DYN_FOREVER_PATH) ? YAML.load_file(DYN_FOREVER_PATH) : []
|
138
|
+
end
|
139
|
+
|
140
|
+
def ps
|
141
|
+
# This is horrible command, but how we can keep compatiblity between darwin and *unix ?
|
142
|
+
result = `ps axo pid,rss,pcpu,command | grep -vE "^USER|grep" | grep Forever: | awk '{print $1"\t"$2"\t"$3"\t"$4" "$5" "$6}'`
|
143
|
+
result = result.chomp.split("\n").map { |line| line.split("\t") }
|
144
|
+
result = result.sort { |a,b| b[1].to_i <=> a[1].to_i }
|
145
|
+
result.each { |column| column[1] = "%d Mb" % [column[1].to_i / 1024] }
|
146
|
+
result.each { |column| column[2] = "%s %" % [column[2]] }
|
147
|
+
result
|
148
|
+
end
|
149
|
+
|
150
|
+
def write_config!(new_config)
|
151
|
+
File.open(DYN_FOREVER_PATH, "w") { |f| f.write new_config.to_yaml }
|
152
|
+
end
|
153
|
+
|
154
|
+
def stop_daemon(conf)
|
155
|
+
say_status "STOPPING", conf[:file]
|
156
|
+
begin
|
157
|
+
pid = File.read(conf[:pid]).to_i
|
158
|
+
Process.kill(:INT, pid)
|
159
|
+
rescue Exception => e
|
160
|
+
say_status "ERROR", e.message, :red
|
161
|
+
end
|
162
|
+
end
|
14
163
|
end
|
164
|
+
|
165
|
+
ARGV << "-h" if ARGV.empty?
|
166
|
+
CLI.start(ARGV)
|
data/bin/dyn-html
CHANGED
@@ -1,120 +1,19 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require 'dyndoc-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
## To put inside yaml config file!
|
18
|
-
root = cfg["root"] || File.join(ENV["HOME"],"RCqls","RodaServer")
|
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")
|
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"
|
24
|
-
|
25
|
-
args=ARGV
|
26
|
-
|
27
|
-
require 'optparse'
|
28
|
-
|
29
|
-
$VERBOSE = nil
|
30
|
-
|
31
|
-
options={first: true}
|
32
|
-
|
33
|
-
OptionParser.new do |opts|
|
34
|
-
opts.banner = "Usage: dyn-html"
|
35
|
-
end.parse!(args)
|
36
|
-
|
37
|
-
## Mandatory input
|
38
|
-
# dyn_file=args[0]
|
39
|
-
# doc_tag="" unless doc_tag
|
40
|
-
# doc_tag="__ALL_DOC_TAG__" if doc_tag.downcase == "all"
|
41
|
-
|
42
|
-
## Detect docs_tags_info
|
43
|
-
# dyn_file=File.join(["","users",current_email],dyn_file) unless dyn_file[0,1]=="/"
|
44
|
-
# filename=File.join(edit_root,dyn_file)
|
45
|
-
|
46
|
-
### doc_tags_info=Dyndoc::Edit.get_doc_tags_info(File.read(filename))
|
47
|
-
|
48
|
-
### if dyn_file and (dyn_file=~/(.*)(?:\.dyn|_html.dyn)$/)
|
49
|
-
#p [:dyn_file,dyn_file,$1]
|
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[""]
|
53
|
-
|
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
|
57
|
-
|
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?
|
62
|
-
|
63
|
-
# Ex for opts:
|
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"}}]
|
65
|
-
# 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"}}]
|
66
|
-
opts = {
|
67
|
-
dyn_root: edit_root,
|
68
|
-
html_root: pages_root,
|
69
|
-
user: current_email
|
70
|
-
}
|
71
|
-
##p opts
|
72
|
-
### file_to_process=File.join(opts[:dyn_root],dyn_file)
|
73
|
-
cmd_to_open=nil
|
74
|
-
if RUBY_PLATFORM =~ /darwin/
|
75
|
-
|
76
|
-
end
|
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
|
105
|
-
%x{osascript<<ENDREFRESH
|
106
|
-
tell app "Safari" to activate
|
107
|
-
tell application "System Events"
|
108
|
-
keystroke "r" using {command down}
|
109
|
-
end tell
|
110
|
-
ENDREFRESH
|
111
|
-
}
|
112
|
-
end
|
113
|
-
end
|
114
|
-
else
|
115
|
-
puts dyn_file[1..-1]+" not well-formed!"
|
116
|
-
end
|
117
|
-
end
|
2
|
+
require 'dyndoc-html-servers'
|
3
|
+
|
4
|
+
if ["--no-forever","--no-daemon"].include? ARGV[0]
|
5
|
+
cfg={}
|
6
|
+
cfg[:dyn_root]=ARGV[1] if ARGV[1]
|
7
|
+
Dyndoc::HtmlServers.dyn_html_filewatcher(cfg)
|
8
|
+
else
|
9
|
+
require 'daemons'
|
10
|
+
require 'dyndoc/init/home'
|
11
|
+
require 'fileutils'
|
12
|
+
|
13
|
+
dir_pids=File.join(Dyndoc.home,"pids")
|
14
|
+
FileUtils.mkdir_p dir_pids
|
15
|
+
Daemons.run_proc('dyn-html',{dir: dir_pids}) do
|
16
|
+
Dyndoc::HtmlServers.dyn_html_filewatcher
|
118
17
|
end
|
119
18
|
|
120
|
-
|
19
|
+
end
|
@@ -19,7 +19,7 @@ cfg=YAML::load_file(cfg_yml) if File.exist? cfg_yml
|
|
19
19
|
|
20
20
|
## To put inside yaml config file!
|
21
21
|
root = cfg["root"] || File.join(ENV["HOME"],"RCqls","RodaServer")
|
22
|
-
edit_root = cfg["edit_root"] || File.join(root ,"edit")
|
22
|
+
edit_root = cfg["src_root"] || cfg["edit_root"] || File.join(root ,"edit")
|
23
23
|
public_root = cfg["public_root"] || File.join(root ,"public")
|
24
24
|
pages_root = File.join(public_root ,"pages")
|
25
25
|
current_email = cfg["email"] || "rdrouilh@gmail.com" #default email user can be overriden by -u option
|
data/bin/dyn-http
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'dyndoc-html-servers'
|
3
|
+
|
4
|
+
if ["--no-forever","--no-daemon"].include? ARGV[0]
|
5
|
+
Dyndoc::HtmlServers.dyn_http_server
|
6
|
+
else
|
7
|
+
require 'daemons'
|
8
|
+
require 'dyndoc/init/home'
|
9
|
+
require 'fileutils'
|
10
|
+
|
11
|
+
dir_pids=File.join(Dyndoc.home,"pids")
|
12
|
+
FileUtils.mkdir_p dir_pids
|
13
|
+
Daemons.run_proc('dyn-http',{dir: dir_pids}) do
|
14
|
+
Dyndoc::HtmlServers.dyn_http_server
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/bin/dyn-srv
CHANGED
@@ -2,4 +2,17 @@
|
|
2
2
|
|
3
3
|
require "dyndoc/srv/interactive-server"
|
4
4
|
|
5
|
-
|
5
|
+
if ["--no-forever","--no-daemon"].include? ARGV[0]
|
6
|
+
Dyndoc::InteractiveServer.new.run
|
7
|
+
else
|
8
|
+
require 'daemons'
|
9
|
+
require 'dyndoc/init/home'
|
10
|
+
require 'fileutils'
|
11
|
+
|
12
|
+
dir_pids=File.join(Dyndoc.home,"pids")
|
13
|
+
FileUtils.mkdir_p dir_pids
|
14
|
+
Daemons.run_proc('dyn-srv',{dir: dir_pids}) do
|
15
|
+
Dyndoc::InteractiveServer.new.run
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/bin/{dyn-env → dyn-win-env}
RENAMED
File without changes
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'dyndoc/init/home'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module Dyndoc
|
5
|
+
module HtmlServers
|
6
|
+
|
7
|
+
@@cfg=nil
|
8
|
+
|
9
|
+
def HtmlServers.cfg
|
10
|
+
unless @@cfg
|
11
|
+
dyndoc_home = Dyndoc.home
|
12
|
+
cfg_yml = File.join(dyndoc_home,"etc","dyn-html.yml")
|
13
|
+
@@cfg=(File.exist? cfg_yml) ? YAML::load_file(cfg_yml) : {}
|
14
|
+
@@cfg["dyndoc_home"]=dyndoc_home
|
15
|
+
end
|
16
|
+
@@cfg
|
17
|
+
end
|
18
|
+
|
19
|
+
def HtmlServers.dyn_http_server(host=nil,port="9292")
|
20
|
+
require 'thin'
|
21
|
+
arg=["-R",File.join(HtmlServers.cfg["dyndoc_home"],"html-srv","dyn-html-srv.ru")]
|
22
|
+
if port
|
23
|
+
arg += ["-p",port]
|
24
|
+
elsif HtmlServers.cfg["html-srv-port"]
|
25
|
+
arg += ["-p",HtmlServers.cfg["html-srv-port"].to_s]
|
26
|
+
end
|
27
|
+
if host
|
28
|
+
arg += ["-a",host]
|
29
|
+
elsif HtmlServers.cfg["html-srv-host"]
|
30
|
+
arg += ["-a",HtmlServers.cfg["html-srv-host"].to_s]
|
31
|
+
end
|
32
|
+
arg << "start"
|
33
|
+
##p [:arg,arg]
|
34
|
+
Thin::Runner.new(arg).run!
|
35
|
+
end
|
36
|
+
|
37
|
+
def HtmlServers.dyn_html_filewatcher(cfg={}) #cfg
|
38
|
+
require 'dyndoc-convert'
|
39
|
+
require 'dyndoc-edit'
|
40
|
+
require 'filewatcher'
|
41
|
+
require 'dyndoc-linter'
|
42
|
+
$VERBOSE = nil
|
43
|
+
options={first: true}
|
44
|
+
## To put inside yaml config file!
|
45
|
+
root ||= cfg["root"] || HtmlServers.cfg["root"] || File.join(ENV["HOME"],"RCqls","RodaServer")
|
46
|
+
dyn_root = cfg["dyn_root"] || HtmlServers.cfg["dyn_root"] || File.join(root ,"edit")
|
47
|
+
public_root = cfg["public_root"] || HtmlServers.cfg["public_root"] || File.join(root ,"public")
|
48
|
+
pages_root = File.join(public_root ,"pages")
|
49
|
+
current_email = cfg["email"] || HtmlServers.cfg["email"] || "rdrouilh@gmail.com" #default email user can be overriden by -u option
|
50
|
+
host=cfg["html-srv-host"] || HtmlServers.cfg["html-srv-host"] || "http://localhost"
|
51
|
+
port=cfg["html-srv-port"] || HtmlServers.cfg["html-srv-port"] || "9292"
|
52
|
+
base_url= host+":"+port
|
53
|
+
|
54
|
+
opts = {
|
55
|
+
dyn_root: dyn_root,
|
56
|
+
html_root: pages_root,
|
57
|
+
user: current_email
|
58
|
+
}
|
59
|
+
|
60
|
+
puts "watching "+ dyn_root
|
61
|
+
old_html_file=""
|
62
|
+
::FileWatcher.new(dyn_root).watch() do |filename, event|
|
63
|
+
##p [:filename,filename]
|
64
|
+
if [:changed,:new].include? event and File.extname(filename) == ".dyn"
|
65
|
+
##p [:filename_event,event,filename]
|
66
|
+
if Dyndoc::Linter.check_file(filename).empty?
|
67
|
+
## find dyn_file (relative path from root)
|
68
|
+
dyn_file="/"+Pathname(filename).relative_path_from(Pathname(dyn_root)).to_s
|
69
|
+
opts_doc=Dyndoc::FileWatcher.get_dyn_html_info(filename,dyn_file,opts[:user])
|
70
|
+
opts.merge! opts_doc
|
71
|
+
##p [:html_files,html_files]
|
72
|
+
|
73
|
+
html_file=opts[:html_files][opts[:current_doc_tag]] # No more default # || html_files[""]
|
74
|
+
##p [:opts,opts,:current_doc_tag,opts[:current_doc_tag]]
|
75
|
+
Dyndoc.cli_convert_from_file(dyn_file[1..-1],html_file, opts)
|
76
|
+
puts dyn_file[1..-1]+" processed!"
|
77
|
+
if RUBY_PLATFORM =~ /darwin/
|
78
|
+
options[:first] = html_file != old_html_file
|
79
|
+
if html_file != old_html_file
|
80
|
+
old_html_file = html_file
|
81
|
+
url=File.join(base_url,html_file)
|
82
|
+
cmd_to_open='tell application "Safari" to set URL of current tab of front window to "'+url+'"'
|
83
|
+
`osascript -e '#{cmd_to_open}'`
|
84
|
+
else
|
85
|
+
%x{osascript<<ENDREFRESH
|
86
|
+
tell app "Safari" to activate
|
87
|
+
tell application "System Events"
|
88
|
+
keystroke "r" using {command down}
|
89
|
+
end tell
|
90
|
+
ENDREFRESH
|
91
|
+
}
|
92
|
+
end
|
93
|
+
end
|
94
|
+
else
|
95
|
+
puts dyn_file[1..-1]+" not well-formed!"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
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.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- RCqls
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: R4rb
|
@@ -94,36 +94,51 @@ dependencies:
|
|
94
94
|
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 3.3.4
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: filewatcher
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.5.3
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.5.3
|
97
111
|
description: |2
|
98
112
|
Provide templating in text document.
|
99
113
|
email: rdrouilh@gmail.com
|
100
114
|
executables:
|
101
115
|
- dyn
|
102
|
-
- dyn-cli
|
103
116
|
- dyn-srv
|
104
117
|
- dpm
|
105
118
|
- dyn-html
|
106
|
-
- dyn-
|
119
|
+
- dyn-http
|
107
120
|
- dyn-init
|
108
121
|
- dyn-scan
|
109
122
|
- dyn-lint
|
123
|
+
- dyn-cli
|
110
124
|
extensions: []
|
111
125
|
extra_rdoc_files: []
|
112
126
|
files:
|
113
127
|
- bin/dpm
|
114
128
|
- bin/dyn
|
115
129
|
- bin/dyn-cli
|
116
|
-
- bin/dyn-env
|
117
130
|
- bin/dyn-forever
|
118
131
|
- bin/dyn-html
|
119
|
-
- bin/dyn-html-onefile
|
120
|
-
- bin/dyn-
|
132
|
+
- bin/dyn-html-fw-onefile
|
133
|
+
- bin/dyn-http
|
121
134
|
- bin/dyn-init
|
122
135
|
- bin/dyn-lint
|
123
136
|
- bin/dyn-scan
|
124
137
|
- bin/dyn-srv
|
138
|
+
- bin/dyn-win-env
|
125
139
|
- lib/dyndoc-convert.rb
|
126
140
|
- lib/dyndoc-edit.rb
|
141
|
+
- lib/dyndoc-html-servers.rb
|
127
142
|
- lib/dyndoc-linter.rb
|
128
143
|
- lib/dyndoc/cli/interactive-client.rb
|
129
144
|
- lib/dyndoc/srv/interactive-server.rb
|
data/bin/dyn-html-srv
DELETED
@@ -1,19 +0,0 @@
|
|
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!
|