dato 0.7.18 → 0.8.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: 43d5a65257051385168de064d1b162bbd0bc5d0ef8523a2079d2f9051dc6b509
4
- data.tar.gz: 23a9293ed05685fd635de711d3b98084dcb9efc92735d0e379b7640798e8a959
3
+ metadata.gz: 9777e0d266657c2dffa3e6651de719c8e24728e311bcb6ed745bc6a7a70d927a
4
+ data.tar.gz: 4d54c4e69249b7d3a30f9c289afe93f8f242c6026f8a62d7e6ae0e18ca8b8eb2
5
5
  SHA512:
6
- metadata.gz: cd30a74fe816ab8d4a3683d62ddfecd1ce350f94c94a4f4bbbcaaabaf88a94677f939c8d7cfaf0c9769040d03adc7da829229d5e8762610491ca7d199244e082
7
- data.tar.gz: 47ebdc307a2c8ae71cd28f0b7ce60c4e2f14802951bbed9b90bd93ff359bd41c240dc3dc4c834febafd32ebe81b4f735f05f9d01a2f7ea245ad9df4324938501
6
+ metadata.gz: 99432305cdb85e390e2435913840f7d2c6a7bf93e7f9b1bfe9eb2b7c87a99da18ecad696f8f73704fc3776f2799206161fc8b9174b5c2aedb0e74efae34fbe48
7
+ data.tar.gz: 8539feabd9684b8c3f8824da200ab28527072468914dd8cbfe25117807bd835250043f22348c0259ed3257781bf3ca9149512b963a78637b4f9e36b9b093485c
data/TODO.md ADDED
@@ -0,0 +1,28 @@
1
+ ```ruby
2
+ StructuredTextRenderer.new(
3
+ foo.content,
4
+ adapter: Adapter.new(
5
+ render_text: lambda do |text|
6
+ text.gsub(/this/, "that")
7
+ end,
8
+ render_fragment: lambda do |children|
9
+ children.join("")
10
+ end,
11
+ render_node: lambda do |tagname, attrs, children|
12
+ # we could ActionView::Helpers::TagHelper
13
+ content_tag(tagname, children, attrs)
14
+ end,
15
+ )
16
+ custom_rules: {
17
+ heading: lambda do |node, children, adapter|
18
+ adapter.render_node("h#{node[:level] + 1}", {}, children)
19
+ end
20
+ },
21
+ render_link_to_record: lambda do |record, children, adapter|
22
+ end,
23
+ render_inline_record: lambda do |record, adapter|
24
+ end,
25
+ render_block: lambda do |record, adapter|
26
+ end
27
+ )
28
+ ```
@@ -89,13 +89,15 @@ module Dato
89
89
 
90
90
  def attributes(resource)
91
91
  if type == 'item'
92
- return resource.keys.map(&:to_sym) - %i[
93
- item_type
94
- id
95
- created_at
96
- updated_at
97
- creator
98
- ]
92
+ return resource.keys.reject do |key|
93
+ %i[
94
+ item_type
95
+ id
96
+ created_at
97
+ updated_at
98
+ creator
99
+ ].include?(key.to_sym)
100
+ end
99
101
  end
100
102
 
101
103
  link_attributes['properties'].keys.map(&:to_sym)
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dato
4
+ module Local
5
+ module FieldType
6
+ class StructuredText
7
+ def self.parse(value, repo)
8
+ new(value, repo)
9
+ end
10
+
11
+ def initialize(value, repo)
12
+ @value = value
13
+ @repo = repo
14
+ end
15
+
16
+ def value
17
+ @value
18
+ end
19
+
20
+ def blocks
21
+ find_all_nodes("block").map do |node|
22
+ @repo.find(node["item"])
23
+ end.uniq
24
+ end
25
+
26
+ def links
27
+ find_all_nodes(["inlineItem", "itemLink"]).map do |node|
28
+ @repo.find(node["item"])
29
+ end.uniq
30
+ end
31
+
32
+ def find_all_nodes(types)
33
+ if value.nil?
34
+ return []
35
+ end
36
+
37
+ types = Array(types)
38
+ result = []
39
+
40
+ visit(value["document"]) do |node|
41
+ if node.is_a?(Hash) && types.include?(node["type"])
42
+ result << node
43
+ end
44
+ end
45
+
46
+ result
47
+ end
48
+
49
+ def visit(node, &block)
50
+ if node.is_a?(Hash) && node["children"].is_a?(Array)
51
+ node["children"].each do |child|
52
+ visit(child, &block)
53
+ end
54
+ end
55
+
56
+ block.call(node)
57
+ end
58
+
59
+ def to_hash(max_depth = 3, current_depth = 0)
60
+ {
61
+ value: value,
62
+ links: links.map { |item| item.to_hash(max_depth, current_depth) },
63
+ blocks: blocks.map { |item| item.to_hash(max_depth, current_depth) },
64
+ }
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
data/lib/dato/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dato
4
- VERSION = '0.7.18'
4
+ VERSION = '0.8.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.18
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Verna
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-26 00:00:00.000000000 Z
11
+ date: 2021-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -380,6 +380,7 @@ files:
380
380
  - LICENSE.txt
381
381
  - README.md
382
382
  - Rakefile
383
+ - TODO.md
383
384
  - bin/console
384
385
  - bin/rspec
385
386
  - bin/setup
@@ -427,6 +428,7 @@ files:
427
428
  - lib/dato/local/field_type/seo.rb
428
429
  - lib/dato/local/field_type/slug.rb
429
430
  - lib/dato/local/field_type/string.rb
431
+ - lib/dato/local/field_type/structured_text.rb
430
432
  - lib/dato/local/field_type/text.rb
431
433
  - lib/dato/local/field_type/theme.rb
432
434
  - lib/dato/local/field_type/upload_id.rb