tocmd 0.0.5 → 0.0.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d905d846ac396dbede31f27fa7f07567d472fbb
4
- data.tar.gz: 47275da1ce1e7d5c29b3526404a93949a3cf497d
3
+ metadata.gz: 6ca9c3473d4031a16b8f7ec55ad4f7d10905367e
4
+ data.tar.gz: dbf56c7e9b7e39aad361ff255e941171a6a3a5a2
5
5
  SHA512:
6
- metadata.gz: fc2d6a9c370b3858ae3ddf9e9b8e1be5ab3e5e3fba660426d9d8f426191f06dc47cb35939281bd720775e104045e74325cf205b0da9a6f5146606251a12ad48d
7
- data.tar.gz: 60d3b63158fcefc176df99405b3270bdad5deb344e0d684622b16e814362751752e606ce7244ea2e29496d0d452e512ce0cf8efe2024a8d6bff801836be9eace
6
+ metadata.gz: 941ab4a09273ef13a0762ac80b0fc38827c98cb279aaaaa085f6d9861deb2e85a4612c8e80f4f3b6db5a5f944783ccd0a7a0f86d6d1c115869b6ab7f5886bf39
7
+ data.tar.gz: dacdf539f11a4e66902d8f4e3149f77d9749b8ec740e851dbb2c0f543e5da4f74ae57a83e2cce586474b4829e5ba6dbee910c56f245d74366d527b6747c19564
data/bin/tocmd CHANGED
@@ -5,7 +5,7 @@ require 'mdpreview'
5
5
  require 'pathname'
6
6
  # p ARGV
7
7
  # puts Mdpreview.hi(ARGV)
8
-
8
+ #
9
9
  # puts __FILE__
10
10
  # puts File.dirname(__FILE__)
11
11
 
@@ -13,7 +13,8 @@ require 'pathname'
13
13
  # File.join(File.dirname(__FILE__), '..', 'lib')
14
14
  path = Pathname.new(File.join(File.dirname(__FILE__), '..')).realpath.to_s
15
15
 
16
- p "开始"
16
+ # p "开始#{Dir.pwd}"
17
+ # p "path = #{path}"
17
18
 
18
19
  require 'optparse'
19
20
 
@@ -31,25 +32,27 @@ option_parser = OptionParser.new do |opts|
31
32
  # end
32
33
  vendor_path = Pathname.new(File.expand_path('../../vendor/', __FILE__)).realpath.to_s
33
34
 
35
+ src_p = Dir.pwd
36
+
34
37
  begin
35
- Dir.delelte(File.join(path ,"preview"))
36
- Dir.mkdir(File.join(path ,"preview"), 0700) #=> 0
38
+ Dir.delelte(File.join(src_p ,"preview"))
39
+ Dir.mkdir(File.join(src_p ,"preview"), 0700) #=> 0
37
40
  rescue
38
41
  ensure
39
42
  end
40
43
 
41
44
  begin
42
- Dir.mkdir(File.join(path ,"preview"), 0700) #=> 0
45
+ Dir.mkdir(File.join(src_p ,"preview"), 0700) #=> 0
43
46
  rescue
44
47
  ensure
45
48
  end
46
49
 
47
50
  begin
48
- Dir.mkdir(File.join(path ,".toc"), 0700) #=> 0
51
+ Dir.mkdir(File.join(src_p ,".toc"), 0700) #=> 0
49
52
  rescue
50
53
  ensure
51
54
  f = File.new(File.join(vendor_path ,"template.html"), "w+").path
52
- FileUtils.cp(f ,File.join(path ,".toc"))
55
+ FileUtils.cp(f ,File.join(src_p ,".toc"))
53
56
  end
54
57
 
55
58
 
@@ -58,8 +61,26 @@ option_parser = OptionParser.new do |opts|
58
61
  opts.on('-f sourceFileNAME', '--name sourceFileNAME', 'Pass-in source file name') do |value|
59
62
  # options[:fname] = value
60
63
 
61
- Mdpreview.hi(path + '/' + value)
64
+ Mdpreview.hi(src_p + '/' + value)
65
+ end
66
+
67
+ opts.on('-d dirNAME', '--name sourceFileNAME', 'Pass-in source file name') do |value|
68
+ # options[:fname] = value
69
+ p value
70
+
71
+ if value == '.'
72
+ Mdpreview.hi_dir(src_p + '/' )
73
+ else
74
+ Mdpreview.hi_dir(src_p + '/' + value)
75
+ end
76
+
62
77
  end
78
+
79
+
80
+ opts.on('-s', '--here', 'Set options as here') do
81
+ # 这个部分就是使用这个Option后执行的代码
82
+ Mdpreview.hi_dir(src_p)
83
+ end
63
84
 
64
85
  # Option 作为flag,带一组用逗号分割的arguments,用于将arguments作为数组解析
65
86
  # opts.on('-a A,B', '--array A,B', Array, 'List of arguments') do |value|
@@ -1,7 +1,5 @@
1
- require 'pathname'
2
- require 'FileUtils'
3
-
4
-
1
+ require 'pathname'
2
+ # require 'FileUtils'
5
3
 
6
4
  class Mdpreview::Translator
7
5
  def initialize(source_file_path)
@@ -12,17 +10,16 @@ class Mdpreview::Translator
12
10
  #editor path
13
11
  @editor_path = Pathname.new(File.expand_path('../../../vendor', __FILE__)).realpath.to_s
14
12
 
15
- p "@gem root_path:::"+@gem_root_path
16
- p "@src file_path:::"+@source_file_path
17
- p "@editor path :::"+@editor_path
13
+ # p "@gem root_path:::"+@gem_root_path
14
+ # p "@src file_path:::"+@source_file_path
15
+ # p "@editor path :::"+@editor_path
18
16
 
19
17
  end
20
18
 
21
19
  def hi
22
20
  generate_meta_js
23
- cp_source_file_to_cur_file
24
- open_in_browser
25
-
21
+ # cp_source_file_to_cur_file
22
+
26
23
  ar = @source_file_path.split('/')
27
24
  ar.pop()
28
25
 
@@ -34,11 +31,56 @@ class Mdpreview::Translator
34
31
 
35
32
  puts "desc path = #{ar.join('/').to_s}"
36
33
 
34
+ build_with_dir(@source_file_path ,dest_dir)
35
+
36
+ open_in_browser
37
+ end
38
+
39
+ def hi_dir
40
+ generate_meta_js
41
+ # cp_source_file_to_cur_file
42
+
43
+
44
+ ar = @source_file_path.split('/')
45
+ # ar.pop()
46
+
47
+ puts "hi_dir src path = #{ar.join('/').to_s}"
48
+ src_path = ar.join('/').to_s
49
+
50
+ ar.push('preview');
51
+ dest_dir = ar.join('/').to_s
52
+
53
+ puts "hi_dir desc path = #{ar.join('/').to_s}"
54
+
37
55
  build_with_dir(src_path ,dest_dir)
56
+
57
+ open_in_browser
38
58
  end
39
59
 
40
60
  def open_in_browser
41
- `open #{@editor_path}/jsoneditor-2.3.6/examples/main.html`
61
+ ar = @source_file_path.split('/')
62
+
63
+ if File.directory?(@source_file_path) == false #普通文件
64
+ file_name = ar.pop().split('.')[0]
65
+ src_path = ar.join('/').to_s
66
+
67
+ ar.push('preview');
68
+ dest_dir = ar.join('/').to_s
69
+
70
+ `open #{ar.join('/').to_s}/#{file_name}.html`
71
+
72
+ else
73
+ # 目录
74
+ src_path = ar.join('/').to_s
75
+
76
+ Dir.foreach(src_path) do |ff|
77
+ file_name = ff.split('.')[0]
78
+ end
79
+
80
+ ar.push('preview');
81
+ dest_dir = ar.join('/').to_s
82
+ `open #{ar.join('/').to_s}/#{file_name}.html`
83
+ end
42
84
  end
43
85
 
44
86
  def generate_meta_js
@@ -53,139 +95,160 @@ class Mdpreview::Translator
53
95
  end
54
96
 
55
97
  def build_with_dir(destiny_dir,dest_dir)
98
+ p "start building......"
99
+
100
+ if File.directory?(destiny_dir) == false
101
+ p 'process_with_one'
102
+ ar = @source_file_path.split('/')
103
+ file_name = ar.pop().split('.')[0]
104
+
105
+ src_path = ar.join('/').to_s
106
+
107
+ ar.push('preview');
108
+ dest_dir = ar.join('/').to_s
109
+
110
+ # return;
111
+ process_with_one(src_path,dest_dir,destiny_dir.split('/').pop().to_s)
112
+
113
+ return;
114
+ end
115
+
116
+ p "src_dir = #{destiny_dir}"
117
+ p "dest_dir = #{dest_dir}"
56
118
  Dir.foreach(destiny_dir) do |ff|
57
119
  # puts ff
58
- unless /^\./ =~ ff ||/^images/ =~ ff ||/^css/ =~ ff || File.directory?(ff) || File.extname(ff) != '.md'
59
-
60
- puts "src = #{ff}"
120
+ unless /^\./ =~ ff ||/^images/ =~ ff ||/^css/ =~ ff || File.directory?(ff) || File.extname(ff) != '.md'
61
121
 
62
- # get markdown text
63
- text = IO.read(destiny_dir + '/' + ff)
122
+ process_with_one(destiny_dir,dest_dir,ff)
123
+
124
+ end
125
+ end
126
+ end
127
+
128
+ def process_with_one(destiny_dir ,dest_dir ,ff)
129
+ # get markdown text
130
+ text = IO.read(destiny_dir + '/' + ff)
131
+
132
+ # options = [:fenced_code,:generate_toc,:hard_wrap,:no_intraemphasis,:strikethrough,:gh_blockcode,:autolink,:xhtml,:tables]
133
+
134
+ # convert to html
135
+ markdown = Redcarpet::Markdown.new(HTMLwithPygments,:gh_blockcode=>true,:no_intra_emphasis=>true,:filter_html => true,:hard_wrap => true,:autolink => true, :space_after_headers => true,:fenced_code_blocks => true)
136
+ parse_markdown = markdown.render(text)
137
+ # parse_markdown = syntax_highlighter(parse_markdown)
64
138
 
65
- # options = [:fenced_code,:generate_toc,:hard_wrap,:no_intraemphasis,:strikethrough,:gh_blockcode,:autolink,:xhtml,:tables]
66
-
67
- # convert to html
68
- markdown = Redcarpet::Markdown.new(HTMLwithPygments,:gh_blockcode=>true,:no_intra_emphasis=>true,:filter_html => true,:hard_wrap => true,:autolink => true, :space_after_headers => true,:fenced_code_blocks => true)
69
- parse_markdown = markdown.render(text)
70
- # parse_markdown = syntax_highlighter(parse_markdown)
71
-
72
- css_link = ''
73
- if destiny_dir.to_s.index('/')
74
- css_link = %Q{
75
- <link href="#{@editor_path}/toc/style/github-bf51422f4bb36427d391e4b75a1daa083c2d840e.css" media="all" rel="stylesheet" type="text/css"/>
76
- <link href="#{@editor_path}/toc//style/github2-d731afd4f624c99a4b19ad69f3083cd6d02b81d5.css" media="all" rel="stylesheet" type="text/css"/>
77
- <link href="#{@editor_path}/toc/css/zTreeStyle/zTreeStyle.css" media="all" rel="stylesheet" type="text/css"/>
78
- }
79
- else
80
- css_link = %Q{
81
- <link href="#{@editor_path}/toc/style/github-bf51422f4bb36427d391e4b75a1daa083c2d840e.css" media="all" rel="stylesheet" type="text/css"/>
82
- <link href="#{@editor_path}/toc/style/github2-d731afd4f624c99a4b19ad69f3083cd6d02b81d5.css" media="all" rel="stylesheet" type="text/css"/>
83
- <link href="#{@editor_path}/toc/css/zTreeStyle/zTreeStyle.css" media="all" rel="stylesheet" type="text/css"/>
139
+ css_link = ''
140
+ if destiny_dir.to_s.index('/')
141
+ css_link = %Q{
142
+ <link href="#{@editor_path}/toc/style/github-bf51422f4bb36427d391e4b75a1daa083c2d840e.css" media="all" rel="stylesheet" type="text/css"/>
143
+ <link href="#{@editor_path}/toc//style/github2-d731afd4f624c99a4b19ad69f3083cd6d02b81d5.css" media="all" rel="stylesheet" type="text/css"/>
144
+ <link href="#{@editor_path}/toc/css/zTreeStyle/zTreeStyle.css" media="all" rel="stylesheet" type="text/css"/>
145
+ }
146
+ else
147
+ css_link = %Q{
148
+ <link href="#{@editor_path}/toc/style/github-bf51422f4bb36427d391e4b75a1daa083c2d840e.css" media="all" rel="stylesheet" type="text/css"/>
149
+ <link href="#{@editor_path}/toc/style/github2-d731afd4f624c99a4b19ad69f3083cd6d02b81d5.css" media="all" rel="stylesheet" type="text/css"/>
150
+ <link href="#{@editor_path}/toc/css/zTreeStyle/zTreeStyle.css" media="all" rel="stylesheet" type="text/css"/>
151
+ }
152
+ end
153
+
154
+ t = %Q{
155
+ <html>
156
+ <head>
157
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
158
+ <title>#{ff.gsub('.md','')}</title>
159
+ #{css_link}
160
+ <style>
161
+ pre {
162
+ counter-reset: line-numbering;
163
+ border: solid 1px #d9d9d9;
164
+ border-radius: 0;
165
+ background: #fff;
166
+ padding: 0;
167
+ line-height: 23px;
168
+ margin-bottom: 30px;
169
+ white-space: pre;
170
+ overflow-x: auto;
171
+ word-break: inherit;
172
+ word-wrap: inherit;
84
173
  }
85
- end
86
-
87
- t = %Q{
88
- <html>
89
- <head>
90
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
91
- <title>#{ff.gsub('.md','')}</title>
92
- #{css_link}
93
- <style>
94
- pre {
95
- counter-reset: line-numbering;
96
- border: solid 1px #d9d9d9;
97
- border-radius: 0;
98
- background: #fff;
99
- padding: 0;
100
- line-height: 23px;
101
- margin-bottom: 30px;
102
- white-space: pre;
103
- overflow-x: auto;
104
- word-break: inherit;
105
- word-wrap: inherit;
106
- }
107
174
 
108
- pre a::before {
109
- content: counter(line-numbering);
110
- counter-increment: line-numbering;
111
- padding-right: 1em; /* space after numbers */
112
- width: 25px;
113
- text-align: right;
114
- opacity: 0.7;
115
- display: inline-block;
116
- color: #aaa;
117
- background: #eee;
118
- margin-right: 16px;
119
- padding: 2px 10px;
120
- font-size: 13px;
121
- -webkit-touch-callout: none;
122
- -webkit-user-select: none;
123
- -khtml-user-select: none;
124
- -moz-user-select: none;
125
- -ms-user-select: none;
126
- user-select: none;
127
- }
175
+ pre a::before {
176
+ content: counter(line-numbering);
177
+ counter-increment: line-numbering;
178
+ padding-right: 1em; /* space after numbers */
179
+ width: 25px;
180
+ text-align: right;
181
+ opacity: 0.7;
182
+ display: inline-block;
183
+ color: #aaa;
184
+ background: #eee;
185
+ margin-right: 16px;
186
+ padding: 2px 10px;
187
+ font-size: 13px;
188
+ -webkit-touch-callout: none;
189
+ -webkit-user-select: none;
190
+ -khtml-user-select: none;
191
+ -moz-user-select: none;
192
+ -ms-user-select: none;
193
+ user-select: none;
194
+ }
128
195
 
129
- pre a:first-of-type::before {
130
- padding-top: 10px;
131
- }
196
+ pre a:first-of-type::before {
197
+ padding-top: 10px;
198
+ }
132
199
 
133
- pre a:last-of-type::before {
134
- padding-bottom: 10px;
135
- }
200
+ pre a:last-of-type::before {
201
+ padding-bottom: 10px;
202
+ }
136
203
 
137
- pre a:only-of-type::before {
138
- padding: 10px;
139
- }
204
+ pre a:only-of-type::before {
205
+ padding: 10px;
206
+ }
207
+
208
+ .highlight { background-color: #ffffcc } /* RIGHT */
209
+ </style>
210
+ </head>
211
+ <body>
212
+ <div>
140
213
 
141
- .highlight { background-color: #ffffcc } /* RIGHT */
142
- </style>
143
- </head>
144
- <body>
145
- <div>
146
-
147
- </div>
148
- <div id='readme' style='width:834px;margin:20px auto'>
149
- <ul id="tree" class="ztree" style="">
214
+ </div>
215
+ <div id='readme' style='width:834px;margin:20px auto'>
216
+ <ul id="tree" class="ztree" style="">
217
+
218
+ </ul>
219
+ <article class='markdown-body'>
220
+ #{parse_markdown}
221
+ </article>
222
+ </div>
223
+ </body>
224
+ </html>
225
+ <script type="text/javascript" src="#{@editor_path}/toc/js/jquery-1.4.4.min.js"></script>
226
+ <script type="text/javascript" src="#{@editor_path}/toc/js/jquery.ztree.core-3.5.js"></script>
227
+ <script type="text/javascript" src="#{@editor_path}/toc/js/jquery.ztree_toc.min.js"></script>
228
+ <SCRIPT type="text/javascript" >
229
+ <!--
230
+ $(document).ready(function(){
231
+ $('#tree').ztree_toc({
150
232
 
151
- </ul>
152
- <article class='markdown-body'>
153
- #{parse_markdown}
154
- </article>
155
- </div>
156
- </body>
157
- </html>
158
- <script type="text/javascript" src="#{@editor_path}/toc/js/jquery-1.4.4.min.js"></script>
159
- <script type="text/javascript" src="#{@editor_path}/toc/js/jquery.ztree.core-3.5.js"></script>
160
- <script type="text/javascript" src="#{@editor_path}/toc/js/jquery.ztree_toc.min.js"></script>
161
- <SCRIPT type="text/javascript" >
162
- <!--
163
- $(document).ready(function(){
164
- $('#tree').ztree_toc({
165
-
166
- });
167
- });
168
- //-->
169
- </SCRIPT>
170
- }
171
-
172
- if destiny_dir.to_s.index('/')
173
- p '1build src/' + destiny_dir.to_s.split('/')[1] + '/' + ff.gsub('.md','') + '.html'
174
- build_dir = 'preview/'
175
-
176
- p 'build = ' + dest_dir + ff.gsub('.md','') + '.html'
177
- IO.write(dest_dir + '/' + ff.gsub('.md','') + '.html',t) # => 10
178
- else
179
- p '2build src/' + ff.gsub('.md','') + '.html'
180
- build_dir = 'preview/'
181
- # write to html file
182
- IO.write(build_dir + '/' + ff.gsub('.md','') + '.html',t) # => 10
183
- end
233
+ });
234
+ });
235
+ //-->
236
+ </SCRIPT>
237
+ }
238
+
239
+ if destiny_dir.to_s.index('/')
240
+ # p '1build src/' + destiny_dir.to_s.split('/')[1] + '/' + ff.gsub('.md','') + '.html'
241
+ build_dir = 'preview/'
184
242
 
185
- end
186
- end
187
- end
188
-
243
+ p 'build = ' + dest_dir + '/' + ff.gsub('.md','') + '.html'
244
+ IO.write(dest_dir + '/' + ff.gsub('.md','') + '.html',t) # => 10
245
+ else
246
+ # p '2build src/' + ff.gsub('.md','') + '.html'
247
+ build_dir = 'preview/'
248
+ # write to html file
249
+ IO.write(build_dir + '/' + ff.gsub('.md','') + '.html',t) # => 10
250
+ end
251
+ end
189
252
 
190
253
  end
191
254
 
@@ -1,3 +1,3 @@
1
1
  module Mdpreview
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/mdpreview.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require "mdpreview/version"
2
2
  require 'mdpreview/translator'
3
3
 
4
-
5
4
  module Mdpreview
6
5
  # Your code goes here...
7
6
  def self.hi(a)
@@ -9,10 +8,12 @@ module Mdpreview
9
8
  translator.hi
10
9
  # puts version info
11
10
  p VERSION
12
-
13
11
  end
14
-
15
-
16
-
17
-
12
+
13
+ def self.hi_dir(a)
14
+ translator = Translator.new(a)
15
+ translator.hi_dir
16
+ # puts version info
17
+ p VERSION
18
+ end
18
19
  end
data/vendor/cur.file CHANGED
@@ -1,6 +0,0 @@
1
- ## 步骤
2
-
3
- 1. 生成.toc目录,把template.html拷贝进去
4
- 1. 生成preview目录
5
- 1. 编译markdown到preview目录
6
- 1. 读取路径,将css和js举例增加到template中
data/vendor/meta.js CHANGED
@@ -1 +1 @@
1
- /Volumes/data/Github/toc.md/README.md
1
+ /Volumes/data/Github/toc.md/
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tocmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - shiren1118