draftjs_html 0.1.0 → 0.2.0

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
  SHA256:
3
- metadata.gz: 007b3fd847f3459f78a1a8d93b04f7483a30b885aef9413ade39f60de7e93651
4
- data.tar.gz: b6a44a4f153ff355937e362474e2700b216101a06f610a772a8230908ac7598e
3
+ metadata.gz: 46ca7464191e9b163ce7d7a9e4175543606090934f08a8190dfd6a2ba4d946ed
4
+ data.tar.gz: 87288cdb9b61b818aa39083571e61f5b34e3f0d60b50d3b58da72b6ce057173f
5
5
  SHA512:
6
- metadata.gz: 34b4e47439bbdb80e0a033ea98ebfab2ebfae8cce677df6c8b3e60f5e924fe470c289b7f56f23067087f449443a0047dbdea243190d865786232d11d05df8e29
7
- data.tar.gz: d3e28487c9700f2beacbb092ead7391e8f7e7e680531cc343978f8b3b0fe7c302a5d07c87ea981da01b84d51bac210b151b561c5f4330e934aabbf719be0c659
6
+ metadata.gz: 52303e5b9f6ce70f2b2736fa34ebaada69e26ce709bfc263302cea4746aad00b8f9a831118e921ada1adb8d7c5eee700388685475347fda38008d27a5575ff73
7
+ data.tar.gz: ca29270b828f3bb15db3e958f7ead590df908bf66d4f0300734d26eba62fa89d9a1001ff3b672b4c67ce4d225d318cbc15eb72b274bd1c308d951ed4155bcbe0
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.7.0
4
+ - 2.7.5
5
+ - 3.0.0
6
+ - 3.1.2
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # DraftjsHtml
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/draftjs_html.svg)](https://badge.fury.io/rb/draftjs_html)
4
+ [![Build Status](https://app.travis-ci.com/dugancathal/draftjs_html.svg?branch=main)](https://app.travis-ci.com/dugancathal/draftjs_html)
5
+
3
6
  This gem provides conversion utilities between "raw" [DraftJS] JSON and HTML.
4
7
  My team and I have found a need on many occasions to manipulate and convert
5
8
  DraftJS on our Ruby backend - this library is the result.
@@ -56,11 +59,11 @@ raw_draftjs = {
56
59
 
57
60
  DraftjsHtml.to_html(raw_draftjs, {
58
61
  entity_style_mappings: {
59
- link: ->(entity, content) {
60
- %Q{<a href="#{entity.data['url']}">#{content}</a>}
62
+ abc: ->(entity, content) {
63
+ %Q{<a href="https://example.com/?id=#{entity.data['user_id']}">#{content}</a>}
61
64
  },
62
65
  },
63
- }) # => <p>Hello </p>
66
+ }) # => <p>Hello <a href="https://example.com/?id=123">@Arya</a></p>
64
67
  ```
65
68
 
66
69
  Almost all of the options support Procs (or otherwise `.call`-ables) to provide
@@ -17,6 +17,10 @@ module DraftjsHtml
17
17
  text.length
18
18
  end
19
19
 
20
+ def blank?
21
+ text.empty? && entity_ranges.empty?
22
+ end
23
+
20
24
  def each_char
21
25
  return to_enum(:each_char) unless block_given?
22
26
 
@@ -107,6 +107,8 @@ module DraftjsHtml
107
107
  end
108
108
 
109
109
  def block_element_for(block)
110
+ return 'br' if block.blank?
111
+
110
112
  @options[:block_type_mapping].fetch(block.type)
111
113
  end
112
114
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DraftjsHtml
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: draftjs_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Taylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-30 00:00:00.000000000 Z
11
+ date: 2022-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -47,6 +47,7 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - ".gitignore"
49
49
  - ".rspec"
50
+ - ".travis.yml"
50
51
  - CODE_OF_CONDUCT.md
51
52
  - Gemfile
52
53
  - LICENSE.txt