wcc-contentful 1.5.0 → 1.5.1
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/wcc/contentful/rich_text_renderer.rb +52 -4
 - data/lib/wcc/contentful/version.rb +1 -1
 - 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: 5599a00c953fc7b5692bc3f3c5b235d621c2d65bb1965e30a5ef89db3006a1c8
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 40731523f1a793e1c85159977e0f3235588fadf82fa2d5b4733f586f33a812fe
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 22ee7a27c1000436dbf3ba622ef1ce412ca62d67bd67e2db0a0cc707a6e85f8e1a62a719729bba7385d8020295ae460779e0e0cc4be7bcac35bea90b855c7baf
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: cee9e57b7f192501d5cfe46338a34a8db64be596e7ab64872495eab6ad33408439d024a8ad9a60f9754487b460eae9cb31ea26c908c40fd828d87289443e9170
         
     | 
| 
         @@ -142,7 +142,7 @@ class WCC::Contentful::RichTextRenderer 
     | 
|
| 
       142 
142 
     | 
    
         
             
                  # Check the first row - if it's a header row, render a <thead>
         
     | 
| 
       143 
143 
     | 
    
         
             
                  first, *rest = node.content
         
     | 
| 
       144 
144 
     | 
    
         
             
                  if first&.content&.all? { |cell| cell.node_type == 'table-header-cell' }
         
     | 
| 
       145 
     | 
    
         
            -
                    concat( 
     | 
| 
      
 145 
     | 
    
         
            +
                    concat(render_table_header(first))
         
     | 
| 
       146 
146 
     | 
    
         
             
                  else
         
     | 
| 
       147 
147 
     | 
    
         
             
                    # Otherwise, render it inside the tbody with the rest
         
     | 
| 
       148 
148 
     | 
    
         
             
                    rest.unshift(first)
         
     | 
| 
         @@ -152,6 +152,38 @@ class WCC::Contentful::RichTextRenderer 
     | 
|
| 
       152 
152 
     | 
    
         
             
                end
         
     | 
| 
       153 
153 
     | 
    
         
             
              end
         
     | 
| 
       154 
154 
     | 
    
         | 
| 
      
 155 
     | 
    
         
            +
              def render_table_header(table_row_node)
         
     | 
| 
      
 156 
     | 
    
         
            +
                # roll up blank table-header-cells into the previous cell w/ colspan
         
     | 
| 
      
 157 
     | 
    
         
            +
                node_contents = []
         
     | 
| 
      
 158 
     | 
    
         
            +
                table_row_node.content.each do |node|
         
     | 
| 
      
 159 
     | 
    
         
            +
                  if node.node_type == 'table-header-cell' &&
         
     | 
| 
      
 160 
     | 
    
         
            +
                      node_is_blank?(node) &&
         
     | 
| 
      
 161 
     | 
    
         
            +
                      node_contents.last&.node_type == 'table-header-cell'
         
     | 
| 
      
 162 
     | 
    
         
            +
             
     | 
| 
      
 163 
     | 
    
         
            +
                    # replace the previous node with a new node with colspan + 1
         
     | 
| 
      
 164 
     | 
    
         
            +
                    last_node = node_contents.pop
         
     | 
| 
      
 165 
     | 
    
         
            +
                    node_contents << WCC::Contentful::RichText.tokenize(
         
     | 
| 
      
 166 
     | 
    
         
            +
                      last_node.as_json.merge(
         
     | 
| 
      
 167 
     | 
    
         
            +
                        'data' => (last_node['data'] || {}).merge({
         
     | 
| 
      
 168 
     | 
    
         
            +
                          'colspan' => (last_node['data']&.try('colspan') || 1) + 1
         
     | 
| 
      
 169 
     | 
    
         
            +
                        })
         
     | 
| 
      
 170 
     | 
    
         
            +
                      )
         
     | 
| 
      
 171 
     | 
    
         
            +
                    )
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
                    # And skip adding this blank node
         
     | 
| 
      
 174 
     | 
    
         
            +
                    next
         
     | 
| 
      
 175 
     | 
    
         
            +
                  end
         
     | 
| 
      
 176 
     | 
    
         
            +
             
     | 
| 
      
 177 
     | 
    
         
            +
                  node_contents << node
         
     | 
| 
      
 178 
     | 
    
         
            +
                end
         
     | 
| 
      
 179 
     | 
    
         
            +
             
     | 
| 
      
 180 
     | 
    
         
            +
                content_tag(:thead) do
         
     | 
| 
      
 181 
     | 
    
         
            +
                  content_tag(:tr) do
         
     | 
| 
      
 182 
     | 
    
         
            +
                    render_content(node_contents)
         
     | 
| 
      
 183 
     | 
    
         
            +
                  end
         
     | 
| 
      
 184 
     | 
    
         
            +
                end
         
     | 
| 
      
 185 
     | 
    
         
            +
              end
         
     | 
| 
      
 186 
     | 
    
         
            +
             
     | 
| 
       155 
187 
     | 
    
         
             
              def render_table_row(node)
         
     | 
| 
       156 
188 
     | 
    
         
             
                content_tag(:tr) do
         
     | 
| 
       157 
189 
     | 
    
         
             
                  render_content(node.content)
         
     | 
| 
         @@ -160,16 +192,23 @@ class WCC::Contentful::RichTextRenderer 
     | 
|
| 
       160 
192 
     | 
    
         | 
| 
       161 
193 
     | 
    
         
             
              def render_table_cell(node)
         
     | 
| 
       162 
194 
     | 
    
         
             
                content_tag(:td) do
         
     | 
| 
       163 
     | 
    
         
            -
                   
     | 
| 
      
 195 
     | 
    
         
            +
                  render_table_cell_content(node.content)
         
     | 
| 
       164 
196 
     | 
    
         
             
                end
         
     | 
| 
       165 
197 
     | 
    
         
             
              end
         
     | 
| 
       166 
198 
     | 
    
         | 
| 
       167 
199 
     | 
    
         
             
              def render_table_header_cell(node)
         
     | 
| 
       168 
     | 
    
         
            -
                content_tag(:th) do
         
     | 
| 
       169 
     | 
    
         
            -
                   
     | 
| 
      
 200 
     | 
    
         
            +
                content_tag(:th, colspan: node.data && node.data['colspan']) do
         
     | 
| 
      
 201 
     | 
    
         
            +
                  render_table_cell_content(node.content)
         
     | 
| 
       170 
202 
     | 
    
         
             
                end
         
     | 
| 
       171 
203 
     | 
    
         
             
              end
         
     | 
| 
       172 
204 
     | 
    
         | 
| 
      
 205 
     | 
    
         
            +
              def render_table_cell_content(content)
         
     | 
| 
      
 206 
     | 
    
         
            +
                # If the content is a single paragraph, render it without the <p> tag
         
     | 
| 
      
 207 
     | 
    
         
            +
                return render_content(content.first.content) if content.size == 1 && content.first.node_type == 'paragraph'
         
     | 
| 
      
 208 
     | 
    
         
            +
             
     | 
| 
      
 209 
     | 
    
         
            +
                render_content(content)
         
     | 
| 
      
 210 
     | 
    
         
            +
              end
         
     | 
| 
      
 211 
     | 
    
         
            +
             
     | 
| 
       173 
212 
     | 
    
         
             
              def render_hyperlink(node)
         
     | 
| 
       174 
213 
     | 
    
         
             
                content_tag(:a,
         
     | 
| 
       175 
214 
     | 
    
         
             
                  href: node.data['uri'],
         
     | 
| 
         @@ -249,6 +288,15 @@ class WCC::Contentful::RichTextRenderer 
     | 
|
| 
       249 
288 
     | 
    
         | 
| 
       250 
289 
     | 
    
         
             
              private
         
     | 
| 
       251 
290 
     | 
    
         | 
| 
      
 291 
     | 
    
         
            +
              def node_is_blank?(node)
         
     | 
| 
      
 292 
     | 
    
         
            +
                case node.node_type
         
     | 
| 
      
 293 
     | 
    
         
            +
                when 'text'
         
     | 
| 
      
 294 
     | 
    
         
            +
                  node.value.blank?
         
     | 
| 
      
 295 
     | 
    
         
            +
                else
         
     | 
| 
      
 296 
     | 
    
         
            +
                  node.content.all? { |n| node_is_blank?(n) }
         
     | 
| 
      
 297 
     | 
    
         
            +
                end
         
     | 
| 
      
 298 
     | 
    
         
            +
              end
         
     | 
| 
      
 299 
     | 
    
         
            +
             
     | 
| 
       252 
300 
     | 
    
         
             
              def resolve_target(target)
         
     | 
| 
       253 
301 
     | 
    
         
             
                unless store.present?
         
     | 
| 
       254 
302 
     | 
    
         
             
                  raise NotConnectedError,
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: wcc-contentful
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.5. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.5.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Watermark Dev
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2023-06- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2023-06-19 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: byebug
         
     |