hiccdown 0.1.5 → 0.2.0
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/hiccdown.rb +16 -6
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 948a40183a474fb17808d1a451b3ba53a95b16a63d7bce1d99072ce09e7cf6bf
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 83fcbc050a814e05173fdf8b14cfa97db9a3e6e8c545f942fb9fe75c5a2df751
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 44dc2d3ea451138e9f4cf22943a3085be4374a45cdff5a4e42a7545b9312f44720cb40f9b69e0bb6681e4686dc1b2ed480974c06112977767ada77d6fdeb79d9
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 01adf06510033153dccf4732a28f23608fd8c851a1dad8de852b46b8c265f7226998a0aa65dfcf40c8a493ed7eb6c7773001f68062510956e78428cd2e156f9f
         
     | 
    
        data/lib/hiccdown.rb
    CHANGED
    
    | 
         @@ -1,23 +1,25 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'cgi'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            module Hiccdown
         
     | 
| 
       2 
4 
     | 
    
         
             
              def self.standalone_tags
         
     | 
| 
       3 
5 
     | 
    
         
             
                Set.new([:area, :base, :br, :col, :command, :embed, :hr, :img, :input, :keygen, :link, :menuitem, :meta, :param, :source, :track, :wbr])
         
     | 
| 
       4 
6 
     | 
    
         
             
              end
         
     | 
| 
       5 
7 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
              def self.to_html structure
         
     | 
| 
      
 8 
     | 
    
         
            +
              def self.to_html structure, escape = true
         
     | 
| 
       7 
9 
     | 
    
         
             
                if structure.is_a? Hash
         
     | 
| 
       8 
10 
     | 
    
         
             
                  structure.reduce([]) do |acc, (key, val)|
         
     | 
| 
       9 
     | 
    
         
            -
                    acc + [[key.to_s, '="', val.to_s, '"'].join]
         
     | 
| 
      
 11 
     | 
    
         
            +
                    acc + [[key.to_s, '="', self.maybe_escape(val.to_s, escape), '"'].join]
         
     | 
| 
       10 
12 
     | 
    
         
             
                  end.join(' ')
         
     | 
| 
       11 
13 
     | 
    
         
             
                elsif structure.is_a? Array
         
     | 
| 
       12 
14 
     | 
    
         
             
                  if structure.first.is_a?(Array)
         
     | 
| 
       13 
     | 
    
         
            -
                    return structure.map { |s| to_html 
     | 
| 
      
 15 
     | 
    
         
            +
                    return structure.map { |s| to_html(s, escape) }.join
         
     | 
| 
       14 
16 
     | 
    
         
             
                  end
         
     | 
| 
       15 
17 
     | 
    
         | 
| 
       16 
18 
     | 
    
         
             
                  if structure[1].is_a? Hash
         
     | 
| 
       17 
     | 
    
         
            -
                    tag, attrs, *children = structure.map { |s| to_html 
     | 
| 
      
 19 
     | 
    
         
            +
                    tag, attrs, *children = structure.map { |s| to_html(s, escape) }
         
     | 
| 
       18 
20 
     | 
    
         
             
                    tag_and_attrs = structure[1].any? ? [tag, ' ', attrs].join : tag
         
     | 
| 
       19 
21 
     | 
    
         
             
                  else
         
     | 
| 
       20 
     | 
    
         
            -
                    tag, *children = structure.map { |s| to_html 
     | 
| 
      
 22 
     | 
    
         
            +
                    tag, *children = structure.map { |s| to_html(s, escape) }
         
     | 
| 
       21 
23 
     | 
    
         
             
                  end
         
     | 
| 
       22 
24 
     | 
    
         | 
| 
       23 
25 
     | 
    
         
             
                  if standalone_tags.include? tag.to_sym
         
     | 
| 
         @@ -26,7 +28,15 @@ module Hiccdown 
     | 
|
| 
       26 
28 
     | 
    
         
             
                    ['<', tag_and_attrs || tag, '>', children.join, '</', tag, '>'].join
         
     | 
| 
       27 
29 
     | 
    
         
             
                  end
         
     | 
| 
       28 
30 
     | 
    
         
             
                else
         
     | 
| 
       29 
     | 
    
         
            -
                  structure.to_s
         
     | 
| 
      
 31 
     | 
    
         
            +
                  self.maybe_escape(structure.to_s, escape)
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
              end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
              def self.maybe_escape escapable, escape
         
     | 
| 
      
 36 
     | 
    
         
            +
                if escape
         
     | 
| 
      
 37 
     | 
    
         
            +
                  CGI::escapeHTML(escapable)
         
     | 
| 
      
 38 
     | 
    
         
            +
                else
         
     | 
| 
      
 39 
     | 
    
         
            +
                  escapable
         
     | 
| 
       30 
40 
     | 
    
         
             
                end
         
     | 
| 
       31 
41 
     | 
    
         
             
              end
         
     | 
| 
       32 
42 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: hiccdown
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Dennis Hackethal
         
     | 
| 
         @@ -10,7 +10,7 @@ bindir: bin 
     | 
|
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
11 
     | 
    
         
             
            date: 2024-07-21 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       13 
     | 
    
         
            -
            description: Generates an HTML string from a Hiccup structure.
         
     | 
| 
      
 13 
     | 
    
         
            +
            description: Generates an HTML string from a Hiccup structure and improves Rails views.
         
     | 
| 
       14 
14 
     | 
    
         
             
            email: engineering@dennishackethal.com
         
     | 
| 
       15 
15 
     | 
    
         
             
            executables: []
         
     | 
| 
       16 
16 
     | 
    
         
             
            extensions: []
         
     |