nydp-html 0.0.11 → 0.0.12

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: af0f3578b42d4d0ceae6736a7682f63ea1618880
4
- data.tar.gz: 55d79621b9c68dfca3b95ccc6ae20b5aba5d0fca
3
+ metadata.gz: c0c8d4046e86547b06be324cebae246e9bdda8e1
4
+ data.tar.gz: 5ac6ebfc0110f70a4baa746dd27de924911b7787
5
5
  SHA512:
6
- metadata.gz: 06c2ffce91f11385f2599149b2a53089b3594bbe0396d3a7c1fafa2e34da0e2f9616c297d699466227d8dfe82a473b7ea50db3bd5526d6a30480f13a3ccc5176
7
- data.tar.gz: 0fe492d9454d1e0f0ee6d831ddba5cdd9fcdda9b0ab9b0fbbe6c36e57a023a0cc34d54c9525005d26cbf41bcd634dc63bb4c7d4c5f36bb9bc1c67093077a44d5
6
+ metadata.gz: 0e08743b4f68407c88565abd23c037ada2b08ed9c632cb07906975ac8405e81f602e4d4245fc61d42cb78f625ef4686845c52e8f6da87c00d67265b16978ddcd
7
+ data.tar.gz: 0e01bedfb632144d879584cecb7f4f3ed23dbbe17c430b9b80e5bc5d66c360bfa6d781a368a81883be2c141b752149414de68cdfa5b6eed5d30157c8cb3ffbaa
@@ -1,20 +1,59 @@
1
- (def interpolate (arg) arg)
1
+ (def default-format (arg)
2
+ ; override this to ensure values are formatted
3
+ ; as you desire it. By default, this returns its
4
+ ; argument unchanged
5
+ arg)
2
6
 
3
- (def html-process-parts (parts converter)
4
- (let separator (random-string 20)
5
- (string-split (converter.method (joinstr "~(just converter.esc)~(just separator)~(just converter.esc)"
6
- parts))
7
- separator)))
7
+ (def interpolate (arg)
8
+ ; override this to provide error handling, logging,
9
+ ; profiling, or whatever it is you might desire.
10
+ ; by default, this delegates to 'default-format
11
+ (default-format arg))
12
+
13
+ (def html-resplit (parts hsh)
14
+ (accum splot
15
+ (each part parts
16
+ (splot (or (hash-get hsh part)
17
+ part)))))
18
+
19
+ (def html-split-fn (seq sep hsh esc)
20
+ (fn (piece)
21
+ (if (isa 'string piece)
22
+ piece
23
+ (let key (j "--l--" (seq) "--r--")
24
+ (hash-set hsh key `(interpolate ,piece))
25
+ (j esc sep key sep esc)))))
8
26
 
9
- (def html-interpolatify-arg (tuple)
10
- (if (cadr tuple)
11
- `(interpolate ,(cadr tuple))
12
- nil))
27
+ (def html-process-parts (parts converter)
28
+ (with (hsh (hash)
29
+ sep (random-string 12))
30
+ (html-resplit (string-split (converter.method
31
+ (j:map (html-split-fn (seqf 0) sep hsh converter.esc)
32
+ parts))
33
+ sep)
34
+ hsh)))
13
35
 
14
36
  (def html-build-interpolator (pieces converter)
15
- (let tuples (pairs pieces)
16
- `(string-pieces ,@(apply + (zip (html-process-parts (map car tuples) converter)
17
- (map html-interpolatify-arg tuples))))))
37
+ `(string-pieces ,@(html-process-parts pieces converter)))
38
+
39
+ (mac render-as-html (arg)
40
+ ; produce code to convert 'arg to html using a null interpreter.
41
+ ; in other words, assume input is already html. Normally, we would
42
+ ; just return the argument, but it's useful to take advantage of the fact that
43
+ ; each interpolation ~(foo) is replaced with ~(interpolate (foo)), and
44
+ ; you may override 'interpolate for your own nefarious purposes.
45
+ ;
46
+ ; for example:
47
+ ;
48
+ ; (render-as-html "<p>hello world</p>") ;=> "<p>hello world</p>"
49
+ ; (render-as-html (get-some-text-from 'somewhere)) ;=> (x1 (get-some-text-from 'somewhere))
50
+ ; (render-as-html "<p>hello ~|name|</p>") ;=> (string-pieces "<p>hello" (interpolate name) "<p>")
51
+ (if (isa 'string arg)
52
+ arg
53
+ (and (pair? arg)
54
+ (eq? 'string-pieces (car arg)))
55
+ (html-build-interpolator (cdr arg) { method x1 esc "" })
56
+ arg))
18
57
 
19
58
  (mac render-as-haml (arg)
20
59
  ; produce code to convert 'arg to html using a haml interpreter
@@ -22,7 +61,7 @@
22
61
  ;
23
62
  ; (render-as-haml "%p hello world") ;=> "<p>hello world</p>"
24
63
  ; (render-as-haml (get-some-text-from 'somewhere)) ;=> (haml-to-html (get-some-text-from 'somewhere))
25
- ; (render-as-haml "%p hello ~name") ;=> (string-pieces "<p>hello" name "<p>")
64
+ ; (render-as-haml "%p hello ~name") ;=> (string-pieces "<p>hello" (interpolate name) "<p>")
26
65
  (if (isa 'string arg)
27
66
  (haml-to-html arg)
28
67
  (and (pair? arg)
@@ -36,7 +75,7 @@
36
75
  ;
37
76
  ; (render-as-textile "hello world") ;=> "<p>hello world</p>"
38
77
  ; (render-as-textile (get-some-text-from 'somewhere)) ;=> (textile-to-html (get-some-text-from 'somewhere))
39
- ; (render-as-textile "hello ~name") ;=> (string-pieces "<p>hello" name "<p>")
78
+ ; (render-as-textile "hello ~name") ;=> (string-pieces "<p>hello" (interpolate name) "<p>")
40
79
  (if (isa 'string arg)
41
80
  (textile-to-html arg)
42
81
  (and (pair? arg)
@@ -67,7 +106,9 @@
67
106
  (hash-keys hsh)))))
68
107
 
69
108
  (def html-tag/ (name attrs) "<~|name|~(as-tag-attrs attrs)/>")
70
- (def html-tag (name attrs . content) "<~|name|~(as-tag-attrs attrs)>~(apply joinstr "" content)</~|name|>")
109
+ (def html-tag (name attrs . content)
110
+ (let formatted (map default-format content)
111
+ "<~|name|~(as-tag-attrs attrs)>~(apply joinstr "" formatted)</~|name|>"))
71
112
  (def img (src) (html-tag/ "img" { src src }))
72
113
  (def link-to (txt path attrs) (html-tag "a" (hash-merge { href path } (or attrs (hash))) txt))
73
114
  (def html-tag-fn (name attrs) (fn content (apply html-tag name attrs content)))
@@ -41,7 +41,7 @@
41
41
  "</p>\n<ul>\n <li>item " (interpolate (assign counter (+ counter 1)))
42
42
  "</li>\n <li>item " (interpolate (assign counter (+ counter 1)))
43
43
  "</li>\n <li>item " (interpolate (assign counter (+ counter 1)))
44
- "</li>\n</ul>\n" nil))
44
+ "</li>\n</ul>\n"))
45
45
 
46
46
  ("compile a function invocation to render as haml"
47
47
  (pre-compile '(render-as-haml a))
@@ -92,6 +92,17 @@
92
92
  <li>item 2</li>
93
93
  <li>item 3</li>
94
94
  </ul>
95
+ ")
96
+
97
+ ("render correctly even when HAML re-orders attributes"
98
+ (with (a 'big b 'little c "http://link")
99
+ (render-as-haml "
100
+ %a(href='~|c|' class='~|a|' alt='~|b|')
101
+ %img(src='~|c|' alt='~|b|' title='~|a|')
102
+ "))
103
+ "<a alt='little' class='big' href='http://link'>
104
+ <img alt='little' src='http://link' title='big'>
105
+ </a>
95
106
  ")
96
107
 
97
108
  ("render a string with nested haml to html"
@@ -0,0 +1,32 @@
1
+ (examples-for html-build-interpolator
2
+ ("takes out all the non-string bits, concatenates, converts to html, then splices in all the bits again"
3
+ (html-build-interpolator (list "<h1>" '(foo 1 2 3) "</h1>")
4
+ { method (curry string-replace "h1" "HEADER-1")
5
+ esc "" })
6
+ (string-pieces "<HEADER-1>" (interpolate (foo 1 2 3)) "</HEADER-1>")))
7
+
8
+ (examples-for render-as-html
9
+ ("return the same string if there are no interpolations"
10
+ (pre-compile '(render-as-html "<p>hello, nydp</p>"))
11
+ "<p>hello, nydp</p>")
12
+
13
+ ("return the same thing if there are no interpolations"
14
+ (pre-compile '(render-as-html (foo bar yobo)))
15
+ (foo bar yobo))
16
+
17
+ ("compile a string with interpolations to an instruction to generate haml"
18
+ (pre-compile '(render-as-html "<h1>HEADER</h1>
19
+ <p>~a and ~b and ~(c 3)</p>
20
+ <ul>
21
+ <li>item ~(assign counter (+ counter 1))</li>
22
+ <li>item ~(assign counter (+ counter 1))</li>
23
+ <li>item ~(assign counter (+ counter 1))</li>
24
+ </ul>
25
+ "))
26
+
27
+ (string-pieces "<h1>HEADER</h1>\n<p>"
28
+ (interpolate a) " and " (interpolate b) " and " (interpolate (c 3))
29
+ "</p>\n<ul>\n <li>item " (interpolate (assign counter (+ counter 1)))
30
+ "</li>\n <li>item " (interpolate (assign counter (+ counter 1)))
31
+ "</li>\n <li>item " (interpolate (assign counter (+ counter 1)))
32
+ "</li>\n</ul>\n")))
@@ -34,7 +34,7 @@ paragraph text
34
34
  "</p>\n<ul>\n\t<li>item " (interpolate (assign counter (+ counter 1)))
35
35
  "</li>\n\t<li>item " (interpolate (assign counter (+ counter 1)))
36
36
  "</li>\n\t<li>item " (interpolate (assign counter (+ counter 1)))
37
- "</li>\n</ul>" nil))
37
+ "</li>\n</ul>"))
38
38
 
39
39
  ("compile a function invocation to render as textile"
40
40
  (pre-compile '(render-as-textile a))
@@ -1,5 +1,5 @@
1
1
  module Nydp
2
2
  module Html
3
- VERSION = "0.0.11"
3
+ VERSION = "0.0.12"
4
4
  end
5
5
  end
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'rspec', '~> 2.9'
25
25
  spec.add_development_dependency 'rspec_numbering_formatter'
26
26
 
27
- spec.add_dependency 'nydp', ['~> 0.1', '>= 0.1.7']
27
+ spec.add_dependency 'nydp', ['~> 0.1', '>= 0.1.13']
28
28
  spec.add_dependency 'haml', '~> 4.0'
29
29
  spec.add_dependency 'RedCloth'
30
30
  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.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Conan Dalton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-15 00:00:00.000000000 Z
11
+ date: 2016-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,7 +75,7 @@ dependencies:
75
75
  version: '0.1'
76
76
  - - ">="
77
77
  - !ruby/object:Gem::Version
78
- version: 0.1.7
78
+ version: 0.1.13
79
79
  type: :runtime
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
@@ -85,7 +85,7 @@ dependencies:
85
85
  version: '0.1'
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
- version: 0.1.7
88
+ version: 0.1.13
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: haml
91
91
  requirement: !ruby/object:Gem::Requirement
@@ -132,6 +132,7 @@ files:
132
132
  - lib/lisp/html-020-help.nydp
133
133
  - lib/lisp/tests/haml-tests.nydp
134
134
  - lib/lisp/tests/help-examples.nydp
135
+ - lib/lisp/tests/html-examples.nydp
135
136
  - lib/lisp/tests/html-tag-tests.nydp
136
137
  - lib/lisp/tests/textile-tests.nydp
137
138
  - lib/nydp/html.rb