ppz 0.0.2 → 1.0.0

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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/doc/index.rb +9 -0
  3. data/lib/{model → doc/model}/abstract/model.rb +0 -0
  4. data/lib/{model → doc/model}/abstract/wrapper-model.rb +0 -0
  5. data/lib/{model → doc/model}/comment/container.rb +1 -1
  6. data/lib/{model → doc/model}/comment/item.rb +1 -1
  7. data/lib/{model → doc/model}/common/escape.rb +0 -0
  8. data/lib/{model → doc/model}/common/tag.rb +0 -0
  9. data/lib/doc/model/index.rb +17 -0
  10. data/lib/{model → doc/model}/list/item/abstract.rb +0 -0
  11. data/lib/{model → doc/model}/list/item/unordered.rb +0 -0
  12. data/lib/{model → doc/model}/list/wrapper/abstract.rb +0 -0
  13. data/lib/{model → doc/model}/list/wrapper/unordered.rb +0 -0
  14. data/lib/{model → doc/model}/p/index.rb +0 -0
  15. data/lib/{model → doc/model}/section/abstract.rb +0 -0
  16. data/lib/{model → doc/model}/section/leaf.rb +0 -0
  17. data/lib/{model → doc/model}/section/root.rb +0 -0
  18. data/lib/doc/model/special-block/container.rb +25 -0
  19. data/lib/{model → doc/model}/special-block/item.rb +1 -1
  20. data/lib/{parser/doc → doc/parser}/abstract.rb +1 -1
  21. data/lib/{parser/common/context/doc.rb → doc/parser/context.rb} +28 -1
  22. data/lib/{parser/doc → doc/parser}/file.rb +0 -0
  23. data/lib/{parser/doc → doc/parser}/string.rb +0 -0
  24. data/lib/folder/index.rb +9 -0
  25. data/lib/folder/model/abstract.rb +90 -0
  26. data/lib/folder/model/file/abstract.rb +23 -0
  27. data/lib/folder/model/file/other.rb +7 -0
  28. data/lib/folder/model/file/ppz.rb +15 -0
  29. data/lib/folder/model/folder.rb +101 -0
  30. data/lib/func/util.rb +9 -1
  31. data/lib/ppz.rb +2 -23
  32. metadata +32 -31
  33. data/asset/style/ppz.css +0 -68
  34. data/asset/style/ppz.styl +0 -59
  35. data/bin/common.rb +0 -43
  36. data/bin/ppz +0 -18
  37. data/lib/model/special-block/container.rb +0 -18
  38. data/lib/parser/common/context/abstract.rb +0 -30
  39. data/lib/parser/folder/index.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50d999d54bdbf78556f37bac10260a0af9315e3b7c708f5e923140628ccbf56e
4
- data.tar.gz: 2a5a604e6f6fdb05c0652322a35cb1231c3701157a189256c87e34fbd692c251
3
+ metadata.gz: d446dbd5570e54876363303e60e7d6b42c74074b231a62a7cd418fa4c241b768
4
+ data.tar.gz: cf6870884a629d64224f256ffe0c7e4620d525e1d1fa1fe7f7739a691981984a
5
5
  SHA512:
6
- metadata.gz: 9f205f57824a0bef8e2f2284135e7da87373eb73cb11a4c635315564e707614328f08d6a34950b4f66bfca32de93b990e6dece6384e94580ff99eabee9f5faaa
7
- data.tar.gz: fe94d84a488ebd411acdc724bcbfe4035011e7948970712b32df71bed3ac2296fde8d98ace6f6c79522ea09e28fb68e8c3616cac80e762ef2fa347e095b65cc3
6
+ metadata.gz: 9b5e40c14d3e4b916a35fbb27691b31d1dff0bda542d09fabbc53b764addd59251e47986e09371a5ac9d1046a0612e783ce7e435b2596019da944c436a0a5104
7
+ data.tar.gz: 572592413bf31f57f23c32d797bc716a849aa1132d0010924d05ea0955fe466e1227c1d977467130f440a0237cc144211573632f9c793301dbf5da15e261ca69
data/lib/doc/index.rb ADDED
@@ -0,0 +1,9 @@
1
+ module PPZ
2
+ # model
3
+ require_relative './model/index'
4
+ # parser
5
+ require_relative './parser/context'
6
+ require_relative './parser/abstract'
7
+ require_relative './parser/file'
8
+ require_relative './parser/string'
9
+ end
File without changes
File without changes
@@ -2,6 +2,6 @@ class PPZ::CommentContainerModel < PPZ::AbstractWrapperModel
2
2
  UpperClass = PPZ::AbstractSectionModel
3
3
 
4
4
  def to_html
5
- "<div class=\"comment\">#{super}</div>"
5
+ "<div class=\"comment-container\">#{super}</div>"
6
6
  end
7
7
  end
@@ -7,6 +7,6 @@ class PPZ::CommentItemModel < PPZ::AbstractModel
7
7
  end
8
8
 
9
9
  def to_html
10
- "<div>#{@content}</div>"
10
+ "<div class=\"comment-item\">#{@content}</div>"
11
11
  end
12
12
  end
File without changes
File without changes
@@ -0,0 +1,17 @@
1
+ module PPZ
2
+ require_relative './abstract/model'
3
+ require_relative './abstract/wrapper-model'
4
+ require_relative './section/abstract'
5
+ require_relative './section/leaf'
6
+ require_relative './section/root'
7
+ require_relative './comment/container'
8
+ require_relative './comment/item'
9
+ require_relative './common/escape'
10
+ require_relative './list/wrapper/abstract'
11
+ require_relative './list/wrapper/unordered'
12
+ require_relative './list/item/abstract'
13
+ require_relative './list/item/unordered'
14
+ require_relative './p/index'
15
+ require_relative './special-block/container'
16
+ require_relative './special-block/item'
17
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,25 @@
1
+ class PPZ::SpecialContainerModel < PPZ::AbstractWrapperModel
2
+ UpperClass = PPZ::AbstractSectionModel
3
+
4
+ REG_EXP = /^```( (.*))?$/
5
+ def self.from_line line
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
15
+ end
16
+
17
+ def initialize name
18
+ @name = name
19
+ super()
20
+ end
21
+
22
+ def to_html
23
+ "<div class=\"special-block-container #{@name}\">#{super}</div>"
24
+ end
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>#{@line}</div>"
6
+ "<div class=\"special-block-item\">#{@line}</div>"
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  class PPZ::AbstractDocParser
4
4
  def initialize
5
- @context = PPZ::DocContext.new PPZ::RootSectionModel.new
5
+ @context = PPZ::ParserContext.new PPZ::RootSectionModel.new
6
6
  end
7
7
 
8
8
  def get_model
@@ -1,4 +1,11 @@
1
- class PPZ::DocContext < PPZ::AbstractContext
1
+ # 当前行,所处的上下文
2
+ # 比如 一级 section 下面的 ul 下的 第 n 个 ul
3
+
4
+ class PPZ::ParserContext
5
+ def initialize root
6
+ @stack = [root]
7
+ end
8
+
2
9
  def append target
3
10
  # ContainerClass: 容器类,如果上级不是,就造一个
4
11
  if(PPZ::Func::class_has_const? target, :ContainerClass) and (head.class != target.class::ContainerClass)
@@ -12,4 +19,24 @@ class PPZ::DocContext < PPZ::AbstractContext
12
19
  head.append target # 加入 model
13
20
  @stack.push target if target.is_a? PPZ::AbstractWrapperModel # 加入 stack
14
21
  end
22
+
23
+ def pop
24
+ @stack.pop
25
+ end
26
+
27
+ def head
28
+ @stack[-1]
29
+ end
30
+
31
+ def root
32
+ @stack[0]
33
+ end
34
+
35
+ private
36
+ def pop_to klass
37
+ loop do
38
+ break if head.is_a? klass
39
+ pop
40
+ end
41
+ end
15
42
  end
File without changes
File without changes
@@ -0,0 +1,9 @@
1
+ # 解析一个文件夹里的 .ppz 文件
2
+
3
+ module PPZ::Folder
4
+ require_relative './model/abstract'
5
+ require_relative './model/folder'
6
+ require_relative './model/file/abstract'
7
+ require_relative './model/file/other'
8
+ require_relative './model/file/ppz'
9
+ end
@@ -0,0 +1,90 @@
1
+ module PPZ::Folder
2
+ class AbstractModel
3
+ attr_reader :index, :name, :level
4
+ attr_accessor :prev_model, :next_model, :father_model
5
+
6
+ def initialize path, level
7
+ throw '文件(夹)的名字得是字符串啊' unless path.is_a? String
8
+ @path = path
9
+ @basename = File.basename path
10
+ @level = level
11
+ end
12
+
13
+ def self.from_path path, level
14
+ level += 1
15
+ if Dir.exist? path
16
+ FolderModel.new path, level
17
+ elsif File.exist? path
18
+ AbstractFileModel.from_path path, level
19
+ else
20
+ throw path + '不存在?'
21
+ end
22
+ end
23
+
24
+ def get_css_path
25
+ ('../' * @level) + 'style.css'
26
+ end
27
+
28
+ def relative_link target
29
+ relative_level = @level - target.level # relative_level 是“目标 model 比当前 level 高几级”
30
+
31
+ (if relative_level > 0
32
+ '../' * relative_level
33
+ elsif relative_level < 0
34
+ result = ''
35
+ father = target.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) + target.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="#{relative_link node}">#{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 = relative_link @prev_model
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 = relative_link @next_model
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
89
+ end
90
+ end
@@ -0,0 +1,23 @@
1
+ module PPZ::Folder
2
+ class AbstractFileModel < AbstractModel
3
+ attr_reader :name
4
+ def self.from_path path, level
5
+ if (File.extname path) == '.ppz'
6
+ PPZFileModel.new path, level
7
+ else
8
+ OtherFileModel.new path, level
9
+ end
10
+ end
11
+
12
+ attr_reader :file_ext
13
+ def initialize path, level
14
+ super
15
+ unless /^((\d+)_)?([^\.]+)(\.[^\.]+)?$/.match @basename
16
+ throw '文件的命名方式不太理解哦:' + path
17
+ end
18
+ @index = $2?($2.to_i):(Float::INFINITY)
19
+ @name = $3
20
+ @file_ext = $4 || ''
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ module PPZ::Folder
2
+ class OtherFileModel < AbstractFileModel
3
+ def _compile dir_out
4
+ FileUtils.cp @path, (dir_out + '/' + @basename)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module PPZ::Folder
2
+ class PPZFileModel < AbstractFileModel
3
+ attr_accessor :left, :right
4
+
5
+ def _compile dir_out
6
+ PPZ::Func::write_to_file (dir_out + '/' + @name + '.html'), to_html
7
+ end
8
+
9
+ private
10
+ def get_content_html
11
+ (PPZ::FileDocParser.new @path)
12
+ .get_model.to_html
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,101 @@
1
+ module PPZ::Folder
2
+ class FolderModel < AbstractModel
3
+ attr_reader :children
4
+
5
+ def initialize path, level
6
+ super
7
+ /^((\d+)_)?(.+)/.match @basename
8
+ @index = $2?($2.to_i):(Float::INFINITY)
9
+ @name = $3
10
+
11
+ @children = []
12
+ (Dir.children path, encoding: 'utf-8').each do |child_name|
13
+ @children.push AbstractModel.from_path (path + '/' + child_name), level
14
+ end
15
+ @children.sort! do |a, b|
16
+ a.index <=> b.index
17
+ end
18
+
19
+ # 设置上级 和 左右
20
+ left = right = nil
21
+ @children.each do |child|
22
+ child.father_model = self # 上级
23
+
24
+ next unless child.is_a? PPZFileModel
25
+ if left
26
+ left.right = child
27
+ child.left = left
28
+ end
29
+ left = child
30
+ end
31
+ end
32
+
33
+ def _compile out_dir # compile 是 _compile 的安全版本
34
+ PPZ::Func.write_to_file (out_dir + '/' + @name + '.html'), to_html
35
+
36
+ children_dir = out_dir + '/' + @name
37
+ Dir.mkdir children_dir
38
+ @children.each { |child| child._compile children_dir }
39
+ end
40
+
41
+ def compile out_dir
42
+ set_prev_and_next_page
43
+
44
+ unless out_dir.is_a? String
45
+ throw 'out_dir 只能是字符串'
46
+ end
47
+ unless Dir.exist? out_dir
48
+ throw "out_dir #{out_dir} 不存在"
49
+ end
50
+ if ['/', '\\'].include? out_dir[-1]
51
+ _compile out_dir[0...-1]
52
+ else
53
+ _compile out_dir
54
+ end
55
+ end
56
+
57
+ def get_content_table_html root
58
+ %~<ul>#{
59
+ @children
60
+ .select do |child|
61
+ (child.class == FolderModel) || (child.file_ext == '.ppz')
62
+ end
63
+ .map do |child|
64
+ result = "<li><a href=\"./#{root.relative_link child}\">#{child.name}</a></li>"
65
+ if child.is_a? FolderModel
66
+ result += child.get_content_table_html root
67
+ end
68
+ result
69
+ end
70
+ .join
71
+ }</ul>~
72
+ end
73
+
74
+ # 设置页面的“上一篇、下一篇”
75
+ private
76
+ def set_prev_and_next_page
77
+ list = []
78
+ linearize_children self, list
79
+ list.inject do |pre, nex|
80
+ pre.next_model = nex
81
+ nex.prev_model = pre
82
+ nex
83
+ end
84
+ end
85
+
86
+ def linearize_children child, list
87
+ if child.is_a? PPZFileModel
88
+ list.push child
89
+ elsif child.is_a? FolderModel
90
+ list.push child
91
+ child.children.each do |cc|
92
+ linearize_children cc, list
93
+ end
94
+ end
95
+ end
96
+
97
+ def get_content_html
98
+ "<article>#{get_content_table_html self}</article>"
99
+ end
100
+ end
101
+ end
data/lib/func/util.rb CHANGED
@@ -4,7 +4,7 @@ class PPZ::Func
4
4
  if File.exist? filepath
5
5
  throw '文件已存在'
6
6
  end
7
- file = File.new filepath, 'w'
7
+ file = File.new filepath, mode: 'w:UTF-8'
8
8
  file.print data
9
9
  file.close
10
10
  end
@@ -17,5 +17,13 @@ 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
20
28
  end
21
29
  end
data/lib/ppz.rb CHANGED
@@ -1,26 +1,5 @@
1
1
  module PPZ
2
2
  require_relative './func/util'
3
-
4
- require_relative './model/abstract/model'
5
- require_relative './model/abstract/wrapper-model'
6
- require_relative './model/section/abstract'
7
- require_relative './model/section/leaf'
8
- require_relative './model/section/root'
9
- require_relative './model/comment/container'
10
- require_relative './model/comment/item'
11
- require_relative './model/common/escape'
12
- require_relative './model/list/wrapper/abstract'
13
- require_relative './model/list/wrapper/unordered'
14
- require_relative './model/list/item/abstract'
15
- require_relative './model/list/item/unordered'
16
- require_relative './model/p/index'
17
- require_relative './model/special-block/container'
18
- require_relative './model/special-block/item'
19
-
20
- require_relative './parser/common/context/abstract'
21
- require_relative './parser/common/context/doc'
22
- require_relative './parser/doc/abstract'
23
- require_relative './parser/doc/file'
24
- require_relative './parser/doc/string'
25
-
3
+ require_relative './doc/index'
4
+ require_relative './folder/index'
26
5
  end
metadata CHANGED
@@ -1,49 +1,50 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ppz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
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-04 00:00:00.000000000 Z
11
+ date: 2021-02-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: 372301467@qq.com
15
- executables:
16
- - ppz
15
+ executables: []
17
16
  extensions: []
18
17
  extra_rdoc_files: []
19
18
  files:
20
- - asset/style/ppz.css
21
- - asset/style/ppz.styl
22
- - bin/common.rb
23
- - bin/ppz
19
+ - lib/doc/index.rb
20
+ - lib/doc/model/abstract/model.rb
21
+ - lib/doc/model/abstract/wrapper-model.rb
22
+ - lib/doc/model/comment/container.rb
23
+ - lib/doc/model/comment/item.rb
24
+ - lib/doc/model/common/escape.rb
25
+ - lib/doc/model/common/tag.rb
26
+ - lib/doc/model/index.rb
27
+ - lib/doc/model/list/item/abstract.rb
28
+ - lib/doc/model/list/item/unordered.rb
29
+ - lib/doc/model/list/wrapper/abstract.rb
30
+ - lib/doc/model/list/wrapper/unordered.rb
31
+ - lib/doc/model/p/index.rb
32
+ - lib/doc/model/section/abstract.rb
33
+ - lib/doc/model/section/leaf.rb
34
+ - lib/doc/model/section/root.rb
35
+ - lib/doc/model/special-block/container.rb
36
+ - lib/doc/model/special-block/item.rb
37
+ - lib/doc/parser/abstract.rb
38
+ - lib/doc/parser/context.rb
39
+ - lib/doc/parser/file.rb
40
+ - lib/doc/parser/string.rb
41
+ - lib/folder/index.rb
42
+ - lib/folder/model/abstract.rb
43
+ - lib/folder/model/file/abstract.rb
44
+ - lib/folder/model/file/other.rb
45
+ - lib/folder/model/file/ppz.rb
46
+ - lib/folder/model/folder.rb
24
47
  - lib/func/util.rb
25
- - lib/model/abstract/model.rb
26
- - lib/model/abstract/wrapper-model.rb
27
- - lib/model/comment/container.rb
28
- - lib/model/comment/item.rb
29
- - lib/model/common/escape.rb
30
- - lib/model/common/tag.rb
31
- - lib/model/list/item/abstract.rb
32
- - lib/model/list/item/unordered.rb
33
- - lib/model/list/wrapper/abstract.rb
34
- - lib/model/list/wrapper/unordered.rb
35
- - lib/model/p/index.rb
36
- - lib/model/section/abstract.rb
37
- - lib/model/section/leaf.rb
38
- - lib/model/section/root.rb
39
- - lib/model/special-block/container.rb
40
- - lib/model/special-block/item.rb
41
- - lib/parser/common/context/abstract.rb
42
- - lib/parser/common/context/doc.rb
43
- - lib/parser/doc/abstract.rb
44
- - lib/parser/doc/file.rb
45
- - lib/parser/doc/string.rb
46
- - lib/parser/folder/index.rb
47
48
  - lib/ppz.rb
48
49
  homepage: https://github.com/daGaiGuanYu/ppz
49
50
  licenses:
@@ -67,5 +68,5 @@ requirements: []
67
68
  rubygems_version: 3.1.4
68
69
  signing_key:
69
70
  specification_version: 4
70
- summary: 写作
71
+ summary: compile ppz to html
71
72
  test_files: []
data/asset/style/ppz.css DELETED
@@ -1,68 +0,0 @@
1
- html {
2
- line-height: 1.5;
3
- }
4
- body,
5
- div,
6
- p,
7
- aside {
8
- box-sizing: border-box;
9
- }
10
- body {
11
- margin: 0;
12
- padding: 0;
13
- position: relative;
14
- }
15
- aside {
16
- overflow-y: auto;
17
- padding: 2rem 1rem;
18
- position: fixed;
19
- top: 0;
20
- left: 0;
21
- width: 188px;
22
- height: 100vh;
23
- }
24
- aside ul {
25
- margin: 0 0 0 1rem;
26
- padding: 0;
27
- list-style: none;
28
- }
29
- aside a {
30
- width: 100%;
31
- overflow: hidden;
32
- text-overflow: ellipsis;
33
- white-space: nowrap;
34
- }
35
- article {
36
- margin-left: 188px;
37
- padding: 1px 1rem;
38
- }
39
- h1 {
40
- font-size: 2rem;
41
- }
42
- h2 {
43
- font-size: 1.3rem;
44
- }
45
- h3 {
46
- font-size: 1.1rem;
47
- opacity: 0.9;
48
- }
49
- h1::before,
50
- h2::before,
51
- h3::before {
52
- content: '# ';
53
- opacity: 0.3;
54
- }
55
- .special-block {
56
- white-space: pre;
57
- background: #141c22;
58
- overflow: auto;
59
- border-radius: 4px;
60
- color: #eee;
61
- padding: 1rem;
62
- }
63
- .special-txt {
64
- background: rgba(27,31,35,0.05);
65
- border-radius: 4px;
66
- font-size: 0.9em;
67
- padding: 2px 4px;
68
- }
data/asset/style/ppz.styl DELETED
@@ -1,59 +0,0 @@
1
- html
2
- line-height 1.5
3
- body, div, p, aside
4
- box-sizing border-box
5
-
6
- body
7
- margin 0
8
- padding 0
9
- position relative
10
-
11
- aside
12
- overflow-y auto
13
- padding: 2rem 1rem;
14
-
15
- position fixed
16
- top 0
17
- left 0
18
- width 188px
19
- height 100vh
20
-
21
- ul
22
- margin 0 0 0 1rem
23
- padding 0
24
- list-style none
25
- a
26
- width 100%
27
- overflow hidden
28
- text-overflow ellipsis
29
- white-space nowrap
30
-
31
- article
32
- margin-left: 188px
33
- padding: 1px 1rem
34
- h1
35
- font-size 2rem
36
- h2
37
- font-size 1.3rem
38
- h3
39
- font-size 1.1rem
40
- opacity 0.9
41
-
42
- h1, h2, h3
43
- &::before
44
- content '# '
45
- opacity 0.3
46
-
47
- .special-block
48
- white-space pre
49
- background #141c22
50
- overflow auto
51
- border-radius 4px
52
- color #eeeeee
53
- padding 1rem
54
-
55
- .special-txt
56
- background rgba(27, 31, 35, 0.05)
57
- border-radius 4px
58
- font-size 0.9em
59
- padding 2px 4px
data/bin/common.rb DELETED
@@ -1,43 +0,0 @@
1
- require 'pathname'
2
-
3
- module PPZMain
4
- CURRENT_PATH = File.dirname __FILE__
5
- WORK_DIRECTORY = Pathname Dir.pwd
6
- CSS_FILE_PATH = (Pathname CURRENT_PATH) + '../asset/style/ppz.css'
7
-
8
- class Util
9
- class << self
10
- def get_in_and_out
11
- target_in, target_out = ARGV
12
-
13
- # + 输入文件
14
- abort '要编译哪那个文件?请告诉我' unless target_in # 检查参数存在
15
- target_in = (WORK_DIRECTORY + target_in).to_s # 绝对路径
16
- unless File.exist? target_in # 不存在的话,看看加上 .ppz 后是否存在
17
- target_in += '.ppz'
18
- abort target_in[0..-5] + ' 不存在' unless File.exist? target_in # 还不存在的话,就说明是写错了
19
- end
20
- abort '尚未支持编译文件夹' if File.directory? target_in
21
-
22
- # + 输出文件
23
- unless target_out
24
- # 从输入文件获取文件名
25
- target_out = (/(.*).ppz$/.match target_in)?$1:target_in
26
- end
27
- target_out = WORK_DIRECTORY + target_out
28
- # ++ 检查上级文件夹是否存在
29
- upper_dir = (target_out + '..').to_s
30
- abort upper_dir + ' 目录不存在' unless Dir.exist? upper_dir
31
- # ++ 检查文件夹:有则检查里面有没有文件;无则创建文件夹
32
- target_out = target_out.to_s
33
- if Dir.exist? target_out
34
- abort target_out + ' 不是一个空文件夹' unless (Dir.children target_out).size == 0
35
- else
36
- Dir.mkdir target_out
37
- end
38
-
39
- [target_in, target_out]
40
- end
41
- end
42
- end
43
- end
data/bin/ppz DELETED
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require_relative '../lib/ppz'
4
- require_relative './common'
5
- require 'fileutils'
6
- require 'pathname'
7
-
8
- target_in, target_out = PPZMain::Util.get_in_and_out
9
-
10
- target_out = Pathname target_out
11
- output_html_path = target_out + 'index.html'
12
- output_css_path = target_out + 'index.css'
13
-
14
- parser = PPZ::FileDocParser.new target_in
15
- model = parser.get_model
16
- output_html = '<link rel="stylesheet" href="./index.css"/>' + model.to_html
17
- PPZ::Func::write_to_file output_html_path.to_s, output_html
18
- FileUtils.cp PPZMain::CSS_FILE_PATH, output_css_path
@@ -1,18 +0,0 @@
1
- class PPZ::SpecialContainerModel < PPZ::AbstractWrapperModel
2
- UpperClass = PPZ::AbstractSectionModel
3
-
4
- REG_EXP = /^```( (.*))?/
5
- def self.from_line line
6
- return nil unless REG_EXP.match(line)
7
- PPZ::SpecialContainerModel.new $2
8
- end
9
-
10
- def initialize name
11
- @name = name
12
- super()
13
- end
14
-
15
- def to_html
16
- "<div class=\"special-block #{@name}\">#{super}</div>"
17
- end
18
- end
@@ -1,30 +0,0 @@
1
- # 当前行,所处的上下文
2
- # 比如 一级 section 下面的 ul 下的 第 n 个 ul
3
-
4
- class PPZ::AbstractContext
5
- def initialize root
6
- @stack = [root]
7
- end
8
-
9
- # def append # 交给子类实现
10
-
11
- def pop
12
- @stack.pop
13
- end
14
-
15
- def head
16
- @stack[-1]
17
- end
18
-
19
- def root
20
- @stack[0]
21
- end
22
-
23
- private
24
- def pop_to klass
25
- loop do
26
- break if head.is_a? klass
27
- pop
28
- end
29
- end
30
- end
@@ -1,7 +0,0 @@
1
- # 解析一个文件夹里的 .ppz 文件
2
-
3
- class FolderParser
4
- def initialize
5
- @context = Context.new
6
- end
7
- end