schizm 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 6f84ad79aced293697aa2a4377ef3e2e441c437e
4
- data.tar.gz: 28a1c9d028c5de7ca4e1c73894d5c04ab860810d
3
+ metadata.gz: ec626d76f2d425ade64be899c1784234153fd8ee
4
+ data.tar.gz: 21b0ae3b7389198d70b078cd6ac9fd757546b1bb
5
5
  SHA512:
6
- metadata.gz: c305dee798979981a5eba2ffc1c2609d945afa2b5aea5da14fc134935c8494ea27e29eeb67ed01c114ee474b831cca81683b1c5268591d3ca232f775769eeb9a
7
- data.tar.gz: 4a10c89712aa6365cf1e4e31053a12f42231f6aac038b9ee74d403c314734d6511a28d30424cf1acc6d169c22e3e6d91dd1fc2ea1abbd999b7a989121bf0081c
6
+ metadata.gz: 0fd538deab37751a92026371b5244af68c57489937ff676d1e62f1d97c3c75650850c8f67b4d53262877af923c7996c32f9cab291b4d80e2681dae51627ce9f7
7
+ data.tar.gz: 6e4e26bbbd82d52a09391856b17e2efc745e10ae6c3afa80a3d92d3dea0db14c59cd4d4345832c1688c5bbb056950073c6a8369ac71ce288d107a2fc3ef1a807
data/lib/schizm/chunk.rb CHANGED
@@ -1,130 +1,158 @@
1
+ # Copyright (c) 2017 M. Grady Saunders
2
+ #
3
+ # Redistribution and use in source and binary forms, with or without
4
+ # modification, are permitted provided that the following conditions
5
+ # are met:
6
+ #
7
+ # 1. Redistributions of source code must retain the above
8
+ # copyright notice, this list of conditions and the following
9
+ # disclaimer.
10
+ #
11
+ # 2. Redistributions in binary form must reproduce the above
12
+ # copyright notice, this list of conditions and the following
13
+ # disclaimer in the documentation and/or other materials
14
+ # provided with the distribution.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18
+ # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24
+ # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
1
28
  require_relative 'env'
2
29
  require_relative 'string'
3
30
  require_relative 'match'
4
31
 
5
32
  module Schizm
6
33
 
7
- class Chunk
34
+ # Structure to resolve chunks of source code.
35
+ class Chunk
8
36
 
9
- def initialize where, label
10
- @where = String.new where
11
- @label = String.new label
12
- @share = Env.var[:share] if Env.var? :share
13
- @target = nil
14
- @blocks = Array.new
15
- @labels = Array.new
16
- @params = Hash.new
17
- end
37
+ def initialize where, label
38
+ @where = String.new where
39
+ @label = String.new label
40
+ @share = Env.var[:share] if Env.var? :share
41
+ @target = nil
42
+ @blocks = Array.new
43
+ @labels = Array.new
44
+ @params = Hash.new
45
+ end
18
46
 
19
- attr_reader :where
20
- attr_reader :label
21
- attr_accessor :share
22
- attr_accessor :target
23
- attr_accessor :blocks
24
-
25
- # Boolean reader for +@share+.
26
- def share?
27
- case
28
- when (@share == true) then return true
29
- when (@share != true) then return false
30
- end
31
- end
47
+ attr_reader :where
48
+ attr_reader :label
49
+ attr_accessor :share
50
+ attr_accessor :target
51
+ attr_accessor :blocks
32
52
 
33
- # Boolean reader for +@target+.
34
- def target?
35
- return false unless @target.is_a? ::String
36
- return false unless @target != ""
37
- return true
53
+ # Boolean reader for +@share+.
54
+ def share?
55
+ case
56
+ when (@share == true) then return true
57
+ when (@share != true) then return false
38
58
  end
59
+ end
39
60
 
40
- # Hash organizing active chunks by +@where+ and +@label+.
41
- @@hash =
42
- Hash.new do |hash, where|
43
- hash[where] =
44
- Hash.new do |hash, label|
45
- hash[label] = Chunk.new where, label
46
- end
47
- end
61
+ # Boolean reader for +@target+.
62
+ def target?
63
+ return false unless @target.is_a? ::String
64
+ return false unless @target != ""
65
+ return true
66
+ end
48
67
 
49
- # Hash reader.
50
- def self.hash
51
- @@hash
68
+ # Hash organizing active chunks by +@where+ and +@label+.
69
+ @@hash =
70
+ Hash.new do |hash, where|
71
+ hash[where] =
72
+ Hash.new do |hash, label|
73
+ hash[label] = Chunk.new where, label
74
+ end
52
75
  end
53
76
 
54
- # Hash iteration interface.
55
- def self.each
56
- @@hash.each do |where, hash|
57
- hash.each do |label, chunk|
58
- yield chunk
59
- end
77
+ # Hash reader.
78
+ def self.hash
79
+ @@hash
80
+ end
81
+
82
+ # Hash iteration interface.
83
+ def self.each
84
+ @@hash.each do |where, hash|
85
+ hash.each do |label, chunk|
86
+ yield chunk
60
87
  end
61
88
  end
89
+ end
62
90
 
63
- # Push a code block.
64
- def push block, label = nil
65
- block = String.new block
66
- label = String.new label if label
67
- @blocks.push block
68
- @labels.push label
69
- end
91
+ # Push a code block.
92
+ def push block, label = nil
93
+ block = String.new block
94
+ label = String.new label if label
95
+ @blocks.push block
96
+ @labels.push label
97
+ end
70
98
 
71
- # Find a chunk relative to +self+. That is, consider only
72
- # chunks defined in the same file, plus chunks shared with the
73
- # entire project.
74
- def find label
75
- Chunk.each do |chunk|
76
- if chunk.label == label and
77
- (chunk.where == @where or chunk.share?)
78
- return chunk
79
- end
99
+ # Find a chunk relative to +self+. That is, consider only
100
+ # chunks defined in the same file, plus chunks shared with the
101
+ # entire project.
102
+ def find label
103
+ Chunk.each do |chunk|
104
+ if chunk.label == label and
105
+ (chunk.where == @where or chunk.share?)
106
+ return chunk
80
107
  end
81
- nil
82
108
  end
109
+ nil
110
+ end
83
111
 
84
- # Resolve chunk references to generate the final source string.
85
- def to_s *trace
86
- if trace.include? @label
87
- raise "Infinite recursion!"
112
+ # Resolve chunk references to generate the final source string.
113
+ def to_s *trace
114
+ if trace.include? @label
115
+ raise "Infinite recursion!"
116
+ end
117
+ total = String.new(@blocks.join "\n")
118
+ total.trim!
119
+ while true
120
+ unless (total.sub! CHUNK_LABEL do
121
+ if (chunk = find $1)
122
+ replace = chunk.to_s *trace, @label
123
+ replace.gsub /(?<=\n)/, " " * String.new($`).find_indent
124
+ else
125
+ "/* " + $1 + " ... */"
126
+ end
127
+ end)
128
+ break
88
129
  end
89
- total = String.new(@blocks.join "\n\n")
90
- total.trim!
91
- while true
92
- unless (total.sub! CHUNK_LABEL do
93
- if (chunk = find $1)
94
- replace = chunk.to_s *trace, @label
95
- replace.gsub /(?<=\n)/, " " * String.new($`).find_indent
96
- else
97
- "/* " + $1 + " ... */"
98
- end
99
- end)
100
- break
130
+ end
131
+ if target?
132
+ if Env.var? :guard and @target =~ HEADER_PATH
133
+ guardify = String.new(@target).guardify
134
+ if Env.var? :title
135
+ guardify.prepend "_"
136
+ guardify.prepend String.new(Env.var[:title]).guardify
101
137
  end
138
+ total.prepend "\#define #{guardify}\n\n"
139
+ total.prepend "\#ifndef #{guardify}\n"
140
+ total.concat "\n\n"
141
+ total.concat "\#endif /* \#ifndef #{guardify} */"
102
142
  end
103
- if target?
104
- if Env.var? :guard and @target =~ HEADER_PATH
105
- guardify = String.new(@target).guardify
106
- if Env.var? :title
107
- guardify.prepend "_"
108
- guardify.prepend String.new(Env.var[:title]).guardify
109
- end
110
- total.prepend "\#define #{guardify}\n\n"
111
- total.prepend "\#ifndef #{guardify}\n"
112
- total.concat "\n\n"
113
- total.concat "\#endif /* \#ifndef #{guardify} */"
114
- end
115
- if File.file? "LICENSE"
116
- total.prepend "\n"
117
- total.prepend String.new(File.read("LICENSE")).comment
118
- end
143
+ if File.file? "LICENSE"
144
+ total.prepend "\n"
145
+ total.prepend String.new(File.read("LICENSE")).comment
119
146
  end
120
- total
121
- end
122
-
123
- # Identifier for a particular block.
124
- def id block = @blocks.size
125
- "#{@label.slugify}-#{block}"
126
147
  end
148
+ total
149
+ end
127
150
 
151
+ # Identifier for +block+.
152
+ def id block = @blocks.size
153
+ String.new "#{@label.slugify}-#{block}"
128
154
  end
129
155
 
130
- end
156
+ end # class Chunk
157
+
158
+ end # module Schizm
data/lib/schizm/env.rb CHANGED
@@ -1,3 +1,30 @@
1
+ # Copyright (c) 2017 M. Grady Saunders
2
+ #
3
+ # Redistribution and use in source and binary forms, with or without
4
+ # modification, are permitted provided that the following conditions
5
+ # are met:
6
+ #
7
+ # 1. Redistributions of source code must retain the above
8
+ # copyright notice, this list of conditions and the following
9
+ # disclaimer.
10
+ #
11
+ # 2. Redistributions in binary form must reproduce the above
12
+ # copyright notice, this list of conditions and the following
13
+ # disclaimer in the documentation and/or other materials
14
+ # provided with the distribution.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18
+ # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24
+ # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
1
28
  require 'etc'
2
29
  require 'optparse'
3
30
  require 'pathname'
@@ -9,19 +36,22 @@ module Schizm
9
36
 
10
37
  module Env
11
38
 
39
+ # Global variable hash.
12
40
  @@var = {}
13
41
 
42
+ # Global variable hash getter.
14
43
  def self.var
15
44
  return @@var
16
45
  end
17
46
 
47
+ # +true+ if +@@var[key]+ is neither +nil+ nor +false+.
18
48
  def self.var? key
19
49
  return true if @@var.has_key?(key) and
20
50
  @@var[key] != nil and @@var[key] != false
21
51
  return false
22
52
  end
23
53
 
24
- # Prompt yes/no question.
54
+ # Prompt the user with a yes/no question.
25
55
  def self.yes? string, backup
26
56
  backup = backup.downcase[0]
27
57
  print "#{string} [Y/n] " if backup == "y"
@@ -31,6 +61,8 @@ module Env
31
61
  return backup == "y"
32
62
  end
33
63
 
64
+ # Write +string+ to +target+. If +target+ is an existing file and
65
+ # +var[:rewrite]+ is not set, prompts the user for permission to rewrite.
34
66
  def self.write target, string
35
67
  if (not File.file? target or
36
68
  var? :rewrite or
@@ -179,19 +211,22 @@ YAMLCONFIG
179
211
  assets = {
180
212
  "schizm.liquid" => "docs/_layouts",
181
213
  "schizm.js" => "docs/assets/js",
182
- "fonts/fira-code.css" => "docs/assets/fonts",
183
- "fonts/fira-code-light.otf" => "docs/assets/fonts",
184
- "fonts/fira-code-regular.otf" => "docs/assets/fonts",
185
- "fonts/fira-code-medium.otf" => "docs/assets/fonts",
186
- "fonts/fira-code-bold.otf" => "docs/assets/fonts",
187
- "fonts/genericons-neue.css" => "docs/assets/fonts",
188
- "fonts/genericons-neue.eot" => "docs/assets/fonts",
189
- "fonts/genericons-neue.ttf" => "docs/assets/fonts",
190
- "fonts/genericons-neue.woff2" => "docs/assets/fonts",
191
- "fonts/social-logos.css" => "docs/assets/fonts",
192
- "fonts/social-logos.eot" => "docs/assets/fonts",
193
- "fonts/social-logos.ttf" => "docs/assets/fonts",
194
- "fonts/social-logos.woff2" => "docs/assets/fonts"
214
+ "fonts/Fira-Code.css" => "docs/assets/fonts",
215
+ "fonts/Fira-Code-Light.otf" => "docs/assets/fonts",
216
+ "fonts/Fira-Code-Regular.otf" => "docs/assets/fonts",
217
+ "fonts/Fira-Code-Medium.otf" => "docs/assets/fonts",
218
+ "fonts/Fira-Code-Bold.otf" => "docs/assets/fonts",
219
+ "fonts/Fira-Code-LICENSE" => "docs/assets/fonts",
220
+ "fonts/Genericons-Neue.css" => "docs/assets/fonts",
221
+ "fonts/Genericons-Neue.eot" => "docs/assets/fonts",
222
+ "fonts/Genericons-Neue.ttf" => "docs/assets/fonts",
223
+ "fonts/Genericons-Neue.woff2" => "docs/assets/fonts",
224
+ "fonts/Genericons-Neue-LICENSE" => "docs/assets/fonts",
225
+ "fonts/Social-Logos.css" => "docs/assets/fonts",
226
+ "fonts/Social-Logos.eot" => "docs/assets/fonts",
227
+ "fonts/Social-Logos.ttf" => "docs/assets/fonts",
228
+ "fonts/Social-Logos.woff2" => "docs/assets/fonts",
229
+ "fonts/Social-Logos-LICENSE" => "docs/assets/fonts"
195
230
  }
196
231
  assets.each do |from, to|
197
232
  write File.join(to, File.basename(from)), resource(from)
@@ -1,7 +1,35 @@
1
+ # Copyright (c) 2017 M. Grady Saunders
2
+ #
3
+ # Redistribution and use in source and binary forms, with or without
4
+ # modification, are permitted provided that the following conditions
5
+ # are met:
6
+ #
7
+ # 1. Redistributions of source code must retain the above
8
+ # copyright notice, this list of conditions and the following
9
+ # disclaimer.
10
+ #
11
+ # 2. Redistributions in binary form must reproduce the above
12
+ # copyright notice, this list of conditions and the following
13
+ # disclaimer in the documentation and/or other materials
14
+ # provided with the distribution.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18
+ # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24
+ # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
1
28
  module Schizm
2
29
 
3
30
  module Env
4
31
 
32
+ # https://material.io/guidelines/style/color.html
5
33
  COLORS = {
6
34
  'red' => {
7
35
  '50' => ['#FFEBEE', '#222222'],