ppz 1.0.0 → 1.0.1

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: d446dbd5570e54876363303e60e7d6b42c74074b231a62a7cd418fa4c241b768
4
- data.tar.gz: cf6870884a629d64224f256ffe0c7e4620d525e1d1fa1fe7f7739a691981984a
3
+ metadata.gz: 5cc249a9892c07ef6b2f3325057c2d90574593435a90b4a097dd2d1f7d5a7d5b
4
+ data.tar.gz: f6573a7c9da1292fcf385a3bc0e23ca9d825219cb2d322316bd82395bde3604e
5
5
  SHA512:
6
- metadata.gz: 9b5e40c14d3e4b916a35fbb27691b31d1dff0bda542d09fabbc53b764addd59251e47986e09371a5ac9d1046a0612e783ce7e435b2596019da944c436a0a5104
7
- data.tar.gz: 572592413bf31f57f23c32d797bc716a849aa1132d0010924d05ea0955fe466e1227c1d977467130f440a0237cc144211573632f9c793301dbf5da15e261ca69
6
+ metadata.gz: c0a8ee4c7b4d6fe3c4bc8ae415d9a2b50cacc828723a0cf07c44fba5714468655cb803b44ba503ba58d70543acdd0d0cb7bfdebed4dab4890994a71d5a1e4a4a
7
+ data.tar.gz: 011012d0ed8c6e63e9fc1ccd6ce540e1098abaa45852cd19013b9bdf3edf8b4cf2a20d45da13b2ee5269ad4305529bf1466cd3f1005458b1573ecb4cef091e33
@@ -20,6 +20,6 @@ class PPZ::SpecialContainerModel < PPZ::AbstractWrapperModel
20
20
  end
21
21
 
22
22
  def to_html
23
- "<div class=\"special-block-container #{@name}\">#{super}</div>"
23
+ "<ol class=\"special-block-container #{@name}\">#{super}</ol>"
24
24
  end
25
25
  end
@@ -3,6 +3,6 @@ class PPZ::SpecialItemModel < PPZ::AbstractModel
3
3
  @line = line
4
4
  end
5
5
  def to_html
6
- "<div class=\"special-block-item\">#{@line}</div>"
6
+ "<li>#{@line}</li>"
7
7
  end
8
8
  end
@@ -1,12 +1,18 @@
1
+ require 'pathname'
2
+
1
3
  module PPZ::Folder
2
4
  class AbstractModel
3
5
  attr_reader :index, :name, :level
4
6
  attr_accessor :prev_model, :next_model, :father_model
5
7
 
6
8
  def initialize path, level
7
- throw '文件(夹)的名字得是字符串啊' unless path.is_a? String
9
+ if path.is_a? String
10
+ path = Pathname path
11
+ elsif !(path.is_a? Pathname)
12
+ throw '文件夹的名字必须是 String 或 Pathname'
13
+ end
8
14
  @path = path
9
- @basename = File.basename path
15
+ @basename = path.basename.to_s
10
16
  @level = level
11
17
  end
12
18
 
@@ -21,10 +27,6 @@ module PPZ::Folder
21
27
  end
22
28
  end
23
29
 
24
- def get_css_path
25
- ('../' * @level) + 'style.css'
26
- end
27
-
28
30
  def relative_link target
29
31
  relative_level = @level - target.level # relative_level 是“目标 model 比当前 level 高几级”
30
32
 
@@ -48,11 +50,13 @@ module PPZ::Folder
48
50
  get_head_html +
49
51
  get_ancestor_html +
50
52
  get_content_html +
51
- get_nav_html
53
+ get_nav_html +
54
+ get_js_html
52
55
  end
53
56
 
54
57
  def get_head_html
55
- %~<title>#{@name}</title><link rel="stylesheet" href="#{get_css_path}"/>~
58
+ css_path = ('../' * @level) + '.ppz/asset/style/index.css'
59
+ %~<title>#{@name}</title><link rel="stylesheet" href="#{css_path}">~
56
60
  end
57
61
 
58
62
  def get_ancestor_html
@@ -86,5 +90,10 @@ module PPZ::Folder
86
90
 
87
91
  %~<ul class="interpage-nav">#{prev_model_html}#{next_model_html}</ul>~
88
92
  end
93
+
94
+ def get_js_html
95
+ js_path = ('../' * @level) + '.ppz/asset/js/index.js'
96
+ %~<script type="module" src="#{js_path}"></script>~
97
+ end
89
98
  end
90
99
  end
@@ -1,6 +1,5 @@
1
1
  module PPZ::Folder
2
2
  class AbstractFileModel < AbstractModel
3
- attr_reader :name
4
3
  def self.from_path path, level
5
4
  if (File.extname path) == '.ppz'
6
5
  PPZFileModel.new path, level
@@ -12,12 +11,17 @@ class AbstractFileModel < AbstractModel
12
11
  attr_reader :file_ext
13
12
  def initialize path, level
14
13
  super
15
- unless /^((\d+)_)?([^\.]+)(\.[^\.]+)?$/.match @basename
16
- throw '文件的命名方式不太理解哦:' + path
14
+ temp_bn = @basename
15
+ if /^(\d+)_/.match temp_bn
16
+ @index = $1.to_i
17
+ temp_bn = temp_bn[($1.size + 1)..-1]
18
+ else
19
+ @index = Float::INFINITY
17
20
  end
18
- @index = $2?($2.to_i):(Float::INFINITY)
19
- @name = $3
20
- @file_ext = $4 || ''
21
+
22
+ /(.*)(\.[^\.]+)$/.match temp_bn
23
+ @name = $1 || temp_bn
24
+ @file_ext = $2 || ''
21
25
  end
22
26
  end
23
27
  end
@@ -1,7 +1,7 @@
1
1
  module PPZ::Folder
2
2
  class OtherFileModel < AbstractFileModel
3
3
  def _compile dir_out
4
- FileUtils.cp @path, (dir_out + '/' + @basename)
4
+ FileUtils.cp @path, (dir_out + @basename)
5
5
  end
6
6
  end
7
7
  end
@@ -3,7 +3,7 @@ module PPZ::Folder
3
3
  attr_accessor :left, :right
4
4
 
5
5
  def _compile dir_out
6
- PPZ::Func::write_to_file (dir_out + '/' + @name + '.html'), to_html
6
+ PPZ::Func::write_to_file (dir_out + (@name + '.html')), to_html
7
7
  end
8
8
 
9
9
  private
@@ -1,3 +1,5 @@
1
+ require 'pathname'
2
+
1
3
  module PPZ::Folder
2
4
  class FolderModel < AbstractModel
3
5
  attr_reader :children
@@ -9,8 +11,8 @@ module PPZ::Folder
9
11
  @name = $3
10
12
 
11
13
  @children = []
12
- (Dir.children path, encoding: 'utf-8').each do |child_name|
13
- @children.push AbstractModel.from_path (path + '/' + child_name), level
14
+ (Dir.children @path, encoding: 'utf-8').each do |child_name|
15
+ @children.push AbstractModel.from_path (@path + child_name), level
14
16
  end
15
17
  @children.sort! do |a, b|
16
18
  a.index <=> b.index
@@ -31,27 +33,28 @@ module PPZ::Folder
31
33
  end
32
34
 
33
35
  def _compile out_dir # compile 是 _compile 的安全版本
34
- PPZ::Func.write_to_file (out_dir + '/' + @name + '.html'), to_html
36
+ out_file_pathname = out_dir + (@name + '.html')
37
+ PPZ::Func.write_to_file out_file_pathname, to_html
35
38
 
36
- children_dir = out_dir + '/' + @name
39
+ children_dir = out_dir + @name
37
40
  Dir.mkdir children_dir
38
41
  @children.each { |child| child._compile children_dir }
39
42
  end
40
43
 
41
44
  def compile out_dir
45
+ if out_dir.is_a? String
46
+ out_dir = Pathname out_dir
47
+ elsif !(out_dir.is_a? Pathname)
48
+ throw '输出文件夹的名字必须是 String 或 Pathname'
49
+ end
50
+
42
51
  set_prev_and_next_page
43
52
 
44
- unless out_dir.is_a? String
45
- throw 'out_dir 只能是字符串'
46
- end
47
53
  unless Dir.exist? out_dir
48
54
  throw "out_dir #{out_dir} 不存在"
49
55
  end
50
- if ['/', '\\'].include? out_dir[-1]
51
- _compile out_dir[0...-1]
52
- else
53
- _compile out_dir
54
- end
56
+
57
+ _compile out_dir
55
58
  end
56
59
 
57
60
  def get_content_table_html root
data/lib/func/util.rb CHANGED
@@ -17,13 +17,5 @@ class PPZ::Func
17
17
  def class_has_const? instance, const_name
18
18
  has_const? instance.class, const_name
19
19
  end
20
-
21
- def format_path path
22
- if ['/', '\\'].include? path[-1]
23
- path[0...-1]
24
- else
25
- path
26
- end
27
- end
28
20
  end
29
21
  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: 1.0.0
4
+ version: 1.0.1
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-24 00:00:00.000000000 Z
11
+ date: 2021-03-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: 372301467@qq.com