teepee 0.15.7 → 0.15.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5e49d5772617f4633782f79e60f7dfd985bf772
4
- data.tar.gz: 224d1e75c81269d77c1f38f8824007f2287ee9d0
3
+ metadata.gz: a354469b71690050b06422444c866f6add0e2a3b
4
+ data.tar.gz: 420ad93e8d5475b06e6a511c5783eb09e8bed1f6
5
5
  SHA512:
6
- metadata.gz: cbb5b1af53b3d8a568bd8eeb35e17e167c5b03ac6881da3741f9dd5750fb03f14be15ec05b8fea15327f75660daf1a1bf6d184236d568d31d1a71a896bd8562f
7
- data.tar.gz: 4693978548e1438d775d9212e981910d2cd9a3a24ed6bdd48b8d141a1f7e54f62bb9eb38fbaa03986d46b2d89d44d1447fa6f2d7c3231519edfd6ef9b00e579a
6
+ metadata.gz: fc12e333e13cc8dbfac1f8eac67ff572820452a8972acd02db6ee5e98c2254547d5948d05b6a4d6befc4f3854b1747c91fb1ac6a4c0252504822bcf11186d210
7
+ data.tar.gz: 9387b9da0c147e875debf1903e43c95fa386616649a2668e4b7525255d9f97915170d183306882967a469dfe340878e5aee0970297ec5d9c897867388e0c1dd7
@@ -0,0 +1,147 @@
1
+ # -*- coding: utf-8 -*-
2
+ # -*- mode: Ruby -*-
3
+
4
+ # Copyright © 2013-2016, Christopher Mark Gore,
5
+ # Soli Deo Gloria,
6
+ # All rights reserved.
7
+ #
8
+ # 2317 South River Road, Saint Charles, Missouri 63303 USA.
9
+ # Web: http://cgore.com
10
+ # Email: cgore@cgore.com
11
+ #
12
+ # Redistribution and use in source and binary forms, with or without
13
+ # modification, are permitted provided that the following conditions are met:
14
+ #
15
+ # * Redistributions of source code must retain the above copyright
16
+ # notice, this list of conditions and the following disclaimer.
17
+ #
18
+ # * Redistributions in binary form must reproduce the above copyright
19
+ # notice, this list of conditions and the following disclaimer in the
20
+ # documentation and/or other materials provided with the distribution.
21
+ #
22
+ # * Neither the name of Christopher Mark Gore nor the names of other
23
+ # contributors may be used to endorse or promote products derived from
24
+ # this software without specific prior written permission.
25
+ #
26
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
30
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
+ # POSSIBILITY OF SUCH DAMAGE.
37
+
38
+
39
+ module Teepee
40
+ module CommanderMixins
41
+ module Boolean
42
+ def ensure_boolean boolean
43
+ if boolean.to_html == "true" or boolean.to_html == "false"
44
+ boolean
45
+ else
46
+ command_error "Non-boolean value."
47
+ end
48
+ end
49
+
50
+ def true_constant
51
+ "true"
52
+ end
53
+
54
+ def false_constant
55
+ "false"
56
+ end
57
+
58
+ def true_constant? expression
59
+ expression.to_html == "true"
60
+ end
61
+
62
+ def false_constant? expression
63
+ expression.to_html == "false"
64
+ end
65
+
66
+ def boolean_and booleans
67
+ if booleans.empty?
68
+ return true_constant
69
+ end
70
+ b = booleans.first.to_html
71
+ if false_constant? b
72
+ false_constant
73
+ elsif true_constant? b or booleans.first.kind_of? WhitespaceToken
74
+ boolean_and booleans[1..-1]
75
+ else
76
+ command_error "Not a boolean value #{booleans.first}"
77
+ end
78
+ end
79
+
80
+ def boolean_nand booleans
81
+ boolean_not boolean_and booleans
82
+ end
83
+
84
+ def boolean_nor booleans
85
+ boolean_not boolean_or booleans
86
+ end
87
+
88
+ def boolean_not boolean
89
+ boolean = boolean.to_html
90
+ if true_constant? boolean
91
+ false_constant
92
+ elsif false_constant? boolean
93
+ true_constant
94
+ else
95
+ command_error "Not a boolean value"
96
+ end
97
+ end
98
+
99
+ def boolean_or booleans
100
+ if booleans.empty?
101
+ return false_constant
102
+ end
103
+ b = booleans.first.to_html
104
+ if true_constant? b
105
+ true_constant
106
+ elsif false_constant? b or booleans.first.kind_of? WhitespaceToken
107
+ boolean_or booleans[1..-1]
108
+ else
109
+ command_error "Not a boolean value"
110
+ end
111
+ end
112
+
113
+ def boolean_xnor booleans
114
+ boolean_not boolean_xor booleans
115
+ end
116
+
117
+ def boolean_xor booleans
118
+ # There are two schools of thought as to what a multi-variable XOR is.
119
+ # 1. Chained XORs, giving a parity check.
120
+ # 2. 'Exclusively' one true for ALL inputs.
121
+ # I'm going with the second: one and only one true, the rest false.
122
+ # It seems therefore that the zero-argument version should be false then.
123
+ if booleans.empty?
124
+ false_constant
125
+ else
126
+ any_trues = false
127
+ booleans.each do |boolean|
128
+ if true_constant? boolean
129
+ if any_trues
130
+ return false_constant
131
+ else
132
+ any_trues = true
133
+ end
134
+ elsif false_constant? boolean
135
+ # do nothing
136
+ elsif boolean.kind_of? WhitespaceToken
137
+ # do nothing
138
+ else
139
+ return command_error "Not a boolean value"
140
+ end
141
+ end
142
+ return any_trues.to_html
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,189 @@
1
+ # -*- coding: utf-8 -*-
2
+ # -*- mode: Ruby -*-
3
+
4
+ # Copyright © 2013-2016, Christopher Mark Gore,
5
+ # Soli Deo Gloria,
6
+ # All rights reserved.
7
+ #
8
+ # 2317 South River Road, Saint Charles, Missouri 63303 USA.
9
+ # Web: http://cgore.com
10
+ # Email: cgore@cgore.com
11
+ #
12
+ # Redistribution and use in source and binary forms, with or without
13
+ # modification, are permitted provided that the following conditions are met:
14
+ #
15
+ # * Redistributions of source code must retain the above copyright
16
+ # notice, this list of conditions and the following disclaimer.
17
+ #
18
+ # * Redistributions in binary form must reproduce the above copyright
19
+ # notice, this list of conditions and the following disclaimer in the
20
+ # documentation and/or other materials provided with the distribution.
21
+ #
22
+ # * Neither the name of Christopher Mark Gore nor the names of other
23
+ # contributors may be used to endorse or promote products derived from
24
+ # this software without specific prior written permission.
25
+ #
26
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
30
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
+ # POSSIBILITY OF SUCH DAMAGE.
37
+
38
+
39
+ module Teepee
40
+ module CommanderMixins
41
+ module Control
42
+ def case_operator expressions
43
+ value, _, *rest = strip expressions
44
+ if value and not rest.empty?
45
+ def cond_helper value, expressions
46
+ test_value, _, form, *rest = strip expressions
47
+ if equal [value.to_html, test_value.to_html]
48
+ form
49
+ elsif not rest.empty?
50
+ cond_helper value, rest
51
+ end
52
+ end
53
+ cond_helper value, rest
54
+ end
55
+ end
56
+
57
+ def comment expressions
58
+ nil
59
+ end
60
+
61
+ def cond_operator expressions
62
+ conditional, _, form, *rest = strip expressions
63
+ if true_constant? conditional.to_html
64
+ form
65
+ elsif not rest.empty?
66
+ cond_operator rest
67
+ end
68
+ end
69
+
70
+ def decrement variable
71
+ return variable_not_defined_error variable if not is_defined? variable
72
+ old_value = get_operator(variable).to_number
73
+ return non_numeric_error old_value if not numeric? old_value
74
+ @parser.variables[variable.to_html] = old_value - 1
75
+ end
76
+
77
+ def define expressions
78
+ variable, _, value = expressions
79
+ k = variable.to_html
80
+ v = value.to_html
81
+ @parser.variables[k] = v
82
+ get_operator k
83
+ end
84
+
85
+ def is_defined? variables
86
+ if not variables.is_a? Array
87
+ return is_defined? [variables]
88
+ elsif Set.new(variables.map(&:to_html)).subset? Set.new(@parser.variables.keys)
89
+ true_constant
90
+ else
91
+ false_constant
92
+ end
93
+ end
94
+
95
+ def dotimes expressions
96
+ n = expressions.first.to_number
97
+ return "" if n.nil? or n < 1
98
+ span_operator expressions[1..-1] * n
99
+ end
100
+
101
+ def equal expressions
102
+ if expressions.empty?
103
+ true_constant
104
+ elsif expressions.length == 1
105
+ true_constant
106
+ else
107
+ expressions[0].to_html == expressions[1].to_html and equal expressions.rest
108
+ end
109
+ end
110
+
111
+ def get_operator variable
112
+ @parser.variables[variable.to_html].to_html
113
+ end
114
+
115
+ def if_operator expressions
116
+ expressions = strip expressions
117
+ conditional, _, true_clause, _, false_clause = expressions
118
+ if true_constant? conditional.to_html
119
+ true_clause.to_html
120
+ elsif false_clause
121
+ false_clause.to_html
122
+ end
123
+ end
124
+
125
+ def increment variable
126
+ return variable_not_defined_error variable if not is_defined? variable
127
+ old_value = get_operator(variable).to_number
128
+ return non_numeric_error old_value if not numeric? old_value
129
+ @parser.variables[variable.to_html] = old_value + 1
130
+ end
131
+
132
+ def not_equal numbers
133
+ if numbers.empty?
134
+ true_constant
135
+ elsif numbers.length == 1
136
+ true_constant
137
+ else
138
+ numbers[0].to_number != numbers[1].to_number and equal numbers.rest
139
+ end
140
+ end
141
+
142
+ def prog1_operator expressions
143
+ expressions.map(&:to_html).first
144
+ end
145
+
146
+ def progn_operator expressions
147
+ expressions.map(&:to_html).last
148
+ end
149
+
150
+ def prognil expressions
151
+ expressions.map(&:to_html)
152
+ ""
153
+ end
154
+
155
+ def undefine expressions
156
+ expressions.each do |expression|
157
+ @parser.variables.delete expression.to_html
158
+ end
159
+ ""
160
+ end
161
+
162
+ def unless_operator expressions
163
+ expressions = strip expressions
164
+ conditional = expressions.first
165
+ expressions = strip expressions.rest
166
+ if false_constant? conditional.to_html
167
+ if expressions.length <= 1
168
+ expressions.first
169
+ else
170
+ span_operator expressions
171
+ end
172
+ end
173
+ end
174
+
175
+ def when_operator expressions
176
+ expressions = strip expressions
177
+ conditional = expressions.first
178
+ expressions = strip expressions.rest
179
+ if true_constant? conditional.to_html
180
+ if expressions.length <= 1
181
+ expressions.first
182
+ else
183
+ span_operator expressions
184
+ end
185
+ end
186
+ end
187
+ end
188
+ end
189
+ end
@@ -0,0 +1,206 @@
1
+ # -*- coding: utf-8 -*-
2
+ # -*- mode: Ruby -*-
3
+
4
+ # Copyright © 2013-2016, Christopher Mark Gore,
5
+ # Soli Deo Gloria,
6
+ # All rights reserved.
7
+ #
8
+ # 2317 South River Road, Saint Charles, Missouri 63303 USA.
9
+ # Web: http://cgore.com
10
+ # Email: cgore@cgore.com
11
+ #
12
+ # Redistribution and use in source and binary forms, with or without
13
+ # modification, are permitted provided that the following conditions are met:
14
+ #
15
+ # * Redistributions of source code must retain the above copyright
16
+ # notice, this list of conditions and the following disclaimer.
17
+ #
18
+ # * Redistributions in binary form must reproduce the above copyright
19
+ # notice, this list of conditions and the following disclaimer in the
20
+ # documentation and/or other materials provided with the distribution.
21
+ #
22
+ # * Neither the name of Christopher Mark Gore nor the names of other
23
+ # contributors may be used to endorse or promote products derived from
24
+ # this software without specific prior written permission.
25
+ #
26
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
30
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
+ # POSSIBILITY OF SUCH DAMAGE.
37
+
38
+
39
+ module Teepee
40
+ module CommanderMixins
41
+ module Formatting
42
+ def html_tag tag, expressions, attribs=nil
43
+ opening_tag = if attribs
44
+ attribs_string = attribs.map {|k,v| %{#{k}="#{v}"}}.join " "
45
+ if expressions.nil?
46
+ "<#{tag} #{attribs_string}/>"
47
+ else
48
+ "<#{tag} #{attribs_string}>"
49
+ end
50
+ else
51
+ if expressions.nil?
52
+ "<#{tag}/>"
53
+ else
54
+ "<#{tag}>"
55
+ end
56
+ end
57
+ if expressions.nil?
58
+ opening_tag
59
+ else
60
+ opening_tag + expressions.map(&:to_html).join.strip + "</#{tag}>"
61
+ end
62
+ end
63
+
64
+ def b expressions
65
+ html_tag :b, expressions
66
+ end
67
+
68
+ def big expressions
69
+ html_tag :big, expressions
70
+ end
71
+
72
+ def br
73
+ html_tag :br, nil
74
+ end
75
+
76
+ def del expressions
77
+ html_tag :del, expressions
78
+ end
79
+
80
+ def enumerate expressions
81
+ html_tag :ol, expressions
82
+ end
83
+
84
+ def enumerate_numeric expressions
85
+ html_tag :ol, expressions, {type: "1"}
86
+ end
87
+
88
+ def enumerate_uppercase expressions
89
+ html_tag :ol, expressions, {type: "A"}
90
+ end
91
+
92
+ def enumerate_lowercase expressions
93
+ html_tag :ol, expressions, {type: "a"}
94
+ end
95
+
96
+ def enumerate_roman_uppercase expressions
97
+ html_tag :ol, expressions, {type: "I"}
98
+ end
99
+
100
+ def enumerate_roman_lowercase expressions
101
+ html_tag :ol, expressions, {type: "i"}
102
+ end
103
+
104
+ def h1 expressions
105
+ html_tag :h1, expressions
106
+ end
107
+
108
+ def h2 expressions
109
+ html_tag :h2, expressions
110
+ end
111
+
112
+ def h3 expressions
113
+ html_tag :h3, expressions
114
+ end
115
+
116
+ def h4 expressions
117
+ html_tag :h4, expressions
118
+ end
119
+
120
+ def h5 expressions
121
+ html_tag :h5, expressions
122
+ end
123
+
124
+ def h6 expressions
125
+ html_tag :h6, expressions
126
+ end
127
+
128
+ def it expressions
129
+ html_tag :i, expressions
130
+ end
131
+
132
+ def item expressions
133
+ html_tag :li, expressions
134
+ end
135
+
136
+ def itemize expressions
137
+ html_tag :ul, expressions
138
+ end
139
+
140
+ def itemize_disc expressions
141
+ html_tag :ul, expressions, {style: "list-style-type:disc"}
142
+ end
143
+
144
+ def itemize_circle expressions
145
+ html_tag :ul, expressions, {style: "list-style-type:circle"}
146
+ end
147
+
148
+ def itemize_square expressions
149
+ html_tag :ul, expressions, {style: "list-style-type:square"}
150
+ end
151
+
152
+ def itemize_none expressions
153
+ html_tag :ul, expressions, {style: "list-style-type:none"}
154
+ end
155
+
156
+ def nbsp count
157
+ if count and count.to_number and count.to_number > 0
158
+ "&nbsp;" * count.to_number
159
+ else
160
+ "&nbsp;"
161
+ end
162
+ end
163
+
164
+ def small expressions
165
+ html_tag :small, expressions
166
+ end
167
+
168
+ def span_operator expressions
169
+ html_tag :span, expressions
170
+ end
171
+
172
+ def sub expressions
173
+ html_tag :sub, expressions
174
+ end
175
+
176
+ def sup expressions
177
+ html_tag :sup, expressions
178
+ end
179
+
180
+ def table expressions
181
+ html_tag :table, expressions
182
+ end
183
+
184
+ def table_data expressions
185
+ html_tag :td, expressions
186
+ end
187
+
188
+ def table_header expressions
189
+ html_tag :th, expressions
190
+ end
191
+
192
+ def table_row expressions
193
+ html_tag :tr, expressions
194
+ end
195
+
196
+ def tt expressions
197
+ html_tag :tt, expressions
198
+ end
199
+
200
+ def u expressions
201
+ html_tag :u, expressions
202
+ end
203
+
204
+ end
205
+ end
206
+ end