dato-rails 0.11.0 → 0.12.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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/app/components/dato/block.md.erb +20 -0
  3. data/app/components/dato/block.rb +2 -2
  4. data/app/components/dato/blockquote.md.erb +4 -0
  5. data/app/components/dato/blockquote.rb +2 -2
  6. data/app/components/dato/code.md.erb +3 -0
  7. data/app/components/dato/code.rb +2 -2
  8. data/app/components/dato/dast_node.md.erb +1 -0
  9. data/app/components/dato/dast_node.rb +2 -2
  10. data/app/components/dato/heading.html.erb +6 -0
  11. data/app/components/dato/heading.md.erb +5 -0
  12. data/app/components/dato/heading.rb +7 -3
  13. data/app/components/dato/image_block_record.md.erb +2 -0
  14. data/app/components/dato/inline_block.md.erb +20 -0
  15. data/app/components/dato/link.md.erb +2 -0
  16. data/app/components/dato/link.rb +2 -2
  17. data/app/components/dato/list.html.erb +6 -0
  18. data/app/components/dato/list.md.erb +6 -0
  19. data/app/components/dato/list.rb +2 -2
  20. data/app/components/dato/list_item.html.erb +6 -0
  21. data/app/components/dato/list_item.md.erb +2 -0
  22. data/app/components/dato/list_item.rb +2 -2
  23. data/app/components/dato/node.rb +21 -3
  24. data/app/components/dato/paragraph.html.erb +6 -0
  25. data/app/components/dato/paragraph.md.erb +8 -0
  26. data/app/components/dato/paragraph.rb +2 -2
  27. data/app/components/dato/span.md.erb +1 -0
  28. data/app/components/dato/span.rb +11 -2
  29. data/app/components/dato/structured_text.md.erb +3 -0
  30. data/app/components/dato/thematic_break.html.erb +1 -0
  31. data/app/components/dato/thematic_break.md.erb +3 -0
  32. data/app/components/dato/thematic_break.rb +2 -2
  33. data/app/views/home/show.html.erb +1 -0
  34. data/app/views/home/show.md.erb +1 -0
  35. data/lib/dato/config.rb +17 -11
  36. data/lib/dato/version.rb +1 -1
  37. metadata +23 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99e4d154a2bfbaafddf661cf61fdb093eb93e2270809e5628b367500a5a6d382
4
- data.tar.gz: 9d7a872b53ce27aceb1b9865bff5124642711cf4a757a130b1d592eb1087cf48
3
+ metadata.gz: 5e19e4ce3d305f7b0231b2eb8f1a8b7d66656651d6d7686f242bd87863dea8a0
4
+ data.tar.gz: 5b6800b3523761a387c1fa22c552b66dcd0939fde9627797aa814f77211f353e
5
5
  SHA512:
6
- metadata.gz: ce096652ef057e9a4f24ef857034b07215be0a797376f2de03e6a66b1a5048d75521da6637c0ff4a0f3b62d33425780cea6c9052a6c6d9f95efa41a1688f93a2
7
- data.tar.gz: 8a8a0bab330cfe44805f57b51062c83adcff8fc919d3f278c081ad1731d7140fd554159111d229fa0ba4d1139b5ddf3a389ef5d4deff059a64a4524936839f9d
6
+ metadata.gz: '0846ce4508a65f97adc2e769f2162f26248db1fde01317706219c9c14824b3037419ce4e4c9804cacac35f05e00afa52c0b446f49edb043e29815883d52788d8'
7
+ data.tar.gz: a5cf7c55353ff9b02f446202c366216f59ffec50e4adda2718649574372f8cbe6db98ec63035d379812b773ade61a76c45636feea361e86c1dea45edf55890d9
@@ -0,0 +1,20 @@
1
+ <% block = blocks&.find { |b| b.id == @node.item } %>
2
+ <% if block.nil? %>
3
+
4
+ > ! There is a block with id <code><%= @node.item %></code> that has not been retrieved by the GraphQL Query.<br>
5
+ > ! It's possible that your query is returning a structured text without blocks.
6
+
7
+ <% elsif block.__typename.nil? %>
8
+
9
+ > ! In order to render a block, you need to return its <code>__typename</code>.<br>
10
+ > ! In your GraphQL query, add <code>__typename</code> to the list of fields returned for the blocks.<br>
11
+ > ! For example:
12
+ > ! ```
13
+ > ! blocks {
14
+ > ! __typename
15
+ > ! }
16
+ > ! ```
17
+
18
+ <% else %>
19
+ <%= render class_for_block(block).new(block, root) %>
20
+ <% end %>
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Dato::Block < Dato::DastNode
4
- def initialize(node, root)
5
- super(node, "block", root)
4
+ def initialize(node, root, parent = nil)
5
+ super(node, "block", root, parent)
6
6
  end
7
7
  end
@@ -0,0 +1,4 @@
1
+ <% @node.children&.each do |node| -%>
2
+ > <%= render_node(node) -%>
3
+ <% end -%>
4
+ > *<%= @node.attribution %>*
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Dato::Blockquote < Dato::DastNode
4
- def initialize(node, root)
5
- super(node, "blockquote", root)
4
+ def initialize(node, root, parent = nil)
5
+ super(node, "blockquote", root, parent)
6
6
  end
7
7
  end
@@ -0,0 +1,3 @@
1
+ ```
2
+ <%== @node.code %>
3
+ ```
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Dato::Code < Dato::DastNode
4
- def initialize(node, root)
5
- super(node, "code", root)
4
+ def initialize(node, root, parent = nil)
5
+ super(node, "code", root, parent)
6
6
  end
7
7
 
8
8
  def generated_tag
@@ -0,0 +1 @@
1
+ <%= @node.value -%><%= @node.children&.map { |node| render_node(node) }&.join(" ") -%>
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Dato
4
4
  class DastNode < Node
5
- def initialize(node, type, root = nil)
6
- super(node, root)
5
+ def initialize(node, type, root = nil, parent = nil)
6
+ super(node, root, parent)
7
7
  unless node.type == type
8
8
  raise ArgumentError.new("The node type is '#{node.type}' instead of '#{type}'")
9
9
  end
@@ -0,0 +1,6 @@
1
+ <%= content_tag generated_tag, class: "dato-cms-#{@node.type}" do -%>
2
+ <%= @node.value -%>
3
+ <% @node.children&.each do |node| -%>
4
+ <%= render_node(node) -%>
5
+ <% end -%>
6
+ <% end -%>
@@ -0,0 +1,5 @@
1
+ <%= "#{("#" * level)} #{@node.value}" -%>
2
+ <% @node.children&.each do |node| -%>
3
+ <%= render_node(node) %>
4
+ <% end %>
5
+
@@ -1,11 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Dato::Heading < Dato::DastNode
4
- def initialize(node, root)
5
- super(node, "heading", root)
4
+ def initialize(node, root, parent = nil)
5
+ super(node, "heading", root, parent)
6
+ end
7
+
8
+ def level
9
+ @node.level
6
10
  end
7
11
 
8
12
  def generated_tag
9
- "h#{@node.level}"
13
+ "h#{level}"
10
14
  end
11
15
  end
@@ -0,0 +1,2 @@
1
+ ![](<%= @node.image.responsiveImage.src %>)
2
+ <%= @node %>
@@ -0,0 +1,20 @@
1
+ <% block = blocks&.find { |b| b.id == @node.item } %>
2
+ <% if block.nil? %>
3
+
4
+ > ! There is an inline block with id <code><%= @node.item %></code> that has not been retrieved by the GraphQL Query.<br>
5
+ > ! It's possible that your query is returning a structured text without blocks.
6
+
7
+ <% elsif block.__typename.nil? %>
8
+
9
+ > ! In order to render an inline block, you need to return its <code>__typename</code>.<br>
10
+ > ! In your GraphQL query, add <code>__typename</code> to the list of fields returned for the blocks.<br>
11
+ > ! For example:<br><br>
12
+ > ! <code>
13
+ > ! blocks {
14
+ > ! __typename
15
+ > ! }
16
+ > ! </code>
17
+
18
+ <% else %>
19
+ <%= render class_for_block(block).new(block, root) %>
20
+ <% end %>
@@ -0,0 +1,2 @@
1
+ [<% @node.children&.each do |node| -%><%= render_node(node) -%>
2
+ <% end -%>](<%= link_attributes["href"] %>)
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Dato::Link < Dato::DastNode
4
- def initialize(node, root)
5
- super(node, "link", root)
4
+ def initialize(node, root, parent = nil)
5
+ super(node, "link", root, parent)
6
6
  end
7
7
 
8
8
  def generated_tag
@@ -0,0 +1,6 @@
1
+ <%= content_tag generated_tag, class: "dato-cms-#{@node.type}" do -%>
2
+ <%= @node.value -%>
3
+ <% @node.children&.each do |node| -%>
4
+ <%= render_node(node) -%>
5
+ <% end -%>
6
+ <% end -%>
@@ -0,0 +1,6 @@
1
+ <%= @node.value -%>
2
+ <% @node.children&.each do |node| -%>
3
+ <% node["style"] ||= @node.style %>
4
+ <%= render_node(node) -%>
5
+ <% end -%>
6
+
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Dato::List < Dato::DastNode
4
- def initialize(node, root)
5
- super(node, "list", root)
4
+ def initialize(node, root, parent = nil)
5
+ super(node, "list", root, parent)
6
6
  end
7
7
 
8
8
  def generated_tag
@@ -0,0 +1,6 @@
1
+ <%= content_tag generated_tag, class: "dato-cms-#{@node.type}" do -%>
2
+ <%= @node.value -%>
3
+ <% @node.children&.each do |node| -%>
4
+ <%= render_node(node) -%>
5
+ <% end -%>
6
+ <% end -%>
@@ -0,0 +1,2 @@
1
+ <%= (find_ancestor("list")&.node&.style == "bulleted") ? "*" : "1." -%> <%= @node.value -%>
2
+ <% @node.children&.each do |node| -%><%= render_node(node) -%><% end -%>
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Dato::ListItem < Dato::DastNode
4
- def initialize(node, root)
5
- super(node, "listItem", root)
4
+ def initialize(node, root, parent = nil)
5
+ super(node, "listItem", root, parent)
6
6
  end
7
7
 
8
8
  def generated_tag
@@ -2,17 +2,35 @@
2
2
 
3
3
  module Dato
4
4
  class Node < ViewComponent::Base
5
- attr_reader :root
5
+ attr_reader :root, :node, :parent
6
6
 
7
- def initialize(node, root = nil)
7
+ def initialize(node, root = nil, parent = nil)
8
8
  @node = node
9
9
  @root = root
10
+ @parent = parent
10
11
  end
11
12
 
12
13
  def render_node(node)
13
- render class_for_node(node).new(node, root)
14
+ render class_for_node(node).new(node, root, self)
14
15
  end
15
16
 
17
+ # Find the first ancestor of a specific type
18
+ # @param type [String] the type to search for (e.g., "list", "structuredText")
19
+ # @return [Node, nil] the first ancestor matching the type or nil
20
+ def find_ancestor(type)
21
+ current = parent
22
+ while current
23
+ return current if current.node_type == type
24
+ current = current.parent
25
+ end
26
+ nil
27
+ end
28
+
29
+ # Get the type of the immediate parent node
30
+ # @return [String, nil] the parent's type or nil if no parent
31
+ def node_type = node&.type
32
+ def parent_type = parent&.node_type
33
+
16
34
  def blocks
17
35
  root.blocks
18
36
  end
@@ -0,0 +1,6 @@
1
+ <%= content_tag generated_tag, class: "dato-cms-#{@node.type}" do -%>
2
+ <%= @node.value -%>
3
+ <% @node.children&.each do |node| -%>
4
+ <%= render_node(node) -%>
5
+ <% end -%>
6
+ <% end -%>
@@ -0,0 +1,8 @@
1
+ <%= @node.value -%><%== @node.children&.map { |node| render_node(node) }&.join -%>
2
+ <% if parent_type.nil? %>
3
+
4
+
5
+ <% elsif "listItem" == parent_type %>
6
+ <% else %>
7
+
8
+ <% end %>
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Dato::Paragraph < Dato::DastNode
4
- def initialize(node, root)
5
- super(node, "paragraph", root)
4
+ def initialize(node, root, parent = nil)
5
+ super(node, "paragraph", root, parent)
6
6
  end
7
7
 
8
8
  def generated_tag
@@ -0,0 +1 @@
1
+ <% unless @node.value.nil? %><%== wrap_styles do -%><%== @node.value -%><% end -%><% end -%>
@@ -1,8 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Dato::Span < Dato::DastNode
4
- def initialize(node, root = nil)
5
- super(node, "span", root)
4
+ def initialize(node, root = nil, parent = nil)
5
+ super(node, "span", root, parent)
6
+ end
7
+
8
+
9
+ def wrap_styles(&block)
10
+ wrapping_symbols = ""
11
+ wrapping_symbols += "**" if @node.marks&.include?("strong")
12
+ wrapping_symbols += "`" if @node.marks&.include?("code")
13
+ wrapping_symbols += "_" if @node.marks&.include?("emphasis")
14
+ "#{wrapping_symbols}#{capture(&block)}#{wrapping_symbols.reverse}"
6
15
  end
7
16
 
8
17
  def styles
@@ -0,0 +1,3 @@
1
+ <% @structured_text_node.value.document.children.each do |node| -%>
2
+ <%= render_node(node) -%>
3
+ <% end -%>
@@ -0,0 +1 @@
1
+ <hr>
@@ -0,0 +1,3 @@
1
+
2
+ ---
3
+
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Dato::ThematicBreak < Dato::DastNode
4
- def initialize(node, root)
5
- super(node, "thematicBreak", root)
4
+ def initialize(node, root, parent = nil)
5
+ super(node, "thematicBreak", root, parent)
6
6
  end
7
7
 
8
8
  def generated_tag
@@ -0,0 +1 @@
1
+ <%= render Dato::StructuredText.new(@content) %>
@@ -0,0 +1 @@
1
+ <%= render Dato::StructuredText.new(@content) %>
data/lib/dato/config.rb CHANGED
@@ -1,16 +1,22 @@
1
1
  module Dato
2
2
  class Config
3
- include ActiveSupport::Configurable
3
+ class_attribute :overrides, default: {}
4
+ class_attribute :links_mapping, default: {}
5
+ class_attribute :blocks, default: {}
6
+ class_attribute :cache, default: false
7
+ class_attribute :cache_namespace, default: "dato-rails"
8
+ class_attribute :api_token, default: ENV.fetch("DATO_API_TOKEN", Rails.application.credentials.dig(:dato, :api_token))
9
+ class_attribute :publish_key, default: ENV.fetch("DATO_PUBLISH_KEY", Rails.application.credentials.dig(:dato, :publish_key))
10
+ class_attribute :build_trigger_id, default: ENV.fetch("DATO_BUILD_TRIGGER_ID", Rails.application.credentials.dig(:dato, :build_trigger_id))
11
+ class_attribute :base_editing_url, default: ENV.fetch("DATO_BASE_EDITING_URL", Rails.application.credentials.dig(:dato, :base_editing_url))
12
+ class_attribute :mount_path, default: "/dato"
4
13
 
5
- config_accessor(:overrides) { {} }
6
- config_accessor(:links_mapping) { {} }
7
- config_accessor(:blocks) { {} }
8
- config_accessor(:cache) { false }
9
- config_accessor(:cache_namespace) { "dato-rails" }
10
- config_accessor(:api_token) { ENV.fetch("DATO_API_TOKEN", Rails.application.credentials.dig(:dato, :api_token)) }
11
- config_accessor(:publish_key) { ENV.fetch("DATO_PUBLISH_KEY", Rails.application.credentials.dig(:dato, :publish_key)) }
12
- config_accessor(:build_trigger_id) { ENV.fetch("DATO_BUILD_TRIGGER_ID", Rails.application.credentials.dig(:dato, :build_trigger_id)) }
13
- config_accessor(:base_editing_url) { ENV.fetch("DATO_BASE_EDITING_URL", Rails.application.credentials.dig(:dato, :base_editing_url)) }
14
- config_accessor(:mount_path) { "/dato" }
14
+ def self.configuration
15
+ @configuration ||= Config.new
16
+ end
17
+
18
+ def self.configure
19
+ yield configuration
20
+ end
15
21
  end
16
22
  end
data/lib/dato/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dato
2
- VERSION = "0.11.0"
2
+ VERSION = "0.12.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dato-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Rodi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-08-28 00:00:00.000000000 Z
10
+ date: 2026-01-15 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rspec-rails
@@ -176,37 +176,56 @@ files:
176
176
  - app/assets/config/dato_rails_manifest.js
177
177
  - app/components/dato/base_component.rb
178
178
  - app/components/dato/block.html.erb
179
+ - app/components/dato/block.md.erb
179
180
  - app/components/dato/block.rb
180
181
  - app/components/dato/blockquote.html.erb
182
+ - app/components/dato/blockquote.md.erb
181
183
  - app/components/dato/blockquote.rb
182
184
  - app/components/dato/code.html.erb
185
+ - app/components/dato/code.md.erb
183
186
  - app/components/dato/code.rb
184
187
  - app/components/dato/dast_node.html.erb
188
+ - app/components/dato/dast_node.md.erb
185
189
  - app/components/dato/dast_node.rb
190
+ - app/components/dato/heading.html.erb
191
+ - app/components/dato/heading.md.erb
186
192
  - app/components/dato/heading.rb
187
193
  - app/components/dato/image_block_record.html.erb
194
+ - app/components/dato/image_block_record.md.erb
188
195
  - app/components/dato/image_block_record.rb
189
196
  - app/components/dato/inline_block.html.erb
197
+ - app/components/dato/inline_block.md.erb
190
198
  - app/components/dato/inline_block.rb
191
199
  - app/components/dato/inline_item.html.erb
192
200
  - app/components/dato/inline_item.rb
193
201
  - app/components/dato/item_link.html.erb
194
202
  - app/components/dato/item_link.rb
195
203
  - app/components/dato/link.html.erb
204
+ - app/components/dato/link.md.erb
196
205
  - app/components/dato/link.rb
206
+ - app/components/dato/list.html.erb
207
+ - app/components/dato/list.md.erb
197
208
  - app/components/dato/list.rb
209
+ - app/components/dato/list_item.html.erb
210
+ - app/components/dato/list_item.md.erb
198
211
  - app/components/dato/list_item.rb
199
212
  - app/components/dato/live_stream.html.erb
200
213
  - app/components/dato/live_stream.rb
201
214
  - app/components/dato/node.rb
202
215
  - app/components/dato/not_rendered.rb
216
+ - app/components/dato/paragraph.html.erb
217
+ - app/components/dato/paragraph.md.erb
203
218
  - app/components/dato/paragraph.rb
204
219
  - app/components/dato/responsive_image.html.erb
205
220
  - app/components/dato/responsive_image.rb
206
221
  - app/components/dato/span.html.erb
222
+ - app/components/dato/span.md.erb
207
223
  - app/components/dato/span.rb
208
224
  - app/components/dato/structured_text.html.erb
225
+ - app/components/dato/structured_text.md.erb
209
226
  - app/components/dato/structured_text.rb
227
+ - app/components/dato/thematic_break.html.erb
228
+ - app/components/dato/thematic_break.md.erb
210
229
  - app/components/dato/thematic_break.rb
211
230
  - app/components/dato/unknown_block.html.erb
212
231
  - app/components/dato/unknown_block.rb
@@ -217,6 +236,8 @@ files:
217
236
  - app/controllers/dato/live_controller.rb
218
237
  - app/controllers/dato/publish_controller.rb
219
238
  - app/views/dato/live/create.turbo_stream.erb
239
+ - app/views/home/show.html.erb
240
+ - app/views/home/show.md.erb
220
241
  - config/routes.rb
221
242
  - lib/dato.rb
222
243
  - lib/dato/cache.rb