nydp-html 0.0.15 → 0.0.16

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: 0b38d1b4cc305721e7e5a8ee1c7e83da29c51d19
4
- data.tar.gz: dbb6da3799767c0270f844f5b97ad3d697aadada
3
+ metadata.gz: 85b8b871b325a09e1ed4092544af3205820e3185
4
+ data.tar.gz: 0138daad46a200840138859679f2a2b2d7987c8d
5
5
  SHA512:
6
- metadata.gz: 6939e44a5e15545d2d6bc16f1dca194b0a1f29d04177daf250e62fc00081750b557db348f947034910f269939e4537354548ce96b93067b9659193e8b2529705
7
- data.tar.gz: 19da1d02f551ce33703e55908834cdf7a29a3ffc4abbabd5f6a0c0e312e7452dcee4110e35340e3590caa1cddc9d76e4af4724e8ef0d01ee64d26d75893e8b05
6
+ metadata.gz: 7e5afdc1dfd90171a94ef3e0e7bcc66e4d44bc076cdbfccb7358cb03fd0025a9576a575a8df6110b50c7813bf2f14ed92444d66123dcf41400e9a828b11663a0
7
+ data.tar.gz: 864f724f996c71ec0f0a61f7b486cbcb87bd86002d0ddd1fd14c7de8fed1363c9dbb116e8e08b3dead3102f92a0756fe01648830ffe2a4ccc8d4d8737db41057
@@ -23,13 +23,13 @@ Also provides percent-syntax for concise html-generation in nydp, for example
23
23
  (splot (or (hash-get hsh part)
24
24
  part)))))
25
25
 
26
- (def html-split-fn (seq sep hsh esc)
26
+ (def html-split-fn (seq sep hsh escapef)
27
27
  (fn (piece)
28
28
  (if (isa 'string piece)
29
29
  piece
30
30
  (let key (j "hsf:" (seq) ":hsf")
31
31
  (hash-set hsh key `(interpolate ,piece))
32
- (j esc sep key sep esc)))))
32
+ (escapef:j sep key sep)))))
33
33
 
34
34
  (def html-process-parts (parts converter)
35
35
  (with (hsh (hash)
@@ -59,7 +59,7 @@ Also provides percent-syntax for concise html-generation in nydp, for example
59
59
  arg
60
60
  (and (pair? arg)
61
61
  (eq? 'string-pieces (car arg)))
62
- (html-build-interpolator (cdr arg) { method x1 esc "" })
62
+ (html-build-interpolator (cdr arg) { method x1 esc x1 })
63
63
  arg))
64
64
 
65
65
  (mac render-as-haml (arg)
@@ -73,9 +73,11 @@ Also provides percent-syntax for concise html-generation in nydp, for example
73
73
  (haml-to-html arg)
74
74
  (and (pair? arg)
75
75
  (eq? 'string-pieces (car arg)))
76
- (html-build-interpolator (cdr arg) { method haml-to-html esc "" })
76
+ (html-build-interpolator (cdr arg) { method haml-to-html esc x1 })
77
77
  `(haml-to-html ,arg)))
78
78
 
79
+ (def notextile-esc (txt) "<notextile>~|txt|</notextile>")
80
+
79
81
  (mac render-as-textile (arg)
80
82
  ; produces code to convert 'arg to html using a textile interpreter
81
83
  ; for example:
@@ -87,7 +89,7 @@ Also provides percent-syntax for concise html-generation in nydp, for example
87
89
  (textile-to-html arg)
88
90
  (and (pair? arg)
89
91
  (eq? 'string-pieces (car arg)))
90
- (html-build-interpolator (cdr arg) { method textile-to-html esc "==" })
92
+ (html-build-interpolator (cdr arg) { method textile-to-html esc notextile-esc })
91
93
  `(textile-to-html ,arg)))
92
94
 
93
95
  (def to-css-rule (prop val) (joinstr "" prop ":" val ";"))
@@ -147,3 +149,14 @@ Also provides percent-syntax for concise html-generation in nydp, for example
147
149
 
148
150
  (dox-add-doc 'textile-to-html 'def '("assumes 'arg is a string in Textile format, converts to html and returns the result") '(arg))
149
151
  (dox-add-doc 'haml-to-html 'def '("assumes 'arg is a string in HAML format, converts to html and returns the result" ) '(arg))
152
+
153
+ (def to-url-params (hsh)
154
+ (joinstr "&" (map λk(joinstr "=" k hsh.,k) (hash-keys hsh))))
155
+
156
+ (def to-url (base params)
157
+ (joinstr "?" (reject !present? (list base (to-url-params params)))))
158
+
159
+ (def hesc (txt)
160
+ (string-replace ">" "&gt;"
161
+ (string-replace "<" "&lt;"
162
+ (string-replace "&" "&amp;" txt))))
@@ -0,0 +1,20 @@
1
+ (examples-for hesc
2
+ ("escapes <"
3
+ (hesc "x < y")
4
+ "x &lt; y")
5
+
6
+ ("escapes >"
7
+ (hesc "x > y")
8
+ "x &gt; y")
9
+
10
+ ("escapes &"
11
+ (hesc "x && y")
12
+ "x &amp;&amp; y")
13
+
14
+ ("escapes < & >"
15
+ (hesc "<script>alert('x && y')</script>")
16
+ "&lt;script&gt;alert('x &amp;&amp; y')&lt;/script&gt;")
17
+
18
+ ("not very cleverly re-escapes escaped entities"
19
+ (hesc "&lt;p&gt;hello Jack &amp; Jill")
20
+ "&amp;lt;p&amp;gt;hello Jack &amp;amp; Jill"))
@@ -2,7 +2,7 @@
2
2
  ("takes out all the non-string bits, concatenates, converts to html, then splices in all the bits again"
3
3
  (html-build-interpolator (list "<h1>" '(foo 1 2 3) "</h1>")
4
4
  { method (curry string-replace "h1" "HEADER-1")
5
- esc "" })
5
+ esc x1 })
6
6
  (string-pieces "<HEADER-1>" (interpolate (foo 1 2 3)) "</HEADER-1>")))
7
7
 
8
8
  (examples-for render-as-html
@@ -0,0 +1,24 @@
1
+ (examples-for percent-encode
2
+ ("escapes space"
3
+ (percent-encode "x y")
4
+ "x%20y")
5
+
6
+ ("escapes <>"
7
+ (percent-encode "x<y>")
8
+ "x%3Cy%3E")
9
+
10
+ ("escapes []"
11
+ (percent-encode "x[y]")
12
+ "x%5By%5D")
13
+
14
+ ("escapes %"
15
+ (percent-encode "%50")
16
+ "%2550")
17
+
18
+ ("does not escape -"
19
+ (percent-encode "a-b")
20
+ "a-b")
21
+
22
+ ("escapes a bunch of stuff in the same string"
23
+ (percent-encode "x[y?]=a&b%c")
24
+ "x%5By%3F%5D=a&b%25c"))
@@ -72,8 +72,26 @@ para
72
72
 
73
73
  "<h1>HEADER</h1>\n<p>1 and 2 and 6</p>\n<ul>\n\t<li>item 1</li>\n\t<li>item 2</li>\n\t<li>item 3</li>\n</ul>")
74
74
 
75
- ("render a string with interpolations to html"
75
+ ("render a string with no interpolations to html"
76
76
  (with (a "hello, world") (render-as-textile a))
77
77
 
78
78
  "<p>hello, world</p>")
79
- ))
79
+
80
+ ("render a string containing only a single interpolation"
81
+ (with (π 3.14 r 12) (render-as-textile "~(* (* r r) π)"))
82
+
83
+ "452.16")
84
+
85
+ ("render a longer multi-line string with some lines containing only a single interpolation"
86
+ (with (π 3.14 r 12) (render-as-textile "Start
87
+
88
+ ~(* (* r r) π)
89
+
90
+ ==-*-==
91
+
92
+ ~(* 2 (* r r) π)
93
+
94
+ end
95
+ "))
96
+
97
+ "<p>Start</p>\n452.16<p>-*-</p>\n904.32<p>end</p>")))
@@ -0,0 +1,8 @@
1
+ (examples-for to-url
2
+ ("parameter-free url"
3
+ (to-url "http://www.conandalton.net")
4
+ "http://www.conandalton.net")
5
+
6
+ ("append simple params"
7
+ (to-url "http://example.com" { x 42 y 65536 })
8
+ "http://example.com?x=42&y=65536"))
@@ -28,13 +28,26 @@ module Nydp
28
28
  end
29
29
 
30
30
  def setup ns
31
- Symbol.mk("textile-to-html", ns).assign(Nydp::Html::TextileToHtml.new)
32
- Symbol.mk("haml-to-html", ns).assign(Nydp::Html::HamlToHtml.new)
31
+ Symbol.mk("textile-to-html", ns).assign(Nydp::Html::TextileToHtml.instance)
32
+ Symbol.mk("haml-to-html", ns).assign(Nydp::Html::HamlToHtml.instance)
33
+ Symbol.mk("percent-encode", ns).assign(Nydp::Html::PercentEncode.instance)
34
+ end
35
+ end
36
+
37
+ class PercentEncode
38
+ include Nydp::Builtin::Base, Singleton
39
+
40
+ def invoke_2 vm, arg
41
+ vm.push_arg Nydp::StringAtom.new percent_encode arg.to_s
42
+ end
43
+
44
+ def percent_encode s
45
+ s.gsub('%', '%25').gsub(/[ \n"\?.<>\\^_`{\|}~\[\]]/) { |x| "%%%2X" % x.ord }
33
46
  end
34
47
  end
35
48
 
36
49
  class HamlToHtml
37
- include Nydp::Builtin::Base
50
+ include Nydp::Builtin::Base, Singleton
38
51
  def normalise_indentation txt
39
52
  lines = txt.split(/\n/).select { |line| line.strip != "" }
40
53
  return txt if lines.length == 0
@@ -64,7 +77,7 @@ module Nydp
64
77
  end
65
78
 
66
79
  class TextileToHtml
67
- include Nydp::Builtin::Base
80
+ include Nydp::Builtin::Base, Singleton
68
81
  def builtin_invoke vm, args
69
82
  src = args.car.to_s
70
83
  rc = RedCloth.new(src)
@@ -1,5 +1,5 @@
1
1
  module Nydp
2
2
  module Html
3
- VERSION = "0.0.15"
3
+ VERSION = "0.0.16"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nydp-html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Conan Dalton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-05 00:00:00.000000000 Z
11
+ date: 2016-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -140,9 +140,12 @@ files:
140
140
  - lib/lisp/html-020-help.nydp
141
141
  - lib/lisp/tests/haml-tests.nydp
142
142
  - lib/lisp/tests/help-examples.nydp
143
+ - lib/lisp/tests/hesc-examples.nydp
143
144
  - lib/lisp/tests/html-examples.nydp
144
145
  - lib/lisp/tests/html-tag-tests.nydp
146
+ - lib/lisp/tests/percent-encode-examples.nydp
145
147
  - lib/lisp/tests/textile-tests.nydp
148
+ - lib/lisp/tests/to-url-examples.nydp
146
149
  - lib/nydp/html.rb
147
150
  - lib/nydp/html/version.rb
148
151
  - nydp-html.gemspec