ppz 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
  SHA256:
3
- metadata.gz: 52c9495b0dd9d71eb9f4cd1a6dcaec7805fb10c450dc1d96d664ae7c30d16e0f
4
- data.tar.gz: 1a2959299c61dcdf554f6923f5c28c713d8667eba7669b6c683b5196081c27b6
3
+ metadata.gz: bad1dbe093ab8a51881656c02401cfbefce4f3ca153a5dfc7b5f9cd5483a161c
4
+ data.tar.gz: 02a01ac4f61ef0e2edd725407ecf1baed235501b635065463049db698a2719d9
5
5
  SHA512:
6
- metadata.gz: 4fc7fbcf2fc28272ab0f453477f8f23eff28bc51040b032896fd58ddb2fd6a28be3afba1ada77b956d577db0ab23e60f7fdb8c9ddd030891687f2893595f6323
7
- data.tar.gz: 7f6013e0106ee614b07b0ba255e4b812cd4f3fb2773dd98fbb71c2098d51a723b3ef7cd47086a96a33db3370448be9397ae32977abfe889113b66056bacdbd57
6
+ metadata.gz: 72f1066915ce586d43b514411d109c7016b754b30cfb192262044813d8db268ca14c99226edadd8bfd5f627f0ef48d96d8ca9337fdb6f7f13e33a10f8c5a67a9
7
+ data.tar.gz: 8e7267e62274f2ff85c89596ab7799a64574fba03da5c776f3293b0e39da4aeebba208b989b04756bb98304a58abb967a0317455a3533e04411917109af318c7
data/asset/style/ppz.css CHANGED
@@ -28,13 +28,40 @@ aside ul {
28
28
  }
29
29
  aside a {
30
30
  width: 100%;
31
+ display: block;
31
32
  overflow: hidden;
32
33
  text-overflow: ellipsis;
33
34
  white-space: nowrap;
34
35
  }
36
+ .ancestor-nav ul {
37
+ margin: 0;
38
+ padding: 0;
39
+ list-style: none;
40
+ font-size: 0.8rem;
41
+ margin: 1rem 2rem 0 0;
42
+ text-align: right;
43
+ }
44
+ .ancestor-nav li {
45
+ margin: 0;
46
+ padding: 0;
47
+ display: inline-block;
48
+ }
49
+ .ancestor-nav li a {
50
+ display: inline-block;
51
+ opacity: 0.66;
52
+ transition: all 0.3s;
53
+ }
54
+ .ancestor-nav li a:hover {
55
+ opacity: 1;
56
+ transform: scale(1.1, 1.1);
57
+ }
58
+ .ancestor-nav li:not(.self)::after {
59
+ content: '/';
60
+ margin: 0 0.36rem;
61
+ }
35
62
  article {
36
63
  margin-left: 188px;
37
- padding: 1px 1rem;
64
+ padding: 1px 2rem 1rem 1rem;
38
65
  }
39
66
  h1 {
40
67
  font-size: 2rem;
@@ -89,9 +116,9 @@ h3::before {
89
116
  padding: 2px 4px;
90
117
  }
91
118
  .interpage-nav {
92
- margin-left: 188px;
119
+ margin: 1rem 2rem 2rem 188px;
120
+ padding: 0 2rem;
93
121
  list-style: none;
94
- padding: 0 1rem;
95
122
  }
96
123
  .interpage-nav .prev {
97
124
  float: left;
@@ -112,6 +139,3 @@ h3::before {
112
139
  display: block;
113
140
  clear: both;
114
141
  }
115
- .folder-nav {
116
- margin: 2rem 3rem;
117
- }
data/asset/style/ppz.styl CHANGED
@@ -26,13 +26,36 @@ aside
26
26
  list-style none
27
27
  a
28
28
  width 100%
29
+ display block
29
30
  overflow hidden
30
31
  text-overflow ellipsis
31
32
  white-space nowrap
33
+ .ancestor-nav
34
+ ul
35
+ margin 0
36
+ padding 0
37
+ list-style none
38
+ font-size 0.8rem
39
+ margin 1rem 2rem 0 0
40
+ text-align right
41
+ li
42
+ margin 0
43
+ padding 0
44
+ display inline-block
45
+ a
46
+ display inline-block
47
+ opacity 0.66
48
+ transition all 0.3s
49
+ &:hover
50
+ opacity 1
51
+ transform scale(1.1, 1.1)
52
+ &:not(.self)::after
53
+ content '/'
54
+ margin 0 .36rem
32
55
 
33
56
  article
34
- margin-left: nav-width
35
- padding: 1px 1rem
57
+ margin-left nav-width
58
+ padding: 1px 2rem 1rem 1rem
36
59
  h1
37
60
  font-size 2rem
38
61
  h2
@@ -84,9 +107,9 @@ h1, h2, h3
84
107
  padding 2px 4px
85
108
 
86
109
  .interpage-nav
87
- margin-left nav-width
110
+ margin 1rem 2rem 2rem nav-width
111
+ padding 0 2rem
88
112
  list-style none
89
- padding 0 1rem
90
113
  .prev
91
114
  float left
92
115
  &::before
@@ -100,7 +123,4 @@ h1, h2, h3
100
123
  &::after
101
124
  content ''
102
125
  display block
103
- clear both
104
-
105
- .folder-nav
106
- margin 2rem 3rem
126
+ clear both
@@ -1,10 +1,17 @@
1
1
  class PPZ::SpecialContainerModel < PPZ::AbstractWrapperModel
2
2
  UpperClass = PPZ::AbstractSectionModel
3
3
 
4
- REG_EXP = /^```( (.*))?/
4
+ REG_EXP = /^```( (.*))?$/
5
5
  def self.from_line line
6
- return nil unless REG_EXP.match(line)
7
- PPZ::SpecialContainerModel.new $2
6
+ if REG_EXP.match line
7
+ if $2 && ($2.include? '```')
8
+ nil
9
+ else
10
+ PPZ::SpecialContainerModel.new $2
11
+ end
12
+ else
13
+ nil
14
+ end
8
15
  end
9
16
 
10
17
  def initialize name
@@ -1,12 +1,6 @@
1
1
  # 解析一个文件夹里的 .ppz 文件
2
2
 
3
3
  module PPZ::Folder
4
- class FolderParser
5
- def initialize
6
- @context = Context.new
7
- end
8
- end
9
-
10
4
  require_relative './model/abstract'
11
5
  require_relative './model/folder'
12
6
  require_relative './model/file/abstract'
@@ -1,6 +1,7 @@
1
1
  module PPZ::Folder
2
2
  class AbstractModel
3
- attr_reader :index, :name
3
+ attr_reader :index, :name, :level
4
+ attr_accessor :prev_model, :next_model, :father_model
4
5
 
5
6
  def initialize path, level
6
7
  throw '文件(夹)的名字得是字符串啊' unless path.is_a? String
@@ -23,5 +24,67 @@ module PPZ::Folder
23
24
  def get_css_path
24
25
  ('../' * @level) + 'style.css'
25
26
  end
27
+
28
+ def relative_link target
29
+ relative_level = target.level - @level # relative_level 是“当前 model 比目标 level 高几级”
30
+
31
+ (if relative_level > 0
32
+ '../' * relative_level
33
+ elsif relative_level < 0
34
+ result = ''
35
+ father = @father_model
36
+ (- relative_level).times do
37
+ result = father.name + '/' + result
38
+ father = father.father_model
39
+ end
40
+ result
41
+ else
42
+ ''
43
+ end) + @name + '.html'
44
+ end
45
+
46
+ private
47
+ def to_html
48
+ get_head_html +
49
+ get_ancestor_html +
50
+ get_content_html +
51
+ get_nav_html
52
+ end
53
+
54
+ def get_head_html
55
+ %~<title>#{@name}</title><link rel="stylesheet" href="#{get_css_path}"/>~
56
+ end
57
+
58
+ def get_ancestor_html
59
+ list = []
60
+ father = self
61
+ loop do
62
+ break unless father.father_model
63
+ father = father.father_model
64
+ list.unshift father
65
+ end
66
+ %~<div class="ancestor-nav"><ul>#{
67
+ (list.collect do |node|
68
+ %`<li><a href="#{node.relative_link self}">#{node.name}</a></li>`
69
+ end
70
+ .join) + %`<li class="self">#{self.name}</li>`
71
+ }</ul></div>~
72
+ end
73
+
74
+ def get_nav_html
75
+ # prev_model nav_html
76
+ prev_model_html = ''
77
+ if @prev_model
78
+ prev_link = @prev_model.relative_link self
79
+ prev_model_html = "<li class=\"prev\"><a href=\"#{prev_link}\">#{@prev_model.name}</a></li>"
80
+ end
81
+ next_model_html = ''
82
+ if @next_model
83
+ next_link = @next_model.relative_link self
84
+ next_model_html = "<li class=\"next\"><a href=\"#{next_link}\">#{@next_model.name}</a></li>"
85
+ end
86
+
87
+ %~<ul class="interpage-nav">#{prev_model_html}#{next_model_html}</ul>~
88
+ end
26
89
  end
27
90
  end
@@ -10,7 +10,6 @@ class AbstractFileModel < AbstractModel
10
10
  end
11
11
 
12
12
  attr_reader :file_ext
13
-
14
13
  def initialize path, level
15
14
  super
16
15
  unless /^((\d+)_)?([^\.]+)(\.[^\.]+)?$/.match @basename
@@ -3,19 +3,13 @@ module PPZ::Folder
3
3
  attr_accessor :left, :right
4
4
 
5
5
  def _compile dir_out
6
- parser = PPZ::FileDocParser.new @path
7
- html_str = %!<link rel="stylesheet" href="#{get_css_path}"/>
8
- <title>#{@name}</title>#{
9
- parser.get_model.to_html
10
- }<ul class="interpage-nav">#{
11
- (@left ?
12
- "<li class=\"prev\"><a href=\"#{@left.name}.html\">#{@left.name}</a></li>"
13
- : "") +
14
- (@right ?
15
- "<li class=\"next\"><a href=\"#{@right.name}.html\">#{@right.name}</a></li>"
16
- : "")
17
- }</ul>!
18
- PPZ::Func::write_to_file (dir_out + '/' + @name + '.html'), html_str
6
+ PPZ::Func::write_to_file (dir_out + '/' + @name + '.html'), to_html
19
7
  end
8
+
9
+ private
10
+ def get_content_html
11
+ (PPZ::FileDocParser.new @path)
12
+ .get_model.to_html
13
+ end
20
14
  end
21
15
  end
@@ -1,5 +1,7 @@
1
1
  module PPZ::Folder
2
2
  class FolderModel < AbstractModel
3
+ attr_reader :children
4
+
3
5
  def initialize path, level
4
6
  super
5
7
  /^((\d+)_)?(.+)/.match @basename
@@ -14,8 +16,11 @@ module PPZ::Folder
14
16
  a.index <=> b.index
15
17
  end
16
18
 
19
+ # 设置上级 和 左右
17
20
  left = right = nil
18
21
  @children.each do |child|
22
+ child.father_model = self # 上级
23
+
19
24
  next unless child.is_a? PPZFileModel
20
25
  if left
21
26
  left.right = child
@@ -25,21 +30,8 @@ module PPZ::Folder
25
30
  end
26
31
  end
27
32
 
28
- def title
29
- @name
30
- end
31
-
32
33
  def _compile out_dir # compile 是 _compile 的安全版本
33
- PPZ::Func.write_to_file (out_dir + '/' + @name + '.html'), %!<title>#{title}</title>
34
- <link rel="stylesheet" href="#{get_css_path}"/><div class="folder-nav"><ul>#{
35
- @children
36
- .map do |child|
37
- child.file_ext == '.ppz' ?
38
- "<li><a href=\"./#{@name}/#{child.name}.html\">#{child.name}</a></li>"
39
- : ''
40
- end
41
- .join
42
- }</ul></div>!
34
+ PPZ::Func.write_to_file (out_dir + '/' + @name + '.html'), to_html
43
35
 
44
36
  children_dir = out_dir + '/' + @name
45
37
  Dir.mkdir children_dir
@@ -47,6 +39,8 @@ module PPZ::Folder
47
39
  end
48
40
 
49
41
  def compile out_dir
42
+ set_prev_and_next_page
43
+
50
44
  unless out_dir.is_a? String
51
45
  throw 'out_dir 只能是字符串'
52
46
  end
@@ -59,5 +53,41 @@ module PPZ::Folder
59
53
  _compile out_dir
60
54
  end
61
55
  end
56
+
57
+ # 设置页面的“上一篇、下一篇”
58
+ private
59
+ def set_prev_and_next_page
60
+ list = []
61
+ linearize_children self, list
62
+ list.inject do |pre, nex|
63
+ pre.next_model = nex
64
+ nex.prev_model = pre
65
+ nex
66
+ end
67
+ end
68
+
69
+ def linearize_children child, list
70
+ if child.is_a? PPZFileModel
71
+ list.push child
72
+ elsif child.is_a? FolderModel
73
+ list.push child
74
+ child.children.each do |cc|
75
+ linearize_children cc, list
76
+ end
77
+ end
78
+ end
79
+
80
+ def get_content_html
81
+ %!<article><ul>#{
82
+ @children
83
+ .select do |child|
84
+ (child.class == FolderModel) || (child.file_ext == '.ppz')
85
+ end
86
+ .map do |child|
87
+ "<li><a href=\"./#{@name}/#{child.name}.html\">#{child.name}</a></li>"
88
+ end
89
+ .join
90
+ }</ul></article>!
91
+ end
62
92
  end
63
93
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ppz
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
  - wuse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-13 00:00:00.000000000 Z
11
+ date: 2021-02-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: 372301467@qq.com