nydp-html 0.0.15 → 0.0.16
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 +4 -4
- data/lib/lisp/html-010-tools.nydp +18 -5
- data/lib/lisp/tests/hesc-examples.nydp +20 -0
- data/lib/lisp/tests/html-examples.nydp +1 -1
- data/lib/lisp/tests/percent-encode-examples.nydp +24 -0
- data/lib/lisp/tests/textile-tests.nydp +20 -2
- data/lib/lisp/tests/to-url-examples.nydp +8 -0
- data/lib/nydp/html.rb +17 -4
- data/lib/nydp/html/version.rb +1 -1
- metadata +5 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 85b8b871b325a09e1ed4092544af3205820e3185
         | 
| 4 | 
            +
              data.tar.gz: 0138daad46a200840138859679f2a2b2d7987c8d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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  | 
| 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  | 
| 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 ">" ">"
         | 
| 161 | 
            +
                (string-replace "<" "<"
         | 
| 162 | 
            +
                  (string-replace "&" "&" txt))))
         | 
| @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            (examples-for hesc
         | 
| 2 | 
            +
              ("escapes <"
         | 
| 3 | 
            +
               (hesc "x < y")
         | 
| 4 | 
            +
               "x < y")
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              ("escapes >"
         | 
| 7 | 
            +
               (hesc "x > y")
         | 
| 8 | 
            +
               "x > y")
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              ("escapes &"
         | 
| 11 | 
            +
               (hesc "x && y")
         | 
| 12 | 
            +
               "x && y")
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              ("escapes < & >"
         | 
| 15 | 
            +
               (hesc "<script>alert('x && y')</script>")
         | 
| 16 | 
            +
               "<script>alert('x && y')</script>")
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              ("not very cleverly re-escapes escaped entities"
         | 
| 19 | 
            +
               (hesc "<p>hello Jack & Jill")
         | 
| 20 | 
            +
               "&lt;p&gt;hello Jack &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>")))
         | 
    
        data/lib/nydp/html.rb
    CHANGED
    
    | @@ -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. | 
| 32 | 
            -
                    Symbol.mk("haml-to-html",     ns).assign(Nydp::Html::HamlToHtml. | 
| 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)
         | 
    
        data/lib/nydp/html/version.rb
    CHANGED
    
    
    
        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. | 
| 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- | 
| 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
         |