dyndoc-ruby 0.7.2 → 0.7.3

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dyndoc-convert.rb +63 -41
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 92dd84790be17ae6abe5454e242718b6e897cb75
4
- data.tar.gz: d991845b13f47faff753fd0624c64408683498bf
3
+ metadata.gz: bfadfdc5ff9a771cb8bd843a041c96b8f1c33c0e
4
+ data.tar.gz: 1561fe45892386f94e8838b7686e853dd8629c99
5
5
  SHA512:
6
- metadata.gz: ad5119617a092ac2a0cf6fe6bd7a34d470d46b8c50b9959f1df98d3c8da0c54fcd7cfe2dcc397aa1879bbbd83f268e533416b8ead65cdf0cef2627c363b0be73
7
- data.tar.gz: 79b146e10822644c55814f98c020557384e63dd81ca427a49ab2bd6dfaaed543ef8c898844761063f26248e3e97685e83415cf908abf0ccb75d6008c6eea061d
6
+ metadata.gz: 0b19568d4e4d4ce2d1133aecea4fbac4c23031a20b9559ad97de7efc2e86cd610fa1f21bbb53140019ed5d78232e313ae28e6958d43a2b68f5d2038f7b361323
7
+ data.tar.gz: 75358580ac47c8815cb15043be4b39500de588c7e63bcf8b4be4f8a61804819616c6ae8cccb1d2dc6ec14baf1156a0923459d2be8398bf0564e5c7c44740832a
@@ -38,7 +38,8 @@ module Dyndoc
38
38
  return cli.content
39
39
  end
40
40
 
41
- def Dyndoc.cli_convert_from_file(dyn_file,dyn_out_file)
41
+ ## TODO: a config.yml file for the site
42
+ def Dyndoc.cli_convert_from_file(dyn_file,html_file,root={}) #ex: root={dyn: , html: }
42
43
  addr="127.0.0.1"
43
44
 
44
45
  dyn_libs,dyn_tags=nil,nil
@@ -54,59 +55,80 @@ module Dyndoc
54
55
  ## Dyn post
55
56
  dyn_post_code=File.read(dyn_file[0...i]+"_post.dyn") if File.exist? dyn_file[0...i]+"_post.dyn"
56
57
 
58
+ cfg={}
59
+
57
60
  if File.exist? dyn_file[0...i]+".dyn_cfg"
58
61
  require 'yaml'
59
62
  cfg=YAML::load_file(dyn_file[0...i]+".dyn_cfg")
63
+ end
60
64
 
61
- dyn_root= cfg["root"] || File.expand_path("..",dyn_file)
65
+ ## code to evaluate
66
+ code=File.read(dyn_file)
62
67
 
63
- if cfg["layout"]
64
- cfg_tmp=File.join(dyn_root,cfg["layout"])
65
- dyn_layout=cfg_tmp if !dyn_layout and File.exist? cfg_tmp
66
- end
67
- if cfg["pre"]
68
- cfg_tmp=File.join(dyn_root,cfg["pre"])
69
- dyn_pre_code=File.read(cfg_tmp) unless dyn_pre_code and File.exist? cfg_tmp
70
- end
68
+ page=nil
71
69
 
72
- if cfg["post"]
73
- cfg_tmp=File.join(dyn_root,cfg["post"])
74
- dyn_post_code=File.read(cfg_tmp) unless dyn_post_code and File.exist? cfg_tmp
70
+ if code =~ /^\-{3}/
71
+ b=code.split(/^\-{3}/)
72
+ if b[0].empty?
73
+ require 'yaml'
74
+ page=YAML.load(b[1])
75
+ cfg.merge!(page)
76
+ code=b[2..-1].join("---")
75
77
  end
78
+ end
76
79
 
77
- dyn_libs=cfg["libs"].strip if cfg["libs"]
80
+ # dyn_root can be overwritten by cfg
81
+ dyn_root= cfg["dyn_root"] || root[:dyn] || File.expand_path("..",dyn_file)
82
+ html_root= cfg["html_root"] || root[:html] || File.expand_path("..",dyn_file)
78
83
 
79
- dyn_tags="[#<]{#opt]"+cfg["tags"].strip+"[#opt}" if cfg["tags"]
84
+ if cfg["layout"]
85
+ cfg_tmp=File.join(dyn_root,cfg["layout"])
86
+ dyn_layout=cfg_tmp if !dyn_layout and File.exist? cfg_tmp
87
+ end
88
+ if cfg["pre"]
89
+ cfg_tmp=File.join(dyn_root,cfg["pre"])
90
+ dyn_pre_code=File.read(cfg_tmp) unless dyn_pre_code and File.exist? cfg_tmp
80
91
  end
81
92
 
82
- end
93
+ if cfg["post"]
94
+ cfg_tmp=File.join(dyn_root,cfg["post"])
95
+ dyn_post_code=File.read(cfg_tmp) unless dyn_post_code and File.exist? cfg_tmp
96
+ end
83
97
 
98
+ if cfg["html_file"] #relative path from (dyn_)root
99
+ html_file=File.join(html_root,cfg["html_file"])
100
+ end
84
101
 
85
- ## code to evaluate
86
- code=File.read(dyn_file)
87
- if dyn_libs or dyn_pre_code
88
- code_pre = ""
89
- code_pre += dyn_pre_code + "\n" if dyn_pre_code
90
- code_pre += '[#require]'+"\n"+dyn_libs if dyn_libs
91
- code = code_pre + '[#main][#>]' + code
92
- end
93
- code += "\n" + dyn_post_code if dyn_post_code
94
- code = dyn_tags + code if dyn_tags
95
- dyndoc_start=[:dyndoc_libs,:dyndoc_layout]
96
-
97
- cli=Dyndoc::InteractiveClient.new(code,dyn_file,addr,dyndoc_start)
98
-
99
- if dyn_layout
100
- cli=Dyndoc::InteractiveClient.new(File.read(dyn_layout),"",addr) #File.expand_path(dyn_layout),addr)
101
- end
102
-
103
- if dyn_out_file and Dir.exist? File.dirname(dyn_out_file)
104
- File.open(dyn_out_file,"w") do |f|
105
- f << cli.content
106
- end
107
- else
108
- puts cli.content
109
- end
102
+ dyn_libs=cfg["libs"].strip if cfg["libs"]
103
+
104
+ dyn_tags="[#<]{#opt]"+cfg["tags"].strip+"[#opt}" if cfg["tags"]
105
+
106
+ if dyn_libs or dyn_pre_code
107
+ code_pre = ""
108
+ code_pre += dyn_pre_code + "\n" if dyn_pre_code
109
+ code_pre += '[#require]'+"\n"+dyn_libs if dyn_libs
110
+ code = code_pre + '[#main][#>]' + code
111
+ end
112
+ code += "\n" + dyn_post_code if dyn_post_code
113
+ ## TO TEST!!!
114
+ code = dyn_tags + code if dyn_tags
115
+ code = "[#rb<]page = " + page.inspect + "[#>]" +code if page
116
+ dyndoc_start=[:dyndoc_libs,:dyndoc_layout]
117
+
118
+ cli=Dyndoc::InteractiveClient.new(code,dyn_file,addr,dyndoc_start)
119
+
120
+ if dyn_layout
121
+ cli=Dyndoc::InteractiveClient.new(File.read(dyn_layout),"",addr) #File.expand_path(dyn_layout),addr)
122
+ end
123
+
124
+ if html_file and Dir.exist? File.dirname(html_file)
125
+ File.open(html_file,"w") do |f|
126
+ f << cli.content
127
+ end
128
+ else
129
+ puts cli.content
130
+ end
131
+ end
110
132
  end
111
133
 
112
134
  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.7.2
4
+ version: 0.7.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-07-03 00:00:00.000000000 Z
11
+ date: 2016-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: R4rb