m2m 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/lib/compiler.rb +1 -1
  3. data/lib/generator.rb +1 -1
  4. data/lib/product.rb +1 -1
  5. data/lib/store.rb +116 -26
  6. data/lib/themes/gitbook/_assets/fonts/fontawesome/FontAwesome.otf +0 -0
  7. data/lib/themes/gitbook/_assets/fonts/fontawesome/fontawesome-webfont.eot +0 -0
  8. data/lib/themes/gitbook/_assets/fonts/fontawesome/fontawesome-webfont.svg +655 -0
  9. data/lib/themes/gitbook/_assets/fonts/fontawesome/fontawesome-webfont.ttf +0 -0
  10. data/lib/themes/gitbook/_assets/fonts/fontawesome/fontawesome-webfont.woff +0 -0
  11. data/lib/themes/gitbook/_assets/fonts/fontawesome/fontawesome-webfont.woff2 +0 -0
  12. data/lib/themes/gitbook/_assets/gitbook.js +4 -0
  13. data/lib/themes/gitbook/_assets/highlight/github.css +124 -0
  14. data/lib/themes/gitbook/_assets/highlight/highlight.js +1 -0
  15. data/lib/themes/gitbook/_assets/images/apple-touch-icon-precomposed-152.png +0 -0
  16. data/lib/themes/gitbook/_assets/images/favicon.ico +0 -0
  17. data/lib/themes/gitbook/_assets/style.css +9 -0
  18. data/lib/themes/gitbook/_assets/theme.js +4 -0
  19. data/lib/themes/gitbook/template/article.mustache +29 -0
  20. data/lib/themes/gitbook/template/home.mustache +24 -0
  21. data/lib/themes/gitbook/template/index.mustache +24 -0
  22. data/lib/themes/gitbook/template/mail.mustache +5 -0
  23. data/lib/themes/gitbook/template/partials/footer.mustache +3 -0
  24. data/lib/themes/gitbook/template/partials/head.mustache +22 -0
  25. data/lib/themes/gitbook/template/partials/header.mustache +78 -0
  26. data/lib/themes/gitbook/template/partials/summary.mustache +31 -0
  27. metadata +23 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f65d9e01f4b4e4f27d439dc9a6fb6a91e686294
4
- data.tar.gz: 57c9b168be1279c46f76e6c8499eae7c09cfac9c
3
+ metadata.gz: a71ff3e033f8825e1b69c2ff5207cf61e2fcac2c
4
+ data.tar.gz: be629fccffa18d444d7710f3c65b34b99b5310c6
5
5
  SHA512:
6
- metadata.gz: 34362e8196765e446f563e9d0006f675b7efdab8567af7719f58e35ff067ce28d52e6b3221ca72b1bf100960045b6089926a9e7569a61d3ddf104fb80d6ba236
7
- data.tar.gz: d500be9c8c50dc9cd9970cf114bf1ab0dba7741ab6680a4ffd104bc14a1fdddae832aad6bab7f9dfeb4757c5e0474689253fbc2028f85b86571527a2e6503a7c
6
+ metadata.gz: 15b1beb6df73185178b992b7e022b44e6035c3b4ecce8293d3e92c028aa25316ef12cbf39536d679dfb855c6c890a9c1504b9626eed073c51637d9d415e7c068
7
+ data.tar.gz: a1d726557ec291ce619cef0d278a98c8b93613204253af58d8b5bccd25c1d56748f8facada6176c3af1436d3ccd7363559b7c3175de1cc7ad0a4956d36f19ac3
data/lib/compiler.rb CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  #使用模板转换为HTML
4
4
 
5
- require 'mustache'
6
5
  require 'pathname'
6
+ require 'mustache'
7
7
  require 'fileutils'
8
8
 
9
9
  require_relative './util'
data/lib/generator.rb CHANGED
@@ -140,7 +140,7 @@ class Generator
140
140
 
141
141
  #编译模板
142
142
  def compiler(filename, template_name, data)
143
- data['tree'] = @store.tree
143
+ data['categories'] = @store.categories
144
144
  data['product'] = @util.get_product
145
145
  data['root/relative_path'] = @util.get_relative_dot(filename)
146
146
 
data/lib/product.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module M2M
4
- VERSION = "0.2.7"
4
+ VERSION = "0.2.8"
5
5
  NAME = "m2m"
6
6
  REPOS = "https://github.com/wvv8oo/m2m"
7
7
  HOMEPAGE = "http://m2m.wvv8oo.com/"
data/lib/store.rb CHANGED
@@ -18,23 +18,22 @@ class Store
18
18
  #首页
19
19
  'home' => nil,
20
20
  #完整的分类
21
- 'categories' => Array.new,
21
+ 'categories' => [],
22
22
  #所有文章列表
23
23
  'articles' => self.get_articles(files),
24
24
  #目录树
25
25
  'tree' => {
26
- @children_key => Array.new
26
+ @children_key => []
27
27
  }
28
28
  }
29
29
 
30
- self.make_tree_index
31
- self.make_categories
30
+ self.make_tree
32
31
  self.sort @data['tree']
33
32
  end
34
33
 
35
34
  #获取所有的分类
36
35
  def categories
37
- @data['categories']
36
+ return @data['categories']
38
37
  end
39
38
 
40
39
  #获取
@@ -69,46 +68,137 @@ class Store
69
68
  result
70
69
  end
71
70
 
72
- #生成分类的列表
73
- def make_categories
74
-
75
- end
76
-
77
- #创建树状结构的索引
78
- def make_tree_index
71
+ #创建树状结构的索引, 以及分类
72
+ def make_tree
79
73
  this = self
80
74
  @data['articles'].each{ |key, article|
81
75
  dir = File::dirname(article['relative_path'])
82
76
  relative_path_md5 = article['relative_path_md5']
83
- this.mount_node_to_tree dir, relative_path_md5
77
+ this.mount_node_to_index dir, relative_path_md5
78
+ this.mount_node_to_categories dir, relative_path_md5
84
79
  }
85
80
  end
86
81
 
87
- #挂到节点上, 如果不在则创建
88
- def mount_node_to_tree(path, relative_path_md5)
89
- node = @data['tree']
82
+ #当前的路径挂到正确的路径上
83
+ def mount_node_to_tree(root, url, children_key, callback)
84
+ #根目录下的, 直接挂上去
85
+ return callback.call root, nil, 0, 0 if url == '.'
86
+
87
+ node = root
88
+ #将路径分成段, 如果没存在这个节点, 则创建
89
+ index = 1
90
+ segments = url.split('/')
91
+ segments.each{ |segment|
92
+ node = callback.call node, segment, index, segments.length
93
+ index = index + 1
94
+ }
95
+ end
90
96
 
91
- if path == '.'
92
- node[@children_key].push relative_path_md5
93
- return
94
- end
97
+ #将节点挂到索引上
98
+ def mount_node_to_index(url, relative_path_md5)
99
+ key = @children_key
100
+ #回调的处理
101
+ callback = lambda { |node, segment, index, total|
102
+ #根节点, 直接插入到items中
103
+ if segment == nil
104
+ node[@children_key].push relative_path_md5
105
+ return node
106
+ end
95
107
 
96
- path.split('/').each{ |segment|
108
+ #如果没有找到, 则创建新的节点
97
109
  current_node = node[segment]
98
110
  if not current_node
99
111
  current_node = Hash.new()
100
- current_node[@children_key] = Array.new
112
+ current_node[key] = Array.new
101
113
  node[segment] = current_node
102
114
  end
103
115
 
104
- node = current_node
105
- node[@children_key].push relative_path_md5
116
+ current_node[key].push relative_path_md5
117
+ return current_node
118
+ }
119
+
120
+ self.mount_node_to_tree @data['tree'], url, @children_key, callback
121
+ end
122
+
123
+ #将节点挂到分类下
124
+ def mount_node_to_categories(url, relative_path_md5)
125
+ #回调的处理
126
+ callback = lambda { |parent, segment, index, total|
127
+ if segment != nil
128
+ node = self.get_categories_node_children parent, segment
129
+ #还不是最后一个节点
130
+ return node if index < total
131
+ else
132
+ node = parent
133
+ end
134
+
135
+ #获取文章的信息
136
+ article = @data['articles'][relative_path_md5]
137
+ meta = article['meta']
138
+
139
+ #分类中的文章
140
+ item = {
141
+ 'title' => meta['title'],
142
+ 'relative_url' => article['relative_url']
143
+ }
106
144
 
107
- #所有的子级,都要向root插入数据
108
- @data['tree'][@children_key].push relative_path_md5
145
+ if segment == nil
146
+ node.push item
147
+ return node
148
+ end
149
+
150
+ #还没有这个键
151
+ node[@children_key] = [] if node[@children_key] == nil
152
+ node[@children_key].push item
153
+ return node
109
154
  }
155
+
156
+ self.mount_node_to_tree @data['categories'], url, @children_key, callback
157
+ end
158
+
159
+ #从数组的分类中,获取节点, 如果节点不存在, 则创建一个
160
+ def get_categories_node_children(parent, segment)
161
+ parent.each { | current |
162
+ return current if current['title'] == segment
163
+ }
164
+
165
+ #如果没有找到, 则创建一个
166
+ node = {
167
+ 'title' => segment,
168
+ @children_key => []
169
+ }
170
+
171
+ parent.push node
172
+ node
110
173
  end
111
174
 
175
+ #挂到节点上, 如果不在则创建
176
+ # def mount_node_to_tree(path, relative_path_md5)
177
+ # node = @data['tree']
178
+
179
+
180
+ # #根目录下的
181
+ # if path == '.'
182
+ # node[@children_key].push relative_path_md5
183
+ # return
184
+ # end
185
+
186
+ # path.split('/').each{ |segment|
187
+ # current_node = node[segment]
188
+ # if not current_node
189
+ # current_node = Hash.new()
190
+ # current_node[@children_key] = Array.new
191
+ # node[segment] = current_node
192
+ # end
193
+
194
+ # node = current_node
195
+ # node[@children_key].push relative_path_md5
196
+
197
+ # #所有的子级,都要向root插入数据
198
+ # @data['tree'][@children_key].push relative_path_md5
199
+ # }
200
+ # end
201
+
112
202
 
113
203
  #给所有的文件夹排序
114
204
  def sort(node)