dato-rails 0.11.0 → 0.12.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/app/components/dato/block.md.erb +20 -0
- data/app/components/dato/block.rb +2 -2
- data/app/components/dato/blockquote.md.erb +4 -0
- data/app/components/dato/blockquote.rb +2 -2
- data/app/components/dato/code.md.erb +3 -0
- data/app/components/dato/code.rb +2 -2
- data/app/components/dato/dast_node.md.erb +1 -0
- data/app/components/dato/dast_node.rb +2 -2
- data/app/components/dato/heading.html.erb +6 -0
- data/app/components/dato/heading.md.erb +5 -0
- data/app/components/dato/heading.rb +7 -3
- data/app/components/dato/image_block_record.md.erb +2 -0
- data/app/components/dato/inline_block.md.erb +20 -0
- data/app/components/dato/link.md.erb +2 -0
- data/app/components/dato/link.rb +2 -2
- data/app/components/dato/list.html.erb +6 -0
- data/app/components/dato/list.md.erb +6 -0
- data/app/components/dato/list.rb +2 -2
- data/app/components/dato/list_item.html.erb +6 -0
- data/app/components/dato/list_item.md.erb +2 -0
- data/app/components/dato/list_item.rb +2 -2
- data/app/components/dato/node.rb +22 -3
- data/app/components/dato/paragraph.html.erb +6 -0
- data/app/components/dato/paragraph.md.erb +8 -0
- data/app/components/dato/paragraph.rb +2 -2
- data/app/components/dato/span.md.erb +1 -0
- data/app/components/dato/span.rb +11 -3
- data/app/components/dato/structured_text.md.erb +3 -0
- data/app/components/dato/thematic_break.html.erb +1 -0
- data/app/components/dato/thematic_break.md.erb +3 -0
- data/app/components/dato/thematic_break.rb +2 -2
- data/app/controllers/dato/live_controller.rb +3 -0
- data/app/views/home/show.html.erb +1 -0
- data/app/views/home/show.md.erb +1 -0
- data/lib/dato/config.rb +13 -11
- data/lib/dato/engine.rb +4 -0
- data/lib/dato/version.rb +1 -1
- metadata +30 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8deafc18f10be673f5349ce8eee374fd4d2cffda9935d9ba1d5809b464e7daec
|
|
4
|
+
data.tar.gz: 6ff76199a809434bf91d4f9db8db9766bdb21a8d1385123cb4a2a985b345a20a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1c3a256fc03848d9366dd73b447cc6f7e34bfb72e88a8ac406c19aad8625606cb9eb72ca173e3ccc80556c6efc0387de152b33eccb4a87740f50f631c8e1e6ac
|
|
7
|
+
data.tar.gz: d806381a4158cdcba8d3655c2cf606a95d315c318009f6cdbc21b009a320d8db206a5f60a15b8fd025e7072394fb184c2a5b9b0c74c727a10ed643bc751ee888
|
|
@@ -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 %>
|
data/app/components/dato/code.rb
CHANGED
|
@@ -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
|
|
@@ -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#{
|
|
13
|
+
"h#{level}"
|
|
10
14
|
end
|
|
11
15
|
end
|
|
@@ -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 %>
|
data/app/components/dato/link.rb
CHANGED
data/app/components/dato/list.rb
CHANGED
data/app/components/dato/node.rb
CHANGED
|
@@ -2,17 +2,36 @@
|
|
|
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
|
+
|
|
33
|
+
def parent_type = parent&.node_type
|
|
34
|
+
|
|
16
35
|
def blocks
|
|
17
36
|
root.blocks
|
|
18
37
|
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<% unless @node.value.nil? %><%== wrap_styles do -%><%== @node.value -%><% end -%><% end -%>
|
data/app/components/dato/span.rb
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
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
|
+
def wrap_styles(&block)
|
|
9
|
+
wrapping_symbols = ""
|
|
10
|
+
wrapping_symbols += "**" if @node.marks&.include?("strong")
|
|
11
|
+
wrapping_symbols += "`" if @node.marks&.include?("code")
|
|
12
|
+
wrapping_symbols += "_" if @node.marks&.include?("emphasis")
|
|
13
|
+
"#{wrapping_symbols}#{capture(&block)}#{wrapping_symbols.reverse}"
|
|
6
14
|
end
|
|
7
15
|
|
|
8
16
|
def styles
|
|
@@ -11,7 +19,7 @@ class Dato::Span < Dato::DastNode
|
|
|
11
19
|
mapping = {
|
|
12
20
|
emphasis: "font-style: italic",
|
|
13
21
|
strong: "font-weight: bold",
|
|
14
|
-
highlight: "background-color: var(--dato-highlight-color, yellow)"
|
|
22
|
+
highlight: "background-color: var(--dato-highlight-color, yellow)"
|
|
15
23
|
}.with_indifferent_access
|
|
16
24
|
|
|
17
25
|
text_decoration_mappings = {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<hr>
|
|
@@ -2,6 +2,9 @@ module Dato
|
|
|
2
2
|
class LiveController < ActionController::Base
|
|
3
3
|
def create
|
|
4
4
|
@data = Hashie::Mash.new(JSON.parse(params[:data], symbolize_names: true).dig(:response, :data))
|
|
5
|
+
# Ensure HTML format is available for ViewComponent template resolution
|
|
6
|
+
# ViewComponent 4 requires explicit format matching
|
|
7
|
+
lookup_context.formats |= [:html]
|
|
5
8
|
end
|
|
6
9
|
end
|
|
7
10
|
end
|
|
@@ -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,18 @@
|
|
|
1
1
|
module Dato
|
|
2
2
|
class Config
|
|
3
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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.configure
|
|
15
|
+
yield self
|
|
16
|
+
end
|
|
15
17
|
end
|
|
16
18
|
end
|
data/lib/dato/engine.rb
CHANGED
|
@@ -4,6 +4,10 @@ module Dato
|
|
|
4
4
|
class Engine < ::Rails::Engine
|
|
5
5
|
isolate_namespace Dato
|
|
6
6
|
|
|
7
|
+
initializer "dato_rails.mime_types", before: :load_config_initializers do
|
|
8
|
+
Mime::Type.register "text/markdown", :md unless Mime::Type.lookup_by_extension(:md)
|
|
9
|
+
end
|
|
10
|
+
|
|
7
11
|
initializer "dato_rails.action_controller" do
|
|
8
12
|
ActiveSupport.on_load(:action_controller) do
|
|
9
13
|
include Dato::Railties::ControllerRuntime
|
data/lib/dato/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.12.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alessandro Rodi
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: rspec-rails
|
|
@@ -99,42 +99,42 @@ dependencies:
|
|
|
99
99
|
requirements:
|
|
100
100
|
- - ">="
|
|
101
101
|
- !ruby/object:Gem::Version
|
|
102
|
-
version: '
|
|
102
|
+
version: '4.0'
|
|
103
103
|
type: :runtime
|
|
104
104
|
prerelease: false
|
|
105
105
|
version_requirements: !ruby/object:Gem::Requirement
|
|
106
106
|
requirements:
|
|
107
107
|
- - ">="
|
|
108
108
|
- !ruby/object:Gem::Version
|
|
109
|
-
version: '
|
|
109
|
+
version: '4.0'
|
|
110
110
|
- !ruby/object:Gem::Dependency
|
|
111
111
|
name: rails
|
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
|
113
113
|
requirements:
|
|
114
114
|
- - ">="
|
|
115
115
|
- !ruby/object:Gem::Version
|
|
116
|
-
version: '
|
|
116
|
+
version: '8'
|
|
117
117
|
type: :runtime
|
|
118
118
|
prerelease: false
|
|
119
119
|
version_requirements: !ruby/object:Gem::Requirement
|
|
120
120
|
requirements:
|
|
121
121
|
- - ">="
|
|
122
122
|
- !ruby/object:Gem::Version
|
|
123
|
-
version: '
|
|
123
|
+
version: '8'
|
|
124
124
|
- !ruby/object:Gem::Dependency
|
|
125
125
|
name: turbo-rails
|
|
126
126
|
requirement: !ruby/object:Gem::Requirement
|
|
127
127
|
requirements:
|
|
128
128
|
- - ">="
|
|
129
129
|
- !ruby/object:Gem::Version
|
|
130
|
-
version: '
|
|
130
|
+
version: '2'
|
|
131
131
|
type: :runtime
|
|
132
132
|
prerelease: false
|
|
133
133
|
version_requirements: !ruby/object:Gem::Requirement
|
|
134
134
|
requirements:
|
|
135
135
|
- - ">="
|
|
136
136
|
- !ruby/object:Gem::Version
|
|
137
|
-
version: '
|
|
137
|
+
version: '2'
|
|
138
138
|
- !ruby/object:Gem::Dependency
|
|
139
139
|
name: gqli
|
|
140
140
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -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
|
|
@@ -252,7 +273,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
252
273
|
- !ruby/object:Gem::Version
|
|
253
274
|
version: '0'
|
|
254
275
|
requirements: []
|
|
255
|
-
rubygems_version:
|
|
276
|
+
rubygems_version: 4.0.2
|
|
256
277
|
specification_version: 4
|
|
257
278
|
summary: Use Dato CMS in your Rails application.
|
|
258
279
|
test_files: []
|