dyndoc-ruby 0.9.8 → 0.9.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/dyn-auto +14 -0
  3. data/lib/dyndoc-convert.rb +195 -0
  4. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1fba357b44769920a52e1b4267e7b31cd71bef4a
4
- data.tar.gz: d1f1b0ba488f063262c3789968c11cee4644eca8
3
+ metadata.gz: da77cb91f143261ef5cef6cf89d0f4016ec88580
4
+ data.tar.gz: f3c3229874249cc9854e401ed4c504d92a9ff681
5
5
  SHA512:
6
- metadata.gz: 50feaa43e83224c5683c5af8a0416c8cc1e8fbebc73898d835a04c26946c078958d951b0eb3a2f361730d66ef24391de5a3022f97e9d9abf021714076bd9b99c
7
- data.tar.gz: c6ad22d41baa0576145540a8c1c51eafb672dc13804410140f44cb7f6c4096feb9dea39639cdcb4ba65a1a8cf047efb7a9d0733fdda8a791dd2fe470d0c2464b
6
+ metadata.gz: 655ae2027b9ad6ef19c9f911430db1e019d19631dcbc33018283b5246985a0393df95c4f673442c836f5d32fb5a30542c6cebc80e692a0527afd255513399e1a
7
+ data.tar.gz: 23a84c99eb88da27b1a718f72042bbe4b89d3d102a77629d2604eefdaff312824a4b4203694837bd8c11e512770611d0b652ea177ce616f48e6b05c911e55c5c
data/bin/dyn-auto ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ require 'dyndoc-convert'
3
+
4
+ dyn_file=ARGV[0]
5
+
6
+ full_dyn_file=File.expand_path(File.join(Dir.pwd,dyn_file))
7
+ full_dyn_file + '.dyn' unless full_dyn_file =~ /.*\.dyn$/
8
+
9
+
10
+ if File.exists? full_dyn_file
11
+ Dyndoc.auto_convert_from_file(full_dyn_file)
12
+ else
13
+ puts "Error: #{full_dyn_file} does not exists"
14
+ end
@@ -238,4 +238,199 @@ module Dyndoc
238
238
  end
239
239
  end
240
240
 
241
+
242
+ ## Very similar to Dyndoc.process_html_file_from_dyn_file
243
+ def Dyndoc.auto_dyn_file(code,output_file,dyn_file,dyn_layout,addr,dyndoc_start)
244
+ cli=Dyndoc::InteractiveClient.new(code,dyn_file,addr,dyndoc_start)
245
+
246
+ if dyn_layout
247
+ cli=Dyndoc::InteractiveClient.new(File.read(dyn_layout),"",addr) #File.expand_path(dyn_layout),addr)
248
+ end
249
+
250
+ if output_file and Dir.exist? File.dirname(output_file)
251
+ File.open(output_file,"w") do |f|
252
+ f << cli.content
253
+ end
254
+ else
255
+ puts cli.content
256
+ end
257
+ end
258
+
259
+ ###################################
260
+ ## Dyndoc.auto_convert_from_file ##
261
+ ###########################################################################
262
+ ## Very similar to Dyndoc.cli_convert_from_file which is (badly) devoted to html file!
263
+ ## This version tries to autoconvert a dyn_file of the form *_<format>.dyn to *.<format>
264
+ ## Multi-documents is not considered here! The goal is to provide autoconversion for simple file (even though we can use template)
265
+ ## :format_output => "html" is not a pb since it is mostly used for verbatim output and it is not the focus here!
266
+
267
+ def Dyndoc.auto_convert_from_file(dyn_file,opts={}) #ex: opts={dyn_root: , doc_tag: } #opts=obtained by commandline
268
+ ## opts[:dyn_root] ||= ENV["HOME"]
269
+
270
+ dyn_libs,dyn_tags,dyn_layout,dyn_pre_code,dyn_post_code=nil,nil,nil,nil,nil
271
+
272
+ dyn_path=dyn_file.split(File::Separator)
273
+
274
+
275
+ if i=(dyn_file =~ /\_([a-z,A-Z,0-9]*)\.dyn$/)
276
+ dyn_extname = $1
277
+ dyn_dirname = File.dirname(dyn_file[0...i])
278
+ dyn_basename = dyn_file[0...i]
279
+
280
+ cfg_files={
281
+ fullname: dyn_file,
282
+ basename: File.basename(dyn_file,".*"),
283
+ tag: opts[:doc_tag],
284
+ dyn_extname: dyn_extname,
285
+ dyn_dirname: dyn_dirname,
286
+ dyn_basename: dyn_basename,
287
+ output_basename: dyn_basename+"."+dyn_extname
288
+ }
289
+
290
+ p [:cfg_files,cfg_files]
291
+
292
+ cfg={}
293
+
294
+ ## find the previous config.yml in the tree folder
295
+ ## TODO: read all previous config.yml and merge them from root to current
296
+ ## The merge could be also to join the content when the key is the same.
297
+ ## Ex: semantic-ui (1st config.yml): css_message
298
+ ## semantic-ui (2nd config.yml): css_icon
299
+ ## becomes: semantic-ui: css_message, css_icon
300
+ ## NEEDS TO DECLARE the fields that behave like this in some other config file (keys.yml)
301
+
302
+ cfg_yml_files=dyn_path.inject([""]) {|res,e| res + [(res[-1,1]+[e]).flatten]}.map{|pa| File.join("",pa,"config.yml")}.reverse
303
+ cfg_yml_file=cfg_yml_files.select{|c| File.exists? c}[0]
304
+ cfg=YAML::load_file(cfg_yml_file) if cfg_yml_file
305
+
306
+ ## add info related to dyn file
307
+ cfg.merge!(cfg_files)
308
+
309
+ ## Dyn layout
310
+ dyn_layout=dyn_file[0...i]+"_#{dyn_extname}-layout.dyn" if File.exist? dyn_file[0...i]+"_#{dyn_extname}-layout.dyn"
311
+
312
+ ## Dyn pre
313
+ dyn_pre_code=File.read(dyn_file[0...i]+"_#{dyn_extname}-pre.dyn") if File.exist? dyn_file[0...i]+"_#{dyn_extname}-pre.dyn"
314
+
315
+ ## Dyn post
316
+ dyn_post_code=File.read(dyn_file[0...i]+"_#{dyn_extname}-post.dyn") if File.exist? dyn_file[0...i]+"_#{dyn_extname}-post.dyn"
317
+
318
+
319
+ if File.exist? dyn_file[0...i]+"_#{dyn_extname}.dyn_cfg" and (yml=YAML::load_file(dyn_file[0...i]+"_#{dyn_extname}.dyn_cfg"))
320
+ cfg.merge!(yml)
321
+ else # try do find (in the Zope spirit) a config file in the nearest folder
322
+ end
323
+
324
+ ## code to evaluate
325
+ code=File.read(dyn_file)
326
+
327
+ page={}
328
+
329
+ if code =~ /^\-{3}/
330
+ b=code.split(/^(\-{3,})/,-1)
331
+ if b[0].empty? and b.length>4
332
+ require 'yaml'
333
+ page=YAML.load(b[2])
334
+ cfg.merge!(page)
335
+ code=b[4..-1].join("")
336
+ end
337
+ end
338
+
339
+ # dyn_root can be overwritten by cfg
340
+ # defines the root of relative predefined dyn (pre, post, ...) files
341
+ dyn_root= cfg["dyn_root"] || opts[:dyn_root] || File.expand_path("..",dyn_file)
342
+
343
+ cfg["layout"] = cfg["pre"] = cfg["post"] = cfg["model"] if cfg["model"]
344
+
345
+ if cfg["layout"]
346
+ if cfg["layout"][0] == "/"
347
+ cfg_tmp=cfg["layout"]
348
+ else
349
+ cfg_tmp=File.join(dyn_root, cfg["layout"])
350
+ end
351
+ cfg_tmp+= ".dyn" if File.extname(cfg_tmp).empty?
352
+ ##Dyndoc.warn :layout,cfg_tmp
353
+ dyn_layout=cfg_tmp if !dyn_layout and File.exist? cfg_tmp
354
+ end
355
+ if cfg["pre"]
356
+ if cfg["pre"][0] == "/"
357
+ cfg_tmp=cfg["pre"]
358
+ else
359
+ cfg_tmp=File.join(dyn_root,cfg["pre"])
360
+ end
361
+ cfg_tmp+= ".dyn" if File.extname(cfg_tmp).empty?
362
+ dyn_pre_code=File.read(cfg_tmp) if !dyn_pre_code and File.exist? cfg_tmp
363
+ end
364
+
365
+ if cfg["post"]
366
+ if cfg["post"][0] == "/"
367
+ cfg_tmp=cfg["post"]
368
+ else
369
+ cfg_tmp=File.join(dyn_root,cfg["post"])
370
+ end
371
+ cfg_tmp+= ".dyn" if File.extname(cfg_tmp).empty?
372
+ dyn_post_code=File.read(cfg_tmp) if !dyn_post_code and File.exist? cfg_tmp
373
+ end
374
+
375
+
376
+ ## deal with html_file
377
+ output_file=File.join(opts[:where] || cfg[:dyn_dirname],File.basename(cfg[:output_basename]))
378
+ unless File.exist? output_file
379
+ dirname=File.dirname(output_file)
380
+ require 'fileutils'
381
+ FileUtils.mkdir_p dirname
382
+ end
383
+
384
+ dyn_libs=cfg["libs"].strip if cfg["libs"]
385
+
386
+ ## mode multi-documents
387
+ docs_tags=[]
388
+ ## 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
389
+ docs_tags << opts[:doc_tag] if opts[:doc_tag]
390
+ ## complete docs_tags with cfg["tags"]
391
+ docs_tags += (cfg["tags"]||"").split(",").map{|e| e.strip}
392
+ dyn_tags="[#<]{#opt]"+docs_tags.join(",")+"[#opt}[#>]" unless docs_tags.empty?
393
+
394
+ ### Dyndoc.warn :dyn_tags,[docs_tags,dyn_tags]
395
+
396
+ if dyn_libs or dyn_pre_code
397
+ code_pre = ""
398
+ code_pre += dyn_pre_code + "\n" if dyn_pre_code
399
+ code_pre += '[#require]'+"\n"+dyn_libs if dyn_libs
400
+ code = code_pre + '[#main][#>]' + code
401
+ end
402
+ code += "\n" + dyn_post_code if dyn_post_code
403
+ ## TO TEST!!!
404
+ ##
405
+ Dyndoc.warn :cfg,cfg
406
+ ##Dyndoc.warn :page,page
407
+ code = "[#rb<]require 'ostruct';cfg = OpenStruct.new(" + cfg.inspect + ")[#>]" +code
408
+ code = dyn_tags + code if dyn_tags
409
+
410
+ ## add path for user
411
+ code_path = "[#path]"
412
+ code_path << "\n" << File.join(dyn_root,'dynlib')
413
+ code_path << "\n" << opts[:dynlib_root] << "\n" if opts[:dynlib_root]
414
+ code_path << "\n" << cfg[:dynlib_root] << "\n" if cfg[:dynlib_root]
415
+ code_path << "[#main][#<]\n"
416
+ code = code_path + code
417
+
418
+ ### Dyndoc.warn :code,code
419
+
420
+ dyndoc_start=[:dyndoc_libs,:dyndoc_layout]
421
+
422
+ opts[:addr] ||= "127.0.0.1"
423
+ ##unless cfg[:doc_tags]
424
+ Dyndoc.auto_dyn_file(code,output_file,dyn_file,dyn_layout,opts[:addr],dyndoc_start)
425
+ # else
426
+ # (cfg[:doc_tags]).each do |doc_tag|
427
+ # output_file = cfg[:outputs][doc_tag] ? (cfg[:outputs][doc_tag][0] == "/" ? cfg[:outputs][doc_tag] : File.join() ) : File.join(opts[:where] || cfg["dyn_dirname"],cfg["output_basename"])
428
+ # p [:html_multi,doc_tag,html_file] #,code.gsub(/__ALL_DOC_TAG__/,doc_tag)]
429
+ # Dyndoc.auto_dyn_file(code,html_file,dyn_file,dyn_layout,addr,dyndoc_start)
430
+ # end
431
+ # end
432
+ end
433
+ end
434
+
435
+
241
436
  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.8
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - RCqls
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-14 00:00:00.000000000 Z
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: R4rb
@@ -121,11 +121,13 @@ executables:
121
121
  - dyn-scan
122
122
  - dyn-lint
123
123
  - dyn-cli
124
+ - dyn-auto
124
125
  extensions: []
125
126
  extra_rdoc_files: []
126
127
  files:
127
128
  - bin/dpm
128
129
  - bin/dyn
130
+ - bin/dyn-auto
129
131
  - bin/dyn-cli
130
132
  - bin/dyn-forever
131
133
  - bin/dyn-html