bin/dyn-html in dyndoc-ruby-0.9.3 vs bin/dyn-html in dyndoc-ruby-0.9.5
- old
+ new
@@ -1,120 +1,19 @@
#!/usr/bin/env ruby
-require 'dyndoc-convert'
-require 'dyndoc-edit'
-require 'dyndoc/init/home'
-require 'pathname'
+require 'dyndoc-html-servers'
-dyndoc_home = Dyndoc.home
-#p Dyndoc.home
+if ["--no-forever","--no-daemon"].include? ARGV[0]
+ cfg={}
+ cfg[:dyn_root]=ARGV[1] if ARGV[1]
+ Dyndoc::HtmlServers.dyn_html_filewatcher(cfg)
+else
+ require 'daemons'
+ require 'dyndoc/init/home'
+ require 'fileutils'
-cfg_yml = File.join(dyndoc_home,"etc","dyn-html.yml")
-
-cfg={}
-
-cfg=YAML::load_file(cfg_yml) if File.exist? cfg_yml
-
-
-## To put inside yaml config file!
-root = cfg["root"] || File.join(ENV["HOME"],"RCqls","RodaServer")
-edit_root = cfg["edit_root"] || File.join(root ,"edit")
-public_root = cfg["public_root"] || File.join(root ,"public")
-pages_root = File.join(public_root ,"pages")
-current_email = cfg["email"] || "rdrouilh@gmail.com" #default email user can be overriden by -u option
-base_url=cfg["base_url"] || "http://localhost:9292"
-
-args=ARGV
-
-require 'optparse'
-
-$VERBOSE = nil
-
-options={first: true}
-
-OptionParser.new do |opts|
- opts.banner = "Usage: dyn-html"
-end.parse!(args)
-
-## Mandatory input
-# dyn_file=args[0]
-# doc_tag="" unless doc_tag
-# doc_tag="__ALL_DOC_TAG__" if doc_tag.downcase == "all"
-
-## Detect docs_tags_info
-# dyn_file=File.join(["","users",current_email],dyn_file) unless dyn_file[0,1]=="/"
-# filename=File.join(edit_root,dyn_file)
-
-### doc_tags_info=Dyndoc::Edit.get_doc_tags_info(File.read(filename))
-
-### if dyn_file and (dyn_file=~/(.*)(?:\.dyn|_html.dyn)$/)
- #p [:dyn_file,dyn_file,$1]
- ### html_files=Dyndoc::Edit.html_files({doc_tags_info: doc_tags_info , dyn_file: dyn_file },current_email)
- ### ##p [:html_files,html_files]
- ### html_file=html_files[doc_tag] || html_files[""]
-
- ### if options[:refresh] and options[:refresh] == :auto
- ### options[:refresh] = File.join(cfg["localhost_url"] || "http://localhost:9292",File.dirname(dyn_file),File.basename(dyn_file,".*"))
- ### end
-
- ### output=""
- ### output << "Watching "+dyn_file if options[:watching]
- ### output << (options[:watching] ? " and refreshing " : "Refreshing ")+options[:refresh] if options[:refresh]
- ### puts output unless output.empty?
-
-# Ex for opts:
-# 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"}}]
-# 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"}}]
- opts = {
- dyn_root: edit_root,
- html_root: pages_root,
- user: current_email
- }
-##p opts
- ### file_to_process=File.join(opts[:dyn_root],dyn_file)
- cmd_to_open=nil
- if RUBY_PLATFORM =~ /darwin/
-
+ dir_pids=File.join(Dyndoc.home,"pids")
+ FileUtils.mkdir_p dir_pids
+ Daemons.run_proc('dyn-html',{dir: dir_pids}) do
+ Dyndoc::HtmlServers.dyn_html_filewatcher
end
- require 'filewatcher'
- require 'dyndoc-linter'
- puts "watching "+File.join(edit_root)
- old_html_file=""
- FileWatcher.new(edit_root).watch() do |filename, event|
- ##p [:filename,filename]
- if [:changed,:new].include? event and File.extname(filename) == ".dyn"
- ##p [:filename_event,event,filename]
- if Dyndoc::Linter.check_file(filename).empty?
- ## find dyn_file (relative path from root)
- dyn_file="/"+Pathname(filename).relative_path_from(Pathname(edit_root)).to_s
- opts_doc=Dyndoc::FileWatcher.get_dyn_html_info(filename,dyn_file,opts[:user])
- opts.merge! opts_doc
- ##p [:html_files,html_files]
-
- html_file=opts[:html_files][opts[:current_doc_tag]] # No more default # || html_files[""]
- ##p [:opts,opts,:current_doc_tag,opts[:current_doc_tag]]
- Dyndoc.cli_convert_from_file(dyn_file[1..-1],html_file, opts)
- puts dyn_file[1..-1]+" processed!"
- if RUBY_PLATFORM =~ /darwin/
- options[:first] = html_file != old_html_file
- if html_file != old_html_file
- old_html_file = html_file
- url=File.join(base_url,html_file)
- cmd_to_open='tell application "Safari" to set URL of current tab of front window to "'+url+'"'
- `osascript -e '#{cmd_to_open}'`
- else
-%x{osascript<<ENDREFRESH
-tell app "Safari" to activate
-tell application "System Events"
- keystroke "r" using {command down}
-end tell
-ENDREFRESH
-}
- end
- end
- else
- puts dyn_file[1..-1]+" not well-formed!"
- end
- end
- end
-
-### end
+end