teepee 0.7.16 → 0.8.0

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: aa225694c765a835dbef542d87979689945f8463
4
- data.tar.gz: c978538afe91da61ef07b46ac465cd9f625058bb
3
+ metadata.gz: 73e4c9f9bfdf81a27259d00bfc83506d5296d091
4
+ data.tar.gz: ca33965c5c377195817a023ab06a86ba385f071a
5
5
  SHA512:
6
- metadata.gz: e35a6b75e3fa7f7d740e222f7f7bafc522b367f4f106d287c1d817b6314d55dc95d9de0b91fffac8a8cfdd7828abca9e6573567cc4a0c9f38d264ce8d52b830d
7
- data.tar.gz: a4231720f0a1c40ce65d8dc1defb05b44b960e498ec9c23a3fd6c913827d27af4959de63c8dab0ab5693603b03a7626350d61f089bbe364cf710e2d3b5640fb9
6
+ metadata.gz: abd50f42a45619391afa669e159abcbca1c4764950cd610e0aa473cae5c92e9b74b85593af3def0439d470b2ae621c74a9b2945de7480ce4332c9cce1b22ab4d
7
+ data.tar.gz: 2bb367a3e121cf795af6f830d7f836a21f87a15cb5664a5a9883e3ab22cfffa67b50757ab8932ab724b5682ab700a95762fb86a8b8cee62eee47af5f2c24b0c5
@@ -278,6 +278,17 @@ module Teepee
278
278
  @@commander./ *numbers_from_expressions
279
279
  when "%"
280
280
  @@commander.% *numbers_from_expressions
281
+ when "+%"
282
+ @@commander.add_percentage *numbers_from_expressions
283
+ when "-%"
284
+ @@commander.subtract_percentage *numbers_from_expressions
285
+ when "%t",
286
+ "%total"
287
+ @@commander.percent_total *numbers_from_expressions
288
+ when "mod",
289
+ "modulus",
290
+ "modulo"
291
+ @@commander.mod *numbers_from_expressions
281
292
  when "^", "**"
282
293
  @@commander.** *numbers_from_expressions
283
294
  when "sin", "cos", "tan",
@@ -310,6 +321,16 @@ module Teepee
310
321
  @@commander.ldexp fraction, exponent
311
322
  when "hypot"
312
323
  @@commander.hypot numbers_from_expressions
324
+ when "true"
325
+ @@commander.true_constant
326
+ when "false"
327
+ @@commander.false_constant
328
+ when "not"
329
+ @@commander.boolean_not first_word_token
330
+ when "and"
331
+ @@commander.boolean_and expressions
332
+ when "or"
333
+ @@commander.boolean_or expressions
313
334
  else
314
335
  command_error "unknown command #{command.to_html}"
315
336
  end
@@ -71,6 +71,14 @@ module Teepee
71
71
  end
72
72
  end
73
73
 
74
+ def ensure_boolean boolean
75
+ if boolean.to_s == "true" or boolean.to_s == "false"
76
+ boolean
77
+ else
78
+ command_error "Non-boolean value."
79
+ end
80
+ end
81
+
74
82
  def html_tag tag, expressions, attribs=nil
75
83
  opening_tag = if attribs
76
84
  attribs_string = attribs.map {|k,v| %{#{k}="#{v}"}}.join " "
@@ -89,7 +97,7 @@ module Teepee
89
97
  if expressions.nil?
90
98
  opening_tag
91
99
  else
92
- opening_tag + expressions.map(&:to_html).join + "</#{tag}>"
100
+ opening_tag + expressions.map(&:to_html).join.strip + "</#{tag}>"
93
101
  end
94
102
  end
95
103
 
@@ -108,10 +116,28 @@ module Teepee
108
116
  elsif not id.to_s =~ /\A[0-9]+\z/
109
117
  command_error "#{singular}_id: error: invalid #{singular} ID specified"
110
118
  else
111
- tb_href "/#{plural}/#{id.to_s}/#{view}", "#{klass.to_s} ##{id.to_s}"
119
+ tb_href "#{plural}/#{id.to_s}/#{view}", "#{klass.to_s} ##{id.to_s}"
112
120
  end
113
121
  end
114
122
 
123
+ def left_strip expressions
124
+ while expressions.first.kind_of? WhitespaceToken
125
+ expressions.shift
126
+ end
127
+ expressions
128
+ end
129
+
130
+ def right_strip expressions
131
+ while expressions.last.kind_of? WhitespaceToken
132
+ expressions.pop
133
+ end
134
+ expressions
135
+ end
136
+
137
+ def strip expressions
138
+ left_strip right_strip expressions
139
+ end
140
+
115
141
  #----------------------------------------------------------------------------
116
142
 
117
143
  def + *numbers
@@ -138,12 +164,28 @@ module Teepee
138
164
  end
139
165
  end
140
166
 
167
+ def ** *numbers
168
+ ensure_numeric numbers.reduce :**
169
+ end
170
+
141
171
  def % *numbers
142
- ensure_numeric numbers.reduce :%
172
+ ensure_numeric numbers
173
+ numbers.inject { |base, percent| base*percent/100.0 }
143
174
  end
144
175
 
145
- def ** *numbers
146
- ensure_numeric numbers.reduce :**
176
+ def add_percentage *numbers
177
+ ensure_numeric numbers
178
+ numbers.inject {|base, percent| base * (1+percent/100.0) }
179
+ end
180
+
181
+ def subtract_percentage *numbers
182
+ ensure_numeric numbers
183
+ numbers.inject {|base, percent| base * (1-percent/100.0) }
184
+ end
185
+
186
+ def percent_total *numbers
187
+ ensure_numeric numbers
188
+ numbers.inject {|total, part| Float(part)/Float(total)*100.0 }
147
189
  end
148
190
 
149
191
  def acos number
@@ -186,6 +228,40 @@ module Teepee
186
228
  id_command_handler id, :Folder, "folder", "folders", "folders/bookmarks_inline", "bookmarks"
187
229
  end
188
230
 
231
+ def boolean_and expressions
232
+ if expressions.empty?
233
+ "true"
234
+ elsif expressions.first.to_s == "false"
235
+ "false"
236
+ elsif expressions.first.to_s == "true" or expressions.first.kind_of? WhitespaceToken
237
+ boolean_and expressions[1..-1]
238
+ else
239
+ command_error "Not a boolean value #{expressions.first}"
240
+ end
241
+ end
242
+
243
+ def boolean_not expression
244
+ if expression.to_s == "true"
245
+ "false"
246
+ elsif expression.to_s == "false"
247
+ "true"
248
+ else
249
+ command_error "Not a boolean value"
250
+ end
251
+ end
252
+
253
+ def boolean_or expressions
254
+ if expressions.empty?
255
+ "false"
256
+ elsif expressions.first.to_s == "true"
257
+ "true"
258
+ elsif expressions.first.to_s == "false" or expressions.first.kind_of? WhitespaceToken
259
+ boolean_or expressions[1..-1]
260
+ else
261
+ command_error "Not a boolean value"
262
+ end
263
+ end
264
+
189
265
  def br
190
266
  html_tag :br, nil
191
267
  end
@@ -242,6 +318,10 @@ module Teepee
242
318
  ensure_numeric Math.erfc number
243
319
  end
244
320
 
321
+ def false_constant
322
+ "false"
323
+ end
324
+
245
325
  def folder_id id
246
326
  id_command_handler id, :Folder
247
327
  end
@@ -259,7 +339,7 @@ module Teepee
259
339
  end
260
340
 
261
341
  def h2 expressions
262
- html_tag :h2gg, expressions
342
+ html_tag :h2, expressions
263
343
  end
264
344
 
265
345
  def h3 expressions
@@ -283,6 +363,7 @@ module Teepee
283
363
  end
284
364
 
285
365
  def image expressions
366
+ expressions = strip expressions
286
367
  uri, *alt_text = expressions
287
368
  uri = ERB::Util.html_escape uri.to_s
288
369
  if not valid_uri? uri
@@ -291,7 +372,7 @@ module Teepee
291
372
  if alt_text.empty?
292
373
  html_tag :img, nil, {src: uri}
293
374
  else
294
- html_tag :img, nil, {src: uri, alt: alt_text}
375
+ html_tag :img, nil, {src: uri, alt: alt_text.map(&:to_s).join.strip}
295
376
  end
296
377
  end
297
378
  end
@@ -349,6 +430,7 @@ module Teepee
349
430
  end
350
431
 
351
432
  def link expressions
433
+ expressions = strip expressions
352
434
  uri, *desc = expressions
353
435
  uri = ERB::Util.html_escape uri.to_s
354
436
  if not valid_uri? uri
@@ -380,6 +462,10 @@ module Teepee
380
462
  ensure_numeric Math.log10 number
381
463
  end
382
464
 
465
+ def mod *numbers
466
+ ensure_numeric numbers.reduce :%
467
+ end
468
+
383
469
  def nbsp
384
470
  "&nbsp;"
385
471
  end
@@ -456,6 +542,10 @@ module Teepee
456
542
  ensure_numeric Math.tanh number
457
543
  end
458
544
 
545
+ def true_constant
546
+ "true"
547
+ end
548
+
459
549
  def tt expressions
460
550
  html_tag :tt, expressions
461
551
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teepee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.16
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Mark Gore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-24 00:00:00.000000000 Z
11
+ date: 2016-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport