dyndoc-ruby 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/dyn-ctl +25 -2
  3. data/lib/dyndoc-html-servers.rb +118 -35
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bebb87f51e0f1e3b9469160469d386ab109c16ae
4
- data.tar.gz: c46b653b64bae640b35c9d62b9a517069832ff09
3
+ metadata.gz: d23a1d92727de7c3993d15a9e29024df5902388a
4
+ data.tar.gz: f06151b02cff15234fe739c7b502f9da1c1c166d
5
5
  SHA512:
6
- metadata.gz: 83b288473b3a2a2e0d57e8a9b0801641d481cb066f2da9d3e540d416dfcdaf045af47b1f07d019616f667207e989bd772d04a0fa6bcdba8edded730d5b33a92d
7
- data.tar.gz: a89b1361426ed5a3258e4cbf063526b5e7c86b08f6dbd7ac7ed00ceceee244b61ecf356ad0da9d6e388ce70a7df548f5196cf2f01a4364a64822fdedc538344b
6
+ metadata.gz: b43e04840641f3c6f1b270495056fbb937dc9a59922ed7c73a9db9e35ba3934fc1f4ff47022817ff11c00757a32836ee4d1de4c3d70c4cf33123fa9b86570665
7
+ data.tar.gz: 66c646c5a6887ac6d48e22c511f3fcc32889eefc9bb3bfbf4c327b9dffe685db6bb83084ed15dc20ebd3594f6bb5425558b0260be9bd5cb78f10a3502f978d0e
data/bin/dyn-ctl CHANGED
@@ -8,7 +8,6 @@ DYNCTL_PLIST=File.expand_path("~/Library/LaunchAgents/local.dyn-ctl.plist")
8
8
 
9
9
  case (ARGV[0] || "start").downcase
10
10
  when "init"
11
- require 'fileutils'
12
11
  rodasrv=File.expand_path("~/RodaSrv")
13
12
  unless Dir.exists? rodasrv
14
13
  FileUtils.mkdir_p rodasrv
@@ -26,7 +25,7 @@ when "init"
26
25
  end
27
26
 
28
27
  user=ARGV[1]
29
-
28
+
30
29
  if user
31
30
  FileUtils.mkdir_p File.join(rodasrv,"edit",user) unless Dir.exists? File.join(rodasrv,"edit",user)
32
31
  FileUtils.mkdir_p File.join(rodasrv,"public","users",user) unless Dir.exists? File.join(rodasrv,"public","users",user)
@@ -35,6 +34,30 @@ when "init"
35
34
  end
36
35
  end
37
36
 
37
+ when "browser"
38
+ browser=ARGV[1]
39
+ require 'dyndoc-html-servers'
40
+ if browser
41
+ browser=browser.downcase
42
+ Dyndoc::Browser.set browser if ["firefox","safari","chrome"].include? browser
43
+ else
44
+ puts "Current browser is #{Dyndoc::Browser.get}"
45
+ end
46
+
47
+ when "unwatch"
48
+ action=ARGV[1] || "ls"
49
+ path=ARGV[2]
50
+ require 'dyndoc-html-servers'
51
+ case action
52
+ when "ls"
53
+ Dyndoc::HtmlServers.unwatch_ls
54
+ when "add"
55
+ Dyndoc::HtmlServers.unwatch_add path
56
+ when "rm"
57
+ Dyndoc::HtmlServers.unwatch_rm path
58
+ end
59
+
60
+
38
61
  when "start"
39
62
  status=SRVS.map do |srv|
40
63
  `#{srv} status`.empty?
@@ -9,6 +9,21 @@ module Dyndoc
9
9
 
10
10
  @@cfg=nil
11
11
 
12
+ @@default_browser=(RUBY_PLATFORM =~ /darwin/ ? "safari" : "firefox")
13
+
14
+ def Browser.set(browser)
15
+ Browser.cfg["browser"]=browser
16
+ Browser.save_cfg
17
+ FileUtils.rm(@@browser_load_osa) if File.exists? @@browser_load_osa
18
+ FileUtils.rm(@@browser_reload_osa) if File.exists? @@browser_reload_osa
19
+ Browser.set_browser_reload
20
+ puts "Current browser is set to "+Browser.get+"!"
21
+ end
22
+
23
+ def Browser.get
24
+ Browser.cfg["browser"] || @@default_browser
25
+ end
26
+
12
27
  def Browser.cfg
13
28
  unless @@cfg
14
29
  @@cfg=(File.exist? @@browser_cfg_file) ? ::YAML::load_file(@@browser_cfg_file) : {}
@@ -16,6 +31,12 @@ module Dyndoc
16
31
  @@cfg
17
32
  end
18
33
 
34
+ def Browser.save_cfg
35
+ File.open(@@browser_cfg_file,"w") do |f|
36
+ f << Browser.cfg.to_yaml
37
+ end
38
+ end
39
+
19
40
  def Browser.name
20
41
  mode=(Browser.cfg["browser"] || :safari).to_sym
21
42
  case mode
@@ -37,7 +58,7 @@ module Dyndoc
37
58
  @@browser_reload_osa= File.join(Dyndoc.home,"etc","browser_reload.osa")
38
59
  def Browser.set_browser_reload
39
60
  activate=Browser.cfg["activate"] || false
40
- mode=(Browser.cfg["browser"] || :safari).to_sym
61
+ mode=Browser.get.to_sym
41
62
  code=case mode
42
63
  when :chrome
43
64
  %Q{
@@ -63,12 +84,10 @@ module Dyndoc
63
84
 
64
85
  when :firefox
65
86
  %Q{
66
- set a to path to frontmost application as text
67
87
  tell application "Firefox"
68
88
  activate
69
89
  tell application "System Events" to keystroke "r" using command down
70
90
  end tell
71
- #{activate ? '' : 'delay 0.2\nactivate application a'}
72
91
  }
73
92
 
74
93
  when :firefox_nightly
@@ -113,10 +132,27 @@ module Dyndoc
113
132
  end
114
133
  end
115
134
 
135
+ @@browser_load_osa= File.join(Dyndoc.home,"etc","browser_load.osa")
116
136
  def Browser.load(url)
117
- mode=(Browser.cfg["browser"] || :safari).to_sym
118
- cmd_to_open='tell application "'+Browser.name+'" to set URL of current tab of front window to "'+url+'"'
119
- `osascript -e '#{cmd_to_open}'`
137
+ if RUBY_PLATFORM =~ /darwin/
138
+ mode=Browser.get.to_sym
139
+ if mode==:safari
140
+ code='tell application "'+Browser.name+'" to set URL of current tab of front window to "'+url+'"'
141
+ elsif mode == :firefox
142
+ code='tell application "Firefox" to open location "'+url+'"'
143
+ elsif mode == :chrome
144
+ code=%Q{
145
+ tell application "Google Chrome"
146
+ set frontIndex to active tab index of front window
147
+ set URL of tab frontIndex of front window to "#{url}"
148
+ end tell
149
+ }
150
+ end
151
+ File.open(@@browser_load_osa,"w") do |f|
152
+ f << code
153
+ end
154
+ `osascript #{@@browser_load_osa}`
155
+ end
120
156
  end
121
157
  end
122
158
  end
@@ -182,6 +218,47 @@ RunCmd = (browser) ->
182
218
  module Dyndoc
183
219
  module HtmlServers
184
220
 
221
+ ## Deal with unwatched files!
222
+
223
+ @@unwatch=[]
224
+ @@unwatch_yml = File.join(Dyndoc.home,"etc","unwatch.yml")
225
+
226
+ def HtmlServers.unwatch_cfg
227
+ if @@unwatch.empty?
228
+ @@unwatch=(File.exist? @@unwatch_yml) ? ::YAML::load_file(@@unwatch_yml) : []
229
+ end
230
+ @@unwatch
231
+ end
232
+
233
+ def HtmlServers.unwatch_ls
234
+ res=HtmlServers.unwatch_cfg.empty? ? "Empty folders list" : (HtmlServers.unwatch_cfg.each_with_index.map {|e,i| (i+1).to_s+") "+e}.join("\n") + "\n")
235
+ puts res
236
+ end
237
+
238
+ def HtmlServers.unwatch_save
239
+ File.open(@@unwatch_yml,"w") do |f|
240
+ f << @@unwatch.to_yaml
241
+ end
242
+ end
243
+
244
+ def HtmlServers.unwatch_add(path)
245
+ return unless path
246
+ HtmlServers.unwatch_cfg.unshift path
247
+ HtmlServers.unwatch_save
248
+ end
249
+
250
+ def HtmlServers.unwatch_rm(path)
251
+ return unless path
252
+ HtmlServers.unwatch_cfg
253
+ @@unwatch -= [path]
254
+ HtmlServers.unwatch_save
255
+ end
256
+
257
+ def HtmlServers.unwatched?(file)
258
+ return "" if HtmlServers.unwatch_cfg.empty?
259
+ return HtmlServers.unwatch_cfg.map{|e| file[0...e.length] == e ? e : ""}[0] || ""
260
+ end
261
+
185
262
  @@cfg=nil
186
263
 
187
264
  def HtmlServers.cfg
@@ -248,35 +325,41 @@ module Dyndoc
248
325
  unless filename =~ /(?:_pre|_post|_lib|_layout)\.dyn$/
249
326
  ## find dyn_file (relative path from root)
250
327
  dyn_file="/"+Pathname(filename).relative_path_from(Pathname(dyn_root)).to_s
251
- opts_doc=Dyndoc::FileWatcher.get_dyn_html_info(filename,dyn_file,opts[:user])
252
- opts.merge! opts_doc
253
- ##p [:html_files,html_files]
254
-
255
- html_file=opts[:html_files][opts[:current_doc_tag]] # No more default # || html_files[""]
256
- ##p [:opts,opts,:current_doc_tag,opts[:current_doc_tag]]
257
- Dyndoc.cli_convert_from_file(dyn_file[1..-1],html_file, opts)
258
- ## fix html_file for _rmd, _adoc and _ttm
259
- if html_file =~ /^(.*)_(rmd|adoc|ttm)\.html$/
260
- html_file = $1+".html"
261
- end
262
- puts dyn_file[1..-1]+" processed => "+html_file+" created!"
263
- if RUBY_PLATFORM =~ /darwin/
264
- options[:first] = html_file != old_html_file
265
- if html_file != old_html_file
266
- old_html_file = html_file
267
- url=File.join(base_url,html_file)
268
- # cmd_to_open='tell application "Safari" to set URL of current tab of front window to "'+url+'"'
269
- # `osascript -e '#{cmd_to_open}'`
270
- Dyndoc::Browser.load(url)
271
- else
272
- Dyndoc::Browser.reload
273
- # %x{osascript<<ENDREFRESH
274
- # tell app "Safari" to activate
275
- # tell application "System Events"
276
- # keystroke "r" using {command down}
277
- # end tell
278
- # ENDREFRESH
279
- # }
328
+ unless HtmlServers.unwatched?(dyn_file[1..-1]).empty?
329
+ if RUBY_PLATFORM =~ /darwin/
330
+ `osascript -e 'display notification "Warning: #{dyn_file} unwatched by #{HtmlServers.unwatched?(dyn_file[1..-1])}!" with title "dyn-ctl unwatch"'`
331
+ end
332
+ else
333
+ opts_doc=Dyndoc::FileWatcher.get_dyn_html_info(filename,dyn_file,opts[:user])
334
+ opts.merge! opts_doc
335
+ ##p [:html_files,html_files]
336
+
337
+ html_file=opts[:html_files][opts[:current_doc_tag]] # No more default # || html_files[""]
338
+ ##p [:opts,opts,:current_doc_tag,opts[:current_doc_tag]]
339
+ Dyndoc.cli_convert_from_file(dyn_file[1..-1],html_file, opts)
340
+ ## fix html_file for _rmd, _adoc and _ttm
341
+ if html_file =~ /^(.*)_(rmd|adoc|ttm)\.html$/
342
+ html_file = $1+".html"
343
+ end
344
+ puts dyn_file[1..-1]+" processed => "+html_file+" created!"
345
+ if RUBY_PLATFORM =~ /darwin/
346
+ options[:first] = html_file != old_html_file
347
+ if html_file != old_html_file
348
+ old_html_file = html_file
349
+ url=File.join(base_url,html_file)
350
+ # cmd_to_open='tell application "Safari" to set URL of current tab of front window to "'+url+'"'
351
+ # `osascript -e '#{cmd_to_open}'`
352
+ Dyndoc::Browser.load(url)
353
+ else
354
+ Dyndoc::Browser.reload
355
+ # %x{osascript<<ENDREFRESH
356
+ # tell app "Safari" to activate
357
+ # tell application "System Events"
358
+ # keystroke "r" using {command down}
359
+ # end tell
360
+ # ENDREFRESH
361
+ # }
362
+ end
280
363
  end
281
364
  end
282
365
  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: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - RCqls
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-01 00:00:00.000000000 Z
11
+ date: 2017-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: R4rb