ppz 0.0.1 → 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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/asset/style/ppz.css +141 -0
  3. data/asset/style/ppz.styl +126 -0
  4. data/bin/common.rb +42 -0
  5. data/bin/doc.rb +17 -0
  6. data/bin/folder.rb +10 -0
  7. data/bin/ppz +12 -10
  8. data/lib/func/util.rb +19 -2
  9. data/lib/{object/model → model}/abstract/model.rb +16 -18
  10. data/lib/model/abstract/wrapper-model.rb +26 -0
  11. data/lib/model/comment/container.rb +7 -0
  12. data/lib/model/comment/item.rb +12 -0
  13. data/lib/{object/model → model}/common/escape.rb +1 -1
  14. data/lib/{object/model → model}/common/tag.rb +0 -0
  15. data/lib/model/list/item/abstract.rb +13 -0
  16. data/lib/model/list/item/unordered.rb +7 -0
  17. data/lib/model/list/wrapper/abstract.rb +12 -0
  18. data/lib/model/list/wrapper/unordered.rb +3 -0
  19. data/lib/model/p/index.rb +17 -0
  20. data/lib/model/section/abstract.rb +15 -0
  21. data/lib/model/section/leaf.rb +29 -0
  22. data/lib/model/section/root.rb +16 -0
  23. data/lib/model/special-block/container.rb +25 -0
  24. data/lib/model/special-block/item.rb +8 -0
  25. data/lib/{object/parser → parser}/common/context/abstract.rb +3 -5
  26. data/lib/parser/common/context/doc.rb +15 -0
  27. data/lib/parser/doc/abstract.rb +68 -0
  28. data/lib/{object/parser → parser}/doc/file.rb +1 -3
  29. data/lib/{object/parser → parser}/doc/string.rb +1 -3
  30. data/lib/parser/folder/index.rb +9 -0
  31. data/lib/parser/folder/model/abstract.rb +90 -0
  32. data/lib/parser/folder/model/file/abstract.rb +23 -0
  33. data/lib/parser/folder/model/file/other.rb +7 -0
  34. data/lib/parser/folder/model/file/ppz.rb +15 -0
  35. data/lib/parser/folder/model/folder.rb +93 -0
  36. data/lib/ppz.rb +26 -1
  37. metadata +34 -26
  38. data/bin/ppz-util.rb +0 -31
  39. data/lib/object/model/abstract/wrapper-model.rb +0 -21
  40. data/lib/object/model/common/tag.test.rb +0 -25
  41. data/lib/object/model/list/item/abstract.rb +0 -15
  42. data/lib/object/model/list/item/unordered.rb +0 -5
  43. data/lib/object/model/list/wrapper/abstract.rb +0 -7
  44. data/lib/object/model/list/wrapper/unordered.rb +0 -5
  45. data/lib/object/model/p/index.rb +0 -15
  46. data/lib/object/model/section/abstract.rb +0 -10
  47. data/lib/object/model/section/leaf.rb +0 -35
  48. data/lib/object/model/section/root.rb +0 -7
  49. data/lib/object/model/section/test.rb +0 -12
  50. data/lib/object/model/special-block/container.rb +0 -18
  51. data/lib/object/model/special-block/item.rb +0 -10
  52. data/lib/object/parser/common/context/doc.rb +0 -15
  53. data/lib/object/parser/doc/abstract.rb +0 -69
  54. data/lib/object/parser/doc/file.test.rb +0 -6
  55. data/lib/object/parser/folder/index.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6ecf116f7998efdb6f554563f6b5e9c447872cc3c8d4531fbdba899b986bfcf
4
- data.tar.gz: 545155a99ebdca8a31cd3ec012c2e6a7971a379bd9b97eba7d867c755930a377
3
+ metadata.gz: bad1dbe093ab8a51881656c02401cfbefce4f3ca153a5dfc7b5f9cd5483a161c
4
+ data.tar.gz: 02a01ac4f61ef0e2edd725407ecf1baed235501b635065463049db698a2719d9
5
5
  SHA512:
6
- metadata.gz: 5743fdd2c32cca4a9a0e5a67859de962af84252cc1bbceac2a697a724bf49ea8941951824bb504e112d6788b29ba21cd6fa3713a2ec49fe0c4ae565a326968c2
7
- data.tar.gz: 3ec750c9c3580309128c5057e787523933997b3a1108e653b4ce6fbf3222c976772ba9e5439856e3b78ddb2703f6a75e06facf04504befffdcc49be47210ad21
6
+ metadata.gz: 72f1066915ce586d43b514411d109c7016b754b30cfb192262044813d8db268ca14c99226edadd8bfd5f627f0ef48d96d8ca9337fdb6f7f13e33a10f8c5a67a9
7
+ data.tar.gz: 8e7267e62274f2ff85c89596ab7799a64574fba03da5c776f3293b0e39da4aeebba208b989b04756bb98304a58abb967a0317455a3533e04411917109af318c7
@@ -0,0 +1,141 @@
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
+ display: block;
32
+ overflow: hidden;
33
+ text-overflow: ellipsis;
34
+ white-space: nowrap;
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
+ }
62
+ article {
63
+ margin-left: 188px;
64
+ padding: 1px 2rem 1rem 1rem;
65
+ }
66
+ h1 {
67
+ font-size: 2rem;
68
+ }
69
+ h2 {
70
+ font-size: 1.3rem;
71
+ }
72
+ h3 {
73
+ font-size: 1.1rem;
74
+ opacity: 0.9;
75
+ }
76
+ h1::before,
77
+ h2::before,
78
+ h3::before {
79
+ content: '# ';
80
+ opacity: 0.3;
81
+ font-size: 1rem;
82
+ }
83
+ .comment-container {
84
+ margin: 1rem 0;
85
+ padding: 1rem 1.6rem;
86
+ background: rgba(0,0,0,0.2);
87
+ font-size: 0.9rem;
88
+ border-radius: 4px;
89
+ }
90
+ .comment-item {
91
+ opacity: 0.8;
92
+ }
93
+ .special-block-container {
94
+ background: #141c22;
95
+ overflow: auto;
96
+ border-radius: 4px;
97
+ color: #eee;
98
+ font-family: monospace;
99
+ white-space: pre;
100
+ margin: 1rem 0;
101
+ padding: 1rem;
102
+ counter-reset: line-index;
103
+ }
104
+ .special-block-item::before {
105
+ counter-increment: line-index;
106
+ content: counter(line-index) " | ";
107
+ opacity: 0.3;
108
+ }
109
+ .special-block-item:hover::before {
110
+ opacity: 0.8;
111
+ }
112
+ .special-txt {
113
+ background: rgba(27,31,35,0.05);
114
+ border-radius: 4px;
115
+ font-size: 0.9em;
116
+ padding: 2px 4px;
117
+ }
118
+ .interpage-nav {
119
+ margin: 1rem 2rem 2rem 188px;
120
+ padding: 0 2rem;
121
+ list-style: none;
122
+ }
123
+ .interpage-nav .prev {
124
+ float: left;
125
+ }
126
+ .interpage-nav .prev::before {
127
+ content: '上一篇:';
128
+ opacity: 0.6;
129
+ }
130
+ .interpage-nav .next {
131
+ float: right;
132
+ }
133
+ .interpage-nav .next::before {
134
+ content: '下一篇:';
135
+ opacity: 0.6;
136
+ }
137
+ .interpage-nav::after {
138
+ content: '';
139
+ display: block;
140
+ clear: both;
141
+ }
@@ -0,0 +1,126 @@
1
+ nav-width = 188px
2
+
3
+ html
4
+ line-height 1.5
5
+ body, div, p, aside
6
+ box-sizing border-box
7
+
8
+ body
9
+ margin 0
10
+ padding 0
11
+ position relative
12
+
13
+ aside
14
+ overflow-y auto
15
+ padding: 2rem 1rem;
16
+
17
+ position fixed
18
+ top 0
19
+ left 0
20
+ width nav-width
21
+ height 100vh
22
+
23
+ ul
24
+ margin 0 0 0 1rem
25
+ padding 0
26
+ list-style none
27
+ a
28
+ width 100%
29
+ display block
30
+ overflow hidden
31
+ text-overflow ellipsis
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
55
+
56
+ article
57
+ margin-left nav-width
58
+ padding: 1px 2rem 1rem 1rem
59
+ h1
60
+ font-size 2rem
61
+ h2
62
+ font-size 1.3rem
63
+ h3
64
+ font-size 1.1rem
65
+ opacity 0.9
66
+
67
+ h1, h2, h3
68
+ &::before
69
+ content '# '
70
+ opacity 0.3
71
+ font-size 1rem
72
+
73
+ .comment-container
74
+ margin 1rem 0
75
+ padding 1rem 1.6rem
76
+ background rgba(0, 0, 0, 0.2)
77
+ font-size 0.9rem
78
+ border-radius 4px
79
+ .comment-item
80
+ opacity 0.8
81
+
82
+ .special-block-container
83
+ background #141c22
84
+ overflow auto
85
+ border-radius 4px
86
+ color #eeeeee
87
+
88
+ font-family monospace
89
+ white-space pre
90
+
91
+ margin 1rem 0
92
+ padding 1rem
93
+
94
+ counter-reset line-index
95
+ .special-block-item
96
+ &::before
97
+ counter-increment line-index
98
+ content counter(line-index) " | "
99
+ opacity 0.3
100
+ &:hover::before
101
+ opacity 0.8
102
+
103
+ .special-txt
104
+ background rgba(27, 31, 35, 0.05)
105
+ border-radius 4px
106
+ font-size 0.9em
107
+ padding 2px 4px
108
+
109
+ .interpage-nav
110
+ margin 1rem 2rem 2rem nav-width
111
+ padding 0 2rem
112
+ list-style none
113
+ .prev
114
+ float left
115
+ &::before
116
+ content '上一篇:'
117
+ opacity 0.6
118
+ .next
119
+ float right
120
+ &::before
121
+ content '下一篇:'
122
+ opacity 0.6
123
+ &::after
124
+ content ''
125
+ display block
126
+ clear both
data/bin/common.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'pathname'
2
+
3
+ module PPZMain
4
+ CURRENT_PATH = File.dirname __FILE__
5
+ CSS_FILE_PATH = (Pathname CURRENT_PATH) + '../asset/style/ppz.css'
6
+
7
+ class Util
8
+ class << self
9
+ def get_in_and_out
10
+ target_in, target_out = ARGV
11
+
12
+ # 输入文件
13
+ abort '要编译哪那个文件?请告诉我' unless target_in # 检查参数存在
14
+ target_in = PPZ::Func.format_path target_in
15
+ unless File.exist? target_in # 不存在的话,看看加上 .ppz 后是否存在
16
+ target_in += '.ppz'
17
+ abort target_in[0..-5] + ' 不存在' unless File.exist? target_in # 还不存在的话,就说明是写错了
18
+ end
19
+ is_folder = File.directory? target_in
20
+
21
+ # 输出文件
22
+ unless target_out
23
+ # 从输入文件获取文件名
24
+ target_out = ((/(.*).ppz$/.match target_in)?$1:target_in) + '.pp'
25
+ end
26
+ # + 检查上级文件夹是否存在
27
+ upper_dir = ((Pathname target_out) + '..').to_s
28
+ abort upper_dir + ' 目录不存在' unless Dir.exist? upper_dir
29
+ # + 检查文件夹:有则检查里面有没有文件;无则创建文件夹
30
+ target_out = target_out.to_s
31
+ if Dir.exist? target_out
32
+ abort target_out + ' 不是一个空文件夹' unless (Dir.children target_out).size == 0
33
+ else
34
+ Dir.mkdir target_out
35
+ end
36
+ target_out = PPZ::Func.format_path target_out
37
+
38
+ [target_in, target_out, is_folder]
39
+ end
40
+ end
41
+ end
42
+ end
data/bin/doc.rb ADDED
@@ -0,0 +1,17 @@
1
+ target_out = Pathname TARGET_OUT
2
+
3
+ # css
4
+ # 输出文件路径
5
+ output_css_path = target_out + 'index.css'
6
+ # 复制
7
+ FileUtils.cp PPZMain::CSS_FILE_PATH, output_css_path
8
+
9
+ # html
10
+ # 输出文件路径
11
+ output_html_path = target_out + 'index.html'
12
+ # 解析文档
13
+ parser = PPZ::FileDocParser.new TARGET_IN
14
+ # 拼接上 css 文件链接
15
+ output_html = '<link rel="stylesheet" href="./index.css"/>' + parser.get_model.to_html
16
+ # 输出
17
+ PPZ::Func::write_to_file output_html_path.to_s, output_html
data/bin/folder.rb ADDED
@@ -0,0 +1,10 @@
1
+ require_relative '../lib/parser/folder/index'
2
+
3
+ puts '输入文件夹: ' + TARGET_IN
4
+ puts '输出文件夹: ' + TARGET_OUT
5
+ puts
6
+
7
+ FileUtils.cp PPZMain::CSS_FILE_PATH, ((Pathname TARGET_OUT) + 'style.css').to_s
8
+
9
+ model = PPZ::Folder::FolderModel.new TARGET_IN, 0
10
+ model.compile TARGET_OUT
data/bin/ppz CHANGED
@@ -1,12 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require_relative './ppz-util'
4
- require_relative '../lib/object/parser/doc/file'
5
- require_relative '../lib/func/util'
6
-
7
- file_in, file_out = UtilInMain.get_file_in_and_out
8
-
9
- parser = FileDocParser.new path
10
- model = parser.get_model
11
-
12
- Func::write_to_file file_out, model.to_html
3
+ require_relative '../lib/ppz'
4
+ require_relative './common'
5
+ require 'fileutils'
6
+ require 'pathname'
7
+
8
+ TARGET_IN, TARGET_OUT, IS_FOLDER = PPZMain::Util.get_in_and_out
9
+
10
+ if IS_FOLDER
11
+ require_relative './folder.rb'
12
+ else
13
+ require_relative './doc.rb'
14
+ end
data/lib/func/util.rb CHANGED
@@ -1,12 +1,29 @@
1
- class Func
1
+ class PPZ::Func
2
2
  class << self
3
3
  def write_to_file filepath, data
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
11
+
12
+ # 检查某类有没有某常量
13
+ def has_const? klass, const_name
14
+ klass.constants.include? const_name
15
+ end
16
+ # 检查某实例的类有没有某常量
17
+ def class_has_const? instance, const_name
18
+ has_const? instance.class, const_name
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
11
28
  end
12
29
  end
@@ -1,19 +1,17 @@
1
- require_relative '../common/escape'
1
+ class PPZ::AbstractModel
2
+ attr_accessor :left_model, :right_model, :index # 左右兄弟 model
3
+ attr_accessor :father_model
2
4
 
3
- class AbstractModel
4
5
  def self.from_line line # 静态方法,从“输入行”里实例化一个 model
5
- if match_data = self::REG_EXP.match(line)
6
- self.new match_data.post_match
7
- else
8
- nil
9
- end
6
+ return nil unless self::REG_EXP.match(line)
7
+ self.new $1
10
8
  end
11
9
 
12
10
  # 加粗、斜体、链接等
13
11
  def transform_inline_element str
14
12
  str = str + ''
15
13
  # 因为加粗、斜体等,会生成 html 代码,为了不使“用户原本输入的 html”和“生成的 html”冲突,因此先把“用户输入的 html 转义
16
- Escape.html_char! str
14
+ PPZ::Escape.html_char! str
17
15
 
18
16
  # 变粗等,使用特殊字符比如 *,来标识
19
17
  # 但这会使用户想输入 * 时,形成歧义
@@ -24,21 +22,21 @@ class AbstractModel
24
22
  # 再识别哪些变斜,哪些变粗
25
23
  # 再把用户原来想输入的 * 放到字符串里(某种形式 -> *)
26
24
 
27
- Escape.ppz_char! str # 把用户输入的 \* 转义 => 剩下的 *** 就肯定是 斜体加粗 了
25
+ PPZ::Escape.ppz_char! str # 把用户输入的 \* 转义 => 剩下的 *** 就肯定是 斜体加粗 了
28
26
 
29
- # 1. 斜体和加粗
27
+ # + 斜体和加粗
30
28
  str.gsub! /\*\*\*(.+)\*\*\*/, '<b><i>\1</i></b>'
31
- # 2. 加粗
29
+ # + 加粗
32
30
  str.gsub! /\*\*(.+)\*\*/, '<b>\1</b>'
33
- # 3. 斜体
31
+ # + 斜体
34
32
  str.gsub! /\*(.+)\*/, '<i>\1</i>'
35
- # 4. 行内块
36
- str.gsub! /```(.+)```/, '<span class="special-txt">\1</span>'
37
- # 5. 链接
38
- str.gsub! /\[([^\]]+)\]\(([^\)]+)\)/, '<a href="\2" title="\2">\1</a>'
39
- # 6. 图片
33
+ # + 行内块
34
+ str.gsub! /```([^(```)]+)```/, '<span class="special-txt">\1</span>'
35
+ # + 图片 先图片后链接
40
36
  str.gsub! /!\[([^\]]*)\]\(([^\)]+)\)/, '<img title="\1" src="\2" />'
37
+ # + 链接 先图片后链接
38
+ str.gsub! /\[([^\]]+)\]\(([^\)]+)\)/, '<a href="\2" title="\2">\1</a>'
41
39
 
42
- Escape.transform_to_real! str
40
+ PPZ::Escape.transform_to_real! str
43
41
  end
44
42
  end